Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: warning about closing an already closed file descriptor



On Mon, 19 Jan 2015 14:33:25 +0100
Kamil Dudka <kdudka@xxxxxxxxxx> wrote:
> zsh prints a warning if an already closed file descriptor is to be closed.  
> While this is technically correct, the other shells I tried (ksh and bash)
> do not print any such warning:
> 
> $ bash -c '(true <&-) <&-'
> $ ksh -c '(true <&-) <&-'
> $ zsh -c '(true <&-) <&-'
> zsh:1: failed to close file descriptor 0: bad file descriptor
> 
> The warning was introduced by the following commit:
> http://sourceforge.net/p/zsh/code/ci/45913f43
> 
> ... and it causes problems when porting legacy scripts to a newer version
> of zsh.  Is there any way to suppress the warning?
> 
> If not, how can one achieve compatibility with other shells (including
> older versions of zsh)?

The problem that change fixed wasn't really intended to have a visible
effect, apart from closing f.d.s the shell didn't know about.  If it's
more useful without the message than with it, it can be removed.  The
shell doesn't make it particularly convenient to test first, either (you
can test something that isn't quite the point by means that aren't quite
intended for it).

Does anyone want to own up to using the message for debugging?

We can special case the {varid}<&- syntax --- that might be useful since
it implies the user was previously in direct control of the f.d. so is
ikely to be interested in an error if closing it failed.

pws



Messages sorted by: Reverse Date, Date, Thread, Author