]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
shared/watchdog: raise log levels for watchdog errors
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Fri, 20 Dec 2024 16:27:57 +0000 (17:27 +0100)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Fri, 21 Mar 2025 10:30:26 +0000 (11:30 +0100)
If we failed to open the watchdog device for any reason, we'd only log at debug
level. This seems iffy: if the user configured a timeout for the watchdog, we
should report when we can't set it up. ENOENT is still logged at debug level
only, since it's somewhat expected to have a watchdog timeout set up, even for
systems which don't have a watchdog, or the device might appear later.

If the device doesn't support WDIOC_GETSUPPORT, still log that we opened a
device.

No change in behaviour, except for the log level threshold. As a side effect,
the reason why we failed to open the device is now stored in watchdog_fd
(previously it was -1 always), but this isn't used for anything.

src/shared/watchdog.c

index 7ac689c1506563efcdd0d53220fa884ecfffe2f6..dc941253794fcfd3ed0c409b1286b74873b7d951 100644 (file)
@@ -195,10 +195,13 @@ usec_t watchdog_get_last_ping(clockid_t clock) {
 }
 
 static int watchdog_ping_now(void) {
+        int r;
+
         assert(watchdog_fd >= 0);
 
-        if (ioctl(watchdog_fd, WDIOC_KEEPALIVE, 0) < 0)
-                return log_warning_errno(errno, "Failed to ping hardware watchdog, ignoring: %m");
+        r = RET_NERRNO(ioctl(watchdog_fd, WDIOC_KEEPALIVE, 0));
+        if (r < 0)
+                return log_warning_errno(r, "Failed to ping hardware watchdog, ignoring: %m");
 
         watchdog_last_ping = now(CLOCK_BOOTTIME);
 
@@ -322,7 +325,7 @@ static int watchdog_open(void) {
                 STRV_MAKE("/dev/watchdog0", "/dev/watchdog") : STRV_MAKE(watchdog_device);
 
         STRV_FOREACH(wd, try_order) {
-                watchdog_fd = open(*wd, O_WRONLY|O_CLOEXEC);
+                watchdog_fd = RET_NERRNO(open(*wd, O_WRONLY|O_CLOEXEC));
                 if (watchdog_fd >= 0) {
                         if (free_and_strdup(&watchdog_device, *wd) < 0) {
                                 r = log_oom_debug();
@@ -332,22 +335,27 @@ static int watchdog_open(void) {
                         break;
                 }
 
-                if (errno != ENOENT)
-                        return log_debug_errno(errno, "Failed to open watchdog device %s: %m", *wd);
+                if (watchdog_fd != -ENOENT)
+                        return log_warning_errno(watchdog_fd, "Failed to open watchdog device %s: %m", *wd);
         }
 
         if (watchdog_fd < 0)
-                return log_debug_errno(SYNTHETIC_ERRNO(ENOENT), "Failed to open watchdog device %s.", watchdog_device ?: "auto");
+                return log_debug_errno(watchdog_fd, "Failed to open %swatchdog device%s%s.",
+                                       watchdog_device ? "" : "any ",
+                                       watchdog_device ? " " : "",
+                                       strempty(watchdog_device));
 
         watchdog_last_ping = USEC_INFINITY;
 
-        if (ioctl(watchdog_fd, WDIOC_GETSUPPORT, &ident) < 0)
-                log_debug_errno(errno, "Hardware watchdog %s does not support WDIOC_GETSUPPORT ioctl, ignoring: %m", watchdog_device);
+        r = RET_NERRNO(ioctl(watchdog_fd, WDIOC_GETSUPPORT, &ident));
+        if (r < 0)
+                log_info_errno(r, "Using hardware watchdog %s, no support for WDIOC_GETSUPPORT ioctl: %m",
+                               watchdog_device);
         else
-                log_info("Using hardware watchdog '%s', version %x, device %s",
+                log_info("Using hardware watchdog %s: '%s', version %x.",
+                         watchdog_device,
                          ident.identity,
-                         ident.firmware_version,
-                         watchdog_device);
+                         ident.firmware_version),
 
         r = watchdog_update_timeout();
         if (r < 0)