diff options
-rw-r--r-- | src/event/SignalMonitor.cxx | 6 | ||||
-rw-r--r-- | src/event/SignalMonitor.hxx | 4 | ||||
-rw-r--r-- | src/unix/SignalHandlers.cxx | 13 | ||||
-rw-r--r-- | test/ShutdownHandler.cxx | 9 |
4 files changed, 18 insertions, 14 deletions
diff --git a/src/event/SignalMonitor.cxx b/src/event/SignalMonitor.cxx index 0e1f4b4f4..16e05b1f6 100644 --- a/src/event/SignalMonitor.cxx +++ b/src/event/SignalMonitor.cxx @@ -158,7 +158,7 @@ SignalMonitorFinish() sa.sa_handler = SIG_DFL; for (unsigned i = 0; i < MAX_SIGNAL; ++i) { - if (signal_handlers[i] != nullptr) { + if (signal_handlers[i]) { x_sigaction(i, sa); signal_handlers[i] = nullptr; } @@ -179,7 +179,7 @@ SignalMonitorGetEventLoop() void SignalMonitorRegister(int signo, SignalHandler handler) { - assert(signal_handlers[signo] == nullptr); + assert(!signal_handlers[signo]); #ifndef USE_SIGNALFD assert(!signal_pending[signo]); #endif @@ -209,7 +209,7 @@ SignalMonitor::OnSocketReady(unsigned) int signo; while ((signo = fd.Read()) >= 0) { assert(unsigned(signo) < MAX_SIGNAL); - assert(signal_handlers[signo] != nullptr); + assert(signal_handlers[signo]); signal_handlers[signo](); } diff --git a/src/event/SignalMonitor.hxx b/src/event/SignalMonitor.hxx index fb56a6312..659a84d14 100644 --- a/src/event/SignalMonitor.hxx +++ b/src/event/SignalMonitor.hxx @@ -26,7 +26,9 @@ class EventLoop; #ifndef WIN32 -typedef void (*SignalHandler)(); +#include "util/BindMethod.hxx" + +typedef BoundMethod<void()> SignalHandler; /** * Initialise the signal monitor subsystem. diff --git a/src/unix/SignalHandlers.cxx b/src/unix/SignalHandlers.cxx index 3f4af5ffb..9bed3df08 100644 --- a/src/unix/SignalHandlers.cxx +++ b/src/unix/SignalHandlers.cxx @@ -34,9 +34,10 @@ static constexpr Domain signal_handlers_domain("signal_handlers"); static void -HandleShutdownSignal() +HandleShutdownSignal(void *ctx) { - SignalMonitorGetEventLoop().Break(); + auto &loop = *(EventLoop *)ctx; + loop.Break(); } static void @@ -47,7 +48,7 @@ x_sigaction(int signum, const struct sigaction *act) } static void -handle_reload_event(void) +handle_reload_event(void *) { LogDebug(signal_handlers_domain, "got SIGHUP, reopening log files"); cycle_log_files(); @@ -68,10 +69,10 @@ SignalHandlersInit(EventLoop &loop) sa.sa_handler = SIG_IGN; x_sigaction(SIGPIPE, &sa); - SignalMonitorRegister(SIGINT, HandleShutdownSignal); - SignalMonitorRegister(SIGTERM, HandleShutdownSignal); + SignalMonitorRegister(SIGINT, {&loop, HandleShutdownSignal}); + SignalMonitorRegister(SIGTERM, {&loop, HandleShutdownSignal}); - SignalMonitorRegister(SIGHUP, handle_reload_event); + SignalMonitorRegister(SIGHUP, {nullptr, handle_reload_event}); #endif } diff --git a/test/ShutdownHandler.cxx b/test/ShutdownHandler.cxx index ce8b9f7b3..2f6cdc39d 100644 --- a/test/ShutdownHandler.cxx +++ b/test/ShutdownHandler.cxx @@ -27,17 +27,18 @@ #include <signal.h> static void -HandleShutdownSignal() +HandleShutdownSignal(void *ctx) { - SignalMonitorGetEventLoop().Break(); + auto &loop = *(EventLoop *)ctx; + loop.Break(); } ShutdownHandler::ShutdownHandler(EventLoop &loop) { SignalMonitorInit(loop); - SignalMonitorRegister(SIGINT, HandleShutdownSignal); - SignalMonitorRegister(SIGTERM, HandleShutdownSignal); + SignalMonitorRegister(SIGINT, {&loop, HandleShutdownSignal}); + SignalMonitorRegister(SIGTERM, {&loop, HandleShutdownSignal}); } ShutdownHandler::~ShutdownHandler() |