[gnome-session/benzea/systemd-issue-32: 2/2] gnome-session-ctl: Unset some systemd environment variables at logout
- From: Benjamin Berg <bberg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-session/benzea/systemd-issue-32: 2/2] gnome-session-ctl: Unset some systemd environment variables at logout
- Date: Tue, 24 Sep 2019 11:23:41 +0000 (UTC)
commit dd9abd3656397bb3f39e072dbde3aa98c6d057aa
Author: Benjamin Berg <bberg redhat com>
Date: Tue Sep 24 13:02:25 2019 +0200
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.
tools/gnome-session-ctl.c | 54 +++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 54 insertions(+)
---
diff --git a/tools/gnome-session-ctl.c b/tools/gnome-session-ctl.c
index c5be00da..ad603638 100644
--- a/tools/gnome-session-ctl.c
+++ b/tools/gnome-session-ctl.c
@@ -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[] = {
+ "DISPLAY",
+ "XAUTHORITY",
+ "WAYLAND_DISPLAY",
+ "WAYLAND_SOCKET",
+ "GNOME_SHELL_SESSION_MODE",
+ NULL
+};
+
static GDBusConnection *
get_session_bus (void)
{
@@ -112,6 +129,42 @@ do_start_unit (const gchar *unit, const char *mode)
error->message);
}
+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)
+ return;
+
+ 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,
+ SYSTEMD_DBUS,
+ SYSTEMD_PATH_DBUS,
+ SYSTEMD_INTERFACE_DBUS,
+ "UnsetEnvironment",
+ g_variant_builder_end (&builder),
+ NULL,
+ G_DBUS_CALL_FLAGS_NO_AUTO_START,
+ -1, NULL, &error);
+
+ if (error != NULL) {
+ g_warning ("Failed to unset systemd environment: %s",
+ error->message);
+ }
+}
+
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 ("gnome-session-shutdown.target", "replace-irreversibly");
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]