diff options
author | John Crispin <blogic@openwrt.org> | 2013-07-14 11:56:32 +0200 |
---|---|---|
committer | John Crispin <blogic@openwrt.org> | 2013-07-14 11:56:32 +0200 |
commit | 36d79a90c28ac9d655ccd8261b3ac0b497a5aec1 (patch) | |
tree | f0f59d33a833809e3414dbc91f0d6050a593734c | |
parent | 434865f6f870f89571d7f2f5fa5690d16d6fb1d9 (diff) | |
download | unitd-36d79a90c28ac9d655ccd8261b3ac0b497a5aec1.tar unitd-36d79a90c28ac9d655ccd8261b3ac0b497a5aec1.zip |
the cloexec logic of the watchdog was broken
Signed-off-by: John Crispin <blogic@openwrt.org>
-rw-r--r-- | main.c | 2 | ||||
-rw-r--r-- | state.c | 7 | ||||
-rw-r--r-- | watchdog.c | 12 | ||||
-rw-r--r-- | watchdog.h | 2 |
4 files changed, 13 insertions, 10 deletions
@@ -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"); @@ -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(); @@ -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); @@ -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); |