the cloexec logic of the watchdog was broken
[project/procd.git] / watchdog.c
index e4b82f5..d927c53 100644 (file)
@@ -91,10 +91,12 @@ char* watchdog_fd(void)
        return fd_buf;
 }
 
-void watchdog_init(void)
+void watchdog_init(int preinit)
 {
        char *env = getenv("WDTFD");
 
+       if (wdt_fd >= 0)
+               return;
 
        wdt_timeout.cb = watchdog_timeout_cb;
        if (env) {
@@ -104,9 +106,13 @@ void watchdog_init(void)
        } else {
                wdt_fd = open("/dev/watchdog", O_WRONLY);
        }
+
        if (wdt_fd < 0)
                return;
-       fcntl(wdt_fd, F_SETFD, fcntl(wdt_fd, F_GETFD) | FD_CLOEXEC);
+
+       if (!preinit)
+               fcntl(wdt_fd, F_SETFD, fcntl(wdt_fd, F_GETFD) | FD_CLOEXEC);
+
        LOG("- watchdog -\n");
        watchdog_timeout(30);
        watchdog_timeout_cb(&wdt_timeout);