From: Zbigniew Jędrzejewski-Szmek Date: Fri, 21 Mar 2025 11:10:35 +0000 (+0100) Subject: shared/watchdog: add MESSAGE_IDs to logs about watchdog opening X-Git-Tag: v258-rc1~1012^2~2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=236ac39b65b0a741827c30dcad8a95d8b66276e5;p=thirdparty%2Fsystemd.git shared/watchdog: add MESSAGE_IDs to logs about watchdog opening 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. --- diff --git a/src/shared/watchdog.c b/src/shared/watchdog.c index 449c070f8f4..6828a22b425 100644 --- a/src/shared/watchdog.c +++ b/src/shared/watchdog.c @@ -7,6 +7,8 @@ #include #include +#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) { diff --git a/src/systemd/sd-messages.h b/src/systemd/sd-messages.h index 60b28087f6f..c35b1bfdec4 100644 --- a/src/systemd/sd-messages.h +++ b/src/systemd/sd-messages.h @@ -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)