diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/rc/openrc-init.c | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/src/rc/openrc-init.c b/src/rc/openrc-init.c index 61052806..621c81ea 100644 --- a/src/rc/openrc-init.c +++ b/src/rc/openrc-init.c @@ -39,6 +39,7 @@ static const char *rc_default_runlevel = "default"; static pid_t do_openrc(const char *runlevel) { pid_t pid; + sigset_t signals; pid = fork(); switch(pid) { @@ -47,6 +48,9 @@ static pid_t do_openrc(const char *runlevel) break; case 0: setsid(); + /* unblock all signals */ + sigemptyset(&signals); + sigprocmask(SIG_SETMASK, &signals, NULL); printf("Starting %s runlevel\n", runlevel); execl("/sbin/openrc", "/sbin/openrc", runlevel, NULL); perror("exec"); @@ -135,11 +139,14 @@ int main(int argc, char **argv) int count; FILE *fifo; bool reexec = false; + sigset_t signals; struct sigaction sa; if (getpid() != 1) return 1; + printf("OpenRC init version %s starting\n", VERSION); + if (argc > 1) default_runlevel = argv[1]; else @@ -148,15 +155,22 @@ int main(int argc, char **argv) if (default_runlevel && strcmp(default_runlevel, "reexec") == 0) reexec = true; - printf("OpenRC init version %s starting\n", VERSION); - if (! reexec) - init(default_runlevel); + /* block all signals we do not handle */ + sigfillset(&signals); + sigdelset(&signals, SIGCHLD); + sigdelset(&signals, SIGINT); + sigprocmask(SIG_SETMASK, &signals, NULL); + + /* install signal handler */ memset(&sa, 0, sizeof(sa)); sa.sa_handler = signal_handler; sigaction(SIGCHLD, &sa, NULL); sigaction(SIGINT, &sa, NULL); reboot(RB_DISABLE_CAD); + if (! reexec) + init(default_runlevel); + if (mkfifo(RC_INIT_FIFO, 0600) == -1 && errno != EEXIST) perror("mkfifo"); |