shared/watchdog: close watchdog device when done with it

The file descriptor was opened with O_CLOEXEC, so in practice this doesn't
change too much, but it seems cleaner to always close the old fd when
changing the device path.
This commit is contained in:
Zbigniew Jędrzejewski-Szmek 2019-08-20 20:24:47 +02:00
parent ba90388221
commit 1fedf13839
1 changed files with 10 additions and 1 deletions

View File

@ -82,7 +82,16 @@ static int open_watchdog(void) {
}
int watchdog_set_device(char *path) {
return free_and_strdup(&watchdog_device, path);
int r;
r = free_and_strdup(&watchdog_device, path);
if (r < 0)
return r;
if (r > 0) /* watchdog_device changed */
watchdog_fd = safe_close(watchdog_fd);
return r;
}
int watchdog_set_timeout(usec_t *usec) {