aboutsummaryrefslogtreecommitdiffstats
path: root/src/event
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2014-02-18 19:13:50 +0100
committerMax Kellermann <max@duempel.org>2014-02-18 19:13:50 +0100
commit5e1e92626c1e07834eb6cdb3d57623c30bf50212 (patch)
tree62bcb3265d5652051050a15fec943196ae569ebb /src/event
parent7fee85c80ab5e0bf16f26e353a32026144dae6a4 (diff)
downloadmpd-5e1e92626c1e07834eb6cdb3d57623c30bf50212.tar.gz
mpd-5e1e92626c1e07834eb6cdb3d57623c30bf50212.tar.xz
mpd-5e1e92626c1e07834eb6cdb3d57623c30bf50212.zip
event/SignalMonitor: unblock signals after fork
Fixes hanging child process in the "pipe" output plugin.
Diffstat (limited to 'src/event')
-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 8c8527a77..eda52aba1 100644
--- a/src/event/SignalMonitor.cxx
+++ b/src/event/SignalMonitor.cxx
@@ -39,6 +39,10 @@
#include <algorithm>
+#ifdef USE_SIGNALFD
+#include <pthread.h>
+#endif
+
class SignalMonitor final : private SocketMonitor {
#ifdef USE_SIGNALFD
SignalFD fd;
@@ -99,7 +103,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)
{
@@ -108,6 +126,7 @@ SignalCallback(int signo)
if (!signal_pending[signo].exchange(true))
monitor->WakeUp();
}
+
#endif
void
@@ -115,6 +134,8 @@ SignalMonitorInit(EventLoop &loop)
{
#ifdef USE_SIGNALFD
sigemptyset(&signal_mask);
+
+ pthread_atfork(nullptr, nullptr, at_fork_child);
#endif
monitor.Construct(loop);