From 2c6397d1c25f45fadedf1be4c5d77dfb1e944844 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Fri, 20 Dec 2024 17:56:07 +0100 Subject: [PATCH] pid1: log if we failed to find a watchdog device 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 | 3 +++ src/shared/watchdog.c | 17 +++++++++++++++++ src/shared/watchdog.h | 1 + 3 files changed, 21 insertions(+) diff --git a/src/core/manager.c b/src/core/manager.c index 12c4e65e520..6d20cf9423f 100644 --- a/src/core/manager.c +++ b/src/core/manager.c @@ -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); } diff --git a/src/shared/watchdog.c b/src/shared/watchdog.c index dc941253794..22c28f0c374 100644 --- a/src/shared/watchdog.c +++ b/src/shared/watchdog.c @@ -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 diff --git a/src/shared/watchdog.h b/src/shared/watchdog.h index bf9212a8650..da63730a5ca 100644 --- a/src/shared/watchdog.h +++ b/src/shared/watchdog.h @@ -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); -- 2.47.3