aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--initd/init.h1
-rw-r--r--initd/runsvc.c7
-rw-r--r--initd/supervisor.c7
-rw-r--r--lib/Makemodule.am1
-rw-r--r--lib/include/util.h26
5 files changed, 33 insertions, 9 deletions
diff --git a/initd/init.h b/initd/init.h
index 005fbba..ad681d9 100644
--- a/initd/init.h
+++ b/initd/init.h
@@ -22,6 +22,7 @@
#include "service.h"
#include "config.h"
+#include "util.h"
#define ENVFILE ETCPATH "/initd.env"
#define PROCFDDIR "/proc/self/fd"
diff --git a/initd/runsvc.c b/initd/runsvc.c
index 8aaa502..95c26cb 100644
--- a/initd/runsvc.c
+++ b/initd/runsvc.c
@@ -186,7 +186,6 @@ static int run_sequentially(exec_t *list, bool direct_exec_last)
pid_t runsvc(service_t *svc)
{
struct sigaction act;
- sigset_t mask;
pid_t pid;
int ret;
@@ -196,8 +195,7 @@ pid_t runsvc(service_t *svc)
perror("fork");
if (pid == 0) {
- sigfillset(&mask);
- sigprocmask(SIG_SETMASK, &mask, NULL);
+ cli(NULL);
memset(&act, 0, sizeof(act));
act.sa_handler = runsvc_sighandler;
@@ -220,8 +218,7 @@ pid_t runsvc(service_t *svc)
exit(EXIT_FAILURE);
}
- sigemptyset(&mask);
- sigprocmask(SIG_SETMASK, &mask, NULL);
+ sti(NULL);
if (svc->flags & SVC_FLAG_SUB_REAPER) {
prctl(PR_SET_CHILD_SUBREAPER, 1, 0, 0, 0);
diff --git a/initd/supervisor.c b/initd/supervisor.c
index 1a131ac..43900a5 100644
--- a/initd/supervisor.c
+++ b/initd/supervisor.c
@@ -179,14 +179,13 @@ out:
bool supervisor_process_queues(void)
{
- sigset_t mask, old_mask;
svc_run_data_t *rt;
+ sigset_t old_mask;
service_t *svc;
size_t count;
bool ret = false;
- sigfillset(&mask);
- sigprocmask(SIG_SETMASK, &mask, &old_mask);
+ cli(&old_mask);
if (waiting)
goto out_unblock;
@@ -224,6 +223,6 @@ bool supervisor_process_queues(void)
print_status(svc->desc, rt->state);
check_target_completion();
out_unblock:
- sigprocmask(SIG_SETMASK, &old_mask, NULL);
+ sti(&old_mask);
return ret;
}
diff --git a/lib/Makemodule.am b/lib/Makemodule.am
index fa8789b..836bd4d 100644
--- a/lib/Makemodule.am
+++ b/lib/Makemodule.am
@@ -1,6 +1,7 @@
libinit_a_SOURCES = lib/init/delsvc.c lib/init/svcmap.c lib/init/rdsvc.c
libinit_a_SOURCES += lib/init/svcscan.c lib/init/del_svc_list.c
libinit_a_SOURCES += lib/init/svc_tsort.c lib/include/service.h
+libinit_a_SOURCES += lib/include/util.h
libinit_a_CPPFLAGS = $(AM_CPPFLAGS)
libinit_a_CFLAGS = $(AM_CFLAGS)
diff --git a/lib/include/util.h b/lib/include/util.h
new file mode 100644
index 0000000..884eeab
--- /dev/null
+++ b/lib/include/util.h
@@ -0,0 +1,26 @@
+#ifndef UTIL_H
+#define UTIL_H
+
+#include <signal.h>
+
+static inline void cli(sigset_t *old_mask)
+{
+ sigset_t mask;
+
+ sigfillset(&mask);
+ sigprocmask(SIG_SETMASK, &mask, old_mask);
+}
+
+static inline void sti(const sigset_t *old_mask)
+{
+ sigset_t mask;
+
+ if (old_mask == NULL) {
+ sigemptyset(&mask);
+ sigprocmask(SIG_SETMASK, &mask, NULL);
+ } else {
+ sigprocmask(SIG_SETMASK, old_mask, NULL);
+ }
+}
+
+#endif /* UTIL_H */