[git commit] ash: mkinit: Split reset into exitreset and reset

Denys Vlasenko vda.linux at googlemail.com
Mon Feb 17 10:22:59 UTC 2020


commit: https://git.busybox.net/busybox/commit/?id=afc91faeddd6b8234dccea2f7913f57a5bb3d1ec
branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master

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 at gondor.apana.org.au>

Signed-off-by: Denys Vlasenko <vda.linux at googlemail.com>
---
 shell/ash.c | 26 +++++++++++++++++++-------
 1 file 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)
 
 /*
  * This routine is called when an error or an interrupt occurs in an
- * interactive shell and control is returned to the main command loop.
- * (In dash, this function is auto-generated by build machinery).
+ * interactive shell and control is returned to the main command loop
+ * but prior to exitshell.
  */
 static void
-reset(void)
+exitreset(void)
 {
 	/* from eval.c: */
 	evalskip = 0;
@@ -14301,14 +14301,23 @@ reset(void)
 	/* from expand.c: */
 	ifsfree();
 
+	/* from redir.c: */
+	unwindredir(NULL);
+}
+
+/*
+ * This routine is called when an error or an interrupt occurs in an
+ * interactive shell and control is returned to the main command loop.
+ * (In dash, this function is auto-generated by build machinery).
+ */
+static void
+reset(void)
+{
 	/* from input.c: */
 	g_parsefile->left_in_buffer = 0;
 	g_parsefile->left_in_line = 0;      /* clear input buffer */
 	popallfiles();
 
-	/* from redir.c: */
-	unwindredir(NULL);
-
 	/* from var.c: */
 	unwindlocalvars(NULL);
 }
@@ -14356,13 +14365,16 @@ int ash_main(int argc UNUSED_PARAM, char **argv)
 		smallint e;
 		smallint s;
 
-		reset();
+		exitreset();
 
 		e = exception_type;
 		s = state;
 		if (e == EXEXIT || s == 0 || iflag == 0 || shlvl) {
 			exitshell();
 		}
+
+		reset();
+
 		if (e == EXINT) {
 			newline_and_flush(stderr);
 		}


More information about the busybox-cvs mailing list