From 5ead1485640c81d0b020768d59a32d9029a164ee Mon Sep 17 00:00:00 2001 From: Ron Yorston Date: Tue, 28 Mar 2023 13:06:56 +0100 Subject: ash: changes to evalsubshell() When a spawn_forkshell() was required in evalsubshell() two calls to expredir() were being made: one in the parent and one in the child. Rearrange the code so there's only one call, in the child. The call to expredir() in the child is necessary because copynode() doesn't take a copy of expfname in the nfile node. Code could be added to do this but it's cheaper to call expredir(). Add code in forkshell_evalsubshell() to turn off the EV_TESTED flag for background processes. I haven't found a case where this makes a difference but no doubt somebody would have eventually. --- shell/ash.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'shell') diff --git a/shell/ash.c b/shell/ash.c index 1eddec4ea..913f0ce22 100644 --- a/shell/ash.c +++ b/shell/ash.c @@ -10473,9 +10473,18 @@ evalsubshell(union node *n, int flags) errlinno = lineno = n->nredir.linno; +#if ENABLE_PLATFORM_MINGW32 + if (!backgnd && (flags & EV_EXIT) && !may_have_traps) { + expredir(n->nredir.redirect); + redirect(n->nredir.redirect, 0); + evaltreenr(n->nredir.n, flags); + /* never returns */ + } +#else expredir(n->nredir.redirect); if (!backgnd && (flags & EV_EXIT) && !may_have_traps) goto nofork; +#endif INT_OFF; if (backgnd == FORK_FG) get_tty_state(); @@ -10486,7 +10495,6 @@ evalsubshell(union node *n, int flags) fs.n = n; fs.flags = flags; spawn_forkshell(&fs, jp, n, backgnd); - if ( 0 ) { #else if (forkshell(jp, n, backgnd) == 0) { /* child */ @@ -10494,12 +10502,12 @@ evalsubshell(union node *n, int flags) flags |= EV_EXIT; if (backgnd) flags &= ~EV_TESTED; -#endif nofork: redirect(n->nredir.redirect, 0); evaltreenr(n->nredir.n, flags); /* never returns */ } +#endif /* parent */ status = 0; if (backgnd == FORK_FG) @@ -16114,6 +16122,8 @@ forkshell_evalsubshell(struct forkshell *fs) TRACE(("ash: subshell: %s\n",__PRETTY_FUNCTION__)); INT_ON; flags |= EV_EXIT; + if (fs->mode) + flags &= ~EV_TESTED; expredir(n->nredir.redirect); redirect(n->nredir.redirect, 0); evaltreenr(n->nredir.n, flags); -- cgit v1.2.3-55-g6feb