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,
struct blob_attr *msg)
{
struct blob_attr *tb[__WDT_MAX];
+ const char *status;
if (!msg)
return UBUS_STATUS_INVALID_ARGUMENT;
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);
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)
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