[gnome-shell/wip/halfline/env] shell-global: import environment from $XDG_RUNTIME_DIR/gnome/environment



commit 832240a80b8f4cc1640601d3e81fb676108bceec
Author: Ray Strode <rstrode redhat com>
Date:   Wed Sep 16 15:34:36 2015 -0400

    shell-global: import environment from $XDG_RUNTIME_DIR/gnome/environment
    
    environment variables are normally propagated from parent to child, but
    they're used to convey information that's typically scoped to the
    session. gnome-shell needs to know about environment variables that
    are set in the session after it's already been started.
    
    gnome-session now exports its environment to
    $XDG_RUNTIME_DIR/gnome/environment so that programs in the session can
    pick up on the latest environment variables.
    
    This commit changes gnome-shell to propagate the gnome-session's latest
    environment when launching new children.

 src/shell-global.c |   60 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 60 insertions(+), 0 deletions(-)
---
diff --git a/src/shell-global.c b/src/shell-global.c
index 188e898..a68bee6 100644
--- a/src/shell-global.c
+++ b/src/shell-global.c
@@ -1566,6 +1566,64 @@ shell_global_get_current_time (ShellGlobal *global)
   return clutter_get_current_event_time ();
 }
 
+static void
+import_session_environment_to_app_launch_context (ShellGlobal       *global,
+                                                  GAppLaunchContext *context)
+{
+  char *environment_dir, *environment_filename;
+  GMappedFile *environment_file;
+
+  environment_dir = g_build_filename (g_get_user_runtime_dir (), "gnome", NULL);
+  environment_filename = g_build_filename (environment_dir, "environment", NULL);
+  g_free (environment_dir);
+
+  environment_file = g_mapped_file_new (environment_filename, FALSE, NULL);
+  g_free (environment_filename);
+
+  if (environment_file != NULL)
+    {
+      GVariant *environment_variant;
+      const char **environment;
+      int i = 0;
+      gconstpointer environment_data;
+      gsize environment_size;
+
+      environment_data = g_mapped_file_get_contents (environment_file);
+      environment_size = g_mapped_file_get_length (environment_file);
+
+      environment_variant = g_variant_new_from_data (G_VARIANT_TYPE_BYTESTRING_ARRAY,
+                                                     environment_data,
+                                                     environment_size,
+                                                     FALSE,
+                                                     NULL,
+                                                     NULL);
+      environment = g_variant_get_bytestring_array (environment_variant, NULL);
+
+      if (environment != NULL)
+        {
+          for (i = 0; environment[i] != NULL; i++)
+            {
+              char **entry;
+              const char *key;
+              const char *value;
+
+              entry = g_strsplit (environment[i], "=", 2);
+              key = entry[0];
+              value = entry[1];
+
+              if (value != NULL)
+                  g_app_launch_context_setenv (context, key, value);
+
+              g_free (entry);
+            }
+
+          g_free (environment);
+        }
+      g_variant_unref (environment_variant);
+    }
+  g_mapped_file_unref (environment_file);
+}
+
 /**
  * shell_global_create_app_launch_context:
  * @global: A #ShellGlobal
@@ -1586,6 +1644,8 @@ shell_global_create_app_launch_context (ShellGlobal *global,
 
   context = gdk_display_get_app_launch_context (global->gdk_display);
 
+  import_session_environment_to_app_launch_context (global, G_APP_LAUNCH_CONTEXT (context));
+
   if (timestamp == 0)
     timestamp = shell_global_get_current_time (global);
   gdk_app_launch_context_set_timestamp (context, timestamp);


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