From 53c7ddcb22a237d1e0e78dec230ae96d65fb8910 Mon Sep 17 00:00:00 2001 From: Joachim Wiberg Date: Sun, 2 May 2021 14:48:49 +0200 Subject: [PATCH] Change SIGUSR1 to be compatible with systemd and SysV init This patch changes the behavior of SIGUSR1. Previously USR1 could be used to halt a running Finit system, similar to BusyBox init. However, compatibility with sysvinit and systemd has been deemed more important. Signed-off-by: Joachim Wiberg --- doc/signals.md | 26 +++++++++++++++++--------- src/reboot.c | 2 +- src/sig.c | 28 ++++++++++++++++------------ 3 files changed, 34 insertions(+), 22 deletions(-) diff --git a/doc/signals.md b/doc/signals.md index c90d88a1..534e7bf4 100644 --- a/doc/signals.md +++ b/doc/signals.md @@ -12,28 +12,36 @@ have been adopted: Same effect as `finit q`, `init q`, or `initctl reload`, reloads all *.conf files in `/etc/finit.d/` +This also restarts the API (initctl) socket, like SysV init and systemd +does on USR1 with their FIFO/D-Bus. + + `SIGUSR1` --------- -Calls shutdown hooks, including `HOOK_SHUTDOWN`, stopping all running -processes, and unmounts all file systems. Then tells kernel to halt. -Most people these days want `SIGUSR2` though. +Since Finit 4.1 this signal causes Finit to restart its API (initctl) +socket, like SysV init and systemd does on USR1 with their FIFO/D-Bus. + +Finit <= 4.0 performed a system halt (like USR2 without power-off), but +this caused compatibility problems with systemd and sysvinit on desktop +systems. Hence, since Finit 4.1 it is no longer possible to halt a +system with a signal. -SysV init and systemd use this to re-open their FIFO/D-Bus. `SIGUSR2` --------- -Like SIGUSR1, but tell kernel to power-off the system, if ACPI or -similar exists to actually do this. If the kernel fails power-off, -Finit falls back to halt. - +Calls shutdown hooks, including `HOOK_SHUTDOWN`, stopping all running +processes, and unmounts all file systems. Then tells kernel to power +off the system, if ACPI or similar exists to actually do this. If the +kernel fails power-off, Finit falls back to halt. + SysV init N/A, systemd dumps its internal state to log. `SIGTERM` --------- -Like `SIGUSR1`, but tell kernel to reboot the system when done. +Like `SIGUSR2`, but tell kernel to reboot the system when done. SysV init N/A, systemd rexecutes itself. diff --git a/src/reboot.c b/src/reboot.c index ce397b96..874e70bd 100644 --- a/src/reboot.c +++ b/src/reboot.c @@ -206,7 +206,7 @@ int reboot_main(int argc, char *argv[]) case CMD_HALT: if (do_halt(NULL)) - do_kill(SIGUSR1, msg); + do_kill(SIGUSR2, msg); break; case CMD_POWEROFF: diff --git a/src/sig.c b/src/sig.c index 90ff1936..5d5a0659 100644 --- a/src/sig.c +++ b/src/sig.c @@ -31,21 +31,24 @@ * does on USR1 with their FIFO/D-Bus. * * SIGUSR1 - * Calls shutdown hooks, including HOOK_SHUTDOWN, stops all running - * processes, and unmounts all file systems. Then tells kernel to - * halt. Most people these days want SIGUSR2 though. + * Restarts API (initctl) socket, like SysV init and systemd does + * on USR1 with their FIFO/D-Bus. * - * (SysV init and systemd use this to re-open their FIFO/D-Bus.) + * Finit <= 4.0 used to perform a system halt on USR1. This caused + * some quite nasty problems on systems with both systemd/sysvinit + * installed alongside finit. For compatibility reasons Finit 4.1 + * changed to partial SIGHUP (api_exit/init). * * SIGUSR2 - * Like SIGUSR1, but tell kernel to power-off the system, if ACPI - * or similar exists to actually do this. If the kernel fails - * power-off, Finit falls back to halt. + * Calls shutdown hooks, including HOOK_SHUTDOWN, stops all running + * processes, and unmounts all file systems. Then tells kernel to + * power-off the system, if ACPI or similar exists to actually do + * this. If the kernel fails power-off, Finit falls back to halt. * * (SysV init N/A, systemd dumps its internal state to log.) * * SIGTERM - * Like SIGUSR1, but tell kernel to reboot the system when done. + * Like SIGUSR2, but tell kernel to reboot the system when done. * * (SysV init N/A, systemd rexecutes itself.) * @@ -323,7 +326,7 @@ static void sigint_cb(uev_t *w, void *arg, int events) } /* - * SIGUSR1: BusyBox style halt + * SIGUSR1: SysV init/systemd API socket restart */ static void sigusr1_cb(uev_t *w, void *arg, int events) { @@ -333,8 +336,9 @@ static void sigusr1_cb(uev_t *w, void *arg, int events) return; } - halt = SHUT_HALT; - service_runlevel(0); + /* Restart initctl API domain socket, similar to systemd/SysV init */ + api_exit(); + api_init(w->ctx); } /* @@ -520,7 +524,7 @@ void sig_setup(uev_ctx_t *ctx) /* Standard SysV init calls ctrl-alt-delete handler */ uev_signal_init(ctx, &sigint_watcher, sigint_cb, NULL, SIGINT); - /* BusyBox init style signals for halt, power-off and reboot. */ + /* BusyBox/SysV init style signals for halt, power-off and reboot. */ uev_signal_init(ctx, &sigusr1_watcher, sigusr1_cb, NULL, SIGUSR1); uev_signal_init(ctx, &sigusr2_watcher, sigusr2_cb, NULL, SIGUSR2); uev_signal_init(ctx, &sigpwr_watcher, sigusr2_cb, NULL, SIGPWR);