]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
watchdog: fix watchdog_set_device() when the default watchdog device is used
authorMichael Olbrich <m.olbrich@pengutronix.de>
Wed, 2 Feb 2022 14:26:53 +0000 (15:26 +0100)
committerMichael Olbrich <m.olbrich@pengutronix.de>
Fri, 4 Feb 2022 11:26:58 +0000 (12:26 +0100)
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

index e8184ff661b8356c4b37f8ed797f394dd59e36dd..e4cc0926f783a65892ea2e5996a403e4e9d8b495 100644 (file)
@@ -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);