aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2009-05-20 14:10:50 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2009-05-20 14:10:50 +0200
commit73f379923625fcbe9b8ea9497309356977e7c33d (patch)
tree5d380b78182d2cedd31ddc6761975981037990e3
parent0149f02a7245910e6d96463432ed8dfe49b878f3 (diff)
parent38478a600f52eb8f00d260a2f99d8430b9aba1e8 (diff)
downloadbusybox-w32-73f379923625fcbe9b8ea9497309356977e7c33d.tar.gz
busybox-w32-73f379923625fcbe9b8ea9497309356977e7c33d.tar.bz2
busybox-w32-73f379923625fcbe9b8ea9497309356977e7c33d.zip
Merge branch 'master' of git+ssh://vda@busybox.net/var/lib/git/busybox
-rw-r--r--shell/hush.c35
1 files changed, 19 insertions, 16 deletions
diff --git a/shell/hush.c b/shell/hush.c
index 370e0d71a..d6286b61c 100644
--- a/shell/hush.c
+++ b/shell/hush.c
@@ -445,6 +445,9 @@ struct globals {
445 int last_jobid; 445 int last_jobid;
446 pid_t saved_tty_pgrp; 446 pid_t saved_tty_pgrp;
447 struct pipe *job_list; 447 struct pipe *job_list;
448# define G_saved_tty_pgrp (G.saved_tty_pgrp)
449#else
450# define G_saved_tty_pgrp 0
448#endif 451#endif
449 smallint flag_SIGINT; 452 smallint flag_SIGINT;
450#if ENABLE_HUSH_LOOPS 453#if ENABLE_HUSH_LOOPS
@@ -1055,8 +1058,8 @@ enum {
1055 | (1 << SIGINT) 1058 | (1 << SIGINT)
1056 | (1 << SIGHUP) 1059 | (1 << SIGHUP)
1057 , 1060 ,
1058#if ENABLE_HUSH_JOB
1059 SPECIAL_JOB_SIGS = 0 1061 SPECIAL_JOB_SIGS = 0
1062#if ENABLE_HUSH_JOB
1060 | (1 << SIGTTIN) 1063 | (1 << SIGTTIN)
1061 | (1 << SIGTTOU) 1064 | (1 << SIGTTOU)
1062 | (1 << SIGTSTP) 1065 | (1 << SIGTSTP)
@@ -1088,8 +1091,8 @@ static void sigexit(int sig)
1088 1091
1089 /* Careful: we can end up here after [v]fork. Do not restore 1092 /* Careful: we can end up here after [v]fork. Do not restore
1090 * tty pgrp then, only top-level shell process does that */ 1093 * tty pgrp then, only top-level shell process does that */
1091 if (G.saved_tty_pgrp && getpid() == G.root_pid) 1094 if (G_saved_tty_pgrp && getpid() == G.root_pid)
1092 tcsetpgrp(G_interactive_fd, G.saved_tty_pgrp); 1095 tcsetpgrp(G_interactive_fd, G_saved_tty_pgrp);
1093 1096
1094 /* Not a signal, just exit */ 1097 /* Not a signal, just exit */
1095 if (sig <= 0) 1098 if (sig <= 0)
@@ -3400,7 +3403,7 @@ static int checkjobs_and_fg_shell(struct pipe* fg_pipe)
3400{ 3403{
3401 pid_t p; 3404 pid_t p;
3402 int rcode = checkjobs(fg_pipe); 3405 int rcode = checkjobs(fg_pipe);
3403 if (G.saved_tty_pgrp) { 3406 if (G_saved_tty_pgrp) {
3404 /* Job finished, move the shell to the foreground */ 3407 /* Job finished, move the shell to the foreground */
3405 p = getpgrp(); /* our process group id */ 3408 p = getpgrp(); /* our process group id */
3406 debug_printf_jobs("fg'ing ourself: getpgrp()=%d\n", (int)p); 3409 debug_printf_jobs("fg'ing ourself: getpgrp()=%d\n", (int)p);
@@ -3656,7 +3659,7 @@ static int run_pipe(struct pipe *pi)
3656 pgrp = getpid(); 3659 pgrp = getpid();
3657 if (setpgid(0, pgrp) == 0 3660 if (setpgid(0, pgrp) == 0
3658 && pi->followup != PIPE_BG 3661 && pi->followup != PIPE_BG
3659 && G.saved_tty_pgrp /* we have ctty */ 3662 && G_saved_tty_pgrp /* we have ctty */
3660 ) { 3663 ) {
3661 /* We do it in *every* child, not just first, 3664 /* We do it in *every* child, not just first,
3662 * to avoid races */ 3665 * to avoid races */
@@ -5954,7 +5957,7 @@ static void block_signals(int second_time)
5954 mask = (1 << SIGQUIT); 5957 mask = (1 << SIGQUIT);
5955 if (G_interactive_fd) { 5958 if (G_interactive_fd) {
5956 mask = (1 << SIGQUIT) | SPECIAL_INTERACTIVE_SIGS; 5959 mask = (1 << SIGQUIT) | SPECIAL_INTERACTIVE_SIGS;
5957 if (G.saved_tty_pgrp) /* we have ctty, job control sigs work */ 5960 if (G_saved_tty_pgrp) /* we have ctty, job control sigs work */
5958 mask |= SPECIAL_JOB_SIGS; 5961 mask |= SPECIAL_JOB_SIGS;
5959 } 5962 }
5960 G.non_DFL_mask = mask; 5963 G.non_DFL_mask = mask;
@@ -6235,10 +6238,10 @@ int hush_main(int argc, char **argv)
6235 */ 6238 */
6236#if ENABLE_HUSH_JOB 6239#if ENABLE_HUSH_JOB
6237 if (isatty(STDIN_FILENO) && isatty(STDOUT_FILENO)) { 6240 if (isatty(STDIN_FILENO) && isatty(STDOUT_FILENO)) {
6238 G.saved_tty_pgrp = tcgetpgrp(STDIN_FILENO); 6241 G_saved_tty_pgrp = tcgetpgrp(STDIN_FILENO);
6239 debug_printf("saved_tty_pgrp:%d\n", G.saved_tty_pgrp); 6242 debug_printf("saved_tty_pgrp:%d\n", G_saved_tty_pgrp);
6240 if (G.saved_tty_pgrp < 0) 6243 if (G_saved_tty_pgrp < 0)
6241 G.saved_tty_pgrp = 0; 6244 G_saved_tty_pgrp = 0;
6242 6245
6243 /* try to dup stdin to high fd#, >= 255 */ 6246 /* try to dup stdin to high fd#, >= 255 */
6244 G_interactive_fd = fcntl(STDIN_FILENO, F_DUPFD, 255); 6247 G_interactive_fd = fcntl(STDIN_FILENO, F_DUPFD, 255);
@@ -6248,7 +6251,7 @@ int hush_main(int argc, char **argv)
6248 if (G_interactive_fd < 0) { 6251 if (G_interactive_fd < 0) {
6249 /* give up */ 6252 /* give up */
6250 G_interactive_fd = 0; 6253 G_interactive_fd = 0;
6251 G.saved_tty_pgrp = 0; 6254 G_saved_tty_pgrp = 0;
6252 } 6255 }
6253 } 6256 }
6254// TODO: track & disallow any attempts of user 6257// TODO: track & disallow any attempts of user
@@ -6258,7 +6261,7 @@ int hush_main(int argc, char **argv)
6258 if (G_interactive_fd) { 6261 if (G_interactive_fd) {
6259 close_on_exec_on(G_interactive_fd); 6262 close_on_exec_on(G_interactive_fd);
6260 6263
6261 if (G.saved_tty_pgrp) { 6264 if (G_saved_tty_pgrp) {
6262 /* If we were run as 'hush &', sleep until we are 6265 /* If we were run as 'hush &', sleep until we are
6263 * in the foreground (tty pgrp == our pgrp). 6266 * in the foreground (tty pgrp == our pgrp).
6264 * If we get started under a job aware app (like bash), 6267 * If we get started under a job aware app (like bash),
@@ -6266,8 +6269,8 @@ int hush_main(int argc, char **argv)
6266 * who gets the foreground */ 6269 * who gets the foreground */
6267 while (1) { 6270 while (1) {
6268 pid_t shell_pgrp = getpgrp(); 6271 pid_t shell_pgrp = getpgrp();
6269 G.saved_tty_pgrp = tcgetpgrp(G_interactive_fd); 6272 G_saved_tty_pgrp = tcgetpgrp(G_interactive_fd);
6270 if (G.saved_tty_pgrp == shell_pgrp) 6273 if (G_saved_tty_pgrp == shell_pgrp)
6271 break; 6274 break;
6272 /* send TTIN to ourself (should stop us) */ 6275 /* send TTIN to ourself (should stop us) */
6273 kill(- shell_pgrp, SIGTTIN); 6276 kill(- shell_pgrp, SIGTTIN);
@@ -6277,7 +6280,7 @@ int hush_main(int argc, char **argv)
6277 /* Block some signals */ 6280 /* Block some signals */
6278 block_signals(signal_mask_is_inited); 6281 block_signals(signal_mask_is_inited);
6279 6282
6280 if (G.saved_tty_pgrp) { 6283 if (G_saved_tty_pgrp) {
6281 /* Set other signals to restore saved_tty_pgrp */ 6284 /* Set other signals to restore saved_tty_pgrp */
6282 set_fatal_handlers(); 6285 set_fatal_handlers();
6283 /* Put ourselves in our own process group 6286 /* Put ourselves in our own process group
@@ -6690,7 +6693,7 @@ static int builtin_fg_bg(char **argv)
6690 found: 6693 found:
6691 /* TODO: bash prints a string representation 6694 /* TODO: bash prints a string representation
6692 * of job being foregrounded (like "sleep 1 | cat") */ 6695 * of job being foregrounded (like "sleep 1 | cat") */
6693 if (argv[0][0] == 'f' && G.saved_tty_pgrp) { 6696 if (argv[0][0] == 'f' && G_saved_tty_pgrp) {
6694 /* Put the job into the foreground. */ 6697 /* Put the job into the foreground. */
6695 tcsetpgrp(G_interactive_fd, pi->pgrp); 6698 tcsetpgrp(G_interactive_fd, pi->pgrp);
6696 } 6699 }