summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLeo Tenenbaum <pommicket@gmail.com>2021-04-17 10:54:22 -0400
committerLeo Tenenbaum <pommicket@gmail.com>2021-04-17 10:54:22 -0400
commit6ad4547b465a83f7f3681d464110288895093944 (patch)
tree6d9e37e31c1c9930e8061bb070f10fe37d8d8780
parentb8c5d256646130067cc6f2d4db676dc2173522ac (diff)
fix process_kill on posix
-rw-r--r--process-posix.c7
-rw-r--r--process-win.c2
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);