diff --git a/src/cmd/ksh93/sh/subshell.c b/src/cmd/ksh93/sh/subshell.c index d18a7aa62..64d1100f8 100644 --- a/src/cmd/ksh93/sh/subshell.c +++ b/src/cmd/ksh93/sh/subshell.c @@ -662,7 +662,9 @@ Sfio_t *sh_subshell(Shell_t *shp,Shnode_t *t, volatile int flags, int comsub) job.bktick_waitall = 0; if(comsub!=1 && shp->spid) { + int e = shp->exitval; job_wait(shp->spid); + shp->exitval = e; if(shp->pipepid==shp->spid) shp->spid = 0; shp->pipepid = 0; diff --git a/src/cmd/ksh93/tests/functions.sh b/src/cmd/ksh93/tests/functions.sh index 63f6450d4..535985f15 100755 --- a/src/cmd/ksh93/tests/functions.sh +++ b/src/cmd/ksh93/tests/functions.sh @@ -1275,5 +1275,36 @@ $SHELL <<- \EOF EOF [[ $? == 2 ]] && err_exit 'Over-shifting in a POSIX function does not terminate the script if the function call has a redirection' +# ====== +# https://bugzilla.redhat.com/1116508 +expect=$'13/37/1/1' +actual=$( + foo() { + print foo | read + return 13 + } + out=$(foo) + print -n $?/ + foo() { + print foo | read + ls /dev/null + return 37 + } + out=$(foo) + print -n $?/ + foo() { + print foo | ! read + } + out=$(foo) + print -n $?/ + foo() { + ! true + } + out=$(foo) + print -n $? +) +[[ $actual == "$expect" ]] || err_exit "wrong exit status from function invoked by command substitution" \ + "(expected $(printf %q "$expect"), got $(printf %q "$actual"))" + # ====== exit $((Errors<125?Errors:125))