From 822f9a3be4def1a117ab18a733fce4e78c5b847d Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Mon, 10 Dec 2012 01:11:34 +0100 Subject: core: Add support for systemd watchdog handling --- src/main.c | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) (limited to 'src/main.c') diff --git a/src/main.c b/src/main.c index f985332a3..9812ab083 100644 --- a/src/main.c +++ b/src/main.c @@ -400,6 +400,13 @@ static int connect_dbus(void) return 0; } +static gboolean watchdog_callback(gpointer user_data) +{ + sd_notify(0, "WATCHDOG=1"); + + return TRUE; +} + static gboolean parse_debug(const char *key, const char *value, gpointer user_data, GError **error) { @@ -433,7 +440,8 @@ int main(int argc, char *argv[]) GError *err = NULL; uint16_t mtu = 0; GKeyFile *config; - guint signal; + guint signal, watchdog; + const char *watchdog_usec; int mgmt_err; init_defaults(); @@ -512,6 +520,18 @@ int main(int argc, char *argv[]) sd_notify(0, "STATUS=Running"); sd_notify(0, "READY=1"); + watchdog_usec = getenv("WATCHDOG_USEC"); + if (watchdog_usec) { + unsigned int seconds; + + seconds = atoi(watchdog_usec) / (1000 * 1000); + info("Watchdog timeout is %d seconds", seconds); + + watchdog = g_timeout_add_seconds(seconds / 2, + watchdog_callback, NULL); + } else + watchdog = 0; + g_main_loop_run(event_loop); sd_notify(0, "STATUS=Quitting"); @@ -537,6 +557,9 @@ int main(int argc, char *argv[]) info("Exit"); + if (watchdog > 0) + g_source_remove(watchdog); + __btd_log_cleanup(); return 0; -- cgit v1.2.1