diff --git a/NEWS b/NEWS index f990d66e1..6bafbaf61 100644 --- a/NEWS +++ b/NEWS @@ -3,6 +3,11 @@ For full details, see the git log at: https://github.com/ksh93/ksh Any uppercase BUG_* names are modernish shell bug IDs. +2021-01-20: + +- Fixed: executing a DEBUG trap in a command substitution had side effects + on the exit status ($?) of non-trap commands. + 2021-01-19: - Fixed a crash when using 'cd' in a virtual/non-forking subshell in a diff --git a/src/cmd/ksh93/include/version.h b/src/cmd/ksh93/include/version.h index 9bbdc7861..4e5797bc7 100644 --- a/src/cmd/ksh93/include/version.h +++ b/src/cmd/ksh93/include/version.h @@ -20,7 +20,7 @@ #define SH_RELEASE_FORK "93u+m" /* only change if you develop a new ksh93 fork */ #define SH_RELEASE_SVER "1.0.0-alpha" /* semantic version number: https://semver.org */ -#define SH_RELEASE_DATE "2021-01-19" /* must be in this format for $((.sh.version)) */ +#define SH_RELEASE_DATE "2021-01-20" /* must be in this format for $((.sh.version)) */ /* Scripts sometimes field-split ${.sh.version}, so don't change amount of whitespace. */ /* Arithmetic $((.sh.version)) uses the last 10 chars, so the date must be at the end. */ diff --git a/src/cmd/ksh93/sh/fault.c b/src/cmd/ksh93/sh/fault.c index 440e761d2..72b3eeaf3 100644 --- a/src/cmd/ksh93/sh/fault.c +++ b/src/cmd/ksh93/sh/fault.c @@ -489,7 +489,7 @@ int sh_trap(const char *trap, int mode) sh_popcontext(shp,&buff); shp->intrap--; sfsync(shp->outpool); - if(!shp->indebug && jmpval!=SH_JMPEXIT && jmpval!=SH_JMPFUN) + if(jmpval!=SH_JMPEXIT && jmpval!=SH_JMPFUN) shp->exitval=savxit; stakset(savptr,staktop); fcrestore(&savefc); diff --git a/src/cmd/ksh93/tests/basic.sh b/src/cmd/ksh93/tests/basic.sh index 8b5acf114..6c4f71bfc 100755 --- a/src/cmd/ksh93/tests/basic.sh +++ b/src/cmd/ksh93/tests/basic.sh @@ -734,5 +734,17 @@ got=$(eval 'x=${ for i in test; do case $i in test) true;; esac; done; }' 2>&1) got=$(eval 'x=`for i in test; do case $i in test) true;; esac; done`' 2>&1) \ || err_exit "case in a for loop inside a \`comsub\` caused syntax error (got $(printf %q "$got"))" +# ====== +# The DEBUG trap had side effects on the exit status +# https://github.com/ksh93/ksh/issues/155 (#4) +trap ':' DEBUG +(exit 123) +(((e=$?)==123)) || err_exit "DEBUG trap run in subshell affects exit status (expected 123, got $e)" +r=$(exit 123) +(((e=$?)==123)) || err_exit "DEBUG trap run in \$(comsub) affects exit status (expected 123, got $e)" +r=`exit 123` +(((e=$?)==123)) || err_exit "DEBUG trap run in \`comsub\` affects exit status (expected 123, got $e)" +trap - DEBUG + # ====== exit $((Errors<125?Errors:125))