summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--system.c15
-rw-r--r--watchdog.c13
-rw-r--r--watchdog.h2
3 files changed, 29 insertions, 1 deletions
diff --git a/system.c b/system.c
index c35f75a..658dd5e 100644
--- a/system.c
+++ b/system.c
@@ -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);
diff --git a/watchdog.c b/watchdog.c
index 0ba8f25..2a516b4 100644
--- a/watchdog.c
+++ b/watchdog.c
@@ -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)
diff --git a/watchdog.h b/watchdog.h
index 92702fd..66037b1 100644
--- a/watchdog.h
+++ b/watchdog.h
@@ -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