Linux bluetooth development
 help / color / mirror / Atom feed
* [PATCH RESEND] client: Clean up agent if bluetoothd exited without releasing it
@ 2014-04-25 10:30 Szymon Janc
  2014-04-28  8:22 ` Johan Hedberg
  0 siblings, 1 reply; 3+ messages in thread
From: Szymon Janc @ 2014-04-25 10:30 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Szymon Janc

From: Szymon Janc <szymon.janc@gmail.com>

If bluetoothd exited without releasing agent (eg. due to crash) it was
not possible to register client as agent after daemon was restarted.
---
 client/agent.c | 21 +++++++++++++++++++--
 1 file changed, 19 insertions(+), 2 deletions(-)

diff --git a/client/agent.c b/client/agent.c
index 2d9dffd..b34ad77 100644
--- a/client/agent.c
+++ b/client/agent.c
@@ -35,6 +35,7 @@
 
 #define AGENT_PATH "/org/bluez/agent"
 #define AGENT_INTERFACE "org.bluez.Agent1"
+#define BLUEZ_NAME "org.bluez"
 
 #define AGENT_PROMPT	COLOR_RED "[agent]" COLOR_OFF " "
 
@@ -43,6 +44,7 @@ static const char *agent_capability = NULL;
 static DBusMessage *pending_message = NULL;
 static char *agent_saved_prompt = NULL;
 static int agent_saved_point = 0;
+static guint watch_id = 0;
 
 static void agent_prompt(const char *msg)
 {
@@ -154,8 +156,7 @@ dbus_bool_t agent_input(DBusConnection *conn, const char *input)
 	return TRUE;
 }
 
-static DBusMessage *release_agent(DBusConnection *conn,
-					DBusMessage *msg, void *user_data)
+static void clean_agent(DBusConnection *conn, void *user_data)
 {
 	agent_registered = FALSE;
 	agent_capability = NULL;
@@ -171,6 +172,15 @@ static DBusMessage *release_agent(DBusConnection *conn,
 
 	g_dbus_unregister_interface(conn, AGENT_PATH, AGENT_INTERFACE);
 
+	g_dbus_remove_watch(conn, watch_id);
+	watch_id = 0;
+}
+
+static DBusMessage *release_agent(DBusConnection *conn, DBusMessage *msg,
+								void *user_data)
+{
+	clean_agent(conn, NULL);
+
 	return dbus_message_new_method_return(msg);
 }
 
@@ -364,6 +374,10 @@ static void register_agent_reply(DBusMessage *message, void *user_data)
 	if (dbus_set_error_from_message(&error, message) == FALSE) {
 		agent_registered = TRUE;
 		rl_printf("Agent registered\n");
+
+		watch_id = g_dbus_add_service_watch(conn, BLUEZ_NAME, NULL,
+							clean_agent, NULL,
+							NULL);
 	} else {
 		rl_printf("Failed to register agent: %s\n", error.name);
 		dbus_error_free(&error);
@@ -425,6 +439,9 @@ static void unregister_agent_reply(DBusMessage *message, void *user_data)
 		if (g_dbus_unregister_interface(conn, AGENT_PATH,
 						AGENT_INTERFACE) == FALSE)
 			rl_printf("Failed to unregister agent object\n");
+
+		g_dbus_remove_watch(conn, watch_id);
+		watch_id = 0;
 	} else {
 		rl_printf("Failed to unregister agent: %s\n", error.name);
 		dbus_error_free(&error);
-- 
1.9.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH RESEND] client: Clean up agent if bluetoothd exited without releasing it
  2014-04-25 10:30 [PATCH RESEND] client: Clean up agent if bluetoothd exited without releasing it Szymon Janc
@ 2014-04-28  8:22 ` Johan Hedberg
  2014-04-28  9:20   ` Szymon Janc
  0 siblings, 1 reply; 3+ messages in thread
From: Johan Hedberg @ 2014-04-28  8:22 UTC (permalink / raw)
  To: Szymon Janc; +Cc: linux-bluetooth, Szymon Janc

Hi Szymon,

On Fri, Apr 25, 2014, Szymon Janc wrote:
> If bluetoothd exited without releasing agent (eg. due to crash) it was
> not possible to register client as agent after daemon was restarted.
> ---
>  client/agent.c | 21 +++++++++++++++++++--
>  1 file changed, 19 insertions(+), 2 deletions(-)

Since client/main.c is already doing tracking or org.bluez I think it
might make more sense to do the agent clearing from there, maybe by
adding an agent_clear function to agent.c and then calling it from
disconnect_handler in main.c. Thoughts?

Johan

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH RESEND] client: Clean up agent if bluetoothd exited without releasing it
  2014-04-28  8:22 ` Johan Hedberg
@ 2014-04-28  9:20   ` Szymon Janc
  0 siblings, 0 replies; 3+ messages in thread
From: Szymon Janc @ 2014-04-28  9:20 UTC (permalink / raw)
  To: Johan Hedberg; +Cc: linux-bluetooth, Szymon Janc

Hi Johan,

On Monday 28 of April 2014 11:22:36 Johan Hedberg wrote:
> Hi Szymon,
> 
> On Fri, Apr 25, 2014, Szymon Janc wrote:
> > If bluetoothd exited without releasing agent (eg. due to crash) it was
> > not possible to register client as agent after daemon was restarted.
> > ---
> >  client/agent.c | 21 +++++++++++++++++++--
> >  1 file changed, 19 insertions(+), 2 deletions(-)
> 
> Since client/main.c is already doing tracking or org.bluez I think it
> might make more sense to do the agent clearing from there, maybe by
> adding an agent_clear function to agent.c and then calling it from
> disconnect_handler in main.c. Thoughts?

There is patch from Luiz that does exactly this and I'm fine with applying it
instead.

"[PATCH BlueZ 2/3] client: Fix not releasing agent if bluetoothd exit without
calling Release" from 26.11.2013.

-- 
Best regards, 
Szymon Janc

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2014-04-28  9:20 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-04-25 10:30 [PATCH RESEND] client: Clean up agent if bluetoothd exited without releasing it Szymon Janc
2014-04-28  8:22 ` Johan Hedberg
2014-04-28  9:20   ` Szymon Janc

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox