From: Luiz Augusto von Dentz <luiz.von.dentz@xxxxxxxxx> This adds watchdog notification support by sending "WATCHDOG=1" twice as frequent as required by WATCHDOG_USEC. --- src/shared/mainloop-notify.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/shared/mainloop-notify.c b/src/shared/mainloop-notify.c index 81b0e15ba..49ca4f6c9 100644 --- a/src/shared/mainloop-notify.c +++ b/src/shared/mainloop-notify.c @@ -37,13 +37,27 @@ #include "mainloop.h" #include "mainloop-notify.h" +#include "timeout.h" + +#define WATCHDOG_TRIGGER_FREQ 2 static char *notify_sock; static int notify_fd = -1; +static unsigned int watchdog; + +static bool watchdog_callback(void *user_data) +{ + mainloop_sd_notify("WATCHDOG=1"); + + return true; +} + void mainloop_notify_init(void) { const char *sock; + const char *watchdog_usec; + int msec; sock = getenv("NOTIFY_SOCKET"); if (!sock) @@ -56,6 +70,17 @@ void mainloop_notify_init(void) notify_sock = strdup(sock); notify_fd = socket(AF_UNIX, SOCK_DGRAM | SOCK_CLOEXEC, 0); + + watchdog_usec = getenv("WATCHDOG_USEC"); + if (!watchdog_usec) + return; + + msec = atoi(watchdog_usec) / 1000; + if (msec < 0) + return; + + watchdog = timeout_add(msec / WATCHDOG_TRIGGER_FREQ, + watchdog_callback, NULL, NULL); } void mainloop_notify_exit(void) @@ -67,6 +92,8 @@ void mainloop_notify_exit(void) free(notify_sock); notify_sock = NULL; + + timeout_remove(watchdog); } int mainloop_sd_notify(const char *state) -- 2.17.2