klibc-bot for Herbert Xu
2019-Jan-25 03:15 UTC
[klibc] [klibc:update-dash] [TRAP] Make sure evalskip is zero before running traps
Commit-ID: e6ebc6f4137090ec4ce858bdb0fe674774173e57 Gitweb: http://git.kernel.org/?p=libs/klibc/klibc.git;a=commit;h=e6ebc6f4137090ec4ce858bdb0fe674774173e57 Author: Herbert Xu <herbert at gondor.apana.org.au> AuthorDate: Thu, 2 Oct 2014 19:49:48 +0800 Committer: Ben Hutchings <ben at decadent.org.uk> CommitDate: Fri, 25 Jan 2019 02:57:21 +0000 [klibc] [TRAP] Make sure evalskip is zero before running traps 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 at gondor.apana.org.au> Signed-off-by: Ben Hutchings <ben at decadent.org.uk> --- usr/dash/eval.c | 6 ++++-- usr/dash/trap.c | 11 +++++++++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/usr/dash/eval.c b/usr/dash/eval.c index 755136e2..741bf120 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 182fa7ac..3ff45318 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; } }
Seemingly Similar Threads
- [klibc:update-dash] dash: [TRAP] Make sure evalskip is zero before running traps
- [klibc:update-dash] [BUILTIN] Exit without arguments in a trap should use status outside traps
- [klibc:update-dash] dash: [BUILTIN] Exit without arguments in a trap should use status outside traps
- [klibc:update-dash] trap: Globally rename pendingsigs to pending_sig
- [klibc:update-dash] dash: trap: Globally rename pendingsigs to pending_sig