]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
pid1: log if we failed to find a watchdog device
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Fri, 20 Dec 2024 16:56:07 +0000 (17:56 +0100)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Fri, 21 Mar 2025 10:38:43 +0000 (11:38 +0100)
I think we need to log at some point if the user configured a watchdog device,
but no devices were found. We can't log ENOENT immediately, because the device
may likely appear during boot. So wait until the end of the initial transaction
and log then.

src/core/manager.c
src/shared/watchdog.c
src/shared/watchdog.h

index 12c4e65e520cd739b88644186f6e9d455431ff76..6d20cf9423f38763f55c6ff36ca5c9a682c05393 100644 (file)
@@ -3871,6 +3871,9 @@ static void manager_notify_finished(Manager *m) {
 
         bus_manager_send_finished(m, firmware_usec, loader_usec, kernel_usec, initrd_usec, userspace_usec, total_usec);
 
+        if (MANAGER_IS_SYSTEM(m) && detect_container() <= 0)
+                watchdog_report_if_missing();
+
         log_taint_string(m);
 }
 
index dc941253794fcfd3ed0c409b1286b74873b7d951..22c28f0c374bd5929f5f1f3b95e0b89db5398500 100644 (file)
@@ -482,6 +482,23 @@ int watchdog_ping(void) {
         return watchdog_ping_now();
 }
 
+void watchdog_report_if_missing(void) {
+        /* If we failed to open the watchdog because the device doesn't exist, report why. If we successfully
+         * opened a device, or opening failed for a different reason, we logged then. But ENOENT failure may
+         * be transient, for example because modules being loaded or the hardware being detected. This
+         * function can be called to log after things have settled down.
+         *
+         * If a device was specified explicitly, raise level. */
+
+        if (watchdog_fd == -ENOENT)
+                log_full_errno(watchdog_device ? LOG_WARNING : LOG_NOTICE,
+                               watchdog_fd,
+                               "Failed to open %swatchdog device%s%s before the initial transaction completed: %m",
+                               watchdog_device ? "" : "any ",
+                               watchdog_device ? " " : "",
+                               strempty(watchdog_device));
+}
+
 void watchdog_close(bool disarm) {
 
         /* Once closed, pinging the device becomes a NOP and we request a new
index bf9212a8650b9431709825e374b4c42f663ec875..da63730a5ca7011e2c81dbe86cc13ce268b50d4b 100644 (file)
@@ -13,6 +13,7 @@ int watchdog_setup(usec_t timeout);
 int watchdog_setup_pretimeout(usec_t usec);
 int watchdog_setup_pretimeout_governor(const char *governor);
 int watchdog_ping(void);
+void watchdog_report_if_missing(void);
 void watchdog_close(bool disarm);
 usec_t watchdog_runtime_wait(void);