diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2007-04-28 16:45:59 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2007-04-28 16:45:59 +0000 |
commit | b5eaabb32221ece5d3a149cb3b49c439fa3647d5 (patch) | |
tree | 5d094f0dc3d45106f67a14026bcc164d6b8101c0 /shell/hush.c | |
parent | 3ac0e00553adcd7962dc99214fda5d4c3a2d811b (diff) | |
download | busybox-w32-b5eaabb32221ece5d3a149cb3b49c439fa3647d5.tar.gz busybox-w32-b5eaabb32221ece5d3a149cb3b49c439fa3647d5.tar.bz2 busybox-w32-b5eaabb32221ece5d3a149cb3b49c439fa3647d5.zip |
hush: add Ctrl-C handling to nofork case
Diffstat (limited to 'shell/hush.c')
-rw-r--r-- | shell/hush.c | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/shell/hush.c b/shell/hush.c index d249dd59e..9e13e4a2e 100644 --- a/shell/hush.c +++ b/shell/hush.c | |||
@@ -481,6 +481,13 @@ struct nofork_save_area nofork_save; | |||
481 | static sigjmp_buf nofork_jb; | 481 | static sigjmp_buf nofork_jb; |
482 | static struct pipe *nofork_pipe; | 482 | static struct pipe *nofork_pipe; |
483 | 483 | ||
484 | static void handler_ctrl_c(int sig) | ||
485 | { | ||
486 | debug_jobs_printf("got sig %d\n", sig); | ||
487 | // as usual we can have all kinds of nasty problems with leaked malloc data here | ||
488 | siglongjmp(nofork_jb, 1); | ||
489 | } | ||
490 | |||
484 | static void handler_ctrl_z(int sig) | 491 | static void handler_ctrl_z(int sig) |
485 | { | 492 | { |
486 | pid_t pid; | 493 | pid_t pid; |
@@ -1503,6 +1510,7 @@ static int run_single_fg_nofork(struct pipe *pi, const struct bb_applet *a, | |||
1503 | save_nofork_data(&nofork_save); | 1510 | save_nofork_data(&nofork_save); |
1504 | if (sigsetjmp(nofork_jb, 1) == 0) { | 1511 | if (sigsetjmp(nofork_jb, 1) == 0) { |
1505 | signal_SA_RESTART(SIGTSTP, handler_ctrl_z); | 1512 | signal_SA_RESTART(SIGTSTP, handler_ctrl_z); |
1513 | signal(SIGINT, handler_ctrl_c); | ||
1506 | rcode = run_nofork_applet_prime(&nofork_save, a, argv); | 1514 | rcode = run_nofork_applet_prime(&nofork_save, a, argv); |
1507 | if (--nofork_save.saved != 0) { | 1515 | if (--nofork_save.saved != 0) { |
1508 | /* Ctrl-Z forked, we are child */ | 1516 | /* Ctrl-Z forked, we are child */ |
@@ -1510,12 +1518,16 @@ static int run_single_fg_nofork(struct pipe *pi, const struct bb_applet *a, | |||
1510 | } | 1518 | } |
1511 | return rcode; | 1519 | return rcode; |
1512 | } | 1520 | } |
1513 | /* Ctrl-Z forked, we are parent. | 1521 | /* Ctrl-Z forked, we are parent; or Ctrl-C. |
1514 | * Sighandler has longjmped us here */ | 1522 | * Sighandler has longjmped us here */ |
1523 | signal(SIGINT, SIG_IGN); | ||
1515 | signal(SIGTSTP, SIG_IGN); | 1524 | signal(SIGTSTP, SIG_IGN); |
1516 | debug_jobs_printf("Exiting nofork early\n"); | 1525 | debug_jobs_printf("Exiting nofork early\n"); |
1517 | restore_nofork_data(&nofork_save); | 1526 | restore_nofork_data(&nofork_save); |
1518 | insert_bg_job(pi); | 1527 | if (nofork_save.saved == 0) /* Ctrl-Z, not Ctrl-C */ |
1528 | insert_bg_job(pi); | ||
1529 | else | ||
1530 | putchar('\n'); /* bash does this on Ctrl-C */ | ||
1519 | return 0; | 1531 | return 0; |
1520 | } | 1532 | } |
1521 | 1533 | ||
@@ -2467,7 +2479,7 @@ static int done_command(struct p_context *ctx) | |||
2467 | prog = pi->progs + pi->num_progs; | 2479 | prog = pi->progs + pi->num_progs; |
2468 | memset(prog, 0, sizeof(*prog)); | 2480 | memset(prog, 0, sizeof(*prog)); |
2469 | /*prog->redirects = NULL;*/ | 2481 | /*prog->redirects = NULL;*/ |
2470 | /*prog->argv = NULL; | 2482 | /*prog->argv = NULL; */ |
2471 | /*prog->is_stopped = 0;*/ | 2483 | /*prog->is_stopped = 0;*/ |
2472 | /*prog->group = NULL;*/ | 2484 | /*prog->group = NULL;*/ |
2473 | /*prog->glob_result.gl_pathv = NULL;*/ | 2485 | /*prog->glob_result.gl_pathv = NULL;*/ |