diff options
Diffstat (limited to 'src/argos-systemd.c')
-rw-r--r-- | src/argos-systemd.c | 56 |
1 files changed, 48 insertions, 8 deletions
diff --git a/src/argos-systemd.c b/src/argos-systemd.c index 493f1f7..3afbb97 100644 --- a/src/argos-systemd.c +++ b/src/argos-systemd.c @@ -18,22 +18,62 @@ #include <systemd/sd-daemon.h> #include <stdlib.h> -/* In case of watchdog based on systemd sd_notify, - * runtime registration does not support. - * Thus, just check whether the watchdog is enabled or not*/ +#define SEC_TO_USEC (1000*1000) + +static unsigned int saved_timeout=0; + +/* Now, systemd support to enable/disable runtime watchdog */ +/* https://github.com/systemd/systemd/commit/2787d83c2 */ +int systemd_change_watchdog_timeout(unsigned int timeout) +{ + return sd_notifyf(0, "WATCHDOG_USEC=%llu", (unsigned long long) timeout*SEC_TO_USEC); +} + int _aw_register(unsigned int timeout) { + int ret; - if ( sd_watchdog_enabled(0, NULL) ) - return 0; - else + ret = systemd_change_watchdog_timeout(timeout); + if(ret <=0) return -1; + + saved_timeout = timeout; + return 0; } -/* NOT Support for systemd backend */ int _aw_control(aw_op_e op, void *data) { - return -ENOTSUP; + int ret=-1; + unsigned int* timeout; + + switch(op){ + case AW_OP_DISABLE: + ret = systemd_change_watchdog_timeout(0); + break; + + case AW_OP_ENABLE: + ret = systemd_change_watchdog_timeout(saved_timeout); + break; + + case AW_OP_CHANGE_TIMEOUT: + timeout = (unsigned int*)(data); + if(timeout == NULL){ + ret = -1; + break; + } + ret = systemd_change_watchdog_timeout(*timeout); + if(ret > 0) + saved_timeout = *timeout; + break; + default: + ret = -1; + break; + } + + if(ret > 0) + return 0; + + return -1; } int _aw_notify(void) |