From nobody@FreeBSD.org  Sun Sep  3 20:58:15 2006
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id E271716A4E8
	for <freebsd-gnats-submit@FreeBSD.org>; Sun,  3 Sep 2006 20:58:15 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (www.freebsd.org [216.136.204.117])
	by mx1.FreeBSD.org (Postfix) with ESMTP id B33EA43D49
	for <freebsd-gnats-submit@FreeBSD.org>; Sun,  3 Sep 2006 20:58:15 +0000 (GMT)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (localhost [127.0.0.1])
	by www.freebsd.org (8.13.1/8.13.1) with ESMTP id k83KwFhQ015303
	for <freebsd-gnats-submit@FreeBSD.org>; Sun, 3 Sep 2006 20:58:15 GMT
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.13.1/8.13.1/Submit) id k83KwFH8015301;
	Sun, 3 Sep 2006 20:58:15 GMT
	(envelope-from nobody)
Message-Id: <200609032058.k83KwFH8015301@www.freebsd.org>
Date: Sun, 3 Sep 2006 20:58:15 GMT
From: Andreas Longwitz <longwitz@incore.de>
To: freebsd-gnats-submit@FreeBSD.org
Subject: /usr/bin/mail hangs on the sigsuspend system call in popen.c
X-Send-Pr-Version: www-2.3

>Number:         102834
>Category:       bin
>Synopsis:       [patch] mail(1) hangs on the sigsuspend system call in popen.c
>Confidential:   no
>Severity:       serious
>Priority:       low
>Responsible:    eadler
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Sun Sep 03 21:00:39 GMT 2006
>Closed-Date:    Wed Jun 13 03:41:18 UTC 2012
>Last-Modified:  Wed Jun 13 03:50:14 UTC 2012
>Originator:     Andreas Longwitz
>Release:        FreeBSD 6.1
>Organization:
Data Service Stockelsdorf, Germany
>Environment:
FreeBSD loserver.longwitz 6.1-RELEASE FreeBSD 6.1-RELEASE #0: Tue May 23 22:16:05 CEST 2006 root@loserver.longwitz:/usr/src/sys/i386/compile/LOSERVER  i386

>Description:
Sometimes the command /usr/bin/mail -s subject mailadr hangs on the
sigsuspend system call in popen.c. This happens when the function
findchild() running from wait_child() is interrupted by sigchild()
running findchild() again. This happens when the child started just
before exits too quickly.
>How-To-Repeat:

>Fix:
In popen.c (functions free_child() and wait_child()) the line
    struct child *cp = findchild(pid);
must be moved after the 3 sigfunction-calls.

>Release-Note:
>Audit-Trail:

From: Andreas Longwitz <longwitz@incore.de>
To: bug-followup@freebsd.org,
 longwitz@incore.de
Cc:  
Subject: Re: bin/102834: [patch] mail(1) hangs on the sigsuspend system call in popen.c
Date: Wed, 10 Jun 2009 18:36:43 +0200

 --Boundary-00=_bE+LKNs2EjMVV2P
 Content-Type: text/plain;
   charset="iso-8859-1"
 Content-Transfer-Encoding: 7bit
 Content-Disposition: inline
 
 The described problem still occurs in all FreeBSD versions especially on SMP 
 machines. The appended patch for 6.4 Stable works without problems for more 
 than 3 years.
 
 Dr. Andreas Longwitz  Data Service GmbH, Beethovenstr. 2A, 23617 Stockelsdorf
 
 --Boundary-00=_bE+LKNs2EjMVV2P
 Content-Type: text/x-diff;
   charset="iso 8859-15";
   name="patch.popen.c.diff"
 Content-Transfer-Encoding: 7bit
 Content-Disposition: attachment;
 	filename="patch.popen.c.diff"
 
 --- popen.c.orig	2002-06-30 07:25:06.000000000 +0200
 +++ popen.c	2009-05-07 15:58:19.000000000 +0200
 @@ -364,11 +364,11 @@
  	int pid;
  {
  	sigset_t nset, oset;
 -	struct child *cp = findchild(pid);
  
  	(void)sigemptyset(&nset);
  	(void)sigaddset(&nset, SIGCHLD);
  	(void)sigprocmask(SIG_BLOCK, &nset, &oset);	
 +	struct child *cp = findchild(pid);
  
  	while (!cp->done)
  		(void)sigsuspend(&oset);
 @@ -386,11 +386,11 @@
  	int pid;
  {
  	sigset_t nset, oset;
 -	struct child *cp = findchild(pid);
  
  	(void)sigemptyset(&nset);
  	(void)sigaddset(&nset, SIGCHLD);
  	(void)sigprocmask(SIG_BLOCK, &nset, &oset);	
 +	struct child *cp = findchild(pid);
  
  	if (cp->done)
  		delchild(cp);
 
 --Boundary-00=_bE+LKNs2EjMVV2P--
State-Changed-From-To: open->analyzed 
State-Changed-By: linimon 
State-Changed-When: Wed Jun 10 20:41:55 UTC 2009 
State-Changed-Why:  
problem confirmed to still exist. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=102834 
Responsible-Changed-From-To: freebsd-bugs->eadler 
Responsible-Changed-By: eadler 
Responsible-Changed-When: Sun May 6 14:46:39 UTC 2012 
Responsible-Changed-Why:  
I'll take it. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=102834 
State-Changed-From-To: analyzed->open 
State-Changed-By: eadler 
State-Changed-When: Sun May 6 14:47:01 UTC 2012 
State-Changed-Why:  
need to check patch 

http://www.freebsd.org/cgi/query-pr.cgi?pr=102834 
State-Changed-From-To: open->analyzed 
State-Changed-By: eadler 
State-Changed-When: Wed May 16 23:52:39 UTC 2012 
State-Changed-Why:  
awaiting approval 

http://www.freebsd.org/cgi/query-pr.cgi?pr=102834 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/102834: commit references a PR
Date: Wed, 30 May 2012 03:55:57 +0000 (UTC)

 Author: eadler
 Date: Wed May 30 03:55:44 2012
 New Revision: 236286
 URL: http://svn.freebsd.org/changeset/base/236286
 
 Log:
   Fix likely race condition if wait_child() is interrupted by sigchild()
   
   PR:		bin/102834
   Submitted by:	Andreas Longwitz <longwitz@incore.de>
   Approved by:	cperciva
   MFC after:	2 weeks
 
 Modified:
   head/usr.bin/mail/popen.c
 
 Modified: head/usr.bin/mail/popen.c
 ==============================================================================
 --- head/usr.bin/mail/popen.c	Wed May 30 03:54:10 2012	(r236285)
 +++ head/usr.bin/mail/popen.c	Wed May 30 03:55:44 2012	(r236286)
 @@ -336,12 +336,14 @@ int
  wait_child(int pid)
  {
  	sigset_t nset, oset;
 -	struct child *cp = findchild(pid);
 +	struct child *cp;
  
  	(void)sigemptyset(&nset);
  	(void)sigaddset(&nset, SIGCHLD);
  	(void)sigprocmask(SIG_BLOCK, &nset, &oset);	
  
 +	cp = findchild(pid);
 +
  	while (!cp->done)
  		(void)sigsuspend(&oset);
  	wait_status = cp->status;
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 
State-Changed-From-To: analyzed->patched 
State-Changed-By: eadler 
State-Changed-When: Wed May 30 04:17:10 UTC 2012 
State-Changed-Why:  
committed, awaiting MFC 

http://www.freebsd.org/cgi/query-pr.cgi?pr=102834 
State-Changed-From-To: patched->closed 
State-Changed-By: eadler 
State-Changed-When: Wed Jun 13 03:41:17 UTC 2012 
State-Changed-Why:  
Committed. Thanks! 

http://www.freebsd.org/cgi/query-pr.cgi?pr=102834 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/102834: commit references a PR
Date: Wed, 13 Jun 2012 03:41:09 +0000 (UTC)

 Author: eadler
 Date: Wed Jun 13 03:40:59 2012
 New Revision: 236984
 URL: http://svn.freebsd.org/changeset/base/236984
 
 Log:
   MFC r236286:
   	Fix likely race condition if wait_child() is interrupted by sigchild()
   
   PR:		bin/102834
   Approved by:	cperciva (implicit)
 
 Modified:
   stable/9/usr.bin/mail/popen.c
 Directory Properties:
   stable/9/usr.bin/mail/   (props changed)
 
 Modified: stable/9/usr.bin/mail/popen.c
 ==============================================================================
 --- stable/9/usr.bin/mail/popen.c	Wed Jun 13 03:34:42 2012	(r236983)
 +++ stable/9/usr.bin/mail/popen.c	Wed Jun 13 03:40:59 2012	(r236984)
 @@ -336,12 +336,14 @@ int
  wait_child(int pid)
  {
  	sigset_t nset, oset;
 -	struct child *cp = findchild(pid);
 +	struct child *cp;
  
  	(void)sigemptyset(&nset);
  	(void)sigaddset(&nset, SIGCHLD);
  	(void)sigprocmask(SIG_BLOCK, &nset, &oset);	
  
 +	cp = findchild(pid);
 +
  	while (!cp->done)
  		(void)sigsuspend(&oset);
  	wait_status = cp->status;
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/102834: commit references a PR
Date: Wed, 13 Jun 2012 03:41:31 +0000 (UTC)

 Author: eadler
 Date: Wed Jun 13 03:41:22 2012
 New Revision: 236985
 URL: http://svn.freebsd.org/changeset/base/236985
 
 Log:
   MFC r236286:
   	Fix likely race condition if wait_child() is interrupted by sigchild()
   
   PR:		bin/102834
   Approved by:	cperciva (implicit)
 
 Modified:
   stable/8/usr.bin/mail/popen.c
 Directory Properties:
   stable/8/usr.bin/mail/   (props changed)
 
 Modified: stable/8/usr.bin/mail/popen.c
 ==============================================================================
 --- stable/8/usr.bin/mail/popen.c	Wed Jun 13 03:40:59 2012	(r236984)
 +++ stable/8/usr.bin/mail/popen.c	Wed Jun 13 03:41:22 2012	(r236985)
 @@ -364,12 +364,14 @@ wait_child(pid)
  	int pid;
  {
  	sigset_t nset, oset;
 -	struct child *cp = findchild(pid);
 +	struct child *cp;
  
  	(void)sigemptyset(&nset);
  	(void)sigaddset(&nset, SIGCHLD);
  	(void)sigprocmask(SIG_BLOCK, &nset, &oset);	
  
 +	cp = findchild(pid);
 +
  	while (!cp->done)
  		(void)sigsuspend(&oset);
  	wait_status = cp->status;
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/102834: commit references a PR
Date: Wed, 13 Jun 2012 03:41:55 +0000 (UTC)

 Author: eadler
 Date: Wed Jun 13 03:41:42 2012
 New Revision: 236986
 URL: http://svn.freebsd.org/changeset/base/236986
 
 Log:
   MFC r236286:
   	Fix likely race condition if wait_child() is interrupted by sigchild()
   
   PR:		bin/102834
   Approved by:	cperciva (implicit)
 
 Modified:
   stable/7/usr.bin/mail/popen.c
 Directory Properties:
   stable/7/usr.bin/mail/   (props changed)
 
 Modified: stable/7/usr.bin/mail/popen.c
 ==============================================================================
 --- stable/7/usr.bin/mail/popen.c	Wed Jun 13 03:41:22 2012	(r236985)
 +++ stable/7/usr.bin/mail/popen.c	Wed Jun 13 03:41:42 2012	(r236986)
 @@ -364,12 +364,14 @@ wait_child(pid)
  	int pid;
  {
  	sigset_t nset, oset;
 -	struct child *cp = findchild(pid);
 +	struct child *cp;
  
  	(void)sigemptyset(&nset);
  	(void)sigaddset(&nset, SIGCHLD);
  	(void)sigprocmask(SIG_BLOCK, &nset, &oset);	
  
 +	cp = findchild(pid);
 +
  	while (!cp->done)
  		(void)sigsuspend(&oset);
  	wait_status = cp->status;
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 
>Unformatted:
