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 /watchdog.c | |
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>
Diffstat (limited to 'watchdog.c')
-rw-r--r-- | watchdog.c | 12 |
1 files changed, 8 insertions, 4 deletions
@@ -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); |