klibc-bot for Antonio Ospite
2020-Mar-28 21:49 UTC
[klibc] [klibc:update-dash] dash: eval: make traps work when "set -e" is enabled
Commit-ID: 7bab7bbbfb0b8914691de08ed22a5cbda336952e Gitweb: http://git.kernel.org/?p=libs/klibc/klibc.git;a=commit;h=7bab7bbbfb0b8914691de08ed22a5cbda336952e Author: Antonio Ospite <ao2 at ao2.it> AuthorDate: Tue, 16 Oct 2018 14:09:52 +0200 Committer: Ben Hutchings <ben at decadent.org.uk> CommitDate: Sat, 28 Mar 2020 21:42:55 +0000 [klibc] dash: eval: make traps work when "set -e" is enabled [ dash commit 06204f0c9f539fcb8cb532166656e80b81bd689a ] When "set -e" is enabled traps are not always executed, in particular the EXIT trap is not executed when the shell exits on an unhandled error. Consider the following test script: #!/bin/dash set -e trap 'ret=$?; echo "EXIT: $ret"' EXIT trap 'exit 2' HUP INT QUIT PIPE TERM read variable By pressing Ctrl-C one would expect the EXIT trap to be called, as it is the case with other shells (bash, zsh), but dash does not do it. By calling dotrap() before jumping to the exit path when checkexit is not zero, dash behaves like other shells. Signed-off-by: Antonio Ospite <ao2 at ao2.it> Signed-off-by: Herbert Xu <herbert at gondor.apana.org.au> Signed-off-by: Ben Hutchings <ben at decadent.org.uk> --- usr/dash/eval.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/usr/dash/eval.c b/usr/dash/eval.c index 01bc5234..09a5cbf1 100644 --- a/usr/dash/eval.c +++ b/usr/dash/eval.c @@ -307,11 +307,11 @@ setstatus: break; } out: + dotrap(); + if (checkexit & status) goto exexit; - dotrap(); - if (flags & EV_EXIT) { exexit: exraise(EXEXIT);
Seemingly Similar Threads
- [klibc:update-dash] [TRAP] Make sure evalskip is zero before running traps
- [klibc:update-dash] dash: [TRAP] Make sure evalskip is zero before running traps
- [klibc:update-dash] dash: eval: Silence compiler warning about missing parentheses
- [klibc:update-dash] eval: Return status in eval functions
- [klibc:update-dash] dash: eval: Return status in eval functions