[gdm/for-gnome-40: 3/9] launch-environment: Read XDG_DATA_DIRS from env.d for initial-setup




commit 6a30523b0fc57732bbf4dda0b4e13616e15f72e8
Author: Cosimo Cecchi <cosimo endlessm com>
Date:   Mon Nov 5 08:42:12 2018 -0800

    launch-environment: Read XDG_DATA_DIRS from env.d for initial-setup
    
    In the initial setup session we may need to run a Flatpak application;
    Flatpak requires XDG_DATA_DIRS to include its locations to work
    correctly, but that's not set at the moment for the initial-setup
    session.
    
    This commit borrows the code from GdmSessionWorker to read
    XDG_DATA_DIRS from gdm's env.d machinery for the initial-setup session
    as well.

 common/gdm-common.c             | 15 ++++++++++----
 common/gdm-common.h             |  1 +
 daemon/gdm-launch-environment.c | 44 ++++++++++++++++++++++++++++++++---------
 daemon/gdm-session-worker.c     |  9 ++-------
 4 files changed, 49 insertions(+), 20 deletions(-)
---
diff --git a/common/gdm-common.c b/common/gdm-common.c
index 6ba3c595d..92029027b 100644
--- a/common/gdm-common.c
+++ b/common/gdm-common.c
@@ -960,12 +960,14 @@ gdm_find_display_session (GPid        pid,
 static void
 load_env_file (GFile *file,
                GdmLoadEnvVarFunc load_env_func,
+               GdmExpandVarFunc  expand_func,
                gpointer user_data)
 {
         gchar *contents;
         gchar **lines;
         gchar *line, *p;
         gchar *var, *var_end;
+        gchar *expanded;
         char *filename;
         int i;
 
@@ -998,7 +1000,10 @@ load_env_file (GFile *file,
                         while (g_ascii_isspace (*p))
                                 p++;
 
-                        load_env_func (var, p, user_data);
+                        expanded = gdm_shell_expand (p, expand_func, user_data);
+                        expanded = g_strchomp (expanded);
+                        load_env_func (var, expanded, user_data);
+                        g_free (expanded);
                 }
                 g_strfreev (lines);
         }
@@ -1014,6 +1019,7 @@ compare_str (gconstpointer  a,
 static void
 gdm_load_env_dir (GFile *dir,
                   GdmLoadEnvVarFunc load_env_func,
+                  GdmExpandVarFunc  expand_func,
                   gpointer user_data)
 {
         GFileInfo *info = NULL;
@@ -1049,7 +1055,7 @@ gdm_load_env_dir (GFile *dir,
         for (i = 0; i < names->len; i++) {
                 name = g_ptr_array_index (names, i);
                 file = g_file_get_child (dir, name);
-                load_env_file (file, load_env_func, user_data);
+                load_env_file (file, load_env_func, expand_func, user_data);
                 g_object_unref (file);
         }
 
@@ -1060,15 +1066,16 @@ gdm_load_env_dir (GFile *dir,
 
 void
 gdm_load_env_d (GdmLoadEnvVarFunc load_env_func,
+                GdmExpandVarFunc  expand_func,
                 gpointer user_data)
 {
         GFile *dir;
 
         dir = g_file_new_for_path (DATADIR "/gdm/env.d");
-        gdm_load_env_dir (dir, load_env_func, user_data);
+        gdm_load_env_dir (dir, load_env_func, expand_func, user_data);
         g_object_unref (dir);
 
         dir = g_file_new_for_path (GDMCONFDIR "/env.d");
-        gdm_load_env_dir (dir, load_env_func, user_data);
+        gdm_load_env_dir (dir, load_env_func, expand_func, user_data);
         g_object_unref (dir);
 }
diff --git a/common/gdm-common.h b/common/gdm-common.h
index 6f0476038..c42f556a4 100644
--- a/common/gdm-common.h
+++ b/common/gdm-common.h
@@ -92,6 +92,7 @@ gboolean      gdm_activate_session_by_id (GDBusConnection *connection,
                                           const char      *session_id);
 
 void          gdm_load_env_d              (GdmLoadEnvVarFunc load_env_func,
+                                           GdmExpandVarFunc  expand_func,
                                            gpointer          user_data);
 
 G_END_DECLS
diff --git a/daemon/gdm-launch-environment.c b/daemon/gdm-launch-environment.c
index feccf057f..87a1c5ffe 100644
--- a/daemon/gdm-launch-environment.c
+++ b/daemon/gdm-launch-environment.c
@@ -113,6 +113,23 @@ static void     gdm_launch_environment_finalize      (GObject
 
 G_DEFINE_TYPE_WITH_PRIVATE (GdmLaunchEnvironment, gdm_launch_environment, G_TYPE_OBJECT)
 
+static char *
+get_var_cb (const char *var,
+            gpointer user_data)
+{
+        const char *value = g_hash_table_lookup (user_data, var);
+        return g_strdup (value);
+}
+
+static void
+load_env_func (const char *var,
+               const char *value,
+               gpointer user_data)
+{
+        GHashTable *environment = user_data;
+        g_hash_table_replace (environment, g_strdup (var), g_strdup (value));
+}
+
 static GHashTable *
 build_launch_environment (GdmLaunchEnvironment *launch_environment,
                           gboolean              start_session)
@@ -159,15 +176,6 @@ build_launch_environment (GdmLaunchEnvironment *launch_environment,
                                      g_strdup (g_getenv (optional_environment[i])));
         }
 
-        system_data_dirs = g_strjoinv (":", (char **) g_get_system_data_dirs ());
-
-        g_hash_table_insert (hash,
-                             g_strdup ("XDG_DATA_DIRS"),
-                             g_strdup_printf ("%s:%s",
-                                              DATADIR "/gdm/greeter",
-                                              system_data_dirs));
-        g_free (system_data_dirs);
-
         if (launch_environment->priv->x11_authority_file != NULL)
                 g_hash_table_insert (hash, g_strdup ("XAUTHORITY"), g_strdup 
(launch_environment->priv->x11_authority_file));
 
@@ -218,6 +226,24 @@ build_launch_environment (GdmLaunchEnvironment *launch_environment,
 
         g_hash_table_insert (hash, g_strdup ("RUNNING_UNDER_GDM"), g_strdup ("true"));
 
+        /* Now populate XDG_DATA_DIRS from env.d if we're running initial setup; this allows
+         * e.g. Flatpak apps to be recognized by gnome-shell.
+         */
+        if (g_strcmp0 (launch_environment->priv->session_mode, INITIAL_SETUP_SESSION_MODE) == 0)
+                gdm_load_env_d (load_env_func, get_var_cb, hash);
+
+        /* Prepend our own XDG_DATA_DIRS value */
+        system_data_dirs = g_strdup (g_hash_table_lookup (hash, "XDG_DATA_DIRS"));
+        if (!system_data_dirs)
+                system_data_dirs = g_strjoinv (":", (char **) g_get_system_data_dirs ());
+
+        g_hash_table_insert (hash,
+                             g_strdup ("XDG_DATA_DIRS"),
+                             g_strdup_printf ("%s:%s",
+                                              DATADIR "/gdm/greeter",
+                                              system_data_dirs));
+        g_free (system_data_dirs);
+
         return hash;
 }
 
diff --git a/daemon/gdm-session-worker.c b/daemon/gdm-session-worker.c
index ee7ffef9c..facd05f40 100644
--- a/daemon/gdm-session-worker.c
+++ b/daemon/gdm-session-worker.c
@@ -1574,12 +1574,7 @@ load_env_func (const char *var,
                gpointer user_data)
 {
         GdmSessionWorker *worker = user_data;
-        char *expanded;
-
-        expanded = gdm_shell_expand (value, get_var_cb, worker);
-        expanded = g_strchomp (expanded);
-        gdm_session_worker_set_environment_variable (worker, var, expanded);
-        g_free (expanded);
+        gdm_session_worker_set_environment_variable (worker, var, value);
 }
 
 static gboolean
@@ -2078,7 +2073,7 @@ gdm_session_worker_start_session (GdmSessionWorker  *worker,
 #endif
 
                 if (!worker->priv->is_program_session) {
-                        gdm_load_env_d (load_env_func, worker);
+                        gdm_load_env_d (load_env_func, get_var_cb, worker);
                 }
 
                 environment = gdm_session_worker_get_environment (worker);


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