From cd32c623cf938065ac8baaeb2bf96c013e242a53 Mon Sep 17 00:00:00 2001 From: Joachim Wiberg Date: Thu, 27 Mar 2025 19:12:10 +0100 Subject: [PATCH] plugins: ignore PID file events for svc_t in setup/teardown/cleanup An svc_t (service/sysv) that is in setup, teardown, or cleanup state must be ignored by the pidfile plugin for any events regarding PID files. E.g., a setup script for a sysv service may create a PID file to alert the system that a setup process for the service is running. Signed-off-by: Joachim Wiberg --- ChangeLog.md | 3 +++ plugins/pidfile.c | 17 +++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/ChangeLog.md b/ChangeLog.md index e431a898..031c3359 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -22,6 +22,9 @@ All relevant changes are documented in this file. optional `env:file` (leading `-`) - Fix blocked signals for pre/post/ready/cleanup scripts preventing normal shutdown when a service/sysv is stopped in its setup state + - Fix issue where a pre:script creates a PID file in `/run` cause the + service to move from setup state to running. Any `svc_t` in setup, + teardown, or cleanup state should be ignored in the pidfile plugin [4.10][] - 2025-03-03 diff --git a/plugins/pidfile.c b/plugins/pidfile.c index ff810b60..f6496d4d 100644 --- a/plugins/pidfile.c +++ b/plugins/pidfile.c @@ -80,6 +80,23 @@ static void pidfile_update_conds(char *dir, char *name, uint32_t mask) return; } + switch (svc->state) { + case SVC_TEARDOWN_STATE: + case SVC_CLEANUP_STATE: + case SVC_SETUP_STATE: + /* + * E.g., a setup script for a container may run in lieu + * of crun, trying to fetch a container image from the + * network. This script may want to advertise its PID + * to the system for clean and swift reboots. + */ + dbg("%s[%d]: ignoring any PID file changes in CLEANUP/TEARDOWN/SETUP", + svc_ident(svc, NULL, 0), svc->pid); + return; + default: + break; + } + /* Service condistion to set/clear */ mkcond(svc, cond, sizeof(cond));