bin/89666: /usr/bin/time leaves extra file open

Arne H Juul Arne.Juul at europe.yahoo-inc.com
Mon Nov 28 12:30:12 GMT 2005


>Number:         89666
>Category:       bin
>Synopsis:       /usr/bin/time leaves extra file open
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Mon Nov 28 12:30:08 GMT 2005
>Closed-Date:
>Last-Modified:
>Originator:     Arne H Juul
>Release:        FreeBSD 6.0-STABLE amd64
>Organization:
Yahoo!
>Environment:
System: FreeBSD dhcp-247.trondheim.corp.yahoo.com 6.0-STABLE FreeBSD 6.0-STABLE #0: Wed Nov 23 15:08:57 CET 2005 arnej at dhcp-247.trondheim.corp.yahoo.com:/usr/obj/usr/src.6/sys/GENERIC amd64

	This bug is in /usr/bin/time from at least FreeBSD 4.x, where
	I originally found it.  Probably it's even older.
>Description:

	When using the -o option to /usr/bin/time to get the
	timing information in its own file, the file is left open
	while running the child process; this isn't usually a problem
	but can cause hard-to-find problems in some cases.  In my case
	a script timed the startup of a server with -o /dev/stdout, which
	made sshd hang waiting for the server to close the file descriptor
	it didn't know about afterwards.

>How-To-Repeat:

	/usr/bin/time -o /tmp/time.output sh -c 'echo foo >&3'
	cat /tmp/time.output
	
>Fix:

Index: time.c
===================================================================
RCS file: /usr/cvs/src/usr.bin/time/time.c,v
retrieving revision 1.27
diff -u -r1.27 time.c
--- time.c	21 May 2005 09:55:08 -0000	1.27
+++ time.c	28 Nov 2005 12:15:03 -0000
@@ -121,6 +121,7 @@
 		err(1, "time");
 		/* NOTREACHED */
 	case 0:				/* child */
+		if (out != stderr) fclose(out);
 		execvp(*argv, argv);
 		err(errno == ENOENT ? 127 : 126, "%s", *argv);
 		/* NOTREACHED */
>Release-Note:
>Audit-Trail:
>Unformatted:


More information about the freebsd-bugs mailing list