From 14fd315f3862b2fd9bc1253f9d0b2536a828d6ea Mon Sep 17 00:00:00 2001 From: Joachim Wiberg Date: Fri, 13 Nov 2026 16:52:22 +0100 Subject: [PATCH] keventd: touch the PID file after SIGHUP After a SIGHUP, from initctl reload or a changed service, Finit waits for a pid-notify daemon to recreate or touch its PID file to reassert readiness. keventd only reloaded its rules, so with a daemon-owned PID file it never did. Touch it with pidfile() after reloading the rules, once keventd has created it. With -c that is after the coldplug queue has drained. Fixes #503 Signed-off-by: Joachim Wiberg --- doc/ChangeLog.md | 3 +++ keventd/keventd.c | 6 ++++++ test/keventd.sh | 8 ++++++++ 3 files changed, 17 insertions(+) diff --git a/doc/ChangeLog.md b/doc/ChangeLog.md index 78ef9224..4abad8eb 100644 --- a/doc/ChangeLog.md +++ b/doc/ChangeLog.md @@ -163,6 +163,9 @@ All relevant changes are documented in this file. - Fix #512: `--` in the `command` of a block-format .conf, it was taken as the start of the description, so `command = "cmd -- arg"` ran `cmd` with description `arg`. Found by Alexandru PaniČ™ +- Fix #503: keventd did not touch its PID file after SIGHUP, so with a + daemon-owned PID file Finit never saw it reassert readiness after a + reload. Reported by Aaron Andersen - Fix a command whose name starts like a service option, e.g. `logger` or `pidof`. It was taken as the `log` or `pid` option and the next argument ran as the command, which also broke the `logger` example in finit.conf(5) diff --git a/keventd/keventd.c b/keventd/keventd.c index 39ff6144..38e22c9f 100644 --- a/keventd/keventd.c +++ b/keventd/keventd.c @@ -143,6 +143,7 @@ static int num_ac; static int level; static int logon; static int passive; /* power-supply only, no device management */ +static int ready; /* pidfile created, see issue #503 */ static struct rule_list rules = TAILQ_HEAD_INITIALIZER(rules); static char *rules_dir; /* extra rules dir from -r option */ @@ -507,10 +508,13 @@ static void sigterm_cb(uev_t *w, void *arg, int events) uev_exit(w->ctx); } +/* Finit expects the pidfile touched to reassert readiness after SIGHUP */ static void sighup_cb(uev_t *w, void *arg, int events) { (void)w; (void)arg; (void)events; kev_rules_reload(); + if (ready) + pidfile(NULL); } static void sigchld_cb(uev_t *w, void *arg, int events) @@ -613,6 +617,7 @@ static void coldplug_pidfile_cb(uev_t *w, void *arg, int events) return; pidfile(NULL); + ready = 1; logit(LOG_NOTICE, "keventd ready, coldplug queue drained"); uev_timer_stop(w); } @@ -826,6 +831,7 @@ int main(int argc, char *argv[]) logit(LOG_NOTICE, "keventd v%s started, draining coldplug queue...", KEVENTD_VERSION); } else { pidfile(NULL); + ready = 1; logit(LOG_NOTICE, "keventd v%s started, waiting for events...", KEVENTD_VERSION); } diff --git a/test/keventd.sh b/test/keventd.sh index b00f6d63..45b4785d 100755 --- a/test/keventd.sh +++ b/test/keventd.sh @@ -39,6 +39,14 @@ run "ip link del probe0" sep "keventd readiness" retry 'assert_ready "keventd"' 50 0.2 +# Finit does not touch a daemon-owned pidfile, so keventd must do it +# after SIGHUP to reassert readiness, see issue #503. Signalled with +# kill to keep Finit out of it. +sep "keventd touches its pidfile on SIGHUP" +run "touch -d '2000-01-01 00:00' /run/keventd.pid" +run "kill -HUP $(texec cat /run/keventd.pid)" +retry "test \$(texec stat -c %Y /run/keventd.pid) -gt 1000000000" 10 0.2 + sep "interface add asserts " cat >> "$SYSROOT$FINIT_CONF" <