diff options
author | Leah Neukirchen <leah@vuxu.org> | 2022-01-06 19:36:27 +0100 |
---|---|---|
committer | Leah Neukirchen <leah@vuxu.org> | 2022-01-06 19:36:27 +0100 |
commit | 1da9e52fe56f0ee34a4ee9eb0f981a87e8e1c984 (patch) | |
tree | b9b1024c7c2157b3f5a4a358aed6cdf9434270ce | |
parent | f4809e60629353a13c3eb699d675f866dd6075cd (diff) | |
download | rvnit-1da9e52fe56f0ee34a4ee9eb0f981a87e8e1c984.tar.gz rvnit-1da9e52fe56f0ee34a4ee9eb0f981a87e8e1c984.tar.xz rvnit-1da9e52fe56f0ee34a4ee9eb0f981a87e8e1c984.zip |
revamp signal handling, use SIGCONT to wake up main thread
support reboot via command
-rw-r--r-- | rvnit.c | 43 |
1 files changed, 28 insertions, 15 deletions
diff --git a/rvnit.c b/rvnit.c index 4c9505c..74af39b 100644 --- a/rvnit.c +++ b/rvnit.c @@ -50,27 +50,29 @@ pthread_t logger_thread; int selflogfd[2]; -sig_atomic_t got_intr; -sig_atomic_t got_sigusr1; +sig_atomic_t want_shutdown; +sig_atomic_t want_rescan; + +int want_reboot = 0; void on_sigint(int sig) { (void)sig; - got_intr = 1; + want_shutdown = 1; } void -on_sigusr1(int sig) +on_sigusr2(int sig) { (void)sig; - got_sigusr1 = 1; } void -on_sigusr2(int sig) +on_sigcont(int sig) { (void)sig; + /* do nothing, but interrupt the system call */ } void @@ -249,12 +251,14 @@ socket_loop(void* ignored) printf("setting %s down\n", services[i].name); services[i].state = DOWN; - pthread_kill(main_thread, SIGUSR1); + want_rescan = 1; + pthread_kill(main_thread, SIGCONT); } else if (cmd == 'u') { printf("setting %s up\n", services[i].name); services[i].state = UP; - pthread_kill(main_thread, SIGUSR1); + want_rescan = 1; + pthread_kill(main_thread, SIGCONT); } else if (charsig(cmd) && services[i].pid > 0) { printf("sending signal %d to %s\n", charsig(cmd), services[i].name); kill(services[i].pid, charsig(cmd)); @@ -264,7 +268,13 @@ socket_loop(void* ignored) } if (cmd == 'X') { - pthread_kill(main_thread, SIGPWR); + want_shutdown = 1; + pthread_kill(main_thread, SIGCONT); + } + if (cmd == 'R') { + want_shutdown = 1; + want_reboot = 1; + pthread_kill(main_thread, SIGCONT); } close(connfd); @@ -574,16 +584,15 @@ main() } sigaction(SIGINT, &(struct sigaction){.sa_handler=on_sigint}, 0); - sigaction(SIGPWR, &(struct sigaction){.sa_handler=on_sigint}, 0); - sigaction(SIGUSR1, &(struct sigaction){.sa_handler=on_sigusr1}, 0); + sigaction(SIGCONT, &(struct sigaction){.sa_handler=on_sigcont}, 0); LOG("system up"); while (1) { - if (got_intr) + if (want_shutdown) break; - if (got_sigusr1) { + if (want_rescan) { printf("rescanning state\n"); for (i = 0; i < MAX_SV; i++) { if (services[i].name[2] == 'D' || @@ -597,7 +606,7 @@ main() } } - got_sigusr1 = 0; + want_rescan = 0; } int status = 0; @@ -743,7 +752,11 @@ fatal: ; // arrives with level < 99 } } - dprintf(selflogfd[1], "shutdown\n"); + if (want_reboot) + dprintf(selflogfd[1], "reboot\n"); + else + dprintf(selflogfd[1], "shutdown\n"); + close(selflogfd[1]); pthread_join(logger_thread, 0); } |