mirror of
https://github.com/EvernodeXRPL/hpcore.git
synced 2026-04-29 15:37:59 +00:00
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:
18
src/util.cpp
18
src/util.cpp
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user