diff options
author | Marcel Holtmann <marcel@holtmann.org> | 2012-12-10 01:11:34 +0100 |
---|---|---|
committer | Marcel Holtmann <marcel@holtmann.org> | 2012-12-10 01:11:34 +0100 |
commit | 822f9a3be4def1a117ab18a733fce4e78c5b847d (patch) | |
tree | 5f8fbc6133c473afddb26f27fc10bd8f4efd97f9 | |
parent | 93e6da1fa4130edba94b6c4eb1f173c0e0dda399 (diff) | |
download | bluez-822f9a3be4def1a117ab18a733fce4e78c5b847d.tar.gz |
core: Add support for systemd watchdog handling
-rw-r--r-- | src/main.c | 25 |
1 files changed, 24 insertions, 1 deletions
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; |