X-Git-Url: http://git.archive.openwrt.org/?a=blobdiff_plain;ds=sidebyside;f=watchdog.c;h=780b321196def0adcca35ba7de2cdf938d265d98;hb=992b796204caf5b0290ea4a1246b43b353b6c1d7;hp=de9556c482d84933abf8bfd067d652a52be003c0;hpb=916f95cb58604038695347ee41a430d8ca1f0556;p=project%2Fprocd.git diff --git a/watchdog.c b/watchdog.c index de9556c..780b321 100644 --- a/watchdog.c +++ b/watchdog.c @@ -32,11 +32,16 @@ static struct uloop_timeout wdt_timeout; static int wdt_fd = -1; static int wdt_frequency = 5; -static void watchdog_timeout_cb(struct uloop_timeout *t) +void watchdog_ping(void) { DEBUG(4, "Ping\n"); - if (write(wdt_fd, "X", 1) < 0) + if (wdt_fd >= 0 && write(wdt_fd, "X", 1) < 0) ERROR("WDT failed to write: %s\n", strerror(errno)); +} + +static void watchdog_timeout_cb(struct uloop_timeout *t) +{ + watchdog_ping(); uloop_timeout_set(t, wdt_frequency * 1000); } @@ -119,3 +124,17 @@ void watchdog_init(int preinit) DEBUG(4, "Opened watchdog with timeout %ds\n", watchdog_timeout(0)); } + + +void watchdog_set_cloexec(bool val) +{ + if (wdt_fd < 0) + return; + + int flags = fcntl(wdt_fd, F_GETFD); + if (val) + flags |= FD_CLOEXEC; + else + flags &= ~FD_CLOEXEC; + fcntl(wdt_fd, F_SETFD, flags); +}