Blame SOURCES/freedesktop-dbus-Try-to-own-the-name-until-after-exp.patch

7bbc84
From ba878013689114bf199ba2260f9282ae82b352c4 Mon Sep 17 00:00:00 2001
7bbc84
From: Ondrej Holy <oholy@redhat.com>
7bbc84
Date: Wed, 22 Feb 2023 16:22:43 +0100
7bbc84
Subject: [PATCH] freedesktop-dbus: Try to own the name until after exporting
7bbc84
 skeleton
7bbc84
7bbc84
Currently, the `g_bus_own_name_on_connection` function is called for the
7bbc84
`org.freedesktop.FileManager1` name before exporting the
7bbc84
`/org/freedesktop/FileManager1` skeleton. This seemingly works fine in most
7bbc84
cases, but occasionally the name is acquired too early and D-Bus clients
7bbc84
can get `No such interface` error. This is regression caused by the commit
7bbc84
2293e813d3cd1cc47b2b8750f7140647aa066fc8. Let's try to own the nam until
7bbc84
after exporting the skeleton to avoid this error.
7bbc84
---
7bbc84
 src/nautilus-freedesktop-dbus.c | 31 +++++++++++++++----------------
7bbc84
 1 file changed, 15 insertions(+), 16 deletions(-)
7bbc84
7bbc84
diff --git a/src/nautilus-freedesktop-dbus.c b/src/nautilus-freedesktop-dbus.c
7bbc84
index c253cfaba..c20166abb 100644
7bbc84
--- a/src/nautilus-freedesktop-dbus.c
7bbc84
+++ b/src/nautilus-freedesktop-dbus.c
7bbc84
@@ -162,20 +162,6 @@ name_lost_cb (GDBusConnection *connection,
7bbc84
     DEBUG ("Lost (or failed to acquire) the name %s on the session message bus\n", name);
7bbc84
 }
7bbc84
 
7bbc84
-static void
7bbc84
-nautilus_freedesktop_dbus_constructed (GObject *object)
7bbc84
-{
7bbc84
-    NautilusFreedesktopDBus *fdb = NAUTILUS_FREEDESKTOP_DBUS (object);
7bbc84
-
7bbc84
-    fdb->owner_id = g_bus_own_name_on_connection (fdb->connection,
7bbc84
-                                                  NAUTILUS_FDO_DBUS_NAME,
7bbc84
-                                                  G_BUS_NAME_OWNER_FLAGS_NONE,
7bbc84
-                                                  name_acquired_cb,
7bbc84
-                                                  name_lost_cb,
7bbc84
-                                                  fdb,
7bbc84
-                                                  NULL);
7bbc84
-}
7bbc84
-
7bbc84
 static void
7bbc84
 nautilus_freedesktop_dbus_dispose (GObject *object)
7bbc84
 {
7bbc84
@@ -252,7 +238,6 @@ nautilus_freedesktop_dbus_class_init (NautilusFreedesktopDBusClass *klass)
7bbc84
     GObjectClass *object_class = G_OBJECT_CLASS (klass);
7bbc84
 
7bbc84
     object_class->dispose = nautilus_freedesktop_dbus_dispose;
7bbc84
-    object_class->constructed = nautilus_freedesktop_dbus_constructed;
7bbc84
     object_class->get_property = nautilus_freedesktop_dbus_get_property;
7bbc84
     object_class->set_property = nautilus_freedesktop_dbus_set_property;
7bbc84
 
7bbc84
@@ -301,7 +286,6 @@ nautilus_freedesktop_dbus_set_open_windows_with_locations (NautilusFreedesktopDB
7bbc84
                                                                         locations);
7bbc84
 }
7bbc84
 
7bbc84
-/* Tries to own the org.freedesktop.FileManager1 service name */
7bbc84
 NautilusFreedesktopDBus *
7bbc84
 nautilus_freedesktop_dbus_new (GDBusConnection *connection)
7bbc84
 {
7bbc84
@@ -310,6 +294,7 @@ nautilus_freedesktop_dbus_new (GDBusConnection *connection)
7bbc84
                          NULL);
7bbc84
 }
7bbc84
 
7bbc84
+/* Tries to own the org.freedesktop.FileManager1 service name */
7bbc84
 gboolean
7bbc84
 nautilus_freedesktop_dbus_register (NautilusFreedesktopDBus  *fdb,
7bbc84
                                     GError                  **error)
7bbc84
@@ -331,12 +316,26 @@ nautilus_freedesktop_dbus_register (NautilusFreedesktopDBus  *fdb,
7bbc84
                           G_CALLBACK (skeleton_handle_show_item_properties_cb), fdb);
7bbc84
     }
7bbc84
 
7bbc84
+    fdb->owner_id = g_bus_own_name_on_connection (fdb->connection,
7bbc84
+                                                  NAUTILUS_FDO_DBUS_NAME,
7bbc84
+                                                  G_BUS_NAME_OWNER_FLAGS_NONE,
7bbc84
+                                                  name_acquired_cb,
7bbc84
+                                                  name_lost_cb,
7bbc84
+                                                  fdb,
7bbc84
+                                                  NULL);
7bbc84
+
7bbc84
     return success;
7bbc84
 }
7bbc84
 
7bbc84
 void
7bbc84
 nautilus_freedesktop_dbus_unregister (NautilusFreedesktopDBus *fdb)
7bbc84
 {
7bbc84
+    if (fdb->owner_id != 0)
7bbc84
+    {
7bbc84
+        g_bus_unown_name (fdb->owner_id);
7bbc84
+        fdb->owner_id = 0;
7bbc84
+    }
7bbc84
+
7bbc84
     g_dbus_interface_skeleton_unexport (G_DBUS_INTERFACE_SKELETON (fdb->skeleton));
7bbc84
 
7bbc84
     g_signal_handlers_disconnect_by_data (fdb->skeleton, fdb);
7bbc84
-- 
7bbc84
2.39.1
7bbc84