Teach keepalives to exit when their parent dies

keepalive processes are typically killed by the main shell process.
However if the main shell exits the keepalive may linger. In WSL
keepalives are used more often, and the lingering keepalives are both
leaks and prevent the tests from finishing.

Have keepalives poll for their parent process ID and exit when it
changes, so they can clean themselves up. The polling frequency can be
low.
This commit is contained in:
ridiculousfish
2018-01-20 23:43:48 -08:00
parent 14880ce7d1
commit 080521071f
3 changed files with 17 additions and 1 deletions

View File

@@ -586,12 +586,13 @@ void exec_job(parser_t &parser, job_t *j) {
if (needs_keepalive) {
// Call fork. No need to wait for threads since our use is confined and simple.
pid_t parent_pid = getpid();
keepalive.pid = execute_fork(false);
if (keepalive.pid == 0) {
// Child
keepalive.pid = getpid();
child_set_group(j, &keepalive);
pause();
run_as_keepalive(parent_pid);
exit_without_destructors(0);
} else {
// Parent