From amdmi3@amdmi3.ru  Fri Apr 30 15:08:59 2010
Return-Path: <amdmi3@amdmi3.ru>
Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52])
	by hub.freebsd.org (Postfix) with ESMTP id 525791065674
	for <FreeBSD-gnats-submit@freebsd.org>; Fri, 30 Apr 2010 15:08:59 +0000 (UTC)
	(envelope-from amdmi3@amdmi3.ru)
Received: from smtp.timeweb.ru (smtp.timeweb.ru [92.53.116.15])
	by mx1.freebsd.org (Postfix) with ESMTP id 0F35B8FC18
	for <FreeBSD-gnats-submit@freebsd.org>; Fri, 30 Apr 2010 15:08:58 +0000 (UTC)
Received: from [213.148.20.85] (helo=hive.panopticon)
	by smtp.timeweb.ru with esmtpsa (TLSv1:CAMELLIA256-SHA:256)
	(Exim 4.71)
	(envelope-from <amdmi3@amdmi3.ru>)
	id 1O7rpo-0006Mq-GX; Fri, 30 Apr 2010 19:08:57 +0400
Received: from hades.panopticon (hades.panopticon [192.168.0.32])
	by hive.panopticon (Postfix) with ESMTP id 1A331B856;
	Fri, 30 Apr 2010 19:08:56 +0400 (MSD)
Received: by hades.panopticon (Postfix, from userid 1000)
	id 06512B829; Fri, 30 Apr 2010 19:08:56 +0400 (MSD)
Message-Id: <20100430150856.06512B829@hades.panopticon>
Date: Fri, 30 Apr 2010 19:08:56 +0400 (MSD)
From: Dmitry Marakasov <amdmi3@FreeBSD.org>
Reply-To: Dmitry Marakasov <amdmi3@FreeBSD.org>
To: FreeBSD-gnats-submit@freebsd.org
Cc: ed@FreeBSD.org
Subject: /usr/bin/script broken in HEAD and 8-STABLE
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         146189
>Category:       bin
>Synopsis:       script(1) broken in HEAD and 8-STABLE
>Confidential:   no
>Severity:       critical
>Priority:       high
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Fri Apr 30 15:10:04 UTC 2010
>Closed-Date:    Sun Aug 08 09:57:56 UTC 2010
>Last-Modified:  Mon May 28 19:00:11 UTC 2012
>Originator:     Dmitry Marakasov
>Release:        FreeBSD 8.0-RELEASE i386
>Organization:
>Environment:
System: FreeBSD hades.panopticon 8.0-RELEASE FreeBSD 8.0-RELEASE #0: Tue Nov 24 22:31:59 MSK 2009 root@hades.panopticon:/async/obj/usr/src/sys/HADES i386

(but the PR applies to CURRENT and 8-STABLE)

>Description:
/usr/bin/script is broken in HEAD by r205008, in 8-STABLE by 205635.

After these changes it no longer exits with the same exit code as the command it runs (thus, if the command fails, it'll still exit with 0)
Among other things, this breaks portupgrade, as it now mistakingly interprets failed port builds as successfull ones, thus removing ports without installing newer versions.

>How-To-Repeat:
/usr/bin/script from r205007
 # script -q /dev/null true; echo $?
 0
 # script -q /dev/null false; echo $?
 1

/usr/bin/script from r205008
 # script -q /dev/null true; echo $? 
 0
 # script -q /dev/null false; echo $?
 0

>Fix:

>Release-Note:
>Audit-Trail:
Date: Fri, 30 Apr 2010 21:05:15 +0200
From: Ed Schouten <ed@80386.nl>
To: Dmitry Marakasov <amdmi3@FreeBSD.org>
Subject: Re: /usr/bin/script broken in HEAD and 8-STABLE

 --wOOEd1gxhwV8K3c+
 Content-Type: text/plain; charset=us-ascii
 Content-Disposition: inline
 Content-Transfer-Encoding: quoted-printable
 
 * Dmitry Marakasov <amdmi3@FreeBSD.org> wrote:
 > After these changes it no longer exits with the same exit code as the com=
 mand it runs (thus, if the command fails, it'll still exit with 0)
 > Among other things, this breaks portupgrade, as it now mistakingly interp=
 rets failed port builds as successfull ones, thus removing ports without in=
 stalling newer versions.
 
 Looks like my fix is correct, but it did expose a new bug inside
 script(1). We must not use WNOHANG in wait3(), because we must now
 really wait for the child process to properly shut down.
 
 Index: script.c
 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
 --- script.c    (revision 207446)
 +++ script.c    (working copy)
 @@ -223,7 +223,7 @@
         int die, e, status;
 
         die =3D e =3D 0;
 -       while ((pid =3D wait3(&status, WNOHANG, 0)) > 0)
 +       while ((pid =3D wait3(&status, 0, 0)) > 0)
                 if (pid =3D=3D child) {
                         die =3D 1;
                         if (WIFEXITED(status))
 
 --=20
  Ed Schouten <ed@80386.nl>
  WWW: http://80386.nl/
 
 --wOOEd1gxhwV8K3c+
 Content-Type: application/pgp-signature
 Content-Disposition: inline
 
 -----BEGIN PGP SIGNATURE-----
 Version: GnuPG v2.0.14 (FreeBSD)
 
 iEYEARECAAYFAkvbKesACgkQ52SDGA2eCwWD+wCdH3TAsaJAerK8Id3lA818dl+8
 7ysAnjGAfsPJElI4PJsooEnXmeLOuKwl
 =xf5v
 -----END PGP SIGNATURE-----
 
 --wOOEd1gxhwV8K3c+--

Date: Fri, 30 Apr 2010 23:48:49 +0400
From: Dmitry Marakasov <amdmi3@amdmi3.ru>
To: Ed Schouten <ed@80386.nl>
Subject: Re: /usr/bin/script broken in HEAD and 8-STABLE

 This seems to work, thanks!
 
 -- 
 Dmitry Marakasov   .   55B5 0596 FF1E 8D84 5F56  9510 D35A 80DD F9D2 F77D
 amdmi3@amdmi3.ru  ..:  jabber: amdmi3@jabber.ru    http://www.amdmi3.ru

State-Changed-From-To: open->patched 
State-Changed-By: ed 
State-Changed-When: Fri Apr 30 22:34:23 UTC 2010 
State-Changed-Why:  


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

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/146189: commit references a PR
Date: Fri, 30 Apr 2010 22:34:08 +0000 (UTC)

 Author: ed
 Date: Fri Apr 30 22:33:49 2010
 New Revision: 207453
 URL: http://svn.freebsd.org/changeset/base/207453
 
 Log:
   Remove WNOHANG flag from wait3().
   
   Because script(1) now reliably terminates when the TTY is closed, it may
   be the case that the call to wait3() occurs just before the child
   process exits. This causes error codes to be ignored.
   
   Just change script(1) to use waitpid() instead of wait3(). This makes it
   more portable and prevents the need for a loop, since waitpid() only
   returns a specified process.
   
   PR:		bin/146189
   Tested by:	amdmi3@, older version
   MFC after:	2 weeks
 
 Modified:
   head/usr.bin/script/script.c
 
 Modified: head/usr.bin/script/script.c
 ==============================================================================
 --- head/usr.bin/script/script.c	Fri Apr 30 22:31:37 2010	(r207452)
 +++ head/usr.bin/script/script.c	Fri Apr 30 22:33:49 2010	(r207453)
 @@ -219,23 +219,17 @@ usage(void)
  void
  finish(void)
  {
 -	pid_t pid;
 -	int die, e, status;
 +	int e, status;
  
 -	die = e = 0;
 -	while ((pid = wait3(&status, WNOHANG, 0)) > 0)
 -	        if (pid == child) {
 -			die = 1;
 -			if (WIFEXITED(status))
 -				e = WEXITSTATUS(status);
 -			else if (WIFSIGNALED(status))
 -				e = WTERMSIG(status);
 -			else /* can't happen */
 -				e = 1;
 -		}
 -
 -	if (die)
 +	if (waitpid(child, &status, 0) == child) {
 +		if (WIFEXITED(status))
 +			e = WEXITSTATUS(status);
 +		else if (WIFSIGNALED(status))
 +			e = WTERMSIG(status);
 +		else /* can't happen */
 +			e = 1;
  		done(e);
 +	}
  }
  
  void
 _______________________________________________
 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/146189: commit references a PR
Date: Fri, 14 May 2010 12:34:16 +0000 (UTC)

 Author: ed
 Date: Fri May 14 12:34:06 2010
 New Revision: 208070
 URL: http://svn.freebsd.org/changeset/base/208070
 
 Log:
   MFC r207453:
   
     Remove WNOHANG flag from wait3().
   
     Because script(1) now reliably terminates when the TTY is closed, it may
     be the case that the call to wait3() occurs just before the child
     process exits. This causes error codes to be ignored.
   
     Just change script(1) to use waitpid() instead of wait3(). This makes it
     more portable and prevents the need for a loop, since waitpid() only
     returns a specified process.
   
   PR:           bin/146189
   Tested by:    amdmi3@, older version
 
 Modified:
   stable/8/usr.bin/script/script.c
 Directory Properties:
   stable/8/usr.bin/script/   (props changed)
 
 Modified: stable/8/usr.bin/script/script.c
 ==============================================================================
 --- stable/8/usr.bin/script/script.c	Fri May 14 10:06:20 2010	(r208069)
 +++ stable/8/usr.bin/script/script.c	Fri May 14 12:34:06 2010	(r208070)
 @@ -219,23 +219,17 @@ usage(void)
  void
  finish(void)
  {
 -	pid_t pid;
 -	int die, e, status;
 +	int e, status;
  
 -	die = e = 0;
 -	while ((pid = wait3(&status, WNOHANG, 0)) > 0)
 -	        if (pid == child) {
 -			die = 1;
 -			if (WIFEXITED(status))
 -				e = WEXITSTATUS(status);
 -			else if (WIFSIGNALED(status))
 -				e = WTERMSIG(status);
 -			else /* can't happen */
 -				e = 1;
 -		}
 -
 -	if (die)
 +	if (waitpid(child, &status, 0) == child) {
 +		if (WIFEXITED(status))
 +			e = WEXITSTATUS(status);
 +		else if (WIFSIGNALED(status))
 +			e = WTERMSIG(status);
 +		else /* can't happen */
 +			e = 1;
  		done(e);
 +	}
  }
  
  void
 _______________________________________________
 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: patched->closed  
State-Changed-By: brucec 
State-Changed-When: Sun Aug 8 09:57:25 UTC 2010 
State-Changed-Why:  
Fix has been merged to stable/8. 

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

From: Bryan Drewery <bryan@shatow.net>
To: bug-followup@FreeBSD.org
Cc: brucec@freebsd.org, ed@80386.nl
Subject: Re: bin/146189: script(1) broken in HEAD and 8-STABLE
Date: Mon, 28 May 2012 13:53:36 -0500

 This is an OpenPGP/MIME signed message (RFC 2440 and 3156)
 --------------enigF3E530D77B34C7C5D6F84530
 Content-Type: text/plain; charset=ISO-8859-1
 Content-Transfer-Encoding: quoted-printable
 
 script(1) is also showing the same incorrect behavior on 7.4 and
 7-STABLE. I believe that the root cause identified in this PR is wrong,
 as r205008 was not MFCd to 7-STABLE.
 
 However, the fix from this PR (r207453) does fix it for 7.4/7-STABLE as
 well.
 
 Without this fix, some automated scripts depending on the return status
 of script(1) will improperly continue, or fail. portupgrade(1) is prone
 to this. See ports/131111 and ports/147242.
 
 Regards,
 Bryan Drewery
 
 
 --------------enigF3E530D77B34C7C5D6F84530
 Content-Type: application/pgp-signature; name="signature.asc"
 Content-Description: OpenPGP digital signature
 Content-Disposition: attachment; filename="signature.asc"
 
 -----BEGIN PGP SIGNATURE-----
 Version: GnuPG v1.4.10 (MingW32)
 Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
 
 iQIcBAEBAgAGBQJPw8mxAAoJEG54KsA8mwz5qZwP/jNHoVrtrwgr6ZjPyUMFCbzi
 4yVKmyb4xdyWkzy56ay7faXJdxzHYl9BTpaLqGHvshJjHkxfTBdXXdcRhbYeDwye
 MCW0Rq6tuHJHbE+qrWupK8l6azILHxWFZF+Q+2eTec9ewiTbuDeJKVDciQySNfF0
 S+r1YKku7FdoiiAcABBF7FHFE02c9QP+VPVlUSl6N/G9OLiHfsQTulRFI3h1wUOf
 Pc5/aQZZSpiV47ZTVpeLxkr5N0IfjkmMPHtBbTWhDMXl3wtg5wSajj+/AnXlK0K4
 LW5VBc7iXn8F9xMVZBOMEhSd6R7bqCwefGQ+Tpfpo03CqBGgh84KkbnZUAUfLDjk
 k28HfFzmS8weYvQ3ukTfY+zFTNWfobed2+r1OslDiEKHXCPWCrWMatlAcL8eMKVY
 Bjwo2k9YRBklodaWW+HeRU6Q0UCDOzGIHKWwBLgTrNh6HBPbxj/ROSbdwNMriyQ8
 55atI2nW63o7l9Z5LqC03Zj4nmcXvj6cguqi2sLsG4v7itAC6Bg3P8w361apatvg
 /G9xiQd+XXzcfMLEzye5Xw/nifz71CnyYQdbpnwDXCVqiGw6l69g0SJ4xBzQI/h8
 BM3pLuveVsqlVN8xvC/EgUoID7PaZ7cR9rrRDvxBRMphsjhe5YxcC1UyqSMgiRnG
 TDYofSCSj8ZIONxlKmqf
 =N5iS
 -----END PGP SIGNATURE-----
 
 --------------enigF3E530D77B34C7C5D6F84530--
>Unformatted:
