Fixed child process signal behaviours. (#128)

* Restored signal handlers upon fork().
* Improved error handling of hpfs process kill scenario.
* Set pgid for forked processes for graceful sending of SIGINT.
This commit is contained in:
Ravin Perera
2020-09-26 21:39:26 +05:30
committed by GitHub
parent 05f356f6e0
commit 4d920a9219
9 changed files with 36 additions and 23 deletions

View File

@@ -206,13 +206,25 @@ namespace util
pthread_sigmask(SIG_BLOCK, &mask, NULL);
}
// Clears signal mask from the calling thread.
// Used for other processes forked from hpcore threads.
void unmask_signal()
/**
* Clears signal mask and signal handlers from the caller.
* Called by other processes forked from hpcore threads so they get detatched from
* the hpcore signal setup.
*/
void fork_detach()
{
// Restore signal handlers to defaults.
signal(SIGINT, SIG_DFL);
signal(SIGSEGV, SIG_DFL);
signal(SIGABRT, SIG_DFL);
// Remove any signal masks applied by hpcore.
sigset_t mask;
sigemptyset(&mask);
pthread_sigmask(SIG_SETMASK, &mask, NULL);
// Set process group id (so the terminal doesn't send kill signals to forked children).
setpgrp();
}
// Kill a process with a signal and if specified, wait until it stops running.