diff --git a/NEWS b/NEWS index e0d06810e..3fea6662b 100644 --- a/NEWS +++ b/NEWS @@ -7,6 +7,9 @@ Any uppercase BUG_* names are modernish shell bug IDs. - Fixed SHLVL so that replacing ksh by itself (exec ksh) will not increase it. +- Fixed a regression introduced on 2020-08-05 that caused a non-interactive + shell to exit if an I/O redirection of a function call encountered an error. + 2021-05-13: - Fixed a bug with 'test -t 1' that was introduced on 2021-04-26: diff --git a/src/cmd/ksh93/sh/xec.c b/src/cmd/ksh93/sh/xec.c index 898f414c8..71b753676 100644 --- a/src/cmd/ksh93/sh/xec.c +++ b/src/cmd/ksh93/sh/xec.c @@ -1550,7 +1550,7 @@ int sh_exec(register const Shnode_t *t, int flags) if(io) { indx = shp->topfd; - sh_pushcontext(shp,buffp,SH_JMPCMD); + sh_pushcontext(shp,buffp,SH_JMPIO); jmpval = sigsetjmp(buffp->buff,0); } if(jmpval == 0) diff --git a/src/cmd/ksh93/tests/exit.sh b/src/cmd/ksh93/tests/exit.sh index 882808500..1dbd07461 100755 --- a/src/cmd/ksh93/tests/exit.sh +++ b/src/cmd/ksh93/tests/exit.sh @@ -127,5 +127,57 @@ exp=1 [[ $exp == $status ]] || err_exit 'bare exit after false' \ "(expected '$exp', got '$status')" +# ====== +# Exit behaviour for commands, expansions and assignments +# https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_08_01 + +builtin -s | while read cmd +do + [[ $cmd == : ]] && continue # ':' never errors out + ("$cmd" --badoption; true) 2>/dev/null \ + && err_exit "Special built-in utility error does not cause shell to exit ($cmd)" + (command "$cmd" --badoption; true) 2>/dev/null \ + || err_exit "Error in special built-in utility prefixed by 'command' causes shell to exit ($cmd)" +done + +(command shift 10; true) 2>/dev/null \ +|| err_exit "Regular built-in utility error causes shell to exit" + +(readonly foo=bar; foo=baz; true) 2>/dev/null \ +&& err_exit "Variable assignment error does not cause shell to exit" + +(command true ${foo@bar}; true) 2>/dev/null \ +&& err_exit "Expansion error does not cause shell to exit" + +(/dev/null/nonexistent; true) 2>/dev/null \ +|| err_exit "Command not found causes shell to exit" + +# Exit behaviour for redirections + +(>/dev/null/nonexistent; true) 2>/dev/null \ +|| err_exit 'Error in lone redirection causes shell to exit' + +(: >/dev/null/nonexistent; true) 2>/dev/null \ +&& err_exit 'Redirection error with special built-in utility does not cause shell to exit' + +(false >/dev/null/nonexistent; true) 2>/dev/null \ +|| err_exit 'Redirection error with regular built-in utility causes shell to exit' + +("$(whence -p false)" >/dev/null/nonexistent; true) 2>/dev/null \ +|| err_exit 'Redirection error with external command causes shell to exit' + +(/dev/null/nonexistent >/dev/null/nonexistent; true) 2>/dev/null \ +|| err_exit 'Redirection error with nonexistent command causes shell to exit' + +(foo=bar >/dev/null/nonexistent; true) 2>/dev/null \ +|| err_exit 'Redirection error with variable assignment causes shell to exit' + +({ false; }; >/dev/null/nonexistent; true) 2>/dev/null \ +|| err_exit 'Redirection error with compound command causes shell to exit' + +# https://github.com/ksh93/ksh/issues/310 +(fn() { false; }; fn >/dev/null/nonexistent; true) 2>/dev/null \ +|| err_exit 'Redirection error with function execution causes shell to exit' + # ====== exit $((Errors<125?Errors:125))