NetBSD Problem Report #45131

From www@NetBSD.org  Sun Jul 10 09:27:42 2011
Return-Path: <www@NetBSD.org>
Received: from mail.netbsd.org (mail.netbsd.org [204.152.190.11])
	by www.NetBSD.org (Postfix) with ESMTP id 3ECD963C12E
	for <gnats-bugs@gnats.NetBSD.org>; Sun, 10 Jul 2011 09:27:42 +0000 (UTC)
Message-Id: <20110710092741.8B74D63B8E2@www.NetBSD.org>
Date: Sun, 10 Jul 2011 09:27:41 +0000 (UTC)
From: o.vd.linden@quicknet.nl
Reply-To: o.vd.linden@quicknet.nl
To: gnats-bugs@NetBSD.org
Subject: csup hangs while trying to exit
X-Send-Pr-Version: www-1.0

>Number:         45131
>Category:       pkg
>Synopsis:       csup hangs while trying to exit
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    pkg-manager
>State:          closed
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sun Jul 10 09:30:00 +0000 2011
>Closed-Date:    Sat May 13 00:51:12 +0000 2023
>Last-Modified:  Sat May 13 00:51:12 +0000 2023
>Originator:     Onno van der Linden
>Release:        5.99.53 i386
>Organization:
>Environment:
NetBSD sheep 5.99.53 NetBSD 5.99.53 (SHEEP) #0: Thu Jun 16 21:15:01 MEST 2011  onno@sheep:/usr/src/sys/arch/i386/compile/SHEEP i386
>Description:
csup hangs after calling pthread_join() in killer_stop() when it is trying to cancel the killer thread  before exiting.

>How-To-Repeat:
csup to an available cvsup server 
>Fix:
Adding a pthread_testcancel() call works for me. Additional check
for error == ECANCELED and calling pthread_testcancel() if true
is another way of fixing it

*** proto.c.orig        Sun Jul 10 11:13:59 2011
--- proto.c     Sun Jul 10 11:15:01 2011
***************
*** 968,973 ****
--- 968,974 ----
        k = arg;
  again:
        error = sigwait(&k->sigset, &sig);
+       pthread_testcancel();
        assert(!error);
        if (sig == SIGINT || sig == SIGHUP || sig == SIGTERM) {
                if (k->killedby == -1) {


>Release-Note:

>Audit-Trail:

Responsible-Changed-From-To: pkg-manager->imil
Responsible-Changed-By: wiz@NetBSD.org
Responsible-Changed-When: Sun, 10 Jul 2011 17:00:36 +0000
Responsible-Changed-Why:
Over to maintainer.


From: Onno van der Linden <o.vd.linden@quicknet.nl>
To: gnats-bugs@netbsd.org
Cc: 
Subject: Re: pkg/45131
Date: Wed, 13 Jul 2011 22:28:56 +0200

 I don't think the csup code needs pthread_testcancel()
 in killer_stop(). It looks like libpthread/pthread_cancelstub.c
 needs an additional entry for sigwait().

 Onno


==

I made the following diff after Onno's recommendation. 

Hisashi T Fujinaka kindly tested it, and reports that it fixes csup.

It'd be great to get some more eyes on this one.

Thanks,
Alistair

Index: pthread_cancelstub.c
===================================================================
RCS file: /cvsroot/src/lib/libpthread/pthread_cancelstub.c,v
retrieving revision 1.35
diff -u -r1.35 pthread_cancelstub.c
--- pthread_cancelstub.c	22 Apr 2011 14:18:34 -0000	1.35
+++ pthread_cancelstub.c	2 Apr 2012 22:45:57 -0000
@@ -58,6 +58,7 @@
 #include <sys/uio.h>
 #include <sys/wait.h>
 #include <aio.h>
+#include <errno.h>
 #include <fcntl.h>
 #include <mqueue.h>
 #include <poll.h>
@@ -577,6 +578,7 @@
 	pthread_t self;
 	int retval;
 	struct timespec tout, *tp;
+
 	if (timeout) {
 		tout = *timeout;
 		tp = &tout;
@@ -591,6 +593,28 @@
 	return retval;
 }

+int                                                                                                                  
+sigwait(const sigset_t * __restrict set, int * __restrict sig)
+{
+	pthread_t	self;
+	int		saved_errno;
+	int		new_errno;
+	int		retval;
+
+	self = pthread__self();
+	saved_errno = errno;
+	TESTCANCEL(self);
+	retval = ____sigtimedwait50(set, NULL, NULL);
+	TESTCANCEL(self);
+	new_errno = errno;
+	errno = saved_errno;
+	if (retval < 0) {
+		return new_errno;
+	}
+	*sig = retval;
+	return 0;
+}
+
 __strong_alias(_close, close)
 __strong_alias(_fcntl, fcntl)
 __strong_alias(_fdatasync, fdatasync)
@@ -608,6 +632,7 @@
 __strong_alias(_pwrite, pwrite)
 __strong_alias(_read, read)
 __strong_alias(_readv, readv)
+__strong_alias(_sigwait, sigwait)
 __strong_alias(_write, write)
 __strong_alias(_writev, writev)

State-Changed-From-To: open->analyzed
State-Changed-By: agc@NetBSD.org
State-Changed-When: Tue, 03 Apr 2012 04:19:43 +0000
State-Changed-Why:
Onno v d Linden analyzed it, and a diff has been included which implements
sigwait() in libpthreads' cancelstubs


From: "Alistair G. Crooks" <agc@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/45131 CVS commit: src/lib/libpthread
Date: Wed, 4 Apr 2012 06:29:17 +0000

 Module Name:	src
 Committed By:	agc
 Date:		Wed Apr  4 06:29:17 UTC 2012

 Modified Files:
 	src/lib/libpthread: pthread_cancelstub.c

 Log Message:
 Add a pthread cancel stub for sigwait, following Onno van der Linden's
 analysis in PR 45131.  Kindly tested by Hisashi T Fujinaka (using csup
 as the test case) with a successful outcome.

 OK martin@


 To generate a diff of this commit:
 cvs rdiff -u -r1.35 -r1.36 src/lib/libpthread/pthread_cancelstub.c

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

State-Changed-From-To: analyzed->feedback
State-Changed-By: agc@NetBSD.org
State-Changed-When: Wed, 04 Apr 2012 16:22:10 +0000
State-Changed-Why:
It's already been reported to work, but let's have some more feedback...


From: Onno van der Linden <o.vd.linden@quicknet.nl>
To: gnats-bugs@NetBSD.org
Cc: 
Subject: Re: pkg/45131 (csup hangs while trying to exit)
Date: Thu, 5 Apr 2012 17:12:03 +0200

 On Wed, Apr 04, 2012 at 04:22:11PM +0000, agc@NetBSD.org wrote:
 > Synopsis: csup hangs while trying to exit
 > 
 > State-Changed-From-To: analyzed->feedback
 > State-Changed-By: agc@NetBSD.org
 > State-Changed-When: Wed, 04 Apr 2012 16:22:10 +0000
 > State-Changed-Why:
 > It's already been reported to work, but let's have some more feedback...

 And here's my confirmation that it works.

 Thanks,

 Onno

From: Robert Elz <kre@munnari.OZ.AU>
To: gnats-bugs@NetBSD.org
Cc: 
Subject: Re: pkg/45131 (csup hangs while trying to exit)
Date: Sat, 07 Apr 2012 08:21:39 +0700

     Date:        Thu,  5 Apr 2012 15:15:04 +0000 (UTC)
     From:        Onno van der Linden <o.vd.linden@quicknet.nl>
     Message-ID:  <20120405151504.35A8263B946@www.NetBSD.org>

   |  On Wed, Apr 04, 2012 at 04:22:11PM +0000, agc@NetBSD.org wrote:
   |  > Synopsis: csup hangs while trying to exit
   |  > 
   |  > It's already been reported to work, but let's have some more feedback...
   |  
   |  And here's my confirmation that it works.

 I believe it is only fixed in NetBSD current, right?   The package still
 either needs a patch, or to be marked NOT_FOR_PLATFORM for NetBSD
 up to (and including) NetBSD 6, right?   I expect that a pullup of the
 fix for NetBSD 6 before it is released might be likely, but there's
 nothing that you can do for NetBSD 5 (the bug can be fixed in some later
 NetBSD 5 release, but nothing is going to change the existing ones).

 I don't even want to think about NetBSD 4 and its somewhat different threading.

 kre

State-Changed-From-To: feedback->open
State-Changed-By: dholland@NetBSD.org
State-Changed-When: Mon, 09 Apr 2012 08:10:24 +0000
State-Changed-Why:
the fix in base works, but we also need a patch in the package like the
original suggestion.


From: "Jeff Rizzo" <riz@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/45131 CVS commit: [netbsd-6] src/lib/libpthread
Date: Mon, 9 Apr 2012 18:15:28 +0000

 Module Name:	src
 Committed By:	riz
 Date:		Mon Apr  9 18:15:28 UTC 2012

 Modified Files:
 	src/lib/libpthread [netbsd-6]: pthread_cancelstub.c

 Log Message:
 Pull up following revision(s) (requested by agc in ticket #174):
 	lib/libpthread/pthread_cancelstub.c: revision 1.36
 Add a pthread cancel stub for sigwait, following Onno van der Linden's
 analysis in PR 45131.  Kindly tested by Hisashi T Fujinaka (using csup
 as the test case) with a successful outcome.
 OK martin@


 To generate a diff of this commit:
 cvs rdiff -u -r1.35 -r1.35.6.1 src/lib/libpthread/pthread_cancelstub.c

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

Responsible-Changed-From-To: imil->pkg-manager
Responsible-Changed-By: wiz@NetBSD.org
Responsible-Changed-When: Mon, 02 Apr 2018 09:32:07 +0000
Responsible-Changed-Why:
imil observes


State-Changed-From-To: open->closed
State-Changed-By: dholland@NetBSD.org
State-Changed-When: Sat, 13 May 2023 00:51:12 +0000
State-Changed-Why:
PRs open only in the hopes of adding workarounds for no-longer-supported
releases don't need to stay open.

(in this case -5)


>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.47 2022/09/11 19:34:41 kim Exp $
$NetBSD: gnats_config.sh,v 1.9 2014/08/02 14:16:04 spz Exp $
Copyright © 1994-2023 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.