From owner-freebsd-bugs@FreeBSD.ORG Thu May 3 05:50:05 2007 Return-Path: X-Original-To: freebsd-bugs@hub.freebsd.org Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 4F7CA16A402 for ; Thu, 3 May 2007 05:50:05 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [69.147.83.40]) by mx1.freebsd.org (Postfix) with ESMTP id 3212313C455 for ; Thu, 3 May 2007 05:50:05 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.13.4/8.13.4) with ESMTP id l435o5Yq073656 for ; Thu, 3 May 2007 05:50:05 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.13.4/8.13.4/Submit) id l435o4hH073652; Thu, 3 May 2007 05:50:04 GMT (envelope-from gnats) Resent-Date: Thu, 3 May 2007 05:50:04 GMT Resent-Message-Id: <200705030550.l435o4hH073652@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-bugs@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, Alexander Melkov Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 91E0316A400 for ; Thu, 3 May 2007 05:47:55 +0000 (UTC) (envelope-from nobody@FreeBSD.org) Received: from www.freebsd.org (www.freebsd.org [69.147.83.33]) by mx1.freebsd.org (Postfix) with ESMTP id 83E4013C447 for ; Thu, 3 May 2007 05:47:55 +0000 (UTC) (envelope-from nobody@FreeBSD.org) Received: from www.freebsd.org (localhost [127.0.0.1]) by www.freebsd.org (8.13.1/8.13.1) with ESMTP id l435ltYZ025360 for ; Thu, 3 May 2007 05:47:55 GMT (envelope-from nobody@www.freebsd.org) Received: (from nobody@localhost) by www.freebsd.org (8.13.1/8.13.1/Submit) id l435grGW024560; Thu, 3 May 2007 05:42:53 GMT (envelope-from nobody) Message-Id: <200705030542.l435grGW024560@www.freebsd.org> Date: Thu, 3 May 2007 05:42:53 GMT From: Alexander Melkov To: freebsd-gnats-submit@FreeBSD.org X-Send-Pr-Version: www-3.0 Cc: Subject: bin/112379: lockf(1): on closing stdin, stdout, stderr X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 03 May 2007 05:50:05 -0000 >Number: 112379 >Category: bin >Synopsis: lockf(1): on closing stdin, stdout, stderr >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: change-request >Submitter-Id: current-users >Arrival-Date: Thu May 03 05:50:04 GMT 2007 >Closed-Date: >Last-Modified: >Originator: Alexander Melkov >Release: 6.2 >Organization: >Environment: >Description: Because lockf command forks but doesn't close input and output file handles in the main process, closing stdin, stdout or stderr inside child processes doesn't cause respective ends of pipes seen as closed by programs that read write to them. For example: (script1.sh | lockf foo script2.sh 2>&1 &) | mail -s something somewhere Suppose that script2.sh closes its standard input and continues some long-time processing before script1.sh completes writing to its stdndard output. script1.sh will hang for a long time (it would not without lockf). As a more practical example, script2.sh redirects its output at some point and continues its business. Because of lockf, mail will needlessly wait until script2.sh completes. I think that stdin should always be closed, and -s switch may be used as a flag that closing stdout and stderr is desirable. >How-To-Repeat: >Fix: This is a patch against src/usr.bin/lockf/lockf.c,v 1.11.8.1 --- lockf.c.orig Thu Jan 11 17:13:33 2007 +++ lockf.c Thu May 3 09:09:42 2007 @@ -120,6 +120,11 @@ signal(SIGINT, SIG_IGN); signal(SIGQUIT, SIG_IGN); signal(SIGTERM, killed); + fclose(stdin); + if (silent) { + fclose(stdout); + fclose(stderr); + } if (waitpid(child, &status, 0) == -1) err(EX_OSERR, "waitpid failed"); return (WIFEXITED(status) ? WEXITSTATUS(status) : 1); >Release-Note: >Audit-Trail: >Unformatted: