From arnej@dhcp-247.trondheim.corp.yahoo.com  Mon Nov 28 12:29:02 2005
Return-Path: <arnej@dhcp-247.trondheim.corp.yahoo.com>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id 85A9516A41F
	for <FreeBSD-gnats-submit@freebsd.org>; Mon, 28 Nov 2005 12:29:02 +0000 (GMT)
	(envelope-from arnej@dhcp-247.trondheim.corp.yahoo.com)
Received: from dhcp-247.trondheim.corp.yahoo.com (pat-gw.trondheim.corp.yahoo.com [217.144.236.4])
	by mx1.FreeBSD.org (Postfix) with ESMTP id D628643D4C
	for <FreeBSD-gnats-submit@freebsd.org>; Mon, 28 Nov 2005 12:29:01 +0000 (GMT)
	(envelope-from arnej@dhcp-247.trondheim.corp.yahoo.com)
Received: from dhcp-247.trondheim.corp.yahoo.com (localhost [127.0.0.1])
	by dhcp-247.trondheim.corp.yahoo.com (8.13.4/8.13.3) with ESMTP id jASCT6OM015304;
	Mon, 28 Nov 2005 13:29:06 +0100 (CET)
	(envelope-from arnej@dhcp-247.trondheim.corp.yahoo.com)
Received: (from arnej@localhost)
	by dhcp-247.trondheim.corp.yahoo.com (8.13.4/8.13.3/Submit) id jASCT6k4015303;
	Mon, 28 Nov 2005 13:29:06 +0100 (CET)
	(envelope-from arnej)
Message-Id: <200511281229.jASCT6k4015303@dhcp-247.trondheim.corp.yahoo.com>
Date: Mon, 28 Nov 2005 13:29:06 +0100 (CET)
From: Arne H Juul <Arne.Juul@europe.yahoo-inc.com>
Reply-To: Arne H Juul <Arne.Juul@europe.yahoo-inc.com>
To: FreeBSD-gnats-submit@freebsd.org
Cc: arnej@pvv.ntnu.no
Subject: /usr/bin/time leaves extra file open
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         89666
>Category:       bin
>Synopsis:       [patch] time(1) leaves extra file open
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Mon Nov 28 12:30:08 GMT 2005
>Closed-Date:    Sun Apr 16 17:45:29 GMT 2006
>Last-Modified:  Sun Apr 16 17:45:29 GMT 2006
>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@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:
State-Changed-From-To: open->closed 
State-Changed-By: maxim 
State-Changed-When: Sun Apr 16 17:44:51 UTC 2006 
State-Changed-Why:  
A bit different code committed to HEAD.  Thanks for the patch! 

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