aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2016-10-01 16:03:11 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2016-10-01 16:03:11 +0200
commit4d12e944eaf54f0fd0bbb6b70abbb77648cca795 (patch)
treed9e8e2ef51b204e2a3a515343c15bf74329c2021
parent0840c91909dd6a9a676ec105ef1ca5e8d36ce6e8 (diff)
downloadbusybox-w32-4d12e944eaf54f0fd0bbb6b70abbb77648cca795.tar.gz
busybox-w32-4d12e944eaf54f0fd0bbb6b70abbb77648cca795.tar.bz2
busybox-w32-4d12e944eaf54f0fd0bbb6b70abbb77648cca795.zip
ash: [ERROR] Set exitstatus in onint
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@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@googlemail.com>
-rw-r--r--shell/ash.c15
1 files changed, 9 insertions, 6 deletions
diff --git a/shell/ash.c b/shell/ash.c
index 644ef6c9d..06df07d06 100644
--- a/shell/ash.c
+++ b/shell/ash.c
@@ -277,8 +277,10 @@ struct jmploc {
277}; 277};
278 278
279struct globals_misc { 279struct globals_misc {
280 /* pid of main shell */ 280 uint8_t exitstatus; /* exit status of last command */
281 int rootpid; 281 uint8_t back_exitstatus;/* exit status of backquoted command */
282 smallint job_warning; /* user was warned about stopped jobs (can be 2, 1 or 0). */
283 int rootpid; /* pid of main shell */
282 /* shell level: 0 for the main shell, 1 for its children, and so on */ 284 /* shell level: 0 for the main shell, 1 for its children, and so on */
283 int shlvl; 285 int shlvl;
284#define rootshell (!shlvl) 286#define rootshell (!shlvl)
@@ -355,10 +357,12 @@ struct globals_misc {
355 random_t random_gen; 357 random_t random_gen;
356#endif 358#endif
357 pid_t backgndpid; /* pid of last background process */ 359 pid_t backgndpid; /* pid of last background process */
358 smallint job_warning; /* user was warned about stopped jobs (can be 2, 1 or 0). */
359}; 360};
360extern struct globals_misc *const ash_ptr_to_globals_misc; 361extern struct globals_misc *const ash_ptr_to_globals_misc;
361#define G_misc (*ash_ptr_to_globals_misc) 362#define G_misc (*ash_ptr_to_globals_misc)
363#define exitstatus (G_misc.exitstatus )
364#define back_exitstatus (G_misc.back_exitstatus )
365#define job_warning (G_misc.job_warning)
362#define rootpid (G_misc.rootpid ) 366#define rootpid (G_misc.rootpid )
363#define shlvl (G_misc.shlvl ) 367#define shlvl (G_misc.shlvl )
364#define minusc (G_misc.minusc ) 368#define minusc (G_misc.minusc )
@@ -380,7 +384,6 @@ extern struct globals_misc *const ash_ptr_to_globals_misc;
380#define trap_ptr (G_misc.trap_ptr ) 384#define trap_ptr (G_misc.trap_ptr )
381#define random_gen (G_misc.random_gen ) 385#define random_gen (G_misc.random_gen )
382#define backgndpid (G_misc.backgndpid ) 386#define backgndpid (G_misc.backgndpid )
383#define job_warning (G_misc.job_warning)
384#define INIT_G_misc() do { \ 387#define INIT_G_misc() do { \
385 (*(struct globals_misc**)&ash_ptr_to_globals_misc) = xzalloc(sizeof(G_misc)); \ 388 (*(struct globals_misc**)&ash_ptr_to_globals_misc) = xzalloc(sizeof(G_misc)); \
386 barrier(); \ 389 barrier(); \
@@ -498,6 +501,8 @@ raise_interrupt(void)
498 } 501 }
499 ex_type = EXINT; 502 ex_type = EXINT;
500 } 503 }
504 /* bash: ^C even on empty command line sets $? */
505 exitstatus = SIGINT + 128;
501 raise_exception(ex_type); 506 raise_exception(ex_type);
502 /* NOTREACHED */ 507 /* NOTREACHED */
503} 508}
@@ -1217,7 +1222,6 @@ static struct parsefile *g_parsefile = &basepf; /* current input file */
1217static int startlinno; /* line # where last token started */ 1222static int startlinno; /* line # where last token started */
1218static char *commandname; /* currently executing command */ 1223static char *commandname; /* currently executing command */
1219static struct strlist *cmdenviron; /* environment for builtin command */ 1224static struct strlist *cmdenviron; /* environment for builtin command */
1220static uint8_t exitstatus; /* exit status of last command */
1221 1225
1222 1226
1223/* ============ Message printing */ 1227/* ============ Message printing */
@@ -5877,7 +5881,6 @@ struct backcmd { /* result of evalbackcmd */
5877}; 5881};
5878 5882
5879/* These forward decls are needed to use "eval" code for backticks handling: */ 5883/* These forward decls are needed to use "eval" code for backticks handling: */
5880static uint8_t back_exitstatus; /* exit status of backquoted command */
5881#define EV_EXIT 01 /* exit after evaluating tree */ 5884#define EV_EXIT 01 /* exit after evaluating tree */
5882static int evaltree(union node *, int); 5885static int evaltree(union node *, int);
5883 5886