summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--manager.c3
-rw-r--r--util.c22
-rw-r--r--util.h2
3 files changed, 27 insertions, 0 deletions
diff --git a/manager.c b/manager.c
index b3123f2b1d..f15cf79869 100644
--- a/manager.c
+++ b/manager.c
@@ -15,6 +15,7 @@
#include "macro.h"
#include "strv.h"
#include "log.h"
+#include "util.h"
Manager* manager_new(void) {
Manager *m;
@@ -41,6 +42,8 @@ Manager* manager_new(void) {
if ((m->epoll_fd = epoll_create1(EPOLL_CLOEXEC)) < 0)
goto fail;
+ assert_se(reset_all_signal_handlers() == 0);
+
assert_se(sigemptyset(&mask) == 0);
assert_se(sigaddset(&mask, SIGCHLD) == 0);
assert_se(sigaddset(&mask, SIGINT) == 0);
diff --git a/util.c b/util.c
index c7b2ca8516..4774610265 100644
--- a/util.c
+++ b/util.c
@@ -468,3 +468,25 @@ char *path_make_absolute(const char *p, const char *prefix) {
return r;
}
+
+int reset_all_signal_handlers(void) {
+ int sig;
+
+ for (sig = 1; sig < _NSIG; sig++) {
+ struct sigaction sa;
+
+ if (sig == SIGKILL || sig == SIGSTOP)
+ continue;
+
+ zero(sa);
+ sa.sa_handler = SIG_DFL;
+
+ /* On Linux the first two RT signals are reserved by
+ * glibc, and sigaction() will return EINVAL for them. */
+ if ((sigaction(sig, &sa, NULL) < 0))
+ if (errno != EINVAL)
+ return -errno;
+ }
+
+ return 0;
+}
diff --git a/util.h b/util.h
index f14751ea5e..a969060331 100644
--- a/util.h
+++ b/util.h
@@ -99,4 +99,6 @@ bool is_path(const char *p);
bool path_is_absolute(const char *p);
char *path_make_absolute(const char *p, const char *prefix);
+int reset_all_signal_handlers(void);
+
#endif