From: Luiz Augusto von Dentz Date: Mon, 26 Nov 2018 14:16:15 +0000 (+0200) Subject: share/mainloop: Add watchdog support X-Git-Tag: submit/tizen/20200220.012900~1^2~1^2~201 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=17ee88a9e1b0635dcc7414f98adbd1d2487085ad;p=platform%2Fupstream%2Fbluez.git share/mainloop: Add watchdog support This adds watchdog notification support by sending "WATCHDOG=1" twice as frequent as required by WATCHDOG_USEC. Change-Id: I713883290a03961276d8f981818abbc922018bd0 Signed-off-by: himanshu --- diff --git a/src/shared/mainloop-notify.c b/src/shared/mainloop-notify.c index fdc2f25..2e3b08f 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 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; struct sockaddr_un addr; + const char *watchdog_usec; + int msec; sock = getenv("NOTIFY_SOCKET"); if (!sock) @@ -67,7 +81,19 @@ void mainloop_notify_init(void) if (bind(notify_fd, (struct sockaddr *) &addr, sizeof(addr)) < 0) { close(notify_fd); notify_fd = -1; + return; } + + 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) @@ -76,6 +102,8 @@ void mainloop_notify_exit(void) close(notify_fd); notify_fd = -1; } + + timeout_remove(watchdog); } int mainloop_sd_notify(const char *state)