PBAP must not use its own private DBus connection, as it needs to receive messages sent to the bus name of the public connection. PBAP must not unregister itself when the program is exiting, as it might cause a long delay. Unregistering at exit is redundant anyway, as the service will be implicitly unregistered when the connection is closed. But PBAP must unregister itself when the user becomes inactive mid-session, so systems with multiple users logged in at once can share bluetooth. Use the public DBus connection instead of a private one, and explicitly unregister the profile if appropriate. Thanks Pauli Virtanen for pointing out the exit issue: https://lore.kernel.org/linux-bluetooth/ae15a9fa4bf0bd509dd3d44f1f364e241e50956c.camel@xxxxxx/ Reported-by: Frédéric Danis <frederic.danis@xxxxxxxxxxxxx> Closes: https://lore.kernel.org/linux-bluetooth/333ad76e-0aba-4f93-b141-8e69fb47535f@xxxxxxxxxxxxx/ Suggested-by: Pauli Virtanen <pav@xxxxxx> Signed-off-by: Andrew Sayers <kernel.org@xxxxxxxxxxxxxxx> --- obexd/client/pbap.c | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/obexd/client/pbap.c b/obexd/client/pbap.c index 7d651722a..78c46bf86 100644 --- a/obexd/client/pbap.c +++ b/obexd/client/pbap.c @@ -1462,7 +1462,7 @@ static int pbap_init_cb(gboolean at_register) DBG(""); - conn = obex_setup_dbus_connection_private(NULL, NULL); + conn = obex_get_dbus_connection(); if (!conn) return -EIO; @@ -1485,9 +1485,28 @@ static int pbap_init_cb(gboolean at_register) static void pbap_exit_cb(gboolean at_unregister) { - (void)at_unregister; + DBusMessage *msg; + DBusMessageIter iter; + char *uuid = PBAP_CLIENT_UUID; + DBG(""); + if (!at_unregister) { + 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); + } + g_dbus_remove_watch(system_conn, listener_id); unregister_profile(); @@ -1499,7 +1518,6 @@ static void pbap_exit_cb(gboolean at_unregister) } if (conn) { - dbus_connection_close(conn); dbus_connection_unref(conn); conn = NULL; } -- 2.49.0