diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2009-04-15 23:29:00 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2009-04-15 23:29:00 +0000 |
commit | c4ada7934307c6ef0b5b207df13a54fecd4ad81d (patch) | |
tree | d2adde9e3873aff2a9725a8219fa6aa2577d6937 | |
parent | 41ddecd9ed27239e478e65886fec3f0fd23f8cdb (diff) | |
download | busybox-w32-c4ada7934307c6ef0b5b207df13a54fecd4ad81d.tar.gz busybox-w32-c4ada7934307c6ef0b5b207df13a54fecd4ad81d.tar.bz2 busybox-w32-c4ada7934307c6ef0b5b207df13a54fecd4ad81d.zip |
hush: remove old disabled ^Z handling
-rw-r--r-- | shell/hush.c | 75 |
1 files changed, 7 insertions, 68 deletions
diff --git a/shell/hush.c b/shell/hush.c index 1753be0d1..16f304d81 100644 --- a/shell/hush.c +++ b/shell/hush.c | |||
@@ -56,7 +56,6 @@ | |||
56 | * figure out what to do with backslash-newline | 56 | * figure out what to do with backslash-newline |
57 | * continuation lines, both explicit and implicit - done? | 57 | * continuation lines, both explicit and implicit - done? |
58 | * SIGHUP handling | 58 | * SIGHUP handling |
59 | * ^Z handling (and explain it in comments for mere humans) | ||
60 | * separate job control from interactiveness | 59 | * separate job control from interactiveness |
61 | * (testcase: booting with init=/bin/hush does not show prompt (2009-04)) | 60 | * (testcase: booting with init=/bin/hush does not show prompt (2009-04)) |
62 | * | 61 | * |
@@ -432,7 +431,6 @@ struct globals { | |||
432 | int last_jobid; | 431 | int last_jobid; |
433 | struct pipe *job_list; | 432 | struct pipe *job_list; |
434 | struct pipe *toplevel_list; | 433 | struct pipe *toplevel_list; |
435 | //// smallint ctrl_z_flag; | ||
436 | #endif | 434 | #endif |
437 | smallint flag_SIGINT; | 435 | smallint flag_SIGINT; |
438 | #if ENABLE_HUSH_LOOPS | 436 | #if ENABLE_HUSH_LOOPS |
@@ -474,12 +472,6 @@ struct globals { | |||
474 | int debug_indent; | 472 | int debug_indent; |
475 | #endif | 473 | #endif |
476 | char user_input_buf[ENABLE_FEATURE_EDITING ? BUFSIZ : 2]; | 474 | char user_input_buf[ENABLE_FEATURE_EDITING ? BUFSIZ : 2]; |
477 | #if ENABLE_FEATURE_SH_STANDALONE | ||
478 | struct nofork_save_area nofork_save; | ||
479 | #endif | ||
480 | #if ENABLE_HUSH_JOB | ||
481 | sigjmp_buf toplevel_jb; | ||
482 | #endif | ||
483 | }; | 475 | }; |
484 | #define G (*ptr_to_globals) | 476 | #define G (*ptr_to_globals) |
485 | /* Not #defining name to G.name - this quickly gets unwieldy | 477 | /* Not #defining name to G.name - this quickly gets unwieldy |
@@ -977,13 +969,14 @@ static void free_strings(char **strings) | |||
977 | * SIGHUP (interactive): | 969 | * SIGHUP (interactive): |
978 | * send SIGCONT to stopped jobs, send SIGHUP to all jobs and exit | 970 | * send SIGCONT to stopped jobs, send SIGHUP to all jobs and exit |
979 | * SIGTTIN, SIGTTOU, SIGTSTP (if job control is on): ignore | 971 | * SIGTTIN, SIGTTOU, SIGTSTP (if job control is on): ignore |
980 | * (note that ^Z is handled not by trapping SIGTSTP, but by seeing | 972 | * Note that ^Z is handled not by trapping SIGTSTP, but by seeing |
981 | * that all pipe members are stopped) (right?) | 973 | * that all pipe members are stopped. Try this in bash: |
974 | * while :; do :; done - ^Z does not background it | ||
975 | * (while :; do :; done) - ^Z backgrounds it | ||
982 | * SIGINT (interactive): wait for last pipe, ignore the rest | 976 | * SIGINT (interactive): wait for last pipe, ignore the rest |
983 | * of the command line, show prompt. NB: ^C does not send SIGINT | 977 | * of the command line, show prompt. NB: ^C does not send SIGINT |
984 | * to interactive shell while shell is waiting for a pipe, | 978 | * to interactive shell while shell is waiting for a pipe, |
985 | * since shell is bg'ed (is not in foreground process group). | 979 | * since shell is bg'ed (is not in foreground process group). |
986 | * (check/expand this) | ||
987 | * Example 1: this waits 5 sec, but does not execute ls: | 980 | * Example 1: this waits 5 sec, but does not execute ls: |
988 | * "echo $$; sleep 5; ls -l" + "kill -INT <pid>" | 981 | * "echo $$; sleep 5; ls -l" + "kill -INT <pid>" |
989 | * Example 2: this does not wait and does not execute ls: | 982 | * Example 2: this does not wait and does not execute ls: |
@@ -3411,12 +3404,11 @@ static int run_pipe(struct pipe *pi) | |||
3411 | if (i >= 0 && APPLET_IS_NOFORK(i)) { | 3404 | if (i >= 0 && APPLET_IS_NOFORK(i)) { |
3412 | rcode = setup_redirects(command, squirrel); | 3405 | rcode = setup_redirects(command, squirrel); |
3413 | if (rcode == 0) { | 3406 | if (rcode == 0) { |
3414 | save_nofork_data(&G.nofork_save); | ||
3415 | new_env = expand_assignments(argv, command->assignment_cnt); | 3407 | new_env = expand_assignments(argv, command->assignment_cnt); |
3416 | old_env = putenv_all_and_save_old(new_env); | 3408 | old_env = putenv_all_and_save_old(new_env); |
3417 | debug_printf_exec(": run_nofork_applet '%s' '%s'...\n", | 3409 | debug_printf_exec(": run_nofork_applet '%s' '%s'...\n", |
3418 | argv_expanded[0], argv_expanded[1]); | 3410 | argv_expanded[0], argv_expanded[1]); |
3419 | rcode = run_nofork_applet_prime(&G.nofork_save, i, argv_expanded); | 3411 | rcode = run_nofork_applet(i, argv_expanded); |
3420 | } | 3412 | } |
3421 | goto clean_up_and_ret; | 3413 | goto clean_up_and_ret; |
3422 | } | 3414 | } |
@@ -3643,7 +3635,7 @@ static int run_list(struct pipe *pi) | |||
3643 | smallint last_rword; /* ditto */ | 3635 | smallint last_rword; /* ditto */ |
3644 | #endif | 3636 | #endif |
3645 | 3637 | ||
3646 | debug_printf_exec("run_list start lvl %d\n", G.run_list_level + 1); | 3638 | debug_printf_exec("run_list start lvl %d\n", G.run_list_level); |
3647 | debug_enter(); | 3639 | debug_enter(); |
3648 | 3640 | ||
3649 | #if ENABLE_HUSH_LOOPS | 3641 | #if ENABLE_HUSH_LOOPS |
@@ -3677,51 +3669,9 @@ static int run_list(struct pipe *pi) | |||
3677 | * in order to return, no direct "return" statements please. | 3669 | * in order to return, no direct "return" statements please. |
3678 | * This helps to ensure that no memory is leaked. */ | 3670 | * This helps to ensure that no memory is leaked. */ |
3679 | 3671 | ||
3680 | ////TODO: ctrl-Z handling needs re-thinking and re-testing | ||
3681 | |||
3682 | #if ENABLE_HUSH_JOB | 3672 | #if ENABLE_HUSH_JOB |
3683 | /* Example of nested list: "while true; do { sleep 1 | exit 2; } done". | 3673 | G.run_list_level++; |
3684 | * We are saving state before entering outermost list ("while...done") | ||
3685 | * so that ctrl-Z will correctly background _entire_ outermost list, | ||
3686 | * not just a part of it (like "sleep 1 | exit 2") */ | ||
3687 | if (++G.run_list_level == 1 && G_interactive_fd) { | ||
3688 | if (sigsetjmp(G.toplevel_jb, 1)) { | ||
3689 | /* ctrl-Z forked and we are parent; or ctrl-C. | ||
3690 | * Sighandler has longjmped us here */ | ||
3691 | signal(SIGINT, SIG_IGN); | ||
3692 | signal(SIGTSTP, SIG_IGN); | ||
3693 | /* Restore level (we can be coming from deep inside | ||
3694 | * nested levels) */ | ||
3695 | G.run_list_level = 1; | ||
3696 | #if ENABLE_FEATURE_SH_STANDALONE | ||
3697 | if (G.nofork_save.saved) { /* if save area is valid */ | ||
3698 | debug_printf_jobs("exiting nofork early\n"); | ||
3699 | restore_nofork_data(&G.nofork_save); | ||
3700 | } | ||
3701 | #endif | ||
3702 | //// if (G.ctrl_z_flag) { | ||
3703 | //// /* ctrl-Z has forked and stored pid of the child in pi->pid. | ||
3704 | //// * Remember this child as background job */ | ||
3705 | //// insert_bg_job(pi); | ||
3706 | //// } else { | ||
3707 | /* ctrl-C. We just stop doing whatever we were doing */ | ||
3708 | bb_putchar('\n'); | ||
3709 | //// } | ||
3710 | USE_HUSH_LOOPS(loop_top = NULL;) | ||
3711 | USE_HUSH_LOOPS(G.depth_of_loop = 0;) | ||
3712 | rcode = 0; | ||
3713 | goto ret; | ||
3714 | } | ||
3715 | //// /* ctrl-Z handler will store pid etc in pi */ | ||
3716 | //// G.toplevel_list = pi; | ||
3717 | //// G.ctrl_z_flag = 0; | ||
3718 | #if ENABLE_FEATURE_SH_STANDALONE | ||
3719 | G.nofork_save.saved = 0; /* in case we will run a nofork later */ | ||
3720 | #endif | 3674 | #endif |
3721 | //// signal_SA_RESTART_empty_mask(SIGTSTP, handler_ctrl_z); | ||
3722 | //// signal(SIGINT, handler_ctrl_c); | ||
3723 | } | ||
3724 | #endif /* JOB */ | ||
3725 | 3675 | ||
3726 | #if HAS_KEYWORDS | 3676 | #if HAS_KEYWORDS |
3727 | rword = RES_NONE; | 3677 | rword = RES_NONE; |
@@ -3967,18 +3917,7 @@ static int run_list(struct pipe *pi) | |||
3967 | } /* for (pi) */ | 3917 | } /* for (pi) */ |
3968 | 3918 | ||
3969 | #if ENABLE_HUSH_JOB | 3919 | #if ENABLE_HUSH_JOB |
3970 | //// if (G.ctrl_z_flag) { | ||
3971 | //// /* ctrl-Z forked somewhere in the past, we are the child, | ||
3972 | //// * and now we completed running the list. Exit. */ | ||
3973 | //////TODO: _exit? | ||
3974 | //// exit(rcode); | ||
3975 | //// } | ||
3976 | ret: | ||
3977 | G.run_list_level--; | 3920 | G.run_list_level--; |
3978 | //// if (!G.run_list_level && G_interactive_fd) { | ||
3979 | //// signal(SIGTSTP, SIG_IGN); | ||
3980 | //// signal(SIGINT, SIG_IGN); | ||
3981 | //// } | ||
3982 | #endif | 3921 | #endif |
3983 | #if ENABLE_HUSH_LOOPS | 3922 | #if ENABLE_HUSH_LOOPS |
3984 | if (loop_top) | 3923 | if (loop_top) |