Add support for sys/pwr/fail and sys/key/ctrlaltdel conditions

This patch drops the default signal handlers for SIGPWR and SIGINT with
optional tasks in /etc/finit.conf, triggered by two new conditions:
sys/pwr/fail and sys/key/ctrlaltdel, respectively.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
Joachim Wiberg
2021-05-18 08:58:11 +02:00
parent e706300b6d
commit b79245ddb3
4 changed files with 41 additions and 9 deletions
+10 -5
View File
@@ -17,11 +17,16 @@ Bug fix release.
* Change how `contrib/debian/install.sh` sets up a Grub boot entry for
finit. We now modify the $SUPPORTED_INITS variable in `10_linux`
* Disable default kernel ctrl-alt-delete handler and let Finit instead
catch `SIGINT` from kernel to be able to perform a proper reboot.
See the TODO for a future `sys/key/ctrlaltdel` condition extension
* Added keventd to provide `sys/pwr/ac` condition to Finit. keventd is
currently only responsible for monitoring `/sys/class/power_supply`
for changes to active AC mains power online status.
catch `SIGINT` from kernel to be able to perform a proper reboot.
There is no default command for this, you need to set up a task that
triggers on `<sys/key/ctrlaltdel>` to issue `initctl reboot`
* Added keventd to provide `<sys/pwr/ac>` condition to Finit. keventd
is currently only responsible for monitoring `/sys/class/power_supply`
for changes to active AC mains power online status
* For handling power fail events (from UPS and similar) a process may
send `SIGPWR` to PID 1. Finit no longer redirects this to `SIGUSR1`
(poweroff). There is no default command for this, you need to set up
a task that triggers on `<sys/pwr/fail>` to issue `initctl poweroff`
### Fixes
* Stricter interface name validation in netlink plugin, modeled after
+8
View File
@@ -35,6 +35,14 @@ tty /dev/tty1
tty /dev/tty2
tty /dev/tty3
# Task to run if ctrl-alt-del is pressed. This condition is asserted by
# Finit upon receiving SIGINT (from the kernel).
task <sys/key/ctrlaltdel> [12345789] initctl reboot -- Rebooting system
# Task to run if the kernel gets a power fail condition is pressed.
# Asserted by Finit upon receiving SIGPWR (from the kernel).
task <sys/pwr/fail> [12345789] initctl poweroff -- Shutting down system
# Alternative method instead of runparts
#task [S] /etc/init.d/keyboard-setup start -- Setting up preliminary keymap
#task [S] /etc/init.d/acpid start -- Starting ACPI Daemon
+2
View File
@@ -115,6 +115,8 @@ Built-in conditions:
- `net/<IFNAME>/up`
- `net/<IFNAME>/running`
- `sys/pwr/ac`
- `sys/pwr/fail`
- `sys/key/ctrlaltdel`
- `usr/foo`
**Note:** `up` means administratively up, the interface flag `IFF_UP`.
+21 -4
View File
@@ -311,7 +311,9 @@ static void sighup_cb(uev_t *w, void *arg, int events)
}
/*
* SIGINT: Should generate <sys/key/ctrlaltdel> condition, for now reboot
* SIGINT: generates <sys/key/ctrlaltdel> condition, which the sys.so
* plugin picks up and tells Finit to start any service(s) or
* task(s) associated with the condition.
*/
static void sigint_cb(uev_t *w, void *arg, int events)
{
@@ -321,8 +323,23 @@ static void sigint_cb(uev_t *w, void *arg, int events)
return;
}
halt = SHUT_REBOOT;
service_runlevel(6);
cond_set_oneshot_noupdate("sys/key/ctrlaltdel");
}
/*
* SIGPWR: generates <sys/pwr/fail> condition, which the sys.so plugin
* picks up and tells Finit to start any service(s) or task(s)
* associated with the condition.
*/
static void sigpwr_cb(uev_t *w, void *arg, int events)
{
_d("...");
if (UEV_ERROR == events) {
_e("Unrecoverable error in signal watcher");
return;
}
cond_set_oneshot_noupdate("sys/pwr/fail");
}
/*
@@ -531,7 +548,7 @@ void sig_setup(uev_ctx_t *ctx)
/* 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);
uev_signal_init(ctx, &sigpwr_watcher, sigpwr_cb, NULL, SIGPWR);
uev_signal_init(ctx, &sigterm_watcher, sigterm_cb, NULL, SIGTERM);
/* Some C APIs may need SIGALRM for implementing timers. */