Commit dd9abd36 authored by Benjamin Berg's avatar Benjamin Berg

gnome-session-ctl: Unset some systemd environment variables at logout

We already unset these variables at login. However, doing so at logout
has two advantages. The first is that the useless environment variables
are cleared for other non-graphical sessions. The second is that we also
clear the variables from dbus with the following dbus restart.
parent 559ef9c0
......@@ -44,6 +44,23 @@
#define SYSTEMD_PATH_DBUS "/org/freedesktop/systemd1"
#define SYSTEMD_INTERFACE_DBUS "org.freedesktop.systemd1.Manager"
/* 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. We unset them
* at logout time again. This is to protect against environment variables
* leaking into new sessions (e.g. when switching from classic to
* default GNOME $GNOME_SHELL_SESSION_MODE will become unset).
static const char * const variable_unsetlist[] = {
static GDBusConnection *
get_session_bus (void)
......@@ -112,6 +129,42 @@ do_start_unit (const gchar *unit, const char *mode)
static void
do_unset_systemd_env (void)
g_autoptr(GDBusConnection) connection = NULL;
g_autoptr(GVariant) reply = NULL;
g_autoptr(GError) error = NULL;
GVariantBuilder builder;
gint i;
connection = get_session_bus ();
if (connection == NULL)
g_variant_builder_init (&builder, G_VARIANT_TYPE ("(as)"));
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);
reply = g_dbus_connection_call_sync (connection,
g_variant_builder_end (&builder),
-1, NULL, &error);
if (error != NULL) {
g_warning ("Failed to unset systemd environment: %s",
static void
do_restart_dbus (void)
......@@ -281,6 +334,7 @@ main (int argc, char *argv[])
if (opt_signal_init) {
do_signal_init ();
} else if (opt_restart_dbus) {
do_unset_systemd_env ();
do_restart_dbus ();
} else if (opt_shutdown) {
do_start_unit ("", "replace-irreversibly");
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