Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: <(...), >(...) and fds above 9
- X-seq: zsh-workers 44478
- From: Stephane Chazelas <stephane.chazelas@xxxxxxxxx>
- To: Peter Stephenson <p.stephenson@xxxxxxxxxxx>
- Subject: Re: <(...), >(...) and fds above 9
- Date: Mon, 1 Jul 2019 21:00:28 +0100
- Cc: Zsh Hackers' List <zsh-workers@xxxxxxx>
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:mail-followup-to:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to:user-agent; bh=qNBPOtOJKhG2JI9pLoxG9b63AMn1RB5KCJMav/WQ/7k=; b=rbPQbH56Pp+M3tE0oKO/c4l7pRSprHcBvfKHpq//6uR2BCK1Ei0adyz18vKqs7ZaOV 3Q3c2TjmZ+G2LVkeIygzEuPpWj2Fv1PBZ+GX58MBypptb7E0nJm+KHbt/Ptfhl/RH09J EwiJ+frDEdKd7SYu8m/aQM/zUDW3AfYQUbgaOU3Ed8jeQmear8hqh3D2H+NRWeEkFE7t rWbMEnn0k3tJUEvSeRUI8OrN5z05y95s092A6uI+nITxQfKnyy8r/EQCsyZjDXpaMxZm sHxlzbpJibkbhLOs2rVOP/FQCGI1aNeHnXHT9jIPZCcvD2aFQgLiwDA6p679WiQqyo8w G42g==
- In-reply-to: <1561999973.6006.21.camel@samsung.com>
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- List-unsubscribe: <mailto:zsh-workers-unsubscribe@zsh.org>
- Mail-followup-to: Peter Stephenson <p.stephenson@xxxxxxxxxxx>, Zsh Hackers' List <zsh-workers@xxxxxxx>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
- References: <CGME20190701100058epcas2p25e5f8dbd14d048fe2be1d831f3cf60ab@epcas2p2.samsung.com> <20190701100001.hbegs7zyu2auckhf@chaz.gmail.com> <1561975733.6006.2.camel@samsung.com> <CAH+w=7Z+UBP-0ZvHbNzfz13a7e4AFGpQyuntEaKNENeLRDdmVQ@mail.gmail.com> <1561994908.6006.19.camel@samsung.com> <20190701162202.5o3cxahc75e2hucz@chaz.gmail.com> <1561999973.6006.21.camel@samsung.com>
2019-07-01 17:52:53 +0100, Peter Stephenson:
> On Mon, 2019-07-01 at 17:22 +0100, Stephane Chazelas wrote:
> > 2019-07-01 16:28:28 +0100, Peter Stephenson:
> > [...]
> > >
> > > Looks like =(...) doesn't call closem() at all when
> > > forking, hence the difference in behaviour. So
> > > =(...) is the odd one out.
> > [...]
> >
> > But is there a good reason why we should close those fds?
>
> The shell has no idea whether you're happy to have lingering file
> descriptors when executing any old external software, so has to play
> safe in general. It assumes you know what you're doing with file
> descriptors 0 to 7 and certain other types, and that others are
> dangerous.
[...]
Thanks, but I don't follow.
In
exec 7< file
I have file open on fd 7 which I can use anywhere, after fork(),
after execve().
With
exec {fd}< file
It's the same except the fd is assigned dynamically but I don't
see how they should be treated differently. Presumably, if I'm
doing that, I want to be able to use that fd later on, most
probably in some command which unless the command happens to be
a builtin involves both a fork() and execve().
In
$ ls -l /proc/self/fd
total 0
lrwx------ 1 chazelas chazelas 64 Jul 1 20:47 0 -> /dev/pts/1
lrwx------ 1 chazelas chazelas 64 Jul 1 20:47 1 -> /dev/pts/1
lr-x------ 1 chazelas chazelas 64 Jul 1 20:47 12 -> /home/chazelas/a
lrwx------ 1 chazelas chazelas 64 Jul 1 20:47 2 -> /dev/pts/1
lr-x------ 1 chazelas chazelas 64 Jul 1 20:47 3 -> /proc/26481/fd
There is both a fork() and a execve() and that fd 12 survived.
It survives in
(ls -l /proc/self/fd)
echo "$(ls -l /proc/self/fd)"
ls -l /proc/self/fd | cat
cat =(ls -l /proc/self/fd)
Not in
ls /proc/self/fd &
coproc ls /proc/self/fd
cat <(ls /proc/self/fd)
It looks like the key is *background* here, and it sounds like
the reason is not so much about what the user expects but
possibly some implementation limitation/consideration, maybe
something to do with job control and/or the fact that some of the
fds above 9 are not user ones but some created internally by zsh
for its own internal soup?
Is it documented anywhere that fds above 9 are closed for all
commands started asynchronously?
--
Stephane
Messages sorted by:
Reverse Date,
Date,
Thread,
Author