shutdown: check WATCHDOG_PID= if it is set

Alternative to: #35167
This commit is contained in:
Lennart Poettering
2026-04-04 22:52:58 +02:00
parent e7182635c6
commit 8cfae74dcd
+16
View File
@@ -286,6 +286,22 @@ static void init_watchdog(void) {
const char *s;
int r;
/* NB: we do not insist on $WATCHDOG_PID being set because old systemd versions didn't set it at all,
* and we want to retain some basic compatibility between an old service manager and a new shutdown
* binary. If it *is* set we'll insist on it being set to 1 however. */
s = secure_getenv("WATCHDOG_PID");
if (s) {
pid_t pid;
r = parse_pid(s, &pid);
if (r < 0)
log_warning_errno(r, "Failed to parse $WATCHDOG_PID, ignoring: %s", s);
else if (pid != getpid_cached()) {
log_warning("$WATCHDOG_PID set, but not to " PID_FMT ", skipping watchdog logic.", getpid_cached());
return;
}
}
s = secure_getenv("WATCHDOG_DEVICE");
if (s) {
r = watchdog_set_device(s);