[gnome-session] gsm-util: save environment to $XDG_RUNTIME_DIR/gnome/environment
- From: Ray Strode <halfline src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-session] gsm-util: save environment to $XDG_RUNTIME_DIR/gnome/environment
- Date: Thu, 17 Sep 2015 02:20:34 +0000 (UTC)
commit db7ce81e9acd5859cb929496e39880d8b4fdc1bf
Author: Ray Strode <rstrode redhat com>
Date: Wed Sep 16 14:51:20 2015 -0400
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
gnome-session/gsm-util.c | 35 +++++++++++++++++++++++++++++++++++
1 files changed, 35 insertions(+), 0 deletions(-)
---
diff --git a/gnome-session/gsm-util.c b/gnome-session/gsm-util.c
index b7d2cda..bca1b38 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 ();
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]