summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRay Strode <rstrode@redhat.com>2015-09-16 15:34:36 -0400
committerRay Strode <rstrode@redhat.com>2015-09-16 21:14:48 -0400
commit832240a80b8f4cc1640601d3e81fb676108bceec (patch)
tree9f895a52302a850c6667c4158c16f8e4367f3681
parent629f408fe5163da68e4a8aa1b63c52cbcb6602f3 (diff)
downloadgnome-shell-wip/halfline/env.tar.gz
shell-global: import environment from $XDG_RUNTIME_DIR/gnome/environmentwip/halfline/env
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.
-rw-r--r--src/shell-global.c60
1 files changed, 60 insertions, 0 deletions
diff --git a/src/shell-global.c b/src/shell-global.c
index 188e89805..a68bee6ab 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);