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()
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);