[git commit] ash: [ERROR] Set exitstatus in onint

Denys Vlasenko vda.linux at googlemail.com
Sat Oct 1 14:03:11 UTC 2016


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

Partially backported this commit:

    Date: Thu, 2 Oct 2014 21:07:55 +0800
    [ERROR] Set exitstatus in onint

    Currently the exit status when we receive SIGINT is set in evalcommand
    which means that it doesn't always get set.  For example, if you press
    CTRL-C at the prompt of an interactive dash, the exit status is not
    set to 130 as it is in many other Bourne shells.

    This patch fixes this by moving the setting of the exit status into
    onint which also simplifies evalcommand.

    Signed-off-by: Herbert Xu <herbert at gondor.apana.org.au>

The part after "if (evalbltin(cmdentry.u.cmd, argc, argv, flags))"
causes testsuite failures in signal handling, so left unchanged.

Signed-off-by: Denys Vlasenko <vda.linux at googlemail.com>
---
 shell/ash.c | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/shell/ash.c b/shell/ash.c
index 644ef6c..06df07d 100644
--- a/shell/ash.c
+++ b/shell/ash.c
@@ -277,8 +277,10 @@ struct jmploc {
 };
 
 struct globals_misc {
-	/* pid of main shell */
-	int rootpid;
+	uint8_t exitstatus;     /* exit status of last command */
+	uint8_t back_exitstatus;/* exit status of backquoted command */
+	smallint job_warning;   /* user was warned about stopped jobs (can be 2, 1 or 0). */
+	int rootpid;            /* pid of main shell */
 	/* shell level: 0 for the main shell, 1 for its children, and so on */
 	int shlvl;
 #define rootshell (!shlvl)
@@ -355,10 +357,12 @@ struct globals_misc {
 	random_t random_gen;
 #endif
 	pid_t backgndpid;        /* pid of last background process */
-	smallint job_warning;    /* user was warned about stopped jobs (can be 2, 1 or 0). */
 };
 extern struct globals_misc *const ash_ptr_to_globals_misc;
 #define G_misc (*ash_ptr_to_globals_misc)
+#define exitstatus        (G_misc.exitstatus )
+#define back_exitstatus   (G_misc.back_exitstatus )
+#define job_warning       (G_misc.job_warning)
 #define rootpid     (G_misc.rootpid    )
 #define shlvl       (G_misc.shlvl      )
 #define minusc      (G_misc.minusc     )
@@ -380,7 +384,6 @@ extern struct globals_misc *const ash_ptr_to_globals_misc;
 #define trap_ptr    (G_misc.trap_ptr   )
 #define random_gen  (G_misc.random_gen )
 #define backgndpid  (G_misc.backgndpid )
-#define job_warning (G_misc.job_warning)
 #define INIT_G_misc() do { \
 	(*(struct globals_misc**)&ash_ptr_to_globals_misc) = xzalloc(sizeof(G_misc)); \
 	barrier(); \
@@ -498,6 +501,8 @@ raise_interrupt(void)
 		}
 		ex_type = EXINT;
 	}
+	/* bash: ^C even on empty command line sets $? */
+	exitstatus = SIGINT + 128;
 	raise_exception(ex_type);
 	/* NOTREACHED */
 }
@@ -1217,7 +1222,6 @@ static struct parsefile *g_parsefile = &basepf;  /* current input file */
 static int startlinno;                 /* line # where last token started */
 static char *commandname;              /* currently executing command */
 static struct strlist *cmdenviron;     /* environment for builtin command */
-static uint8_t exitstatus;             /* exit status of last command */
 
 
 /* ============ Message printing */
@@ -5877,7 +5881,6 @@ struct backcmd {                /* result of evalbackcmd */
 };
 
 /* These forward decls are needed to use "eval" code for backticks handling: */
-static uint8_t back_exitstatus; /* exit status of backquoted command */
 #define EV_EXIT 01              /* exit after evaluating tree */
 static int evaltree(union node *, int);
 


More information about the busybox-cvs mailing list