summaryrefslogtreecommitdiffstats
path: root/bin/sh
diff options
context:
space:
mode:
authorjilles <jilles@FreeBSD.org>2013-03-03 17:33:59 +0000
committerjilles <jilles@FreeBSD.org>2013-03-03 17:33:59 +0000
commitd0155c5dccc3af5494798ad79b42ad906bfd8671 (patch)
tree8f22588cd3d7dd9680e3d8df2bb3c64c95436187 /bin/sh
parent82dd943a5ebeb1f62f5815e263e3de810e3fbf55 (diff)
downloadFreeBSD-src-d0155c5dccc3af5494798ad79b42ad906bfd8671.zip
FreeBSD-src-d0155c5dccc3af5494798ad79b42ad906bfd8671.tar.gz
sh: When executing a trap, keep exit status along with evalskip.
This ensures 'return' in a trap returns the correct status to the caller. If evalskip is not set or if it is overridden by a previous evalskip, keep the old behaviour of restoring the exit status from before the trap.
Diffstat (limited to 'bin/sh')
-rw-r--r--bin/sh/trap.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/bin/sh/trap.c b/bin/sh/trap.c
index 0a9eb60..6c4cbbe 100644
--- a/bin/sh/trap.c
+++ b/bin/sh/trap.c
@@ -455,7 +455,6 @@ dotrap(void)
last_trapsig = i;
savestatus = exitstatus;
evalstring(trap[i], 0);
- exitstatus = savestatus;
/*
* If such a command was not
@@ -464,9 +463,11 @@ dotrap(void)
* trap action to have an effect
* outside of it.
*/
- if (prev_evalskip != 0) {
+ if (evalskip == 0 ||
+ prev_evalskip != 0) {
evalskip = prev_evalskip;
skipcount = prev_skipcount;
+ exitstatus = savestatus;
}
if (i == SIGCHLD)
OpenPOWER on IntegriCloud