Blob Blame History Raw
diff -up gdm-3.14.2/daemon/gdm-session-worker.c.fix-headless gdm-3.14.2/daemon/gdm-session-worker.c
--- gdm-3.14.2/daemon/gdm-session-worker.c.fix-headless        2015-06-23 10:42:17.802937143 -0400
+++ gdm-3.14.2/daemon/gdm-session-worker.c        2015-06-23 10:52:26.055317210 -0400
@@ -2059,6 +2059,43 @@ fail:
 }
 #endif
 
+#ifdef __linux__
+static gboolean
+set_xdg_vtnr_to_current_vt (GdmSessionWorker *worker)
+{
+        int fd;
+        char vt_string[256];
+        struct vt_stat vt_state = { 0 };
+
+        fd = open ("/dev/tty0", O_RDWR | O_NOCTTY);
+
+        if (fd < 0) {
+                g_debug ("GdmSessionWorker: couldn't open VT master: %m");
+                return FALSE;
+        }
+
+        if (ioctl (fd, VT_GETSTATE, &vt_state) < 0) {
+                g_debug ("GdmSessionWorker: couldn't get current VT: %m");
+                goto fail;
+        }
+
+        close (fd);
+        fd = -1;
+
+        g_snprintf (vt_string, sizeof (vt_string), "%d", vt_state.v_active);
+
+        gdm_session_worker_set_environment_variable (worker,
+                                                     "XDG_VTNR",
+                                                     vt_string);
+
+        return TRUE;
+
+fail:
+        close (fd);
+        return FALSE;
+}
+#endif
+
 static gboolean
 set_up_for_current_vt (GdmSessionWorker  *worker,
                        GError           **error)
@@ -2124,6 +2161,16 @@ set_up_for_current_vt (GdmSessionWorker
                 g_free (pam_xauth);
          }
 #endif
+
+#ifdef __linux__
+        if (g_strcmp0 (worker->priv->display_seat_id, "seat0") == 0) {
+                g_debug ("GdmSessionWorker: setting XDG_VTNR to current vt");
+                set_xdg_vtnr_to_current_vt (worker);
+        } else {
+                g_debug ("GdmSessionWorker: not setting XDG_VTNR since not seat0");
+        }
+#endif
+
         return TRUE;
 out:
         return FALSE;