diff options
author | William Hubbs <w.d.hubbs@gmail.com> | 2017-04-13 12:54:18 -0500 |
---|---|---|
committer | William Hubbs <w.d.hubbs@gmail.com> | 2017-04-13 12:54:30 -0500 |
commit | 4694900190a9078397bb9083328b68b489af92f4 (patch) | |
tree | deac948799cf8329d2f61868b2b23c85fa51f53f /src/rc/openrc-init.c | |
parent | 05738bfce120114037d4f02c67ec740813f94b89 (diff) |
init: fix signal handling
The only signals we handle are SIGINT and SIGCHLD, so block all others
and unblock them in the child process before we start a rurnlevel.
Diffstat (limited to 'src/rc/openrc-init.c')
-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"); |