aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHerbert Xu <herbert@gondor.apana.org.au>2014-10-02 19:49:48 +0800
committerBen Hutchings <ben@decadent.org.uk>2020-03-28 21:42:54 +0000
commit9d16e7c25d87057eae0b8bbbd512dd768f409e01 (patch)
tree86226be6412956b9a3d283e9c7990e709f717c08
parent097a6e92dd6aea6d1e1e872c3aa02d677a004a88 (diff)
downloadklibc-9d16e7c25d87057eae0b8bbbd512dd768f409e01.tar.gz
[klibc] dash: [TRAP] Make sure evalskip is zero before running traps
[ dash commit d28c13e7119a605ef152a4310e9415dc7ae9b8f3 ] As it is if dotrap is called with evalskip set to a nonzero value, it'll try to execute any set traps. The result is that the first command in the first set trap will be executed while the rest of the trap will be silently ignored due to evalskip. This is highly counterintuitive, even though both bash and ksh exhibit a similar behaviour. This patch fixes it by skipping trap processing if evalskip is set on entry. It also adds a dotrap call to the top of evaltree to ensure that while continue; do continue; done has a chance of running traps. Finally the pendingsigs check is moved into dotrap for compactness. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
-rw-r--r--usr/dash/eval.c6
-rw-r--r--usr/dash/trap.c11
2 files changed, 13 insertions, 4 deletions
diff --git a/usr/dash/eval.c b/usr/dash/eval.c
index adf05fdec231c..578d8919f506f 100644
--- a/usr/dash/eval.c
+++ b/usr/dash/eval.c
@@ -197,6 +197,9 @@ evaltree(union node *n, int flags)
TRACE(("evaltree(NULL) called\n"));
goto out;
}
+
+ dotrap();
+
#ifndef SMALL
displayhist = 1; /* show history substitutions done with fc */
#endif
@@ -308,8 +311,7 @@ out:
if (checkexit & exitstatus)
goto exexit;
- if (pendingsigs)
- dotrap();
+ dotrap();
if (flags & EV_EXIT) {
exexit:
diff --git a/usr/dash/trap.c b/usr/dash/trap.c
index 182fa7ac9473e..3ff45318eef32 100644
--- a/usr/dash/trap.c
+++ b/usr/dash/trap.c
@@ -315,6 +315,9 @@ void dotrap(void)
int i;
int savestatus;
+ if (!pendingsigs)
+ return;
+
savestatus = exitstatus;
pendingsigs = 0;
barrier();
@@ -322,6 +325,12 @@ void dotrap(void)
for (i = 0, q = gotsig; i < NSIG - 1; i++, q++) {
if (!*q)
continue;
+
+ if (evalskip) {
+ pendingsigs = i + 1;
+ break;
+ }
+
*q = 0;
p = trap[i + 1];
@@ -329,8 +338,6 @@ void dotrap(void)
continue;
evalstring(p, 0);
exitstatus = savestatus;
- if (evalskip)
- break;
}
}