]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
shared/watchdog: close watchdog device when done with it 13368/head
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Tue, 20 Aug 2019 18:24:47 +0000 (20:24 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Tue, 20 Aug 2019 19:15:13 +0000 (21:15 +0200)
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.

src/shared/watchdog.c

index c423af6917a534e164d303d6e442237d394b3330..98fefb39569b51fc2e750bb62d128a1fba0a43c8 100644 (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) {