[Xfce4-commits] [xfce/xfce4-settings] 01/01: Remove dbus-glib and use gdbus instead (Bug #14426)

noreply at xfce.org noreply at xfce.org
Sun Jun 3 17:55:49 CEST 2018


This is an automated email from the git hooks/post-receive script.

a   l   i       p   u   s   h   e   d       a       c   o   m   m   i   t       t   o       b   r   a   n   c   h       m   a   s   t   e   r   
   in repository xfce/xfce4-settings.

commit 6298f07ae1eaa499caf9b267df6c7fd74809f806
Author: Ali Abdallah <ali at xfce.org>
Date:   Sun Jun 3 17:49:52 2018 +0200

    Remove dbus-glib and use gdbus instead (Bug #14426)
    
    Original patch attached to the bug report has been modified to avoid the
    dbus queue on bus name request when --replace is specified.
    D-Bus has a flag to avoid this, which is DBUS_NAME_FLAG_DO_NOT_QUEUE. No
    equivalent in gdbus, but using always the flag for the name request to
    G_BUS_NAME_OWNER_FLAGS_ALLOW_REPLACEMENT |
    G_BUS_NAME_OWNER_FLAGS_REPLACE, has the same effect and bus does not
    queue us waiting for the current owner to unown the name.
---
 configure.ac.in                                    |   1 -
 xfce4-settings-editor/Makefile.am                  |   3 +-
 .../xfce-settings-cell-renderer.c                  |   3 +-
 xfce4-settings-editor/xfce-settings-prop-dialog.c  |   1 -
 xfsettingsd/Makefile.am                            |   2 -
 xfsettingsd/keyboard-shortcuts.c                   |   2 -
 xfsettingsd/main.c                                 | 101 ++++++++++-----------
 xfsettingsd/pointers.c                             |   2 -
 8 files changed, 50 insertions(+), 65 deletions(-)

diff --git a/configure.ac.in b/configure.ac.in
index c138a1a..c562c74 100644
--- a/configure.ac.in
+++ b/configure.ac.in
@@ -97,7 +97,6 @@ XDT_CHECK_PACKAGE([LIBXFCE4UTIL], [libxfce4util-1.0], [4.9.0])
 XDT_CHECK_PACKAGE([LIBXFCE4UI], [libxfce4ui-2], [4.13.0])
 XDT_CHECK_PACKAGE([LIBXFCE4KBD_PRIVATE], [libxfce4kbd-private-3], [4.12.0])
 XDT_CHECK_PACKAGE([XFCONF], [libxfconf-0], [4.13.0])
-XDT_CHECK_PACKAGE([DBUS_GLIB], [dbus-glib-1], [0.84])
 XDT_CHECK_PACKAGE([FONTCONFIG], [fontconfig], [2.6.0])
 
 XDT_CHECK_PACKAGE([XI], [xi], [1.2.0], [],
diff --git a/xfce4-settings-editor/Makefile.am b/xfce4-settings-editor/Makefile.am
index 028f50c..9b0c9f6 100644
--- a/xfce4-settings-editor/Makefile.am
+++ b/xfce4-settings-editor/Makefile.am
@@ -43,8 +43,7 @@ xfce4_settings_editor_LDADD = \
 	$(GTK_LIBS) \
 	$(LIBXFCE4UTIL_LIBS) \
 	$(LIBXFCE4UI_LIBS) \
-	$(XFCONF_LIBS) \
-	$(DBUS_GLIB_LIBS)
+	$(XFCONF_LIBS)
 
 desktopdir = $(datadir)/applications
 desktop_in_files = xfce4-settings-editor.desktop.in
diff --git a/xfce4-settings-editor/xfce-settings-cell-renderer.c b/xfce4-settings-editor/xfce-settings-cell-renderer.c
index b2e7956..d293d78 100644
--- a/xfce4-settings-editor/xfce-settings-cell-renderer.c
+++ b/xfce4-settings-editor/xfce-settings-cell-renderer.c
@@ -26,7 +26,6 @@
 #endif
 
 #include <gtk/gtk.h>
-#include <dbus/dbus-glib.h>
 
 #include <libxfce4util/libxfce4util.h>
 
@@ -630,7 +629,7 @@ xfce_settings_array_type (void)
 
     if (type == 0)
     {
-        type = dbus_g_type_get_collection ("GPtrArray", G_TYPE_VALUE);
+        type = g_type_from_name ("GPtrArray");
         g_value_register_transform_func (type, G_TYPE_STRING,
                                          xfce_settings_array_to_string);
     }
diff --git a/xfce4-settings-editor/xfce-settings-prop-dialog.c b/xfce4-settings-editor/xfce-settings-prop-dialog.c
index 63f5c2c..45f8434 100644
--- a/xfce4-settings-editor/xfce-settings-prop-dialog.c
+++ b/xfce4-settings-editor/xfce-settings-prop-dialog.c
@@ -29,7 +29,6 @@
 #endif
 
 #include <gtk/gtk.h>
-#include <dbus/dbus-glib.h>
 
 #include <libxfce4util/libxfce4util.h>
 #include <libxfce4ui/libxfce4ui.h>
diff --git a/xfsettingsd/Makefile.am b/xfsettingsd/Makefile.am
index 2d3ed9a..0df1069 100644
--- a/xfsettingsd/Makefile.am
+++ b/xfsettingsd/Makefile.am
@@ -42,7 +42,6 @@ xfsettingsd_CFLAGS = \
 	$(GLIB_CFLAGS) \
 	$(GTHREAD_CFLAGS) \
 	$(GIO_CFLAGS) \
-	$(DBUS_GLIB_CFLAGS) \
 	$(XFCONF_CFLAGS) \
 	$(LIBXFCE4UTIL_CFLAGS) \
 	$(LIBXFCE4UI_CFLAGS) \
@@ -70,7 +69,6 @@ xfsettingsd_LDADD = \
 	$(GLIB_LIBS) \
 	$(GTHREAD_LIBS) \
 	$(GIO_LIBS) \
-	$(DBUS_GLIB_LIBS) \
 	$(XFCONF_LIBS) \
 	$(LIBXFCE4UTIL_LIBS) \
 	$(LIBXFCE4UI_LIBS) \
diff --git a/xfsettingsd/keyboard-shortcuts.c b/xfsettingsd/keyboard-shortcuts.c
index c964025..0248b85 100644
--- a/xfsettingsd/keyboard-shortcuts.c
+++ b/xfsettingsd/keyboard-shortcuts.c
@@ -33,8 +33,6 @@
 #include <gdk/gdkx.h>
 #include <gdk/gdkkeysyms.h>
 
-#include <dbus/dbus-glib.h>
-
 #include <libxfce4ui/libxfce4ui.h>
 #include <libxfce4util/libxfce4util.h>
 #include <xfconf/xfconf.h>
diff --git a/xfsettingsd/main.c b/xfsettingsd/main.c
index 388a757..4fc5c9b 100644
--- a/xfsettingsd/main.c
+++ b/xfsettingsd/main.c
@@ -36,8 +36,8 @@
 #endif
 
 #include <glib.h>
+#include <gio/gio.h>
 #include <gtk/gtk.h>
-#include <dbus/dbus.h>
 
 #ifdef GDK_WINDOWING_X11
 #include <gdk/gdkx.h>
@@ -69,10 +69,11 @@
 
 
 static XfceSMClient *sm_client = NULL;
-
 static gboolean opt_version = FALSE;
 static gboolean opt_no_daemon = FALSE;
 static gboolean opt_replace = FALSE;
+static guint owner_id;
+
 static GOptionEntry option_entries[] =
 {
     { "version", 'V', 0, G_OPTION_ARG_NONE, &opt_version, N_("Version information"), NULL },
@@ -81,7 +82,15 @@ static GOptionEntry option_entries[] =
     { NULL }
 };
 
+static void
+on_name_lost (GDBusConnection *connection,
+              const gchar     *name,
+              gpointer         user_data)
+{
 
+    g_printerr (G_LOG_DOMAIN ": %s\n", "Another instance took over. Leaving...");
+    gtk_main_quit ();
+}
 
 static void
 signal_handler (gint signum,
@@ -91,39 +100,6 @@ signal_handler (gint signum,
     gtk_main_quit ();
 }
 
-
-
-static DBusHandlerResult
-dbus_connection_filter_func (DBusConnection *connection,
-                             DBusMessage    *message,
-                             void           *user_data)
-{
-    gchar *name, *old, *new;
-
-    if (dbus_message_is_signal (message, DBUS_INTERFACE_DBUS, "NameOwnerChanged"))
-    {
-        /* double check if it is really org.xfce.SettingsDaemon
-         * being replaced, see bug 9273 */
-        if (dbus_message_get_args (message, NULL,
-                                   DBUS_TYPE_STRING, &name,
-                                   DBUS_TYPE_STRING, &old,
-                                   DBUS_TYPE_STRING, &new,
-                                   DBUS_TYPE_INVALID))
-        {
-            if (g_strcmp0 (name, XFSETTINGS_DBUS_NAME) == 0)
-            {
-                g_printerr (G_LOG_DOMAIN ": %s\n", "Another instance took over. Leaving...");
-                gtk_main_quit ();
-                return DBUS_HANDLER_RESULT_HANDLED;
-            }
-        }
-    }
-
-    return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
-}
-
-
-
 static gint
 daemonize (void)
 {
@@ -169,9 +145,10 @@ main (gint argc, gchar **argv)
     GObject              *workspaces_helper;
     guint                 i;
     const gint            signums[] = { SIGQUIT, SIGTERM };
-    DBusConnection       *dbus_connection;
-    gint                  result;
-    guint                 dbus_flags;
+    GDBusConnection       *dbus_connection;
+    GBusNameOwnerFlags    dbus_flags;
+    gboolean name_owned;
+    GVariant* name_owned_variant;
 
     xfce_textdomain (GETTEXT_PACKAGE, LOCALEDIR, "UTF-8");
 
@@ -238,29 +215,48 @@ main (gint argc, gchar **argv)
         return EXIT_FAILURE;
     }
 
-    dbus_connection = dbus_bus_get (DBUS_BUS_SESSION, NULL);
-    if (G_LIKELY (dbus_connection != NULL))
+    dbus_connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error);
+    if (G_LIKELY (!error))
     {
-        dbus_connection_set_exit_on_disconnect (dbus_connection, FALSE);
+        g_object_set(G_OBJECT (dbus_connection), "exit-on-close", TRUE, NULL);
+
+        name_owned_variant = g_dbus_connection_call_sync (dbus_connection,
+                                                          "org.freedesktop.DBus",
+                                                          "/org/freedesktop/DBus",
+                                                          "org.freedesktop.DBus",
+                                                          "NameHasOwner",
+                                                          g_variant_new ("(s)", XFSETTINGS_DBUS_NAME),
+                                                          G_VARIANT_TYPE ("(b)"),
+                                                          G_DBUS_CALL_FLAGS_NONE,
+                                                          -1,
+                                                          NULL,
+                                                          &error);
+
+        if (G_UNLIKELY (error)) {
+            g_printerr ("%s: %s.\n", G_LOG_DOMAIN, error->message);
+            g_error_free (error);
+            return EXIT_FAILURE;
+        }
 
-        dbus_flags = DBUS_NAME_FLAG_ALLOW_REPLACEMENT | DBUS_NAME_FLAG_DO_NOT_QUEUE;
-        if (opt_replace)
-          dbus_flags |= DBUS_NAME_FLAG_REPLACE_EXISTING;
+        name_owned = FALSE;
+        g_variant_get(name_owned_variant, "(b)", &name_owned, NULL);
 
-        result = dbus_bus_request_name (dbus_connection, XFSETTINGS_DBUS_NAME, dbus_flags, NULL);
-        if (result != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER)
-        {
+        if(G_UNLIKELY (name_owned && !opt_replace)) {
             xfsettings_dbg (XFSD_DEBUG_XSETTINGS, "Another instance is already running. Leaving.");
-            dbus_connection_unref (dbus_connection);
+            g_dbus_connection_close_sync (dbus_connection, NULL, NULL);
             return EXIT_SUCCESS;
         }
 
-        dbus_bus_add_match (dbus_connection, "type='signal',member='NameOwnerChanged',arg0='"XFSETTINGS_DBUS_NAME"'", NULL);
-        dbus_connection_add_filter (dbus_connection, dbus_connection_filter_func, NULL, NULL);
+        /* Allow the settings daemon to be replaced */
+        dbus_flags = G_BUS_NAME_OWNER_FLAGS_ALLOW_REPLACEMENT | G_BUS_NAME_OWNER_FLAGS_REPLACE;
+
+        owner_id = g_bus_own_name (G_BUS_TYPE_SESSION, XFSETTINGS_DBUS_NAME, dbus_flags, NULL, NULL, on_name_lost, NULL, NULL );
     }
     else
     {
+        g_printerr ("%s: %s.\n", G_LOG_DOMAIN, error->message);
         g_error ("Failed to connect to the dbus session bus.");
+        g_error_free (error);
         return EXIT_FAILURE;
     }
 
@@ -326,9 +322,8 @@ main (gint argc, gchar **argv)
     /* release the dbus name */
     if (dbus_connection != NULL)
     {
-        dbus_connection_remove_filter (dbus_connection, dbus_connection_filter_func, NULL);
-        dbus_bus_release_name (dbus_connection, XFSETTINGS_DBUS_NAME, NULL);
-        dbus_connection_unref (dbus_connection);
+        g_bus_unown_name (owner_id);
+        g_dbus_connection_close_sync (dbus_connection, NULL, NULL);
     }
 
     /* release the sub daemons */
diff --git a/xfsettingsd/pointers.c b/xfsettingsd/pointers.c
index 86b551f..cbd0299 100644
--- a/xfsettingsd/pointers.c
+++ b/xfsettingsd/pointers.c
@@ -41,8 +41,6 @@
 #include <libxfce4util/libxfce4util.h>
 #include <locale.h>
 
-#include <dbus/dbus-glib.h>
-
 #include "debug.h"
 #include "pointers.h"
 #include "pointers-defines.h"

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the Xfce4-commits mailing list