init: add support for sysupgrades triggered from preinit
[project/procd.git] / watchdog.c
index 3c097e2..780b321 100644 (file)
@@ -35,7 +35,7 @@ static int wdt_frequency = 5;
 void watchdog_ping(void)
 {
        DEBUG(4, "Ping\n");
-       if (write(wdt_fd, "X", 1) < 0)
+       if (wdt_fd >= 0 && write(wdt_fd, "X", 1) < 0)
                ERROR("WDT failed to write: %s\n", strerror(errno));
 }
 
@@ -126,10 +126,15 @@ void watchdog_init(int preinit)
 }
 
 
-void watchdog_no_cloexec(void)
+void watchdog_set_cloexec(bool val)
 {
        if (wdt_fd < 0)
                return;
 
-       fcntl(wdt_fd, F_SETFD, fcntl(wdt_fd, F_GETFD) & ~FD_CLOEXEC);
+       int flags = fcntl(wdt_fd, F_GETFD);
+       if (val)
+               flags |= FD_CLOEXEC;
+       else
+               flags &= ~FD_CLOEXEC;
+       fcntl(wdt_fd, F_SETFD,  flags);
 }