From 20544e1f1898e18b19a4f30fb4a36df252174f5c Mon Sep 17 00:00:00 2001 From: Giulio Eulisse Date: Wed, 20 May 2020 10:37:29 +0200 Subject: [PATCH] Do not handle double SIGTERM as abort A double SIGTERM, or even worse a SIGINT + SIGTERM combination should not result in an abort, given such a signal really means "die whenever you want" and can only be generated programmatically. If one wants the child to die programmatically, they should use SIGKILL. On the other hand that bashing ctrl-c (i.e. SIGINT) multiple times on the keyboard really means abort. --- fairmq/plugins/Control.cxx | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/fairmq/plugins/Control.cxx b/fairmq/plugins/Control.cxx index 729cf961..028d89fb 100644 --- a/fairmq/plugins/Control.cxx +++ b/fairmq/plugins/Control.cxx @@ -24,7 +24,7 @@ namespace std::atomic gLastSignal(0); std::atomic gSignalCount(0); - extern "C" auto signal_handler(int signal) -> void + extern "C" auto sigint_handler(int signal) -> void { ++gSignalCount; gLastSignal = signal; @@ -33,6 +33,11 @@ namespace std::abort(); } } + + extern "C" auto sigterm_handler(int signal) -> void + { + gLastSignal = signal; + } } namespace fair @@ -85,8 +90,8 @@ Control::Control(const string& name, const Plugin::Version version, const string if (GetProperty("catch-signals") > 0) { LOG(debug) << "Plugin '" << name << "' is setting up signal handling for SIGINT and SIGTERM"; fSignalHandlerThread = thread(&Control::SignalHandler, this); - signal(SIGINT, signal_handler); - signal(SIGTERM, signal_handler); + signal(SIGINT, sigint_handler); + signal(SIGTERM, sigterm_handler); } else { LOG(warn) << "Signal handling (e.g. Ctrl-C) has been deactivated."; }