If we change the watchdog device we should disarm the old one first.
Similar, if we open the watchdog, but then fail setting it up, disarm it
before closing it again.
STRV_FOREACH(wd, try_order) {
watchdog_fd = open(*wd, O_WRONLY|O_CLOEXEC);
if (watchdog_fd >= 0) {
- r = free_and_strdup(&watchdog_device, *wd);
- if (r < 0)
- return log_oom_debug();
+ if (free_and_strdup(&watchdog_device, *wd) < 0) {
+ r = log_oom_debug();
+ goto close_and_fail;
+ }
break;
}
r = update_timeout();
if (r < 0)
- watchdog_close(true);
+ goto close_and_fail;
+
+ return 0;
+close_and_fail:
+ watchdog_close(/* disarm= */ true);
return r;
}
r = free_and_strdup(&watchdog_device, path);
if (r > 0) /* watchdog_device changed */
- watchdog_fd = safe_close(watchdog_fd);
+ watchdog_close(/* disarm= */ true);
return r;
}