diff options
author | Ambroz Bizjak <ambrop7@gmail.com> | 2016-04-24 11:01:05 +0300 |
---|---|---|
committer | Ambroz Bizjak <ambrop7@gmail.com> | 2016-04-24 11:01:05 +0300 |
commit | 3897cdf4aa7deb1fc863cb198fb7381b224ff793 (patch) | |
tree | 2790ddbfeb8a54fc7b1a482a19239b69d5a97579 | |
parent | 61a68b25878dbf48d45df064b2e8215e48db45ce (diff) |
BSignal: Also catch SIGHUP.
This allows NCD to clean up orderly if the terminal it was running in is closed.
-rw-r--r-- | ncd/ncd.h | 2 | ||||
-rw-r--r-- | system/BSignal.c | 3 | ||||
-rw-r--r-- | system/BSignal.h | 3 |
3 files changed, 5 insertions, 3 deletions
@@ -33,7 +33,7 @@ // how long to wait after an error before retrying #define DEFAULT_RETRY_TIME 5000 -// default exit code when terminated by SIGINT/SIGTERM +// default exit code when terminated by SIGINT/SIGTERM/SIGHUP #define DEFAULT_SIGNAL_EXIT_CODE 1 // default loglevel diff --git a/system/BSignal.c b/system/BSignal.c index 520a167..2db9595 100644 --- a/system/BSignal.c +++ b/system/BSignal.c @@ -94,7 +94,7 @@ static BOOL WINAPI ctrl_handler (DWORD type) static void unix_signal_handler (void *user, int signo) { - ASSERT(signo == SIGTERM || signo == SIGINT) + ASSERT(signo == SIGTERM || signo == SIGINT || signo == SIGHUP) ASSERT(bsignal_global.initialized) ASSERT(!bsignal_global.finished) @@ -141,6 +141,7 @@ int BSignal_Init (BReactor *reactor, BSignal_handler handler, void *user) ASSERT_FORCE(sigemptyset(&sset) == 0) ASSERT_FORCE(sigaddset(&sset, SIGTERM) == 0) ASSERT_FORCE(sigaddset(&sset, SIGINT) == 0) + ASSERT_FORCE(sigaddset(&sset, SIGHUP) == 0) // init BUnixSignal if (!BUnixSignal_Init(&bsignal_global.signal, bsignal_global.reactor, sset, unix_signal_handler, NULL)) { diff --git a/system/BSignal.h b/system/BSignal.h index 41f17e2..1ad1ee7 100644 --- a/system/BSignal.h +++ b/system/BSignal.h @@ -45,7 +45,8 @@ typedef void (*BSignal_handler) (void *user); * {@link BLog_Init} must have been done. * * WARNING: make sure this won't interfere with other components: - * - on Linux, this uses {@link BUnixSignal} to catch SIGTERM and SIGINT, + * - On Linux, this uses {@link BUnixSignal} to catch SIGTERM, SIGINT + * and SIGHUP. * - on Windows, this sets up a handler with SetConsoleCtrlHandler. * * @param reactor {@link BReactor} from which the handler will be called |