From: Peter Stephenson <p.stephenson@samsung.com>
To: Zsh hackers list <zsh-workers@zsh.org>
Subject: Re: fd used for saving redirected fds leaked to child processes
Date: Mon, 14 Aug 2017 10:09:56 +0100 [thread overview]
Message-ID: <20170814100956.363c7ea8@pwslap01u.europe.root.pri> (raw)
In-Reply-To: <CAH+w=7Y3OaN0JJOo=jG-G+yRZ9NUqbNCGZBw6b452_nOWUAKMA@mail.gmail.com>
On Sun, 13 Aug 2017 14:45:12 -0700
Bart Schaefer <schaefer@brasslantern.com> wrote:
> On Sun, Aug 13, 2017 at 11:49 AM, Peter Stephenson
> <p.w.stephenson@ntlworld.com> wrote:
> >
> > +/* FDs saved for possible restoring, not needed in a subshell
> > + * where we will never need to restore them. Hence if we enter
> > + * a subshell these will simply be closed unconditionally.
> > + *
> > + * A value >= 10 indicates a valid saved fd.
> > + */
>
> No objection to defensive programming, but would it not be a bug for
> an fd < 10 to ever be assigned to a slot in saved_fds[] in the first
> place?
Yes, it would --- I just need to exclude the case of 0 as that's the
default (wasn't worth statically initialising to -1's), but checked
the range instead.
> It feels as though there's probably a reason that (int *save) is
> passed around as a parameter to addfd() et al. rather than being a
> global to begin with. Are you sure there aren't circumstances where
> the same fd might get saved more than once at different levels of the
> recursive execsomething() hierarchy, causing saved_fds[] to contain
> incomplete information? I'm envisioning something like
>
> { { cmd1 ; cmd2 } > file2; cmd3 } > file1 &
Yes, exactly that did occur to me later.
We need to expose the entire hierarchy for this particular case, but
that looks like a stack or a linked list, which seems a little
heavyweight for this case. It needs a bit more thought. A linked
list rooted at each fd 0 to 9 is the best I've come up with so far.
pws
next prev parent reply other threads:[~2017-08-14 9:10 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-08-13 16:12 Stephane Chazelas
2017-08-13 18:49 ` Bart Schaefer
2017-08-13 18:49 ` Peter Stephenson
2017-08-13 21:45 ` Bart Schaefer
2017-08-14 9:09 ` Peter Stephenson [this message]
2017-08-14 14:49 ` Bart Schaefer
2017-08-14 15:24 ` Peter Stephenson
2017-08-14 15:31 ` Bart Schaefer
2017-08-14 19:19 ` Peter Stephenson
2017-09-29 15:06 ` Daniel Shahaf
2017-09-29 15:18 ` Peter Stephenson
2017-08-15 18:42 ` Peter Stephenson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170814100956.363c7ea8@pwslap01u.europe.root.pri \
--to=p.stephenson@samsung.com \
--cc=zsh-workers@zsh.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).