event/SignalMonitor: use BoundMethod instead of raw function pointer
This commit is contained in:
parent
c3d9c32615
commit
4280f84535
@ -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]();
|
||||
}
|
||||
|
@ -26,7 +26,9 @@ class EventLoop;
|
||||
|
||||
#ifndef WIN32
|
||||
|
||||
typedef void (*SignalHandler)();
|
||||
#include "util/BindMethod.hxx"
|
||||
|
||||
typedef BoundMethod<void()> SignalHandler;
|
||||
|
||||
/**
|
||||
* Initialise the signal monitor subsystem.
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
@ -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()
|
||||
|
Loading…
Reference in New Issue
Block a user