diff options
author | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2019-08-20 20:24:47 +0200 |
---|---|---|
committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2019-08-20 21:15:13 +0200 |
commit | 1fedf13839a2be4788bf99ae2073381cdadf5eb3 (patch) | |
tree | f87dd6b14592d7be126ce737cd365a8eb2f1e70d /src/shared/watchdog.c | |
parent | Merge pull request #13367 from poettering/null-console-fixes (diff) | |
download | systemd-1fedf13839a2be4788bf99ae2073381cdadf5eb3.tar.xz systemd-1fedf13839a2be4788bf99ae2073381cdadf5eb3.zip |
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.
Diffstat (limited to '')
-rw-r--r-- | src/shared/watchdog.c | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/src/shared/watchdog.c b/src/shared/watchdog.c index c423af6917..98fefb3956 100644 --- a/src/shared/watchdog.c +++ b/src/shared/watchdog.c @@ -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) { |