[gdm] daemon: import DISPLAY into user bus



commit d1820d8c4d6f4828d14e74edb422554ba31b3c14
Author: Ray Strode <rstrode redhat com>
Date:   Wed May 4 14:02:17 2016 -0400

    daemon: import DISPLAY into user bus
    
    commit 99eeae91c1f11997521ad3bc016a7b2d23ec7942 attempted to
    support dbus user buses with X sessions, by supposedly importing
    DISPLAY and XAUTHORITY into the dbus user bus activation
    environment.
    
    It didn't actually work, though, because the spawn_bus function
    quits early if the dbus daemon is already running.
    
    This commit fixes the code so that the activation environment is
    always updated.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=761568

 daemon/gdm-x-session.c |  102 +++++++++++++++++++++++++++++-------------------
 1 files changed, 62 insertions(+), 40 deletions(-)
---
diff --git a/daemon/gdm-x-session.c b/daemon/gdm-x-session.c
index 9414f97..87cfc51 100644
--- a/daemon/gdm-x-session.c
+++ b/daemon/gdm-x-session.c
@@ -370,6 +370,60 @@ out:
 }
 
 static gboolean
+update_bus_environment (State        *state,
+                        GCancellable *cancellable)
+{
+        GDBusConnection     *connection = NULL;
+        GVariantBuilder      builder;
+        GVariant            *reply = NULL;
+        GError              *error = NULL;
+        gboolean             environment_updated = FALSE;
+
+        connection = g_dbus_connection_new_for_address_sync (state->bus_address,
+                                                             G_DBUS_CONNECTION_FLAGS_AUTHENTICATION_CLIENT |
+                                                             G_DBUS_CONNECTION_FLAGS_MESSAGE_BUS_CONNECTION,
+                                                             NULL,
+                                                             cancellable,
+                                                             &error);
+
+        if (connection == NULL) {
+                g_debug ("could not open connection to session bus: %s",
+                         error->message);
+                goto out;
+        }
+
+        g_variant_builder_init (&builder, G_VARIANT_TYPE ("a{ss}"));
+        g_variant_builder_add (&builder, "{ss}", "DISPLAY", state->display_name);
+        g_variant_builder_add (&builder, "{ss}", "XAUTHORITY", state->auth_file);
+
+        reply = g_dbus_connection_call_sync (connection,
+                                             "org.freedesktop.DBus",
+                                             "/org/freedesktop/DBus",
+                                             "org.freedesktop.DBus",
+                                             "UpdateActivationEnvironment",
+                                             g_variant_new ("(@a{ss})",
+                                                            g_variant_builder_end (&builder)),
+                                             NULL,
+                                             G_DBUS_CALL_FLAGS_NONE,
+                                             -1, NULL, &error);
+
+        if (reply == NULL) {
+                g_debug ("could not update activation environment: %s", error->message);
+                goto out;
+        }
+
+        g_variant_unref (reply);
+
+        environment_updated = TRUE;
+
+out:
+        g_clear_object (&connection);
+        g_clear_error (&error);
+
+        return environment_updated;
+}
+
+static gboolean
 spawn_bus (State        *state,
            GCancellable *cancellable)
 {
@@ -378,9 +432,6 @@ spawn_bus (State        *state,
         GSubprocess         *subprocess = NULL;
         GInputStream        *input_stream = NULL;
         GDataInputStream    *data_stream = NULL;
-        GDBusConnection     *connection = NULL;
-        GVariantBuilder      builder;
-        GVariant            *reply = NULL;
         GError              *error = NULL;
         const char          *bus_env = NULL;
         char                *bus_address_fd_string;
@@ -462,44 +513,8 @@ spawn_bus (State        *state,
                                  on_bus_finished,
                                  state);
 
-        connection = g_dbus_connection_new_for_address_sync (state->bus_address,
-                                                             G_DBUS_CONNECTION_FLAGS_AUTHENTICATION_CLIENT |
-                                                             G_DBUS_CONNECTION_FLAGS_MESSAGE_BUS_CONNECTION,
-                                                             NULL,
-                                                             cancellable,
-                                                             &error);
-
-        if (connection == NULL) {
-                g_debug ("could not open connection to session bus: %s",
-                         error->message);
-                goto out;
-        }
-
-        g_variant_builder_init (&builder, G_VARIANT_TYPE ("a{ss}"));
-        g_variant_builder_add (&builder, "{ss}", "DISPLAY", state->display_name);
-        g_variant_builder_add (&builder, "{ss}", "XAUTHORITY", state->auth_file);
-
-        reply = g_dbus_connection_call_sync (connection,
-                                             "org.freedesktop.DBus",
-                                             "/org/freedesktop/DBus",
-                                             "org.freedesktop.DBus",
-                                             "UpdateActivationEnvironment",
-                                             g_variant_new ("(@a{ss})",
-                                                            g_variant_builder_end (&builder)),
-                                             NULL,
-                                             G_DBUS_CALL_FLAGS_NONE,
-                                             -1, NULL, &error);
-
-        if (reply == NULL) {
-                g_debug ("could not update activation environment: %s", error->message);
-                goto out;
-        }
-
-        g_variant_unref (reply);
-
         is_running = TRUE;
 out:
-        g_clear_object (&connection);
         g_clear_object (&data_stream);
         g_clear_object (&subprocess);
         g_clear_object (&launcher);
@@ -508,7 +523,6 @@ out:
         return is_running;
 }
 
-
 static void
 on_session_finished (GSubprocess  *subprocess,
                      GAsyncResult *result,
@@ -794,6 +808,14 @@ main (int    argc,
                 goto out;
         }
 
+        ret = update_bus_environment (state, state->cancellable);
+
+        if (!ret) {
+                g_printerr ("Unable to update bus environment\n");
+                exit_status = EX_SOFTWARE;
+                goto out;
+        }
+
         ret = register_display (state, state->cancellable);
 
         if (!ret) {


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]