All of lore.kernel.org
 help / color / mirror / Atom feed
From: Luiz Augusto von Dentz <luiz.dentz@gmail.com>
To: linux-bluetooth@vger.kernel.org
Subject: [PATCH BlueZ 2/6] share/mainloop: Add watchdog support
Date: Mon, 26 Nov 2018 18:24:34 +0200	[thread overview]
Message-ID: <20181126162438.27872-2-luiz.dentz@gmail.com> (raw)
In-Reply-To: <20181126162438.27872-1-luiz.dentz@gmail.com>

From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

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 fef333c24..cb895086f 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_THRESHOLD 2
 
 static char *notify_sock;
 static int notify_fd = -1;
 
+static unsigned int watchdog;
+
+static bool watchdog_callback(void *user_data)
+{
+	mainloop_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_THRESHOLD,
+				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_notify(const char *state)
-- 
2.17.2


  reply	other threads:[~2018-11-26 16:24 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-11-26 16:24 [PATCH BlueZ 1/6] share/mainloop: Add handling of NOTIFY_SOCKET Luiz Augusto von Dentz
2018-11-26 16:24 ` Luiz Augusto von Dentz [this message]
2018-11-26 16:24 ` [PATCH BlueZ 3/6] tool/btmon-logger: Use mainloop_notify instead of sd_notify Luiz Augusto von Dentz
2018-11-26 16:24 ` [PATCH BlueZ 4/6] core: " Luiz Augusto von Dentz
2018-11-26 16:24 ` [PATCH BlueZ 5/6] core: Remove old code related to sd_notify Luiz Augusto von Dentz
2018-11-26 16:24 ` [PATCH BlueZ 6/6] shared/timeout-glib: Check 0 id when removing timeout Luiz Augusto von Dentz
2018-11-26 17:54 ` [PATCH BlueZ 1/6] share/mainloop: Add handling of NOTIFY_SOCKET Marcel Holtmann
2018-11-27  9:51   ` Luiz Augusto von Dentz
2018-11-27 13:30     ` Marcel Holtmann
2018-11-27 15:19       ` Luiz Augusto von Dentz

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20181126162438.27872-2-luiz.dentz@gmail.com \
    --to=luiz.dentz@gmail.com \
    --cc=linux-bluetooth@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.