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();
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);
#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);