From 2e152e720807a92c6b8dbf5f496f096fece381e6 Mon Sep 17 00:00:00 2001
From: Ray Strode <rstrode@redhat.com>
Date: Wed, 21 Sep 2016 15:57:04 -0400
Subject: [PATCH] Fix log in after log out

Resolves: #1373169
---
 ...don-t-start-new-session-with-stale-s.patch | 95 +++++++++++++++++++
 gdm.spec                                      |  9 +-
 2 files changed, 103 insertions(+), 1 deletion(-)
 create mode 100644 0001-wayland-session-don-t-start-new-session-with-stale-s.patch

diff --git a/0001-wayland-session-don-t-start-new-session-with-stale-s.patch b/0001-wayland-session-don-t-start-new-session-with-stale-s.patch
new file mode 100644
index 0000000..d814b27
--- /dev/null
+++ b/0001-wayland-session-don-t-start-new-session-with-stale-s.patch
@@ -0,0 +1,95 @@
+From e39d4dacfab25ff4500cbd4dae89d1882d7491dd Mon Sep 17 00:00:00 2001
+From: Ray Strode <rstrode@redhat.com>
+Date: Wed, 21 Sep 2016 15:38:02 -0400
+Subject: [PATCH] wayland-session: don't start new session with stale session
+ env vars
+
+commit 448134d3cdbc54e5359ea33d387993b0defdaefa changed gdm to
+import the session from systemd --user.
+
+Unfortunately, it broke log in after log out. The problem is, certain
+session specific environment variables from the previous session
+were getting leaked into the new session.
+
+This commit wipes the ones causing the most problems on the GDM side,
+but gnome-session should also probably purge them from the systemd
+--user environment when it exits.
+---
+ daemon/gdm-wayland-session.c | 7 +++++++
+ 1 file changed, 7 insertions(+)
+
+diff --git a/daemon/gdm-wayland-session.c b/daemon/gdm-wayland-session.c
+index 503c398..8b0e56a 100644
+--- a/daemon/gdm-wayland-session.c
++++ b/daemon/gdm-wayland-session.c
+@@ -291,60 +291,67 @@ spawn_session (State        *state,
+         if (!ret) {
+                 g_debug ("could not parse session arguments: %s", error->message);
+                 goto out;
+         }
+ 
+         launcher = g_subprocess_launcher_new (G_SUBPROCESS_FLAGS_NONE);
+ 
+         if (state->environment != NULL) {
+                 size_t i;
+ 
+                 for (i = 0; state->environment[i] != NULL; i++) {
+                         g_auto(GStrv) environment_entry = NULL;
+ 
+                         if (state->environment[i] == '\0') {
+                                 continue;
+                         }
+ 
+                         environment_entry = g_strsplit (state->environment[i], "=", 2);
+ 
+                         if (environment_entry[0] == NULL || environment_entry[1] == NULL) {
+                                 continue;
+                         }
+ 
+                         g_subprocess_launcher_setenv (launcher, environment_entry[0], environment_entry[1], FALSE);
+                 }
+         }
+ 
+         if (state->bus_address != NULL) {
+                 g_subprocess_launcher_setenv (launcher, "DBUS_SESSION_BUS_ADDRESS", state->bus_address, TRUE);
+         }
++
++        /* Don't allow session specific environment variables from earlier sessions to leak through */
++        g_subprocess_launcher_unsetenv (launcher, "DISPLAY");
++        g_subprocess_launcher_unsetenv (launcher, "XAUTHORITY");
++        g_subprocess_launcher_unsetenv (launcher, "WAYLAND_DISPLAY");
++        g_subprocess_launcher_unsetenv (launcher, "WAYLAND_SOCKET");
++
+         subprocess = g_subprocess_launcher_spawnv (launcher,
+                                                    (const char * const *) argv,
+                                                    &error);
+         g_strfreev (argv);
+ 
+         if (subprocess == NULL) {
+                 g_debug ("could not start session: %s", error->message);
+                 goto out;
+         }
+ 
+         state->session_subprocess = g_object_ref (subprocess);
+ 
+         g_subprocess_wait_async (state->session_subprocess,
+                                  cancellable,
+                                  (GAsyncReadyCallback)
+                                  on_session_finished,
+                                  state);
+ 
+         is_running = TRUE;
+ out:
+         g_clear_object (&subprocess);
+         return is_running;
+ }
+ 
+ static void
+ signal_subprocesses (State *state)
+ {
+         if (state->session_subprocess != NULL) {
+                 g_subprocess_send_signal (state->session_subprocess, SIGTERM);
+         }
+-- 
+2.9.3
+
diff --git a/gdm.spec b/gdm.spec
index 61d6572..45f2169 100644
--- a/gdm.spec
+++ b/gdm.spec
@@ -10,7 +10,7 @@
 Summary: The GNOME Display Manager
 Name: gdm
 Version: 3.22.0
-Release: 1%{?dist}
+Release: 2%{?dist}
 Epoch: 1
 License: GPLv2+
 Group: User Interface/X
@@ -87,6 +87,8 @@ Provides: gdm-plugin-smartcard = %{epoch}:%{version}-%{release}
 Obsoletes: gdm-plugin-fingerprint < 1:3.2.1
 Provides: gdm-plugin-fingerprint = %{epoch}:%{version}-%{release}
 
+Patch0: 0001-wayland-session-don-t-start-new-session-with-stale-s.patch
+
 %description
 GDM provides the graphical login screen, shown shortly after boot up,
 log out, and when user-switching.
@@ -102,6 +104,7 @@ files needed to build custom greeters.
 
 %prep
 %setup -q
+%patch0 -p1 -b .fix-login-after-logout
 
 autoreconf -i -f
 intltoolize -f
@@ -296,6 +299,10 @@ gtk-update-icon-cache %{_datadir}/icons/hicolor >&/dev/null || :
 %{_libdir}/pkgconfig/gdm.pc
 
 %changelog
+* Wed Sep 21 2016 Ray Strode <rstrode@redhat.com> - 3.22.0-2
+- Fix log in after log out
+  Resolves: #1373169
+
 * Tue Sep 20 2016 Kalev Lember <klember@redhat.com> - 1:3.22.0-1
 - Update to 3.22.0