From 6ad4547b465a83f7f3681d464110288895093944 Mon Sep 17 00:00:00 2001 From: Leo Tenenbaum Date: Sat, 17 Apr 2021 10:54:22 -0400 Subject: fix process_kill on posix --- process-posix.c | 7 +++++-- process-win.c | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/process-posix.c b/process-posix.c index 1236323..f35017f 100644 --- a/process-posix.c +++ b/process-posix.c @@ -14,12 +14,15 @@ bool process_run(Process *proc, char const *command) { memset(proc, 0, sizeof *proc); bool success = false; - int pipefd[2]; if (pipe(pipefd) == 0) { pid_t pid = fork(); if (pid == 0) { // child process + // put child in its own group. it will be in this group with all of its descendents, + // so by killing everything in the group, we kill all the descendents of this process. + // if we didn't do this, we would just be killing the sh process in process_kill. + setpgid(0, 0); // send stdout and stderr to pipe dup2(pipefd[1], STDOUT_FILENO); dup2(pipefd[1], STDERR_FILENO); @@ -64,7 +67,7 @@ long long process_read(Process *proc, char *data, size_t size) { } void process_kill(Process *proc) { - kill(proc->pid, SIGKILL); + kill(-proc->pid, SIGKILL); // kill everything in process group // get rid of zombie process waitpid(proc->pid, NULL, 0); close(proc->pipe); diff --git a/process-win.c b/process-win.c index d7ff4b2..a5f05c0 100644 --- a/process-win.c +++ b/process-win.c @@ -26,7 +26,7 @@ bool process_run(Process *process, char const *command) { strbuf_printf(process->error, "Out of memory."); return false; } - // we need to create a "job" for this, because apparently when you kill a process on windows, + // we need to create a "job" for this, because when you kill a process on windows, // all its children just keep going. so cmd.exe would die, but not the actual build process. // jobs fix this, apparently. HANDLE job = CreateJobObjectA(NULL, NULL); -- cgit v1.2.3