diff options
author | Herbert Xu <herbert@gondor.apana.org.au> | 2018-05-19 02:39:40 +0800 |
---|---|---|
committer | Ben Hutchings <ben@decadent.org.uk> | 2020-03-28 21:42:55 +0000 |
commit | 7f799aacc75667708bafe8f4411891ec053d7d65 (patch) | |
tree | 64fa4e3e1764a118fac369f90f75f75fd6cfc61d | |
parent | bb0a62dfa61fec6497f1409c3cdfe8ceec94f1fa (diff) | |
download | klibc-7f799aacc75667708bafe8f4411891ec053d7d65.tar.gz |
[klibc] dash: mkinit: Split reset into exitreset and reset
[ dash commit 983085923ae1d45196868b48f576b1a19e03e72b ]
Previously reset was called after exitshell. This was changed
so that it was called before exitshell because certain state needed
to be reset in order for the EXIT trap to work.
However, this caused issues because certain other states (such
as local variables) should not be reset. This patch fixes this
by creating a new function exitreset that is called prior to
exitshell and moving reset back to its original location.
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.c | 2 | ||||
-rw-r--r-- | usr/dash/expand.c | 2 | ||||
-rw-r--r-- | usr/dash/init.h | 2 | ||||
-rw-r--r-- | usr/dash/main.c | 4 | ||||
-rw-r--r-- | usr/dash/mkinit.c | 8 | ||||
-rw-r--r-- | usr/dash/redir.c | 2 |
6 files changed, 15 insertions, 5 deletions
diff --git a/usr/dash/eval.c b/usr/dash/eval.c index 13e690e74765f..ff27ba9c85288 100644 --- a/usr/dash/eval.c +++ b/usr/dash/eval.c @@ -112,7 +112,7 @@ STATIC const struct builtincmd bltin = { #ifdef mkinit INCLUDE "eval.h" -RESET { +EXITRESET { evalskip = 0; loopnest = 0; if (savestatus >= 0) { diff --git a/usr/dash/expand.c b/usr/dash/expand.c index 59a202cb7602b..6ea0562ff0a22 100644 --- a/usr/dash/expand.c +++ b/usr/dash/expand.c @@ -1780,7 +1780,7 @@ varunset(const char *end, const char *var, const char *umsg, int varflags) INCLUDE "expand.h" -RESET { +EXITRESET { ifsfree(); } diff --git a/usr/dash/init.h b/usr/dash/init.h index e026e86862fed..49791a07330e1 100644 --- a/usr/dash/init.h +++ b/usr/dash/init.h @@ -35,5 +35,5 @@ */ void init(void); +void exitreset(void); void reset(void); -void initshellproc(void); diff --git a/usr/dash/main.c b/usr/dash/main.c index 9f0371733aeed..8b3511891ce45 100644 --- a/usr/dash/main.c +++ b/usr/dash/main.c @@ -106,7 +106,7 @@ main(int argc, char **argv) int e; int s; - reset(); + exitreset(); e = exception; @@ -114,6 +114,8 @@ main(int argc, char **argv) if (e == EXEXIT || s == 0 || iflag == 0 || shlvl) exitshell(); + reset(); + if (e == EXINT #if ATTY && (! attyset() || equal(termval(), "emacs")) diff --git a/usr/dash/mkinit.c b/usr/dash/mkinit.c index 9714bee0659de..5bca9ee8b556b 100644 --- a/usr/dash/mkinit.c +++ b/usr/dash/mkinit.c @@ -106,6 +106,13 @@ char init[] = "\ * Initialization code.\n\ */\n"; +char exitreset[] = "\ +/*\n\ + * This routine is called when an error or an interrupt occurs in an\n\ + * interactive shell and control is returned to the main command loop\n\ + * but prior to exitshell. \n\ + */\n"; + char reset[] = "\ /*\n\ * This routine is called when an error or an interrupt occurs in an\n\ @@ -115,6 +122,7 @@ char reset[] = "\ struct event event[] = { {"INIT", "init", init}, + {"EXITRESET", "exitreset", exitreset}, {"RESET", "reset", reset}, {NULL, NULL} }; diff --git a/usr/dash/redir.c b/usr/dash/redir.c index 71b0f77412bf4..e67cc0ab960bc 100644 --- a/usr/dash/redir.c +++ b/usr/dash/redir.c @@ -374,7 +374,7 @@ popredir(int drop) INCLUDE "redir.h" -RESET { +EXITRESET { /* * Discard all saved file descriptors. */ |