diff --git a/src/cmd/ksh93/sh/subshell.c b/src/cmd/ksh93/sh/subshell.c index dd0e26d02..0b31429cd 100644 --- a/src/cmd/ksh93/sh/subshell.c +++ b/src/cmd/ksh93/sh/subshell.c @@ -187,7 +187,6 @@ void sh_subfork(void) else { /* this is the child part of the fork */ - sh_onstate(SH_FORKED); /* * $RANDOM is only reseeded when it's used in a subshell, so if $RANDOM hasn't * been reseeded yet set rp->rand_last to -2. This allows sh_save_rand_seed() diff --git a/src/cmd/ksh93/sh/xec.c b/src/cmd/ksh93/sh/xec.c index 65c3c805c..08f485985 100644 --- a/src/cmd/ksh93/sh/xec.c +++ b/src/cmd/ksh93/sh/xec.c @@ -1993,7 +1993,11 @@ int sh_exec(register const Shnode_t *t, int flags) t = t->lst.lstrit; } while(t->tre.tretyp == TLST); - sh_exec(t,flags); + /* + * if sh_state(SH_FORKED) was turned on in the meantime, mix it in to the flags to allow a last-command + * no_fork optimization via execflg2 -- this happens when a subshell forks mid-execution (sh_subfork()) + */ + sh_exec(t,flags|sh_isstate(SH_FORKED)); break; } diff --git a/src/cmd/ksh93/tests/basic.sh b/src/cmd/ksh93/tests/basic.sh index 7fc2207cf..31fb6336d 100755 --- a/src/cmd/ksh93/tests/basic.sh +++ b/src/cmd/ksh93/tests/basic.sh @@ -927,5 +927,15 @@ AIX | SunOS) ;; esac +# ====== +( + ulimit -t unlimited 2>/dev/null + print "${.sh.pid:-$("$SHELL" -c 'echo "$PPID"')}" # fallback for pre-93u+m ksh without ${.sh.pid} + "$SHELL" -c 'print "$$"' +) >out +pid1= pid2= +{ read pid1 && read pid2; }