From: Mikel Astiz <mikel.astiz@xxxxxxxxxxxx> The D-Bus signal AdapterAdded can be received during our call to GetProperties(), before the reply is received. In this case, the adapter will be listed twice and thus the endpoint registration will fail with "AlreadyExists" as follows: D: [pulseaudio] bluetooth-util.c: dbus: interface=org.bluez.Manager, path=/, member=AdapterAdded D: [pulseaudio] bluetooth-util.c: Adapter /org/bluez/21220/hci0 created D: [pulseaudio] bluetooth-util.c: Registering /MediaEndpoint/HFPAG on adapter /org/bluez/21220/hci0. D: [pulseaudio] bluetooth-util.c: Registering /MediaEndpoint/HFPHS on adapter /org/bluez/21220/hci0. D: [pulseaudio] bluetooth-util.c: Registering /MediaEndpoint/A2DPSource on adapter /org/bluez/21220/hci0. D: [pulseaudio] bluetooth-util.c: Registering /MediaEndpoint/A2DPSink on adapter /org/bluez/21220/hci0. D: [pulseaudio] bluetooth-util.c: Registering /MediaEndpoint/HFPAG on adapter /org/bluez/21220/hci0. D: [pulseaudio] bluetooth-util.c: Registering /MediaEndpoint/HFPHS on adapter /org/bluez/21220/hci0. D: [pulseaudio] bluetooth-util.c: Registering /MediaEndpoint/A2DPSource on adapter /org/bluez/21220/hci0. D: [pulseaudio] bluetooth-util.c: Registering /MediaEndpoint/A2DPSink on adapter /org/bluez/21220/hci0. E: [pulseaudio] bluetooth-util.c: RegisterEndpoint() failed: org.bluez.Error.AlreadyExists: Already Exists E: [pulseaudio] bluetooth-util.c: RegisterEndpoint() failed: org.bluez.Error.AlreadyExists: Already Exists E: [pulseaudio] bluetooth-util.c: RegisterEndpoint() failed: org.bluez.Error.AlreadyExists: Already Exists E: [pulseaudio] bluetooth-util.c: RegisterEndpoint() failed: org.bluez.Error.AlreadyExists: Already Exists --- src/modules/bluetooth/bluetooth-util.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/modules/bluetooth/bluetooth-util.c b/src/modules/bluetooth/bluetooth-util.c index 98e795c..8818c76 100644 --- a/src/modules/bluetooth/bluetooth-util.c +++ b/src/modules/bluetooth/bluetooth-util.c @@ -67,6 +67,7 @@ struct pa_bluetooth_discovery { pa_core *core; pa_dbus_connection *connection; PA_LLIST_HEAD(pa_dbus_pending, pending); + bool adapters_listed; pa_hashmap *devices; pa_hashmap *transports; pa_hook hooks[PA_BLUETOOTH_HOOK_MAX]; @@ -278,8 +279,11 @@ static int parse_manager_property(pa_bluetooth_discovery *y, DBusMessageIter *i, DBusMessageIter ai; dbus_message_iter_recurse(&variant_i, &ai); - if (dbus_message_iter_get_arg_type(&ai) == DBUS_TYPE_OBJECT_PATH && - pa_streq(key, "Adapters")) { + if (pa_streq(key, "Adapters")) { + y->adapters_listed = true; + + if (dbus_message_iter_get_arg_type(&ai) != DBUS_TYPE_OBJECT_PATH) + break; while (dbus_message_iter_get_arg_type(&ai) != DBUS_TYPE_INVALID) { const char *value; @@ -870,6 +874,8 @@ static void list_adapters(pa_bluetooth_discovery *y) { DBusMessage *m; pa_assert(y); + y->adapters_listed = false; + pa_assert_se(m = dbus_message_new_method_call("org.bluez", "/", "org.bluez.Manager", "GetProperties")); send_and_add_to_pending(y, m, get_properties_reply, NULL); } @@ -959,6 +965,11 @@ static DBusHandlerResult filter_cb(DBusConnection *bus, DBusMessage *m, void *us goto fail; } + if (!y->adapters_listed) { + pa_log_debug("Ignoring 'AdapterAdded' because initial adapter list has not been received yet."); + return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; + } + pa_log_debug("Adapter %s created", path); found_adapter(y, path); -- 1.8.1