From cperciva@beastie.daemonology.net  Fri Aug 29 17:29:03 2003
Return-Path: <cperciva@beastie.daemonology.net>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id 08E8E16A4BF
	for <FreeBSD-gnats-submit@freebsd.org>; Fri, 29 Aug 2003 17:29:03 -0700 (PDT)
Received: from builder.daemonology.net (h24-87-233-42.vc.shawcable.net [24.87.233.42])
	by mx1.FreeBSD.org (Postfix) with SMTP id D3C7743FE5
	for <FreeBSD-gnats-submit@freebsd.org>; Fri, 29 Aug 2003 17:29:01 -0700 (PDT)
	(envelope-from cperciva@beastie.daemonology.net)
Received: (qmail 35845 invoked from network); 30 Aug 2003 00:28:01 -0000
Received: (for user qmaild)
Received: from unknown (HELO beastie.daemonology.net) (127.0.0.1)
  by localhost with SMTP; 30 Aug 2003 00:28:01 -0000
Received: (qmail 84571 invoked by uid 0); 30 Aug 2003 00:07:42 -0000
Message-Id: <20030830000742.84570.qmail@beastie.daemonology.net>
Date: 30 Aug 2003 00:07:42 -0000
From: Colin Percival <cperciva@daemonology.net>
Reply-To: Colin Percival <cperciva@daemonology.net>
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: /usr/bin/script exits prematurely if STDIN is closed
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         56166
>Category:       bin
>Synopsis:       /usr/bin/script exits prematurely if STDIN is closed
>Confidential:   no
>Severity:       serious
>Priority:       high
>Responsible:    cperciva
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Fri Aug 29 17:30:07 PDT 2003
>Closed-Date:    Sat Mar 13 01:25:00 PST 2004
>Last-Modified:  Sat Mar 13 01:25:00 PST 2004
>Originator:     Colin Percival
>Release:        FreeBSD 4.7-SECURITY i386
>Organization:
>Environment:
System: FreeBSD beastie.daemonology.net 4.7-SECURITY FreeBSD 4.7-SECURITY #0: Tue Aug 12 16:54:33 GMT 2003 root@builder.daemonology.net:/usr/obj/usr/src/sys/GENERICMP i386

>Description:

If the standard input is closed, /usr/bin/script will exit immediately.  
This behaviour is sensible if script is being used interactively (to log a 
shell session) but not sensible otherwise (eg, if script is being used to 
log the output of a program).

>How-To-Repeat:

beastie# script -q /dev/null echo hello world
hello world
beastie# echo "hello world" | xargs script -q /dev/null echo
beastie#

>Fix:

--- script.diff begins here ---
--- usr.bin/script.c.orig	Thu Jul 20 11:35:21 2000
+++ usr.bin/script.c	Sat Aug 30 00:58:04 2003
@@ -170,7 +170,7 @@
 		n = select(master + 1, &rfd, 0, 0, tvp);
 		if (n < 0 && errno != EINTR)
 			break;
-		if (n > 0 && FD_ISSET(STDIN_FILENO, &rfd)) {
+		if (! argv[0] && n > 0 && FD_ISSET(STDIN_FILENO, &rfd)) {
 			cc = read(STDIN_FILENO, ibuf, BUFSIZ);
 			if (cc <= 0)
 				break;
--- script.diff ends here ---
>Release-Note:
>Audit-Trail:

From: Colin Percival <colin.percival@wadham.ox.ac.uk>
To: freebsd-gnats-submit@FreeBSD.org
Cc:  
Subject: Re: bin/56166: /usr/bin/script exits prematurely if STDIN is
  closed
Date: Fri, 10 Oct 2003 20:12:50 +0100

 See also bin/57414.
 
 Colin Percival
 

From: Colin Percival <colin.percival@wadham.ox.ac.uk>
To: freebsd-gnats-submit@FreeBSD.org
Cc:  
Subject: Re: bin/56166: /usr/bin/script exits prematurely if STDIN is
  closed
Date: Thu, 16 Oct 2003 20:32:23 +0100

 Improved patch:
 
 --- script.diff begins here ---
 --- script.c.orig	Thu Jul 20 11:35:21 2000
 +++ script.c	Thu Oct 16 20:25:20 2003
 @@ -162,7 +162,8 @@
   	FD_ZERO(&rfd);
   	for (;;) {
   		FD_SET(master, &rfd);
 -		FD_SET(STDIN_FILENO, &rfd);
 +		if (argv[0] == NULL)
 +			FD_SET(STDIN_FILENO, &rfd);
   		if (flushtime > 0) {
   			tv.tv_sec = flushtime;
   			tv.tv_usec = 0;
 --- script.diff ends here ---
 
State-Changed-From-To: open->patched 
State-Changed-By: cperciva 
State-Changed-When: Thu Jan 22 13:07:11 PST 2004 
State-Changed-Why:  
Fixed in -current, will MFC in 7 days. 
Claim ownership to remind myself to close this later. 



Responsible-Changed-From-To: freebsd-bugs->cperciva 
Responsible-Changed-By: cperciva 
Responsible-Changed-When: Thu Jan 22 13:07:11 PST 2004 
Responsible-Changed-Why:  
Fixed in -current, will MFC in 7 days. 
Claim ownership to remind myself to close this later. 


http://www.freebsd.org/cgi/query-pr.cgi?pr=56166 
State-Changed-From-To: patched->closed 
State-Changed-By: cperciva 
State-Changed-When: Sat Mar 13 01:24:07 PST 2004 
State-Changed-Why:  
MFC to RELENG_4 is done. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=56166 
>Unformatted:
