diff mbox series

[BlueZ,1/4] pbap: Support calling pbap_init() after pbap_exit()

Message ID 20250423163343.4160595-2-kernel.org@pileofstuff.org
State New
Headers show
Series [BlueZ,1/4] pbap: Support calling pbap_init() after pbap_exit() | expand

Commit Message

Andrew Sayers April 23, 2025, 4:33 p.m. UTC
pbap_exit() didn't previously unregister itself thoroughly.  That
was fine if it was only called when the service was about to exit,
because everything was implicitly unregistered when the process ended.
But we need to be more scrupulous if this can be called throughout
the program's lifecycle.

Send the UnregisterProfile message directly from pbap_exit(),
then call unregister_profile().

The UnregisterProfile message can't be sent directly from
unregister_profile(), because that also needs to be called when
register_profile() fails halfway through.

Signed-off-by: Andrew Sayers <kernel.org@pileofstuff.org>
---
 obexd/client/pbap.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
diff mbox series

Patch

diff --git a/obexd/client/pbap.c b/obexd/client/pbap.c
index 2f234fadf..e2a3c1b90 100644
--- a/obexd/client/pbap.c
+++ b/obexd/client/pbap.c
@@ -1483,8 +1483,28 @@  int pbap_init(void)
 
 void pbap_exit(void)
 {
+	DBusMessage *msg;
+	DBusMessageIter iter;
+	char *uuid = PBAP_CLIENT_UUID;
+
 	DBG("");
 
+	client_path = g_strconcat("/org/bluez/obex/", uuid, NULL);
+	g_strdelimit(client_path, "-", '_');
+
+	msg = dbus_message_new_method_call("org.bluez", "/org/bluez",
+						"org.bluez.ProfileManager1",
+						"UnregisterProfile");
+
+	dbus_message_iter_init_append(msg, &iter);
+
+	dbus_message_iter_append_basic(&iter, DBUS_TYPE_OBJECT_PATH,
+							&client_path);
+
+	g_dbus_send_message(system_conn, msg);
+
+	unregister_profile();
+
 	dbus_connection_unref(conn);
 	conn = NULL;