move /dev/shm to /tmp/shm
[project/procd.git] / watchdog.c
index de9556c..592ae7e 100644 (file)
@@ -32,11 +32,16 @@ static struct uloop_timeout wdt_timeout;
 static int wdt_fd = -1;
 static int wdt_frequency = 5;
 
-static void watchdog_timeout_cb(struct uloop_timeout *t)
+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));
+}
+
+static void watchdog_timeout_cb(struct uloop_timeout *t)
+{
+       watchdog_ping();
        uloop_timeout_set(t, wdt_frequency * 1000);
 }
 
@@ -119,3 +124,12 @@ void watchdog_init(int preinit)
 
        DEBUG(4, "Opened watchdog with timeout %ds\n", watchdog_timeout(0));
 }
+
+
+void watchdog_no_cloexec(void)
+{
+       if (wdt_fd < 0)
+               return;
+
+       fcntl(wdt_fd, F_SETFD, fcntl(wdt_fd, F_GETFD) & ~FD_CLOEXEC);
+}