klibc-bot for Herbert Xu
2020-Mar-28 21:48 UTC
[klibc] [klibc:update-dash] dash: [TRAP] Make sure evalskip is zero before running traps
Commit-ID: 9d16e7c25d87057eae0b8bbbd512dd768f409e01 Gitweb: http://git.kernel.org/?p=libs/klibc/klibc.git;a=commit;h=9d16e7c25d87057eae0b8bbbd512dd768f409e01 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: Sat, 28 Mar 2020 21:42:54 +0000 [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 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 adf05fde..578d8919 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; } }
Possibly Parallel Threads
- [klibc:update-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