diff options
author | David Oberhollenzer <goliath@infraroot.at> | 2020-05-08 01:50:49 +0200 |
---|---|---|
committer | David Oberhollenzer <goliath@infraroot.at> | 2020-05-08 02:08:00 +0200 |
commit | 62133a68b7a1aecf65765f7137ef8d6e0eed913e (patch) | |
tree | f271dc8b24c4db4f7b054b633c4fa6f6e2157d5c /initd/main.c | |
parent | 13aa3840cc94ce37ef1e63c093c0f71ac84e90fd (diff) |
Cleanup: complete redesign of the initd supervisor
- Cleanly seperate service description parsed from file
from the actual run-time data.
- Remove the use of the signalfd and make asyncronous calls
into the supervisor from signal context work.
Signed-off-by: David Oberhollenzer <goliath@infraroot.at>
Diffstat (limited to 'initd/main.c')
-rw-r--r-- | initd/main.c | 73 |
1 files changed, 14 insertions, 59 deletions
diff --git a/initd/main.c b/initd/main.c index 5a4c37a..caa2a1e 100644 --- a/initd/main.c +++ b/initd/main.c @@ -1,20 +1,12 @@ /* SPDX-License-Identifier: ISC */ #include "init.h" -static int sigfd = -1; - -static void handle_signal(void) +static void handle_signal(int signo) { - struct signalfd_siginfo info; int status; pid_t pid; - if (read(sigfd, &info, sizeof(info)) != sizeof(info)) { - perror("read on signal fd"); - return; - } - - switch (info.ssi_signo) { + switch (signo) { case SIGCHLD: while ((pid = waitpid(-1, &status, WNOHANG)) > 0) { status = WIFEXITED(status) ? WEXITSTATUS(status) : @@ -52,66 +44,29 @@ void target_completed(int target) } } -static int sigsetup(void) +int main(void) { - sigset_t mask; - int sfd; + struct sigaction act; - sigfillset(&mask); - if (sigprocmask(SIG_SETMASK, &mask, NULL) == -1) { - perror("sigprocmask"); - return -1; - } + supervisor_init(); - sfd = signalfd(-1, &mask, SFD_CLOEXEC); - if (sfd == -1) { - perror("signalfd"); - return -1; - } + memset(&act, 0, sizeof(act)); + act.sa_handler = handle_signal; + + sigaction(SIGCHLD, &act, NULL); + sigaction(SIGTERM, &act, NULL); + sigaction(SIGINT, &act, NULL); + sigaction(SIGHUP, &act, NULL); + sigaction(SIGUSR1, &act, NULL); if (reboot(LINUX_REBOOT_CMD_CAD_OFF)) perror("cannot disable CTRL+ALT+DEL"); - return sfd; -} - -int main(void) -{ - int i, ret, count; - struct pollfd pfd[2]; - - if (getpid() != 1) { - fputs("init does not have pid 1, terminating!\n", stderr); - return EXIT_FAILURE; - } - - supervisor_init(); - - sigfd = sigsetup(); - if (sigfd < 0) - return -1; - for (;;) { while (supervisor_process_queues()) ; - memset(pfd, 0, sizeof(pfd)); - count = 0; - - pfd[count].fd = sigfd; - pfd[count].events = POLLIN; - ++count; - - ret = poll(pfd, count, -1); - if (ret <= 0) - continue; - - for (i = 0; i < count; ++i) { - if (pfd[i].revents & POLLIN) { - if (pfd[i].fd == sigfd) - handle_signal(); - } - } + pause(); } return EXIT_SUCCESS; |