bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [bash 3.2.39] File descriptor 10 is always duplicated from 0 and can


From: Chet Ramey
Subject: Re: [bash 3.2.39] File descriptor 10 is always duplicated from 0 and cannot be closed
Date: Sun, 02 Nov 2008 17:19:09 -0500
User-agent: Thunderbird 2.0.0.17 (Macintosh/20080914)

Clark J. Wang wrote:

> When I was doing some testing I found the file descriptor 10 is always
> duplicate of fd 0 and it cannot be closed.

Half right.  When a redirection involving fd 0 is evaluated, the shell
has to save fd 0 somewhere so it can be restored.  It uses fcntl to
duplicate fd 0 to something above the traditional user-addressable fd
range (0-9).  (You can check the code in redir.c:add_undo_redirect(),
which happens to use fds 10 and above).

Since there's no real guaranteed-safe file descriptor range for the
shell's use, it's possible, as you did, to use the fd bash uses to save
fd 0.  And since fd 0 is saved before the rest of the redirection is
evaluated, state can change in the middle of the redirection's logical
evaluation.

This doesn't really have anything to do with closing fd 10, which
succeeded.

There are things that the shell can do to try and minimize such collisions,
and bash-4.0 will do a better job at it.

Chet

-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer

Chet Ramey, ITS, CWRU    chet@case.edu    http://cnswww.cns.cwru.edu/~chet/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]