From 0ce8d7773f344016431468ea3e8cedb9d86352ff Mon Sep 17 00:00:00 2001 From: Stijn Tintel Date: Fri, 17 Jun 2022 18:51:56 +0300 Subject: [PATCH] watchdog: add remaining time to ubus output Signed-off-by: Stijn Tintel --- system.c | 7 ++++++- watchdog.c | 9 +++++++++ watchdog.h | 2 ++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/system.c b/system.c index 93eac59..7d9594f 100644 --- a/system.c +++ b/system.c @@ -457,6 +457,7 @@ static int watchdog_set(struct ubus_context *ctx, struct ubus_object *obj, { struct blob_attr *tb[__WDT_MAX]; const char *status; + ssize_t timeleft = -1; if (!msg) return UBUS_STATUS_INVALID_ARGUMENT; @@ -493,14 +494,18 @@ static int watchdog_set(struct ubus_context *ctx, struct ubus_object *obj, status = "offline"; else if (watchdog_get_stopped()) status = "stopped"; - else + else { status = "running"; + timeleft = watchdog_get_timeleft(); + } blob_buf_init(&b, 0); blobmsg_add_string(&b, "status", status); blobmsg_add_u32(&b, "timeout", watchdog_timeout(0)); blobmsg_add_u32(&b, "frequency", watchdog_frequency(0)); blobmsg_add_u8(&b, "magicclose", watchdog_get_magicclose()); + if (timeleft >= 0) + blobmsg_add_u32(&b, "timeleft", timeleft); ubus_send_reply(ctx, req, b.head); return 0; diff --git a/watchdog.c b/watchdog.c index 39ae9ff..bedb545 100644 --- a/watchdog.c +++ b/watchdog.c @@ -216,3 +216,12 @@ void watchdog_set_cloexec(bool val) flags &= ~FD_CLOEXEC; fcntl(wdt_fd, F_SETFD, flags); } + +ssize_t watchdog_get_timeleft(void) +{ + ssize_t timeleft; + + ioctl(wdt_fd, WDIOC_GETTIMELEFT, &timeleft); + + return timeleft; +} diff --git a/watchdog.h b/watchdog.h index 73c75d5..6176b49 100644 --- a/watchdog.h +++ b/watchdog.h @@ -15,6 +15,7 @@ #ifndef __PROCD_WATCHDOG_H #define __PROCD_WATCHDOG_H +#include #include #ifndef DISABLE_INIT @@ -28,6 +29,7 @@ void watchdog_set_stopped(bool val); bool watchdog_get_stopped(void); void watchdog_set_cloexec(bool val); void watchdog_ping(void); +ssize_t watchdog_get_timeleft(void); #else static inline void watchdog_init(int preinit) { -- 2.30.2