[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: |
Clark J. Wang |
Subject: |
Re: [bash 3.2.39] File descriptor 10 is always duplicated from 0 and cannot be closed |
Date: |
Mon, 3 Nov 2008 09:41:56 +0800 |
On Mon, Nov 3, 2008 at 06:19, Chet Ramey <chet.ramey@case.edu> wrote:
> 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).
>
Thanks. I found the macro definition in redir.c:
#define SHELL_FD_BASE 10
>
> 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.
>
This is the first time of my hearing of bash-4.0. Looking forward to 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/ <http://cnswww.cns.cwru.edu/%7Echet/>
>