bin/112379: lockf(1): on closing stdin, stdout, stderr

Alexander Melkov melkov at comptek.ru
Thu May 3 05:50:05 UTC 2007


>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:


More information about the freebsd-bugs mailing list