aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2020-02-17 11:22:59 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2020-02-17 11:22:59 +0100
commitafc91faeddd6b8234dccea2f7913f57a5bb3d1ec (patch)
treeae4b2d8f7802cc94987841832d010ba3129773a1
parent9ee5892798be81f7a6f3e070ecd52cbf0d55740e (diff)
downloadbusybox-w32-afc91faeddd6b8234dccea2f7913f57a5bb3d1ec.tar.gz
busybox-w32-afc91faeddd6b8234dccea2f7913f57a5bb3d1ec.tar.bz2
busybox-w32-afc91faeddd6b8234dccea2f7913f57a5bb3d1ec.zip
ash: mkinit: Split reset into exitreset and reset
Upstream commit: Date: Sat, 19 May 2018 02:39:40 +0800 mkinit: Split reset into exitreset and reset 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: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--shell/ash.c26
1 files changed, 19 insertions, 7 deletions
diff --git a/shell/ash.c b/shell/ash.c
index dfe6d1c48..fbe8dd9e4 100644
--- a/shell/ash.c
+++ b/shell/ash.c
@@ -14284,11 +14284,11 @@ read_profile(const char *name)
14284 14284
14285/* 14285/*
14286 * This routine is called when an error or an interrupt occurs in an 14286 * This routine is called when an error or an interrupt occurs in an
14287 * interactive shell and control is returned to the main command loop. 14287 * interactive shell and control is returned to the main command loop
14288 * (In dash, this function is auto-generated by build machinery). 14288 * but prior to exitshell.
14289 */ 14289 */
14290static void 14290static void
14291reset(void) 14291exitreset(void)
14292{ 14292{
14293 /* from eval.c: */ 14293 /* from eval.c: */
14294 evalskip = 0; 14294 evalskip = 0;
@@ -14301,14 +14301,23 @@ reset(void)
14301 /* from expand.c: */ 14301 /* from expand.c: */
14302 ifsfree(); 14302 ifsfree();
14303 14303
14304 /* from redir.c: */
14305 unwindredir(NULL);
14306}
14307
14308/*
14309 * This routine is called when an error or an interrupt occurs in an
14310 * interactive shell and control is returned to the main command loop.
14311 * (In dash, this function is auto-generated by build machinery).
14312 */
14313static void
14314reset(void)
14315{
14304 /* from input.c: */ 14316 /* from input.c: */
14305 g_parsefile->left_in_buffer = 0; 14317 g_parsefile->left_in_buffer = 0;
14306 g_parsefile->left_in_line = 0; /* clear input buffer */ 14318 g_parsefile->left_in_line = 0; /* clear input buffer */
14307 popallfiles(); 14319 popallfiles();
14308 14320
14309 /* from redir.c: */
14310 unwindredir(NULL);
14311
14312 /* from var.c: */ 14321 /* from var.c: */
14313 unwindlocalvars(NULL); 14322 unwindlocalvars(NULL);
14314} 14323}
@@ -14356,13 +14365,16 @@ int ash_main(int argc UNUSED_PARAM, char **argv)
14356 smallint e; 14365 smallint e;
14357 smallint s; 14366 smallint s;
14358 14367
14359 reset(); 14368 exitreset();
14360 14369
14361 e = exception_type; 14370 e = exception_type;
14362 s = state; 14371 s = state;
14363 if (e == EXEXIT || s == 0 || iflag == 0 || shlvl) { 14372 if (e == EXEXIT || s == 0 || iflag == 0 || shlvl) {
14364 exitshell(); 14373 exitshell();
14365 } 14374 }
14375
14376 reset();
14377
14366 if (e == EXINT) { 14378 if (e == EXINT) {
14367 newline_and_flush(stderr); 14379 newline_and_flush(stderr);
14368 } 14380 }