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.
}
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);
}
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;
}