Blame SOURCES/0001-bluez5-do-NameHasOwner-before-using-org.bluez.patch

a7afc7
From e50ec0deb7c20d1daa26cc7eab5a1ff75b9f7bf8 Mon Sep 17 00:00:00 2001
a7afc7
From: Wim Taymans <wtaymans@redhat.com>
a7afc7
Date: Wed, 17 Nov 2021 12:28:23 +0100
a7afc7
Subject: [PATCH] bluez5: do NameHasOwner before using org.bluez
a7afc7
a7afc7
We should not be using org.bluez when the bluetooth service is not
a7afc7
running or else we might try to activate it. The activation of the
a7afc7
bluetooth service should be done at boot time.
a7afc7
---
a7afc7
 src/modules/bluetooth/bluez5-util.c | 61 ++++++++++++++++++++++++++++-
a7afc7
 1 file changed, 60 insertions(+), 1 deletion(-)
a7afc7
a7afc7
diff --git a/src/modules/bluetooth/bluez5-util.c b/src/modules/bluetooth/bluez5-util.c
a7afc7
index a21896ede..282886e45 100644
a7afc7
--- a/src/modules/bluetooth/bluez5-util.c
a7afc7
+++ b/src/modules/bluetooth/bluez5-util.c
a7afc7
@@ -1095,6 +1095,65 @@ static void get_managed_objects(pa_bluetooth_discovery *y) {
a7afc7
     send_and_add_to_pending(y, m, get_managed_objects_reply, NULL);
a7afc7
 }
a7afc7
 
a7afc7
+static void check_name_owner_reply(DBusPendingCall *pending, void *userdata) {
a7afc7
+    pa_dbus_pending *p;
a7afc7
+    pa_bluetooth_discovery *y;
a7afc7
+    DBusMessage *r;
a7afc7
+    DBusError err;
a7afc7
+    bool running;
a7afc7
+
a7afc7
+    pa_assert_se(p = userdata);
a7afc7
+    pa_assert_se(y = p->context_data);
a7afc7
+    pa_assert_se(r = dbus_pending_call_steal_reply(pending));
a7afc7
+
a7afc7
+    if (dbus_message_is_error(r, DBUS_ERROR_UNKNOWN_METHOD)) {
a7afc7
+        pa_log_warn("BlueZ D-Bus ObjectManager not available");
a7afc7
+        goto finish;
a7afc7
+    }
a7afc7
+
a7afc7
+    if (dbus_message_get_type(r) == DBUS_MESSAGE_TYPE_ERROR) {
a7afc7
+        pa_log_error("NameHasOwner() failed: %s: %s", dbus_message_get_error_name(r), pa_dbus_get_error_message(r));
a7afc7
+        goto finish;
a7afc7
+    }
a7afc7
+
a7afc7
+    if (!pa_streq(dbus_message_get_signature(r), "b")) {
a7afc7
+        pa_log_error("Invalid reply signature for NameHasOwner()");
a7afc7
+        goto finish;
a7afc7
+    }
a7afc7
+
a7afc7
+    dbus_error_init(&err;;
a7afc7
+    if (!dbus_message_get_args(r, &err, DBUS_TYPE_BOOLEAN, &running, DBUS_TYPE_INVALID)) {
a7afc7
+        pa_log_error("Could not check bluetooth service: %s", err.message);
a7afc7
+        dbus_error_free(&err;;
a7afc7
+        goto finish;
a7afc7
+   }
a7afc7
+
a7afc7
+   pa_log_info("bluetooth service running: %s", running ? "yes" : "no");
a7afc7
+   if (running)
a7afc7
+       get_managed_objects(y);
a7afc7
+
a7afc7
+finish:
a7afc7
+    dbus_message_unref(r);
a7afc7
+
a7afc7
+    PA_LLIST_REMOVE(pa_dbus_pending, y->pending, p);
a7afc7
+    pa_dbus_pending_free(p);
a7afc7
+}
a7afc7
+
a7afc7
+static void check_name_owner(pa_bluetooth_discovery *y) {
a7afc7
+    DBusMessage *m;
a7afc7
+    const char *service = BLUEZ_SERVICE;
a7afc7
+
a7afc7
+    pa_assert(y);
a7afc7
+
a7afc7
+    pa_assert_se(m = dbus_message_new_method_call("org.freedesktop.DBus",
a7afc7
+                            "/org/freedesktop/DBus",
a7afc7
+                            "org.freedesktop.DBus",
a7afc7
+                            "NameHasOwner"));
a7afc7
+    dbus_message_append_args(m, DBUS_TYPE_STRING, &service, DBUS_TYPE_INVALID);
a7afc7
+
a7afc7
+    send_and_add_to_pending(y, m, check_name_owner_reply, NULL);
a7afc7
+}
a7afc7
+
a7afc7
 pa_hook* pa_bluetooth_discovery_hook(pa_bluetooth_discovery *y, pa_bluetooth_hook_t hook) {
a7afc7
     pa_assert(y);
a7afc7
     pa_assert(PA_REFCNT_VALUE(y) > 0);
a7afc7
@@ -1653,7 +1712,7 @@ pa_bluetooth_discovery* pa_bluetooth_discovery_get(pa_core *c, int headset_backe
a7afc7
         pa_xfree(endpoint);
a7afc7
     }
a7afc7
 
a7afc7
-    get_managed_objects(y);
a7afc7
+    check_name_owner(y);
a7afc7
 
a7afc7
     return y;
a7afc7
 
a7afc7
-- 
a7afc7
2.36.1
a7afc7