public inbox for linux-bluetooth@vger.kernel.org
 help / color / mirror / Atom feed
From: Andrew Sayers <kernel.org@pileofstuff.org>
To: linux-bluetooth@vger.kernel.org
Cc: luiz.dentz@gmail.com, pav@iki.fi,
	Andrew Sayers <kernel.org@pileofstuff.org>
Subject: [PATCH BlueZ v4 5/6] obexd: Support sd_login_monitor_get_timeout()
Date: Mon, 28 Apr 2025 14:15:34 +0100	[thread overview]
Message-ID: <20250428131842.488921-6-kernel.org@pileofstuff.org> (raw)
In-Reply-To: <20250428131842.488921-1-kernel.org@pileofstuff.org>

The documentation for sd_login_monitor_get_timeout() implies the API
may need to be checked after some time, even if no events have been
received via the fd.

In practice, the implementation has always returned a dummy value,
and changing it now would cause enough breakage in other projects
to make it unlikely to ever happen.

Add a handler for that case, even though it can't currently
happen in the real world.

Cc: Pauli Virtanen <pav@iki.fi>
Signed-off-by: Andrew Sayers <kernel.org@pileofstuff.org>
---
 obexd/src/logind.c | 33 ++++++++++++++++++++++++++++++++-
 1 file changed, 32 insertions(+), 1 deletion(-)

diff --git a/obexd/src/logind.c b/obexd/src/logind.c
index eb4924684..5bb9a5986 100644
--- a/obexd/src/logind.c
+++ b/obexd/src/logind.c
@@ -101,6 +101,37 @@ static gboolean event_handler(GIOChannel *source, GIOCondition condition,
 	return TRUE;
 }
 
+static gboolean timeout_handler(gpointer user_data)
+{
+	uint64_t timeout_usec;
+	int res;
+
+	if (!event_handler(NULL, 0, NULL))
+		return FALSE;
+
+	res = sd_login_monitor_get_timeout(monitor, &timeout_usec);
+	if (res < 0) {
+		error("sd_login_monitor_get_timeout(): %s", strerror(-res));
+		return FALSE;
+	}
+
+	if (timeout_usec != (uint64_t)-1) {
+		uint64_t time_usec;
+		struct timespec ts;
+
+		res = clock_gettime(CLOCK_MONOTONIC, &ts);
+		if (res < 0)
+			return -errno;
+		time_usec = (uint64_t) ts.tv_sec * 1000000 + ts.tv_nsec / 1000;
+		if (time_usec > timeout_usec)
+			return timeout_handler(user_data);
+		g_timeout_add((timeout_usec - time_usec + 999) / 1000,
+				timeout_handler, user_data);
+	}
+
+	return FALSE;
+}
+
 static int logind_init(void)
 {
 	GIOChannel *channel;
@@ -146,7 +177,7 @@ static int logind_init(void)
 
 	g_io_channel_unref(channel);
 
-	event_handler(NULL, 0, NULL);
+	timeout_handler(NULL);
 
 	return 0;
 
-- 
2.49.0


  parent reply	other threads:[~2025-04-28 13:19 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-04-28 13:15 [PATCH BlueZ v4 0/6] obexd: unregister profiles when the user is inactive Andrew Sayers
2025-04-28 13:15 ` [PATCH BlueZ v4 1/6] pbap: Support calling pbap_init() after pbap_exit() Andrew Sayers
2025-04-28 14:57   ` obexd: unregister profiles when the user is inactive bluez.test.bot
2025-04-28 21:47   ` [PATCH BlueZ v4 1/6] pbap: Support calling pbap_init() after pbap_exit() Luiz Augusto von Dentz
2025-04-28 13:15 ` [PATCH BlueZ v4 2/6] obexd/bluetooth: Support calling bluetooth_init() after bluetooth_exit() Andrew Sayers
2025-04-28 13:15 ` [PATCH BlueZ v4 3/6] obexd: Support creating private system/session bus connections Andrew Sayers
2025-04-28 13:15 ` [PATCH BlueZ v4 4/6] obexd: Unregister profiles when the user is inactive Andrew Sayers
2025-04-28 13:15 ` Andrew Sayers [this message]
2025-04-28 17:11   ` [PATCH BlueZ v4 5/6] obexd: Support sd_login_monitor_get_timeout() Pauli Virtanen
2025-04-28 13:15 ` [PATCH BlueZ v4 6/6] Revert "obexd: only run one instance at once" Andrew Sayers

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=20250428131842.488921-6-kernel.org@pileofstuff.org \
    --to=kernel.org@pileofstuff.org \
    --cc=linux-bluetooth@vger.kernel.org \
    --cc=luiz.dentz@gmail.com \
    --cc=pav@iki.fi \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox