From f4b1a6b6419b771d26342a9b75b1d77ee9d90133 Mon Sep 17 00:00:00 2001 From: Michael Olbrich Date: Wed, 2 Feb 2022 15:26:53 +0100 Subject: [PATCH 1/2] watchdog: fix watchdog_set_device() when the default watchdog device is used If watchdog_set_device() is not called before open_watchdog() then 'watchdog_device' remains 'NULL' while the device is open. As a result, the "same device" check in watchdog_set_device() does not work correctly: If no device is specified (e.g. from watchdog_free_device()) then the current fd is not closed. Fix this by setting 'watchdog_device' to the correct device during open_watchdog() --- src/shared/watchdog.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/shared/watchdog.c b/src/shared/watchdog.c index e8184ff661..e4cc0926f7 100644 --- a/src/shared/watchdog.c +++ b/src/shared/watchdog.c @@ -133,6 +133,10 @@ static int open_watchdog(void) { fn = !watchdog_device || path_equal(watchdog_device, "/dev/watchdog") ? "/dev/watchdog0" : watchdog_device; + r = free_and_strdup(&watchdog_device, fn); + if (r < 0) + return log_oom_debug(); + watchdog_fd = open(fn, O_WRONLY|O_CLOEXEC); if (watchdog_fd < 0) return log_debug_errno(errno, "Failed to open watchdog device %s, ignoring: %m", fn); From 119d5126d1c69ae0920a6e888e4b419458c5e292 Mon Sep 17 00:00:00 2001 From: Michael Olbrich Date: Wed, 2 Feb 2022 15:33:07 +0100 Subject: [PATCH 2/2] shutdown: don't stop the watchdog This basically reverts #22079. Stopping the watchdog is wrong. The reboot watchdog is supposed to cover the whole time from the point when systemd start systemd-reboot until the hardware resets. Otherwise the system may hang in the final shutdown phase. Add a comment, why keeping the watchdog running is correct here. --- src/shutdown/shutdown.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/shutdown/shutdown.c b/src/shutdown/shutdown.c index 15fd6f93d3..2c3cbec02c 100644 --- a/src/shutdown/shutdown.c +++ b/src/shutdown/shutdown.c @@ -531,8 +531,9 @@ int main(int argc, char *argv[]) { need_md_detach ? " MD devices," : ""); } - /* We're done with the watchdog. */ - watchdog_close(true); + /* We're done with the watchdog. Note that the watchdog is explicitly not + * stopped here. It remains active to guard against any issues during the + * rest of the shutdown sequence. */ watchdog_free_device(); arguments[0] = NULL;