]> git.tue.mpg.de Git - paraslash.git/commitdiff
gui: Kill also child processes of external commands.
authorAndre Noll <maan@tuebingen.mpg.de>
Mon, 19 Aug 2024 19:41:23 +0000 (21:41 +0200)
committerAndre Noll <maan@tuebingen.mpg.de>
Tue, 17 Sep 2024 15:58:38 +0000 (17:58 +0200)
When a command is executed as a display command from para_gui, and
the command is interrupted from within para_gui by pressing any key,
para_gui only kills the spawned process but leaves alone its child
processes.

Address this problem by putting the spawned process into a separate
process group so that we can easily kill all processes of the group
by passing the negated PID of the child to kill(2).

In theory, the change in exec.c also affects para_mixer, which executes
para_client and para_audioc. However, para_mixer never kills any of
its child processes.

exec.c
gui.c

diff --git a/exec.c b/exec.c
index 38f445ee20b4151b38d4b4fa296f25d10103e2e2..364395bd4e1ae0fb3e199471dbbbfa0065d41efb 100644 (file)
--- a/exec.c
+++ b/exec.c
@@ -69,6 +69,14 @@ static int para_exec(pid_t *pid, const char *file, char *const *const args, int
                }
                if (null >= 0)
                        close(null);
+               /*
+                * If stdin is redirected, the foreground process group can no
+                * longer be signalled with CTRL+C. Set the process group ID of
+                * the child to its PID so that the parent can send a signal to
+                * the process group to kill the child and all its subprocesses.
+                */
+               if (fds[0] >= 0)
+                       setpgid(0, 0);
                execvp(file, args);
                _exit(EXIT_FAILURE);
        }
diff --git a/gui.c b/gui.c
index 66fb7870bd65868a750b5918747da59ad4681b6d..2ad8ae46202f98dc545bd4115561d8d317f4b486 100644 (file)
--- a/gui.c
+++ b/gui.c
@@ -1119,8 +1119,8 @@ static int input_post_monitor(__a_unused struct sched *s,
                return 0;
        if (exs == EXEC_IDLE)
                handle_command(ret);
-       else if (exec_pid > 0)
-               kill(exec_pid, SIGTERM);
+       else if (exec_pid > 0) /* negate to kill whole process group */
+               kill(-exec_pid, SIGTERM);
        return 0;
 }