diff options
author | Florent Le Coz <louiz@louiz.org> | 2015-04-20 23:58:05 +0200 |
---|---|---|
committer | Florent Le Coz <louiz@louiz.org> | 2015-04-20 23:58:05 +0200 |
commit | 6a28bde1dd21809b3c1202aab0b695b11f4d4846 (patch) | |
tree | b33e8cc8a486e61a350ad24fee6794086ff9ed56 | |
parent | 0d706741c6b3a8bdf6b4f8ca0b1ac00cb27bd8b8 (diff) | |
download | biboumi-6a28bde1dd21809b3c1202aab0b695b11f4d4846.tar.gz biboumi-6a28bde1dd21809b3c1202aab0b695b11f4d4846.tar.bz2 biboumi-6a28bde1dd21809b3c1202aab0b695b11f4d4846.tar.xz biboumi-6a28bde1dd21809b3c1202aab0b695b11f4d4846.zip |
Reset the signal handlers when SIGINT or SIGTERM is received
To avoid doing a double exit when receiving bot SIGINT and SIGTERM
-rw-r--r-- | src/main.cpp | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/src/main.cpp b/src/main.cpp index cc73244..62a28a5 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -40,6 +40,18 @@ int config_help(const std::string& missing_option) static void sigint_handler(int sig, siginfo_t*, void*) { + // We reset the SIGTERM or SIGINT (the one that didn't trigger this + // handler) signal handler to its default value. This avoid calling this + // handler twice, if the process receive both signals in a quick + // succession. + int sig_to_reset = (sig == SIGINT? SIGTERM: SIGINT); + sigset_t mask; + sigemptyset(&mask); + struct sigaction sigreset = {}; + sigreset.sa_handler = SIG_DFL; + sigreset.sa_mask = mask; + sigaction(sig_to_reset, &sigreset, nullptr); + // In 2 seconds, repeat the same signal, to force the exit TimedEventsManager::instance().add_event(TimedEvent(std::chrono::steady_clock::now() + 2s, [sig]() { raise(sig); })); |