summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRay Strode <rstrode@redhat.com>2015-09-16 14:51:20 -0400
committerRay Strode <rstrode@redhat.com>2015-09-16 22:04:20 -0400
commitdb7ce81e9acd5859cb929496e39880d8b4fdc1bf (patch)
treefdea3175dfc1ac5909ac211bef2ff4edb5fd84af
parente9310040c25d7e8eb4dc43b7fc7dcff71dbc7cab (diff)
downloadgnome-session-db7ce81e9acd5859cb929496e39880d8b4fdc1bf.tar.gz
gsm-util: save environment to $XDG_RUNTIME_DIR/gnome/environment
Environment variables are problematic because they require a parent child inheritance model, but they're often used in a per-session scope. gnome-session provides a mechanism for children to affect the environment of future siblings via the SetEnv dbus method call. Unfortunately that change does not affect existing siblings, or their offspring. This commit centralizes gnome-session's environment into a file, $XDG_RUNTIME_DIR/gnome/environment so other components in the session can ensure their children get the most up to date environment possible. https://bugzilla.gnome.org/show_bug.cgi?id=738205
-rw-r--r--gnome-session/gsm-util.c35
1 files changed, 35 insertions, 0 deletions
diff --git a/gnome-session/gsm-util.c b/gnome-session/gsm-util.c
index b7d2cdab..bca1b383 100644
--- a/gnome-session/gsm-util.c
+++ b/gnome-session/gsm-util.c
@@ -447,6 +447,39 @@ gsm_util_generate_startup_id (void)
sequence);
}
+static void
+gsm_util_save_environment (void)
+{
+ g_autoptr(GVariant) environment = NULL;
+ g_autoptr(GError) error = NULL;
+ g_autofree char *environment_dir = NULL;
+ g_autofree char *filename = NULL;
+ gconstpointer environment_data;
+ gsize size;
+ int ret;
+ gboolean contents_set;
+
+ environment_dir = g_build_filename (g_get_user_runtime_dir (), "gnome", NULL);
+ ret = g_mkdir_with_parents (environment_dir, 0700);
+
+ if (ret < 0) {
+ g_warning ("can't create gnome runtime dir: %m");
+ return;
+ }
+
+ environment = g_variant_new_bytestring_array ((const gchar * const *) g_get_environ (), -1);
+ size = g_variant_get_size (environment);
+ environment_data = g_variant_get_data (environment);
+
+ filename = g_build_filename (environment_dir, "environment", NULL);
+
+ contents_set = g_file_set_contents (filename, environment_data, size, &error);
+
+ if (!contents_set) {
+ g_warning ("can't save environment: %s", error->message);
+ }
+}
+
static gboolean
gsm_util_update_activation_environment (const char *variable,
const char *value,
@@ -511,4 +544,6 @@ gsm_util_setenv (const char *variable,
g_warning ("Could not make bus activated clients aware of %s=%s environment variable: %s", variable, value, bus_error->message);
g_error_free (bus_error);
}
+
+ gsm_util_save_environment ();
}