diff options
author | Felix Fietkau <nbd@openwrt.org> | 2013-04-07 13:44:32 +0200 |
---|---|---|
committer | Felix Fietkau <nbd@openwrt.org> | 2013-04-07 13:44:36 +0200 |
commit | b9fcb589a4c086d786891f13dfececcfabc0c91f (patch) | |
tree | 5aecce53216349920314dada47e23e2dba3c870c | |
parent | 5c6859ddf9f0ca57e297d2d178504c5ad1c063e7 (diff) | |
download | unitd-b9fcb589a4c086d786891f13dfececcfabc0c91f.tar unitd-b9fcb589a4c086d786891f13dfececcfabc0c91f.zip |
watchdog: add support for starting/stopping watchdog refresh
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
-rw-r--r-- | system.c | 15 | ||||
-rw-r--r-- | watchdog.c | 13 | ||||
-rw-r--r-- | watchdog.h | 2 |
3 files changed, 29 insertions, 1 deletions
@@ -58,12 +58,14 @@ static int system_info(struct ubus_context *ctx, struct ubus_object *obj, enum { WDT_FREQUENCY, WDT_TIMEOUT, + WDT_STOP, __WDT_MAX }; static const struct blobmsg_policy watchdog_policy[__WDT_MAX] = { [WDT_FREQUENCY] = { .name = "frequency", .type = BLOBMSG_TYPE_INT32 }, [WDT_TIMEOUT] = { .name = "timeout", .type = BLOBMSG_TYPE_INT32 }, + [WDT_STOP] = { .name = "stop", .type = BLOBMSG_TYPE_BOOL }, }; static int watchdog_set(struct ubus_context *ctx, struct ubus_object *obj, @@ -71,6 +73,7 @@ static int watchdog_set(struct ubus_context *ctx, struct ubus_object *obj, struct blob_attr *msg) { struct blob_attr *tb[__WDT_MAX]; + const char *status; if (!msg) return UBUS_STATUS_INVALID_ARGUMENT; @@ -96,8 +99,18 @@ static int watchdog_set(struct ubus_context *ctx, struct ubus_object *obj, watchdog_timeout(timeout); } + if (tb[WDT_STOP]) + watchdog_set_stopped(blobmsg_get_bool(tb[WDT_STOP])); + + if (watchdog_fd() < 0) + status = "offline"; + else if (watchdog_get_stopped()) + status = "stopped"; + else + status = "running"; + blob_buf_init(&b, 0); - blobmsg_add_string(&b, "status", (watchdog_fd() >= 0) ? ("running") : ("offline")); + blobmsg_add_string(&b, "status", status); blobmsg_add_u32(&b, "timeout", watchdog_timeout(0)); blobmsg_add_u32(&b, "frequency", watchdog_frequency(0)); ubus_send_reply(ctx, req, b.head); @@ -40,6 +40,19 @@ static void watchdog_timeout_cb(struct uloop_timeout *t) uloop_timeout_set(t, wdt_frequency * 1000); } +void watchdog_set_stopped(bool val) +{ + if (val) + uloop_timeout_cancel(&wdt_timeout); + else + watchdog_timeout_cb(&wdt_timeout); +} + +bool watchdog_get_stopped(void) +{ + return !wdt_timeout.pending; +} + int watchdog_timeout(int timeout) { if (wdt_fd < 0) @@ -19,5 +19,7 @@ void watchdog_init(void); char* watchdog_fd(void); int watchdog_timeout(int timeout); int watchdog_frequency(int frequency); +void watchdog_set_stopped(bool val); +bool watchdog_get_stopped(void); #endif |