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

Re: fd used for saving redirected fds leaked to child processes



On Sun, Aug 13, 2017 at 11:49 AM, Peter Stephenson
<p.w.stephenson@xxxxxxxxxxxx> 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?

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 &



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