[PATCH] ash: add process substitution in bash-compatibility mode

Denys Vlasenko vda.linux at googlemail.com
Tue Jan 29 10:01:05 UTC 2019


On Mon, Jan 28, 2019 at 10:16 AM Ron Yorston <rmy at pobox.com> wrote:
> Denys wrote:
> >Can we use popredir() mechanism instead?
>
> It's possible but it adds more complication to already complex code.
> Currently the stack of redir fds is always unwound unconditionally.
> The procsub fds are conditionally removed depending on whether or not
> we're in a shell function.

That what looked unusual to me at once. Redirections should not depend
on things like that.

I think redirections should be closed when the command terminates,
and bash seems to do this:

$ strace -ozz1 -f -tt -s99 bash -c 'echo <(sleep 9); sleep 0'
/dev/fd/63

Here, "echo" ends way before "sleep 9" terminates. Strace log reveals
and fd #63 is closed immediately when "echo" command completes:

12436 10:53:51.101718 dup2(3, 63)       = 63
12436 10:53:51.101743 close(3)          = 0
12436 10:53:51.101762 prlimit64(0, RLIMIT_NOFILE, NULL,
{rlim_cur=1024, rlim_max=4*1024}) = 0
12436 10:53:51.101783 rt_sigprocmask(SIG_BLOCK, [CHLD], [], 8) = 0
12436 10:53:51.101807 rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
12436 10:53:51.101827 rt_sigprocmask(SIG_BLOCK, [INT CHLD], [], 8) = 0
12436 10:53:51.101847 clone(child_stack=NULL,
flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|SIGCHLD,
child_tidptr=0x7f3afe16ca10) = 12437
12436 10:53:51.101927 rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
12436 10:53:51.101949 rt_sigaction(SIGCHLD,
{sa_handler=0x55677c59b120, sa_mask=[],
sa_flags=SA_RESTORER|SA_RESTART, sa_restorer=0x7f3afe1a75c0},
{sa_handler=0x55677c59b120, sa_mask=[], sa_flags=SA_RESTORER|SA_R
12437 10:53:51.101967 getpid( <unfinished ...>
12436 10:53:51.101974 rt_sigprocmask(SIG_BLOCK, [CHLD],  <unfinished ...>
12437 10:53:51.101981 <... getpid resumed> ) = 12437
12436 10:53:51.101989 <... rt_sigprocmask resumed> [], 8) = 0
12437 10:53:51.101998 rt_sigprocmask(SIG_SETMASK, [],  <unfinished ...>
12436 10:53:51.102005 rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
12436 10:53:51.102024 close(4)          = 0
12437 10:53:51.102056 <... rt_sigprocmask resumed> NULL, 8) = 0
12436 10:53:51.102063 fstat(1, {st_mode=S_IFCHR|0620,
st_rdev=makedev(136, 1), ...}) = 0
12437 10:53:51.102079 rt_sigaction(SIGTSTP, {sa_handler=SIG_DFL,
sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7f3afe1a75c0},
<unfinished ...>
12436 10:53:51.102087 write(1, "/dev/fd/63\n", 11) = 11
12436 10:53:51.102133 close(63)                    = 0


More information about the busybox mailing list