chiark / gitweb /
sd-event: make sd_event_add_signal() fail with EBUSY if signal is not blocked
authorLennart Poettering <lennart@poettering.net>
Mon, 23 Dec 2013 20:44:20 +0000 (21:44 +0100)
committerLennart Poettering <lennart@poettering.net>
Mon, 23 Dec 2013 20:44:20 +0000 (21:44 +0100)
src/libsystemd-bus/sd-event.c

index 0317088..0b7b71d 100644 (file)
@@ -22,6 +22,7 @@
 #include <sys/epoll.h>
 #include <sys/timerfd.h>
 #include <sys/wait.h>
+#include <pthread.h>
 
 #include "sd-id128.h"
 #include "sd-daemon.h"
@@ -813,6 +814,7 @@ _public_ int sd_event_add_signal(
                 sd_event_source **ret) {
 
         sd_event_source *s;
+        sigset_t ss;
         int r;
 
         assert_return(e, -EINVAL);
@@ -823,6 +825,13 @@ _public_ int sd_event_add_signal(
         assert_return(e->state != SD_EVENT_FINISHED, -ESTALE);
         assert_return(!event_pid_changed(e), -ECHILD);
 
+        r = pthread_sigmask(SIG_SETMASK, NULL, &ss);
+        if (r < 0)
+                return -errno;
+
+        if (!sigismember(&ss, sig))
+                return -EBUSY;
+
         if (!e->signal_sources) {
                 e->signal_sources = new0(sd_event_source*, _NSIG);
                 if (!e->signal_sources)