[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Process-substitution FDs closed prematurely
From: |
Chet Ramey |
Subject: |
Re: Process-substitution FDs closed prematurely |
Date: |
Wed, 07 Nov 2012 18:05:21 -0500 |
User-agent: |
Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:16.0) Gecko/20121026 Thunderbird/16.0.2 |
On 11/6/12 7:09 AM, Zev Weiss wrote:
> Bash Version: 4.2
> Patch Level: 39
> Release Status: release
>
> Description:
>
> It seems that when bash passes (the expanded form of) a
> process substitution to a function and that function then uses
> the argument in a pipeline, the file descriptor for the
> substituted pipe gets closed prematurely. This does not occur
> with bash-4.1.11 on FreeBSD, but does with 4.2.39 on Linux (I
> attempted to compile 4.1.11 from source on Linux to test it,
> but the build failed).
>
> Repeat-By:
> Shell transcript demonstrating it:
>
> [zev@hatter: tmp]% cat test.sh
> #!/bin/bash
> fn() { cat | cat "$1"; }
> fn <(:) < /dev/null
> [zev@hatter: tmp]% bash ./test.sh
> cat: /dev/fd/63: No such file or directory
> [zev@hatter: tmp]% echo $?
> 1
>
> Expected behavior is no output and an exit status of zero.
Thanks for the report. The difference you observed is not the change
from bash-4.1 to bash-4.2, but Linux using /dev/fd and FreeBSD using
explicitly-created and destroyed FIFOs.
It's important to close /dev/fd file descriptors (which are essentially
pipes) in the various processes that use and inherit them. The bash-4.2
(and previous) code closes those file descriptors after creating the first
process in a pipeline instead of, say, the last (thereby making them
unavailable to the rest of the pipeline processes). I will look at
changing that for the next version.
Chet
--
``The lyf so short, the craft so long to lerne.'' - Chaucer
``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, ITS, CWRU chet@case.edu http://cnswww.cns.cwru.edu/~chet/