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.
This commit is contained in:
Giulio Eulisse 2020-05-20 10:37:29 +02:00 committed by Alexey Rybalchenko
parent b32e04db60
commit 20544e1f18

View File

@ -24,7 +24,7 @@ namespace
std::atomic<sig_atomic_t> gLastSignal(0); std::atomic<sig_atomic_t> gLastSignal(0);
std::atomic<int> gSignalCount(0); std::atomic<int> gSignalCount(0);
extern "C" auto signal_handler(int signal) -> void extern "C" auto sigint_handler(int signal) -> void
{ {
++gSignalCount; ++gSignalCount;
gLastSignal = signal; gLastSignal = signal;
@ -33,6 +33,11 @@ namespace
std::abort(); std::abort();
} }
} }
extern "C" auto sigterm_handler(int signal) -> void
{
gLastSignal = signal;
}
} }
namespace fair namespace fair
@ -85,8 +90,8 @@ Control::Control(const string& name, const Plugin::Version version, const string
if (GetProperty<int>("catch-signals") > 0) { if (GetProperty<int>("catch-signals") > 0) {
LOG(debug) << "Plugin '" << name << "' is setting up signal handling for SIGINT and SIGTERM"; LOG(debug) << "Plugin '" << name << "' is setting up signal handling for SIGINT and SIGTERM";
fSignalHandlerThread = thread(&Control::SignalHandler, this); fSignalHandlerThread = thread(&Control::SignalHandler, this);
signal(SIGINT, signal_handler); signal(SIGINT, sigint_handler);
signal(SIGTERM, signal_handler); signal(SIGTERM, sigterm_handler);
} else { } else {
LOG(warn) << "Signal handling (e.g. Ctrl-C) has been deactivated."; LOG(warn) << "Signal handling (e.g. Ctrl-C) has been deactivated.";
} }