From 43863a70c87c80e3a15315f561c3a247b27c81fa Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Fri, 18 Oct 2013 08:44:40 +0200 Subject: SignalMonitor: add SignalMonitorGetEventLoop() Eliminate the global variable "shutdown_loop". --- src/SignalHandlers.cxx | 7 +------ src/event/SignalMonitor.cxx | 8 ++++++++ src/event/SignalMonitor.hxx | 7 +++++++ 3 files changed, 16 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/SignalHandlers.cxx b/src/SignalHandlers.cxx index c884b97fd..b18fce0fa 100644 --- a/src/SignalHandlers.cxx +++ b/src/SignalHandlers.cxx @@ -25,9 +25,7 @@ #include "Log.hxx" #include "LogInit.hxx" -#include "Main.hxx" #include "event/Loop.hxx" -#include "GlobalEvents.hxx" #include "system/FatalError.hxx" #include "util/Domain.hxx" @@ -35,12 +33,10 @@ static constexpr Domain signal_handlers_domain("signal_handlers"); -static EventLoop *shutdown_loop; - static void HandleShutdownSignal() { - shutdown_loop->Break(); + SignalMonitorGetEventLoop().Break(); } static void @@ -72,7 +68,6 @@ SignalHandlersInit(EventLoop &loop) sa.sa_handler = SIG_IGN; x_sigaction(SIGPIPE, &sa); - shutdown_loop = &loop; SignalMonitorRegister(SIGINT, HandleShutdownSignal); SignalMonitorRegister(SIGTERM, HandleShutdownSignal); diff --git a/src/event/SignalMonitor.cxx b/src/event/SignalMonitor.cxx index ee72dea72..8c8527a77 100644 --- a/src/event/SignalMonitor.cxx +++ b/src/event/SignalMonitor.cxx @@ -63,6 +63,8 @@ public: SocketMonitor::Steal(); } + using SocketMonitor::GetEventLoop; + #ifdef USE_SIGNALFD void Update(sigset_t &mask) { const bool was_open = SocketMonitor::IsDefined(); @@ -153,6 +155,12 @@ SignalMonitorFinish() monitor.Destruct(); } +EventLoop & +SignalMonitorGetEventLoop() +{ + return monitor->GetEventLoop(); +} + void SignalMonitorRegister(int signo, SignalHandler handler) { diff --git a/src/event/SignalMonitor.hxx b/src/event/SignalMonitor.hxx index 94ab0aa30..1ecccd40b 100644 --- a/src/event/SignalMonitor.hxx +++ b/src/event/SignalMonitor.hxx @@ -40,6 +40,13 @@ SignalMonitorInit(EventLoop &loop); void SignalMonitorFinish(); +/** + * Obtain a reference to the #EventLoop that was passed to + * SignalMonitorInit(). + */ +EventLoop & +SignalMonitorGetEventLoop(); + /** * Register a handler for the specified signal. The handler will be * invoked in a safe context. -- cgit v1.2.3