klibc-bot for Herbert Xu
2020-Mar-28 21:49 UTC
[klibc] [klibc:update-dash] dash: eval: Only restore exit status on exit/return
Commit-ID: 0d63aab8d433cd244e221aee978d2bcd4153cd1a Gitweb: http://git.kernel.org/?p=libs/klibc/klibc.git;a=commit;h=0d63aab8d433cd244e221aee978d2bcd4153cd1a Author: Herbert Xu <herbert at gondor.apana.org.au> AuthorDate: Fri, 14 Dec 2018 13:52:02 +0800 Committer: Ben Hutchings <ben at decadent.org.uk> CommitDate: Sat, 28 Mar 2020 21:42:55 +0000 [klibc] dash: eval: Only restore exit status on exit/return [ dash commit 62cf6955f8abe875752d7163f6f3adbc7e49ebae ] We unconditionally restore the saved status in exitreset, which is incorrect as we only want to do it for exitcmd and returncmd. This patch fixes the problem by introducing EXEND. Reported-by: Martijn Dekker <martijn at inlv.org> Fixes: da30b4b78769 ("[BUILTIN] Exit without arguments in a trap...") Signed-off-by: Herbert Xu <herbert at gondor.apana.org.au> Signed-off-by: Ben Hutchings <ben at decadent.org.uk> --- usr/dash/error.h | 3 ++- usr/dash/eval.c | 9 +++++---- usr/dash/exec.c | 2 +- usr/dash/main.c | 2 +- usr/dash/trap.c | 5 ++++- 5 files changed, 13 insertions(+), 8 deletions(-) diff --git a/usr/dash/error.h b/usr/dash/error.h index f91d11d1..8df0134f 100644 --- a/usr/dash/error.h +++ b/usr/dash/error.h @@ -69,7 +69,8 @@ extern int exception; /* exceptions */ #define EXINT 0 /* SIGINT received */ #define EXERROR 1 /* a generic error */ -#define EXEXIT 4 /* exit the shell */ +#define EXEND 3 /* exit the shell */ +#define EXEXIT 4 /* exit the shell via exitcmd */ /* diff --git a/usr/dash/eval.c b/usr/dash/eval.c index bba0e7f8..1aad31a0 100644 --- a/usr/dash/eval.c +++ b/usr/dash/eval.c @@ -114,12 +114,13 @@ STATIC const struct builtincmd bltin = { INCLUDE "eval.h" EXITRESET { - evalskip = 0; - loopnest = 0; if (savestatus >= 0) { - exitstatus = savestatus; + if (exception == EXEXIT || evalskip == SKIPFUNCDEF) + exitstatus = savestatus; savestatus = -1; } + evalskip = 0; + loopnest = 0; } #endif @@ -318,7 +319,7 @@ out: if (flags & EV_EXIT) { exexit: - exraise(EXEXIT); + exraise(EXEND); } popstackmark(&smark); diff --git a/usr/dash/exec.c b/usr/dash/exec.c index 9d0215a6..87354d49 100644 --- a/usr/dash/exec.c +++ b/usr/dash/exec.c @@ -143,7 +143,7 @@ shellexec(char **argv, const char *path, int idx) exitstatus = exerrno; TRACE(("shellexec failed for %s, errno %d, suppressint %d\n", argv[0], e, suppressint )); - exerror(EXEXIT, "%s: %s", argv[0], errmsg(e, E_EXEC)); + exerror(EXEND, "%s: %s", argv[0], errmsg(e, E_EXEC)); /* NOTREACHED */ } diff --git a/usr/dash/main.c b/usr/dash/main.c index 6d53e009..6b3a0909 100644 --- a/usr/dash/main.c +++ b/usr/dash/main.c @@ -111,7 +111,7 @@ main(int argc, char **argv) e = exception; s = state; - if (e == EXEXIT || s == 0 || iflag == 0 || shlvl) + if (e == EXEND || e == EXEXIT || s == 0 || iflag == 0 || shlvl) exitshell(); reset(); diff --git a/usr/dash/trap.c b/usr/dash/trap.c index 1ad27e99..838008d2 100644 --- a/usr/dash/trap.c +++ b/usr/dash/trap.c @@ -42,6 +42,7 @@ #include "main.h" #include "nodes.h" /* for other headers */ #include "eval.h" +#include "init.h" #include "jobs.h" #include "show.h" #include "options.h" @@ -396,8 +397,10 @@ exitshell(void) trap[0] = NULL; evalskip = 0; evalstring(p, 0); + evalskip = SKIPFUNCDEF; } out: + exitreset(); /* * Disable job control so that whoever had the foreground before we * started can get it back. @@ -405,7 +408,7 @@ out: if (likely(!setjmp(loc.loc))) setjobctl(0); flushall(); - _exit(savestatus); + _exit(exitstatus); /* NOTREACHED */ }
Maybe Matching Threads
- [klibc:update-dash] dash: mkinit: Split reset into exitreset and reset
- [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] [BUILTIN] Return without arguments in a trap should use status outside traps
- [klibc:update-dash] dash: [BUILTIN] Return without arguments in a trap should use status outside traps