aboutsummaryrefslogtreecommitdiffstats
path: root/src/event/SignalMonitor.cxx
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2014-02-18 21:46:41 +0100
committerMax Kellermann <max@duempel.org>2014-02-18 21:46:41 +0100
commitc32477a223ad09dc0fc0708e95e09799eecb930b (patch)
tree8680c2f80b781f9d19870409171867bf114b8fa5 /src/event/SignalMonitor.cxx
parenta0c25941a83ba7e558fccbba4a1cb4bda90d4863 (diff)
parent5e1e92626c1e07834eb6cdb3d57623c30bf50212 (diff)
downloadmpd-c32477a223ad09dc0fc0708e95e09799eecb930b.tar.gz
mpd-c32477a223ad09dc0fc0708e95e09799eecb930b.tar.xz
mpd-c32477a223ad09dc0fc0708e95e09799eecb930b.zip
Merge branch 'v0.18.x'
Diffstat (limited to 'src/event/SignalMonitor.cxx')
-rw-r--r--src/event/SignalMonitor.cxx23
1 files changed, 22 insertions, 1 deletions
diff --git a/src/event/SignalMonitor.cxx b/src/event/SignalMonitor.cxx
index a845030c4..2d8fe681f 100644
--- a/src/event/SignalMonitor.cxx
+++ b/src/event/SignalMonitor.cxx
@@ -39,6 +39,10 @@
#include <algorithm>
+#ifdef USE_SIGNALFD
+#include <pthread.h>
+#endif
+
#include <assert.h>
#include <signal.h>
@@ -94,7 +98,21 @@ static std::atomic_bool signal_pending[MAX_SIGNAL];
static Manual<SignalMonitor> monitor;
-#ifndef USE_SIGNALFD
+#ifdef USE_SIGNALFD
+
+/**
+ * This is a pthread_atfork() callback that unblocks the signals that
+ * were blocked for our signalfd(). Without this, our child processes
+ * would inherit the blocked signals.
+ */
+static void
+at_fork_child()
+{
+ sigprocmask(SIG_UNBLOCK, &signal_mask, nullptr);
+}
+
+#else
+
static void
SignalCallback(int signo)
{
@@ -103,6 +121,7 @@ SignalCallback(int signo)
if (!signal_pending[signo].exchange(true))
monitor->WakeUp();
}
+
#endif
void
@@ -110,6 +129,8 @@ SignalMonitorInit(EventLoop &loop)
{
#ifdef USE_SIGNALFD
sigemptyset(&signal_mask);
+
+ pthread_atfork(nullptr, nullptr, at_fork_child);
#endif
monitor.Construct(loop);