]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
shared/watchdog: add MESSAGE_IDs to logs about watchdog opening
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Fri, 21 Mar 2025 11:10:35 +0000 (12:10 +0100)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Fri, 21 Mar 2025 14:55:50 +0000 (15:55 +0100)
One ID for the success case, with WATCHDOG_DEVICE= showing the device,
and one ID for the failure case, with WATCHDOG_DEVICE= if configured,
and ERRNO= set automatically.

src/shared/watchdog.c
src/systemd/sd-messages.h

index 449c070f8f4b123ed36560a95b8e56f1ce5fd65e..6828a22b425e39307b7a8d0a9ad1c80807e5e20f 100644 (file)
@@ -7,6 +7,8 @@
 #include <unistd.h>
 #include <linux/watchdog.h>
 
+#include "sd-messages.h"
+
 #include "devnum-util.h"
 #include "errno-util.h"
 #include "fd-util.h"
@@ -344,7 +346,10 @@ static int watchdog_open(bool ignore_ratelimit) {
                 }
 
                 if (watchdog_fd != -ENOENT)
-                        return log_warning_errno(watchdog_fd, "Failed to open watchdog device %s: %m", *wd);
+                        return log_struct_errno(LOG_WARNING, watchdog_fd,
+                                                LOG_MESSAGE("Failed to open watchdog device %s: %m", *wd),
+                                                "MESSAGE_ID=" SD_MESSAGE_WATCHDOG_OPEN_FAILED_STR,
+                                                "WATCHDOG_DEVICE=%s", *wd);
         }
 
         if (watchdog_fd < 0)
@@ -357,13 +362,19 @@ static int watchdog_open(bool ignore_ratelimit) {
 
         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);
+                log_struct_errno(LOG_INFO, r,
+                                 LOG_MESSAGE("Using hardware watchdog %s, no support for WDIOC_GETSUPPORT ioctl: %m",
+                                             watchdog_device),
+                                 "MESSAGE_ID=" SD_MESSAGE_WATCHDOG_OPENED_STR,
+                                 "WATCHDOG_DEVICE=%s", watchdog_device);
         else
-                log_info("Using hardware watchdog %s: '%s', version %x.",
-                         watchdog_device,
-                         ident.identity,
-                         ident.firmware_version),
+                log_struct(LOG_INFO,
+                           LOG_MESSAGE("Using hardware watchdog %s: '%s', version %x.",
+                                       watchdog_device,
+                                       ident.identity,
+                                       ident.firmware_version),
+                           "MESSAGE_ID=" SD_MESSAGE_WATCHDOG_OPENED_STR,
+                           "WATCHDOG_DEVICE=%s", watchdog_device);
 
         r = watchdog_update_timeout();
         if (r < 0)
@@ -505,12 +516,16 @@ void watchdog_report_if_missing(void) {
         if (watchdog_open(/* ignore_ratelimit= */ true) >= 0)
                 return;
 
-        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));
+        if (watchdog_device)
+                log_struct_errno(LOG_WARNING, watchdog_fd,
+                                 LOG_MESSAGE("Failed to open watchdog device %s before the initial transaction completed: %m",
+                                             watchdog_device),
+                                 "MESSAGE_ID=" SD_MESSAGE_WATCHDOG_OPEN_FAILED_STR,
+                                 "WATCHDOG_DEVICE=%s", watchdog_device);
+        else
+                log_struct_errno(LOG_WARNING, watchdog_fd,
+                                 LOG_MESSAGE("Failed to open any watchdog device before the initial transaction completed: %m"),
+                                 "MESSAGE_ID=" SD_MESSAGE_WATCHDOG_OPEN_FAILED_STR);
 }
 
 void watchdog_close(bool disarm) {
index 60b28087f6f0a3a387bc1f1190233af7604a94ed..c35b1bfdec4f5e6eb891f31704ea3d0521080f6b 100644 (file)
@@ -256,6 +256,12 @@ _SD_BEGIN_DECLARATIONS;
 #define SD_MESSAGE_TIME_BUMP                          SD_ID128_MAKE(7d,b7,3c,8a,f0,d9,4e,eb,82,2a,e0,43,23,fe,6a,b6)
 #define SD_MESSAGE_TIME_BUMP_STR                      SD_ID128_MAKE_STR(7d,b7,3c,8a,f0,d9,4e,eb,82,2a,e0,43,23,fe,6a,b6)
 
+#define SD_MESSAGE_WATCHDOG_OPENED                    SD_ID128_MAKE(21,66,8d,bd,3d,7a,4a,32,a2,67,6d,53,da,da,b0,22)
+#define SD_MESSAGE_WATCHDOG_OPENED_STR                SD_ID128_MAKE_STR(21,66,8d,bd,3d,7a,4a,32,a2,67,6d,53,da,da,b0,22)
+
+#define SD_MESSAGE_WATCHDOG_OPEN_FAILED               SD_ID128_MAKE(37,5a,c1,51,ef,9d,4d,e3,90,68,b3,ef,bf,ed,0c,ee)
+#define SD_MESSAGE_WATCHDOG_OPEN_FAILED_STR           SD_ID128_MAKE_STR(37,5a,c1,51,ef,9d,4d,e3,90,68,b3,ef,bf,ed,0c,ee)
+
 #define SD_MESSAGE_SHUTDOWN_SCHEDULED                 SD_ID128_MAKE(9e,70,66,27,9d,c8,40,3d,a7,9c,e4,b1,a6,90,64,b2)
 #define SD_MESSAGE_SHUTDOWN_SCHEDULED_STR             SD_ID128_MAKE_STR(9e,70,66,27,9d,c8,40,3d,a7,9c,e4,b1,a6,90,64,b2)