1
0
Fork 0
mirror of git://git.code.sf.net/p/cdesktopenv/code synced 2025-03-09 15:50:02 +00:00

Allow exec of last command in forked non-bg subshell (re: 16b38021)

The exec optimization only happened in background subshells and not
in regular subshells when they had forked via sh_subfork(), which
makes little sense.

src/cmd/ksh93/sh/xec.c: sh_exec: case TLST:
- A subshell is executed as a list of commands which is TLST. If
  the shell had not forked at the beginning of the subshell, the
  sh_state(SH_FORKED) flag was not passed on to recursive sh_exec()
  invocations, and a sh_subfork() event did not change this. To fix
  this, re-check for the SH_FORKED state and pass that bit on to
  the recursive sh_exec() invocation if set (note that sh_isstate()
  returns a bitmask and not a boolean value).

src/cmd/ksh93/sh/subshell.c: sh_subfork():
- Remove redundant sh_onstate(SH_FORKED); this is already done in
  sh_fork() which this function calls.
This commit is contained in:
Martijn Dekker 2022-06-18 12:45:51 +01:00
parent 16b3802148
commit d6c9821c5b
3 changed files with 15 additions and 2 deletions

View file

@ -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; } <out && let "pid1 == pid2" \
|| err_exit "last command in forked subshell not exec-optimized ($pid1 != $pid2)"
# ======
exit $((Errors<125?Errors:125))