From: Michael Olbrich Date: Wed, 2 Feb 2022 14:26:53 +0000 (+0100) Subject: watchdog: fix watchdog_set_device() when the default watchdog device is used X-Git-Tag: v251-rc1~351^2~1 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=f4b1a6b6419b771d26342a9b75b1d77ee9d90133;p=thirdparty%2Fsystemd.git 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() --- diff --git a/src/shared/watchdog.c b/src/shared/watchdog.c index e8184ff661b..e4cc0926f78 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);