From 858091c25687727c335880dca459fe5b24259009 Mon Sep 17 00:00:00 2001 From: Ron Yorston Date: Thu, 13 Dec 2018 15:18:20 +0000 Subject: 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. --- shell/ash.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) 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 { /* type of forkshell */ int fpid; + /* generic data, used by forkshell_child */ + int mode; + int nprocs; + /* optional data, used by forkshell_child */ int flags; int fd[3]; @@ -15100,6 +15104,8 @@ spawn_forkshell(struct job *jp, struct forkshell *fs, int mode) intptr_t ret; new = forkshell_prepare(fs); + new->mode = mode; + new->nprocs = jp == NULL ? 0 : jp->nprocs; sprintf(buf, "%p", new->hMapFile); argv[2] = buf; ret = mingw_spawn_proc(argv); @@ -15725,6 +15731,14 @@ forkshell_init(const char *idstr) reinitvar(); shlvl++; + if (fs->mode == FORK_BG) { + SetConsoleCtrlHandler(NULL, TRUE); + if (fs->nprocs == 0) { + close(0); + if (open(bb_dev_null, O_RDONLY) != 0) + ash_msg_and_raise_perror("can't open '%s'", bb_dev_null); + } + } forkshell_child(fs); } -- cgit v1.2.3-55-g6feb