Commit b7b24627 authored by Benjamin Berg's avatar Benjamin Berg

util: Unset some environment variables on systemd

Variables like GNOME_SHELL_SESSION_MODE may not always be set at login,
causing them to survive between session. Add a list of variables that
need to be unset, and explicitly unset them on the systemd side.

The list is taken from GDMs list of variables.
parent adfdf7f6
......@@ -35,6 +35,12 @@
static gchar *_saved_session_dir = NULL;
static gchar **child_environment;
/* These are variables that will not be passed on to subprocesses
* (either directly, via systemd or DBus).
* Some of these are blacklisted as they might end up in the wrong session
* (e.g. XDG_VTNR), others because they simply must never be passed on
static const char * const variable_blacklist[] = {
......@@ -43,6 +49,24 @@ static const char * const variable_blacklist[] = {
/* The following is copied from GDMs spawn_session function.
* Environment variables listed here will be copied into the user's service
* environments if they are set in gnome-session's environment. If they are
* not set in gnome-session's environment, they will be removed from the
* service environments. This is to protect against environment variables
* leaking from previous sessions (e.g. when switching from classic to
* default GNOME $GNOME_SHELL_SESSION_MODE will become unset).
static const char * const variable_unsetlist[] = {
char *
gsm_util_find_desktop_file_for_app_name (const char *name,
gboolean look_in_saved_session,
......@@ -616,10 +640,17 @@ gsm_util_export_user_environment (GError **error)
entries = g_get_environ ();
for (; variable_blacklist[i] != NULL; i++)
for (i = 0; variable_blacklist[i] != NULL; i++)
entries = g_environ_unsetenv (entries, variable_blacklist[i]);
g_variant_builder_init (&builder, G_VARIANT_TYPE ("as"));
g_variant_builder_init (&builder, G_VARIANT_TYPE ("(asas)"));
g_variant_builder_open (&builder, G_VARIANT_TYPE ("as"));
for (i = 0; variable_unsetlist[i] != NULL; i++)
g_variant_builder_add (&builder, "s", variable_unsetlist[i]);
g_variant_builder_close (&builder);
g_variant_builder_open (&builder, G_VARIANT_TYPE ("as"));
for (i = 0; entries[i] != NULL; i++) {
const char *entry = entries[i];
......@@ -631,6 +662,7 @@ gsm_util_export_user_environment (GError **error)
g_variant_builder_add (&builder, "s", entry);
g_variant_builder_close (&builder);
g_regex_unref (regex);
g_strfreev (entries);
......@@ -639,9 +671,8 @@ gsm_util_export_user_environment (GError **error)
g_variant_new ("(@as)",
g_variant_builder_end (&builder)),
g_variant_builder_end (&builder),
-1, NULL, &bus_error);
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment