]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
shutdown: check WATCHDOG_PID= if it is set
authorLennart Poettering <lennart@amutable.com>
Thu, 26 Mar 2026 07:50:08 +0000 (08:50 +0100)
committerLennart Poettering <lennart@amutable.com>
Sat, 4 Apr 2026 20:52:58 +0000 (22:52 +0200)
Alternative to: #35167

src/shutdown/shutdown.c

index 83fa8c0b668f0be57e978cc29979d768c2667704..9b0328bfca05efc624fa64231cda281fe026c8e2 100644 (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);