summaryrefslogtreecommitdiffstats
path: root/watchdog.c
diff options
context:
space:
mode:
authorJohn Crispin <blogic@openwrt.org>2013-07-14 11:56:32 +0200
committerJohn Crispin <blogic@openwrt.org>2013-07-14 11:56:32 +0200
commit36d79a90c28ac9d655ccd8261b3ac0b497a5aec1 (patch)
treef0f59d33a833809e3414dbc91f0d6050a593734c /watchdog.c
parent434865f6f870f89571d7f2f5fa5690d16d6fb1d9 (diff)
downloadunitd-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.c12
1 files changed, 8 insertions, 4 deletions
diff --git a/watchdog.c b/watchdog.c
index dc54308..d927c53 100644
--- a/watchdog.c
+++ b/watchdog.c
@@ -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);