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

Arne H Juul Arne.Juul at
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
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Mon Nov 28 12:30:08 GMT 2005
>Originator:     Arne H Juul
>Release:        FreeBSD 6.0-STABLE amd64
System: FreeBSD 6.0-STABLE FreeBSD 6.0-STABLE #0: Wed Nov 23 15:08:57 CET 2005 arnej at amd64

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

	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.


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

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");
 	case 0:				/* child */
+		if (out != stderr) fclose(out);
 		execvp(*argv, argv);
 		err(errno == ENOENT ? 127 : 126, "%s", *argv);

More information about the freebsd-bugs mailing list