diff options
author | Ron Yorston <rmy@pobox.com> | 2018-12-13 15:18:20 +0000 |
---|---|---|
committer | Ron Yorston <rmy@pobox.com> | 2018-12-13 15:35:12 +0000 |
commit | 858091c25687727c335880dca459fe5b24259009 (patch) | |
tree | c07a68285bc3a2bcc700df251b43058bb24dbdb3 /shell | |
parent | c17f7130a77698ba440525919a20d08b26333dd3 (diff) | |
download | busybox-w32-858091c25687727c335880dca459fe5b24259009.tar.gz busybox-w32-858091c25687727c335880dca459fe5b24259009.tar.bz2 busybox-w32-858091c25687727c335880dca459fe5b24259009.zip |
ash: prevent ctrl-c from killing background processes
spawn_forkshell() was missing some code that would normally have
been run from forkchild when a background process was started:
- the ctrl-c handler wasn't disabled;
- standard input wasn't connected to /dev/null.
Using ctrl-c to kill a foreground process also killed background
processes.
Fixing this requires passing the forkshell mode and the number of
processes associated with the forkshell job to the child process.
Diffstat (limited to 'shell')
-rw-r--r-- | shell/ash.c | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/shell/ash.c b/shell/ash.c index 188ec0979..0b41e7931 100644 --- a/shell/ash.c +++ b/shell/ash.c | |||
@@ -355,6 +355,10 @@ struct forkshell { | |||
355 | /* type of forkshell */ | 355 | /* type of forkshell */ |
356 | int fpid; | 356 | int fpid; |
357 | 357 | ||
358 | /* generic data, used by forkshell_child */ | ||
359 | int mode; | ||
360 | int nprocs; | ||
361 | |||
358 | /* optional data, used by forkshell_child */ | 362 | /* optional data, used by forkshell_child */ |
359 | int flags; | 363 | int flags; |
360 | int fd[3]; | 364 | int fd[3]; |
@@ -15100,6 +15104,8 @@ spawn_forkshell(struct job *jp, struct forkshell *fs, int mode) | |||
15100 | intptr_t ret; | 15104 | intptr_t ret; |
15101 | 15105 | ||
15102 | new = forkshell_prepare(fs); | 15106 | new = forkshell_prepare(fs); |
15107 | new->mode = mode; | ||
15108 | new->nprocs = jp == NULL ? 0 : jp->nprocs; | ||
15103 | sprintf(buf, "%p", new->hMapFile); | 15109 | sprintf(buf, "%p", new->hMapFile); |
15104 | argv[2] = buf; | 15110 | argv[2] = buf; |
15105 | ret = mingw_spawn_proc(argv); | 15111 | ret = mingw_spawn_proc(argv); |
@@ -15725,6 +15731,14 @@ forkshell_init(const char *idstr) | |||
15725 | reinitvar(); | 15731 | reinitvar(); |
15726 | 15732 | ||
15727 | shlvl++; | 15733 | shlvl++; |
15734 | if (fs->mode == FORK_BG) { | ||
15735 | SetConsoleCtrlHandler(NULL, TRUE); | ||
15736 | if (fs->nprocs == 0) { | ||
15737 | close(0); | ||
15738 | if (open(bb_dev_null, O_RDONLY) != 0) | ||
15739 | ash_msg_and_raise_perror("can't open '%s'", bb_dev_null); | ||
15740 | } | ||
15741 | } | ||
15728 | forkshell_child(fs); | 15742 | forkshell_child(fs); |
15729 | } | 15743 | } |
15730 | 15744 | ||