the cloexec logic of the watchdog was broken
authorJohn Crispin <blogic@openwrt.org>
Sun, 14 Jul 2013 09:56:32 +0000 (11:56 +0200)
committerJohn Crispin <blogic@openwrt.org>
Sun, 14 Jul 2013 09:56:32 +0000 (11:56 +0200)
Signed-off-by: John Crispin <blogic@openwrt.org>
main.c
state.c
watchdog.c
watchdog.h

diff --git a/main.c b/main.c
index a1b4fdb1de4429bd92b90342cd43d3271eeafb5e..49d85f4c13e68269507d5b07e9f6f3f4dae61b29 100644 (file)
--- a/main.c
+++ b/main.c
@@ -40,7 +40,7 @@ static int main_procd_init(int argc, char **argv)
        procd_signal_preinit();
        procd_early();
        debug_init();
-       watchdog_init();
+       watchdog_init(1);
        system("/sbin/kmodloader /etc/modules-boot.d/");
        uloop_init();
        hotplug("/etc/hotplug-preinit.json");
diff --git a/state.c b/state.c
index 71890a26847024091c116a399e9d6e09c1bbc5fa..9cde905619bdac8348a8a8ebbc00cfcc7099ebb2 100644 (file)
--- a/state.c
+++ b/state.c
@@ -40,15 +40,14 @@ static void state_enter(void)
        switch (state) {
        case STATE_EARLY:
                LOG("- early -\n");
-               watchdog_init();
+               watchdog_init(0);
                hotplug("/etc/hotplug.json");
                procd_coldplug();
                break;
 
        case STATE_INIT:
-               // check if the wdt appeared during coldplug
-               if (!watchdog_fd())
-                       watchdog_init();
+               // try to reopen incase the wdt was not available before coldplug
+               watchdog_init(0);
                LOG("- init -\n");
                log_init();
                procd_connect_ubus();
index dc543085d05c71104aae7f73cf24fa5515980bf1..d927c53f42672734bd63706f46a5a7ddaa8c4aa4 100644 (file)
@@ -91,24 +91,28 @@ 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) {
                DEBUG(1, "Watchdog handover: fd=%s\n", env);
                wdt_fd = atoi(env);
                unsetenv("WDTFD");
-               fcntl(wdt_fd, F_SETFD, fcntl(wdt_fd, F_GETFD) | FD_CLOEXEC);
        } else {
                wdt_fd = open("/dev/watchdog", O_WRONLY);
-               if ((getpid() != 1) && (wdt_fd >= 0))
-                       fcntl(wdt_fd, F_SETFD, fcntl(wdt_fd, F_GETFD) | FD_CLOEXEC);
        }
+
        if (wdt_fd < 0)
                return;
+
+       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);
index 66037b18cd2833aa21aec955068b82653ed5bdb0..cebbc33088d762839837fdad84a3e9e4adea4c41 100644 (file)
@@ -15,7 +15,7 @@
 #ifndef __PROCD_WATCHDOG_H
 #define __PROCD_WATCHDOG_H
 
-void watchdog_init(void);
+void watchdog_init(int preinit);
 char* watchdog_fd(void);
 int watchdog_timeout(int timeout);
 int watchdog_frequency(int frequency);