1
0
Fork 0
mirror of git://git.code.sf.net/p/cdesktopenv/code synced 2025-02-15 04:32:24 +00:00

Correctly exit from namespace on error (re: f73b8617)

The referenced commit introduced at least one bug: EXIT traps were
not triggered if a special builtin threw an error in a namespace
that is within a virtual subshell.

src/cmd/ksh93/sh/xec.c: sh_exec(): TNSPACE:
- When an error occurs, siglongjmp to the previous saved
  environment; it is not correct to sh_exit directly.

src/cmd/ksh93/tests/namespace.sh:
- Remove the forkign workaround and the TODO where I incorrectly
  blamed this problem on the virtual subshell mechanism.
This commit is contained in:
Martijn Dekker 2022-06-02 03:19:16 +01:00
parent ea300089a1
commit 6dbde5ec7c
2 changed files with 2 additions and 5 deletions

View file

@ -2523,7 +2523,7 @@ int sh_exec(register const Shnode_t *t, int flags)
sh_popcontext(chkp); sh_popcontext(chkp);
enter_namespace(oldnspace); enter_namespace(oldnspace);
if(jmpval) /* error occurred */ if(jmpval) /* error occurred */
sh_exit(sh.exitval); siglongjmp(*sh.jmplist,jmpval);
break; break;
} }
#endif /* SHOPT_NAMESPACE */ #endif /* SHOPT_NAMESPACE */

View file

@ -133,11 +133,8 @@ set +o allexport
# ====== # ======
# A namespace's parent scope should be restored after an error occurs. # A namespace's parent scope should be restored after an error occurs.
# https://github.com/ksh93/ksh/issues/479#issuecomment-1140514159 # https://github.com/ksh93/ksh/issues/479#issuecomment-1140514159
#
# TODO: this test fails when run in a non-forking comsub: the trap
# is not executed -- the zillionth bug with virtual subshells >:-/
exp=$'123 456\n789 456' exp=$'123 456\n789 456'
got=$(ulimit -t unlimited 2>/dev/null # workaround: force fork got=$(
trap 'echo $x ${.test.x}; x=789; echo $x ${.test.x}' EXIT trap 'echo $x ${.test.x}; x=789; echo $x ${.test.x}' EXIT
x=123 x=123
namespace test namespace test