diff options
author | Eric Andersen <andersen@codepoet.org> | 2001-06-28 01:10:11 +0000 |
---|---|---|
committer | Eric Andersen <andersen@codepoet.org> | 2001-06-28 01:10:11 +0000 |
commit | 028b65b0606b3c44db768ccfd591dda914581b4a (patch) | |
tree | 07f6b00198270e9801f0272c8fd4fe7d0c21f941 | |
parent | 07abfe209276f22ce0bdb9ecf021f951a2eb5269 (diff) | |
download | busybox-w32-028b65b0606b3c44db768ccfd591dda914581b4a.tar.gz busybox-w32-028b65b0606b3c44db768ccfd591dda914581b4a.tar.bz2 busybox-w32-028b65b0606b3c44db768ccfd591dda914581b4a.zip |
More thrashing about trying to make hush behave itself wrt job
control...
-rw-r--r-- | hush.c | 34 | ||||
-rw-r--r-- | shell/hush.c | 34 |
2 files changed, 36 insertions, 32 deletions
@@ -395,7 +395,6 @@ static void remove_bg_job(struct pipe *pi); | |||
395 | static char *get_local_var(const char *var); | 395 | static char *get_local_var(const char *var); |
396 | static void unset_local_var(const char *name); | 396 | static void unset_local_var(const char *name); |
397 | static int set_local_var(const char *s, int flg_export); | 397 | static int set_local_var(const char *s, int flg_export); |
398 | static void sigchld_handler(int sig); | ||
399 | 398 | ||
400 | /* Table of built-in functions. They can be forked or not, depending on | 399 | /* Table of built-in functions. They can be forked or not, depending on |
401 | * context: within pipes, they fork. As simple commands, they do not. | 400 | * context: within pipes, they fork. As simple commands, they do not. |
@@ -569,17 +568,21 @@ static int builtin_fg_bg(struct child_prog *child) | |||
569 | } | 568 | } |
570 | 569 | ||
571 | if (*child->argv[0] == 'f') { | 570 | if (*child->argv[0] == 'f') { |
572 | /* Make this job the foreground job */ | 571 | /* Put the job into the foreground. */ |
573 | /* suppress messages when run from /linuxrc mag@sysgo.de */ | 572 | tcsetpgrp(shell_terminal, pi->pgrp); |
574 | if (tcsetpgrp(shell_terminal, pi->pgrp) && errno != ENOTTY) | ||
575 | perror_msg("tcsetpgrp-1"); | ||
576 | } | 573 | } |
577 | 574 | ||
578 | /* Restart the processes in the job */ | 575 | /* Restart the processes in the job */ |
579 | for (i = 0; i < pi->num_progs; i++) | 576 | for (i = 0; i < pi->num_progs; i++) |
580 | pi->progs[i].is_stopped = 0; | 577 | pi->progs[i].is_stopped = 0; |
581 | 578 | ||
582 | kill(-pi->pgrp, SIGCONT); | 579 | if ( (i=kill(- pi->pgrp, SIGCONT)) < 0) { |
580 | if (i == ESRCH) { | ||
581 | remove_bg_job(pi); | ||
582 | } else { | ||
583 | perror_msg("kill (SIGCONT)"); | ||
584 | } | ||
585 | } | ||
583 | 586 | ||
584 | pi->stopped_progs = 0; | 587 | pi->stopped_progs = 0; |
585 | return EXIT_SUCCESS; | 588 | return EXIT_SUCCESS; |
@@ -1185,6 +1188,11 @@ static void remove_bg_job(struct pipe *pi) | |||
1185 | prev_pipe = prev_pipe->next; | 1188 | prev_pipe = prev_pipe->next; |
1186 | prev_pipe->next = pi->next; | 1189 | prev_pipe->next = pi->next; |
1187 | } | 1190 | } |
1191 | if (job_list) | ||
1192 | last_jobid = job_list->jobid; | ||
1193 | else | ||
1194 | last_jobid = 0; | ||
1195 | |||
1188 | pi->stopped_progs = 0; | 1196 | pi->stopped_progs = 0; |
1189 | free_pipe(pi, 0); | 1197 | free_pipe(pi, 0); |
1190 | free(pi); | 1198 | free(pi); |
@@ -1261,8 +1269,8 @@ static int checkjobs(struct pipe* fg_pipe) | |||
1261 | perror_msg("waitpid"); | 1269 | perror_msg("waitpid"); |
1262 | 1270 | ||
1263 | /* move the shell to the foreground */ | 1271 | /* move the shell to the foreground */ |
1264 | if (interactive && tcsetpgrp(shell_terminal, getpgid(0))) | 1272 | //if (interactive && tcsetpgrp(shell_terminal, getpgid(0))) |
1265 | perror_msg("tcsetpgrp-2"); | 1273 | // perror_msg("tcsetpgrp-2"); |
1266 | return -1; | 1274 | return -1; |
1267 | } | 1275 | } |
1268 | 1276 | ||
@@ -1508,8 +1516,8 @@ static int run_list_real(struct pipe *pi) | |||
1508 | if ( (rcode==EXIT_SUCCESS && pi->followup==PIPE_OR) || | 1516 | if ( (rcode==EXIT_SUCCESS && pi->followup==PIPE_OR) || |
1509 | (rcode!=EXIT_SUCCESS && pi->followup==PIPE_AND) ) | 1517 | (rcode!=EXIT_SUCCESS && pi->followup==PIPE_AND) ) |
1510 | skip_more_in_this_rmode=rmode; | 1518 | skip_more_in_this_rmode=rmode; |
1519 | checkjobs(NULL); | ||
1511 | } | 1520 | } |
1512 | checkjobs(NULL); | ||
1513 | return rcode; | 1521 | return rcode; |
1514 | } | 1522 | } |
1515 | 1523 | ||
@@ -2530,12 +2538,6 @@ static int parse_file_outer(FILE *f) | |||
2530 | return rcode; | 2538 | return rcode; |
2531 | } | 2539 | } |
2532 | 2540 | ||
2533 | static void sigchld_handler(int sig) | ||
2534 | { | ||
2535 | checkjobs(NULL); | ||
2536 | signal(SIGCHLD, sigchld_handler); | ||
2537 | } | ||
2538 | |||
2539 | /* Make sure we have a controlling tty. If we get started under a job | 2541 | /* Make sure we have a controlling tty. If we get started under a job |
2540 | * aware app (like bash for example), make sure we are now in charge so | 2542 | * aware app (like bash for example), make sure we are now in charge so |
2541 | * we don't fight over who gets the foreground */ | 2543 | * we don't fight over who gets the foreground */ |
@@ -2552,7 +2554,7 @@ static void setup_job_control() | |||
2552 | signal(SIGTSTP, SIG_IGN); | 2554 | signal(SIGTSTP, SIG_IGN); |
2553 | signal(SIGTTIN, SIG_IGN); | 2555 | signal(SIGTTIN, SIG_IGN); |
2554 | signal(SIGTTOU, SIG_IGN); | 2556 | signal(SIGTTOU, SIG_IGN); |
2555 | signal(SIGCHLD, sigchld_handler); | 2557 | signal(SIGCHLD, SIG_IGN); |
2556 | 2558 | ||
2557 | /* Put ourselves in our own process group. */ | 2559 | /* Put ourselves in our own process group. */ |
2558 | setsid(); | 2560 | setsid(); |
diff --git a/shell/hush.c b/shell/hush.c index 34dc277b5..b74b9d159 100644 --- a/shell/hush.c +++ b/shell/hush.c | |||
@@ -395,7 +395,6 @@ static void remove_bg_job(struct pipe *pi); | |||
395 | static char *get_local_var(const char *var); | 395 | static char *get_local_var(const char *var); |
396 | static void unset_local_var(const char *name); | 396 | static void unset_local_var(const char *name); |
397 | static int set_local_var(const char *s, int flg_export); | 397 | static int set_local_var(const char *s, int flg_export); |
398 | static void sigchld_handler(int sig); | ||
399 | 398 | ||
400 | /* Table of built-in functions. They can be forked or not, depending on | 399 | /* Table of built-in functions. They can be forked or not, depending on |
401 | * context: within pipes, they fork. As simple commands, they do not. | 400 | * context: within pipes, they fork. As simple commands, they do not. |
@@ -569,17 +568,21 @@ static int builtin_fg_bg(struct child_prog *child) | |||
569 | } | 568 | } |
570 | 569 | ||
571 | if (*child->argv[0] == 'f') { | 570 | if (*child->argv[0] == 'f') { |
572 | /* Make this job the foreground job */ | 571 | /* Put the job into the foreground. */ |
573 | /* suppress messages when run from /linuxrc mag@sysgo.de */ | 572 | tcsetpgrp(shell_terminal, pi->pgrp); |
574 | if (tcsetpgrp(shell_terminal, pi->pgrp) && errno != ENOTTY) | ||
575 | perror_msg("tcsetpgrp-1"); | ||
576 | } | 573 | } |
577 | 574 | ||
578 | /* Restart the processes in the job */ | 575 | /* Restart the processes in the job */ |
579 | for (i = 0; i < pi->num_progs; i++) | 576 | for (i = 0; i < pi->num_progs; i++) |
580 | pi->progs[i].is_stopped = 0; | 577 | pi->progs[i].is_stopped = 0; |
581 | 578 | ||
582 | kill(-pi->pgrp, SIGCONT); | 579 | if ( (i=kill(- pi->pgrp, SIGCONT)) < 0) { |
580 | if (i == ESRCH) { | ||
581 | remove_bg_job(pi); | ||
582 | } else { | ||
583 | perror_msg("kill (SIGCONT)"); | ||
584 | } | ||
585 | } | ||
583 | 586 | ||
584 | pi->stopped_progs = 0; | 587 | pi->stopped_progs = 0; |
585 | return EXIT_SUCCESS; | 588 | return EXIT_SUCCESS; |
@@ -1185,6 +1188,11 @@ static void remove_bg_job(struct pipe *pi) | |||
1185 | prev_pipe = prev_pipe->next; | 1188 | prev_pipe = prev_pipe->next; |
1186 | prev_pipe->next = pi->next; | 1189 | prev_pipe->next = pi->next; |
1187 | } | 1190 | } |
1191 | if (job_list) | ||
1192 | last_jobid = job_list->jobid; | ||
1193 | else | ||
1194 | last_jobid = 0; | ||
1195 | |||
1188 | pi->stopped_progs = 0; | 1196 | pi->stopped_progs = 0; |
1189 | free_pipe(pi, 0); | 1197 | free_pipe(pi, 0); |
1190 | free(pi); | 1198 | free(pi); |
@@ -1261,8 +1269,8 @@ static int checkjobs(struct pipe* fg_pipe) | |||
1261 | perror_msg("waitpid"); | 1269 | perror_msg("waitpid"); |
1262 | 1270 | ||
1263 | /* move the shell to the foreground */ | 1271 | /* move the shell to the foreground */ |
1264 | if (interactive && tcsetpgrp(shell_terminal, getpgid(0))) | 1272 | //if (interactive && tcsetpgrp(shell_terminal, getpgid(0))) |
1265 | perror_msg("tcsetpgrp-2"); | 1273 | // perror_msg("tcsetpgrp-2"); |
1266 | return -1; | 1274 | return -1; |
1267 | } | 1275 | } |
1268 | 1276 | ||
@@ -1508,8 +1516,8 @@ static int run_list_real(struct pipe *pi) | |||
1508 | if ( (rcode==EXIT_SUCCESS && pi->followup==PIPE_OR) || | 1516 | if ( (rcode==EXIT_SUCCESS && pi->followup==PIPE_OR) || |
1509 | (rcode!=EXIT_SUCCESS && pi->followup==PIPE_AND) ) | 1517 | (rcode!=EXIT_SUCCESS && pi->followup==PIPE_AND) ) |
1510 | skip_more_in_this_rmode=rmode; | 1518 | skip_more_in_this_rmode=rmode; |
1519 | checkjobs(NULL); | ||
1511 | } | 1520 | } |
1512 | checkjobs(NULL); | ||
1513 | return rcode; | 1521 | return rcode; |
1514 | } | 1522 | } |
1515 | 1523 | ||
@@ -2530,12 +2538,6 @@ static int parse_file_outer(FILE *f) | |||
2530 | return rcode; | 2538 | return rcode; |
2531 | } | 2539 | } |
2532 | 2540 | ||
2533 | static void sigchld_handler(int sig) | ||
2534 | { | ||
2535 | checkjobs(NULL); | ||
2536 | signal(SIGCHLD, sigchld_handler); | ||
2537 | } | ||
2538 | |||
2539 | /* Make sure we have a controlling tty. If we get started under a job | 2541 | /* Make sure we have a controlling tty. If we get started under a job |
2540 | * aware app (like bash for example), make sure we are now in charge so | 2542 | * aware app (like bash for example), make sure we are now in charge so |
2541 | * we don't fight over who gets the foreground */ | 2543 | * we don't fight over who gets the foreground */ |
@@ -2552,7 +2554,7 @@ static void setup_job_control() | |||
2552 | signal(SIGTSTP, SIG_IGN); | 2554 | signal(SIGTSTP, SIG_IGN); |
2553 | signal(SIGTTIN, SIG_IGN); | 2555 | signal(SIGTTIN, SIG_IGN); |
2554 | signal(SIGTTOU, SIG_IGN); | 2556 | signal(SIGTTOU, SIG_IGN); |
2555 | signal(SIGCHLD, sigchld_handler); | 2557 | signal(SIGCHLD, SIG_IGN); |
2556 | 2558 | ||
2557 | /* Put ourselves in our own process group. */ | 2559 | /* Put ourselves in our own process group. */ |
2558 | setsid(); | 2560 | setsid(); |