32ae6ba
commit 01247e06779bef0b4619d6807f31e118d5b55cf0
32ae6ba
Author: Ray Strode <rstrode@halfline-kentsfield.usersys.redhat.com>
32ae6ba
Date:   Thu Sep 11 12:54:19 2008 -0400
32ae6ba
32ae6ba
    Force vt if force-display-on-active-vt is set
32ae6ba
    
32ae6ba
    This will allow plymouth and gdm to transition smoothly
32ae6ba
32ae6ba
diff --git a/configure.ac b/configure.ac
32ae6ba
index 4a08418..8891882 100644
32ae6ba
--- a/configure.ac
32ae6ba
+++ b/configure.ac
32ae6ba
@@ -1311,6 +1311,23 @@ fi
32ae6ba
 AC_SUBST(GDM_XAUTH_DIR)
32ae6ba
 
32ae6ba
 dnl ---------------------------------------------------------------------------
32ae6ba
+dnl - Directory to spool events from other processes
32ae6ba
+dnl ---------------------------------------------------------------------------
32ae6ba
+
32ae6ba
+AC_ARG_WITH(spool-dir,
32ae6ba
+            AS_HELP_STRING([--with-spool-dir=<dir>],
32ae6ba
+                           [spool directory]))
32ae6ba
+
32ae6ba
+if ! test -z "$with_spool_dir"; then
32ae6ba
+   GDM_SPOOL_DIR=$with_spool_dir
32ae6ba
+else
32ae6ba
+   GDM_SPOOL_DIR=${localstatedir}/spool/gdm
32ae6ba
+fi
32ae6ba
+
32ae6ba
+AC_SUBST(GDM_SPOOL_DIR)
32ae6ba
+
32ae6ba
+
32ae6ba
+dnl ---------------------------------------------------------------------------
32ae6ba
 dnl - Finish
32ae6ba
 dnl ---------------------------------------------------------------------------
32ae6ba
 
32ae6ba
diff --git a/daemon/Makefile.am b/daemon/Makefile.am
32ae6ba
index 1846ed2..ced03a3 100644
32ae6ba
--- a/daemon/Makefile.am
32ae6ba
+++ b/daemon/Makefile.am
32ae6ba
@@ -16,6 +16,7 @@ INCLUDES = \
32ae6ba
 	-DPIXMAPDIR=\"$(pixmapdir)\"			\
32ae6ba
 	-DSBINDIR=\"$(sbindir)\"			\
32ae6ba
 	-DGNOMELOCALEDIR=\""$(datadir)/locale"\"	\
633208c
+        -DGDM_SPOOL_DIR=\"$(GDM_SPOOL_DIR)\"  \
32ae6ba
 	-DGDM_XAUTH_DIR=\"$(GDM_XAUTH_DIR)\"		\
32ae6ba
 	-DGDM_DEFAULTS_CONF=\"$(GDM_DEFAULTS_CONF)\"	\
32ae6ba
 	-DGDM_CUSTOM_CONF=\"$(GDM_CUSTOM_CONF)\"	\
32ae6ba
diff --git a/daemon/gdm-server.c b/daemon/gdm-server.c
32ae6ba
index ca37a2a..e6f821f 100644
32ae6ba
--- a/daemon/gdm-server.c
32ae6ba
+++ b/daemon/gdm-server.c
32ae6ba
@@ -34,6 +34,8 @@
32ae6ba
 #include <signal.h>
32ae6ba
 #include <sys/resource.h>
32ae6ba
 
32ae6ba
+#include <linux/vt.h>
32ae6ba
+
32ae6ba
 #include <glib.h>
32ae6ba
 #include <glib/gi18n.h>
32ae6ba
 #include <glib/gstdio.h>
32ae6ba
@@ -663,6 +665,56 @@ gdm_server_spawn (GdmServer  *server,
32ae6ba
         return ret;
32ae6ba
 }
32ae6ba
 
32ae6ba
+static gboolean
32ae6ba
+should_force_display_on_active_vt (void)
32ae6ba
+{
633208c
+        gboolean should_force_display_on_active_vt;
32ae6ba
+
633208c
+        should_force_display_on_active_vt = g_file_test (GDM_SPOOL_DIR "/force-display-on-active-vt",
633208c
+                                                         G_FILE_TEST_EXISTS);
633208c
+        g_unlink (GDM_SPOOL_DIR "/force-display-on-active-vt");
32ae6ba
+
633208c
+        return should_force_display_on_active_vt;
32ae6ba
+}
32ae6ba
+
32ae6ba
+static int
32ae6ba
+get_active_vt (void)
32ae6ba
+{
633208c
+        int console_fd;
633208c
+        struct vt_stat console_state = { 0 };
32ae6ba
+
633208c
+        console_fd = open ("/dev/tty0", O_RDONLY | O_NOCTTY);
32ae6ba
+
633208c
+        if (console_fd < 0) {
633208c
+                goto out;
633208c
+        }
32ae6ba
+
633208c
+        if (ioctl (console_fd, VT_GETSTATE, &console_state) < 0) {
633208c
+                goto out;
633208c
+        }
32ae6ba
+
32ae6ba
+out:
633208c
+        if (console_fd >= 0) {
633208c
+                close (console_fd);
633208c
+        }
32ae6ba
+
633208c
+        return console_state.v_active;
32ae6ba
+}
32ae6ba
+
32ae6ba
+static char *
32ae6ba
+get_active_vt_as_string (void)
32ae6ba
+{
633208c
+        int vt;
32ae6ba
+
633208c
+        vt = get_active_vt ();
32ae6ba
+
633208c
+        if (vt <= 0) {
633208c
+                return NULL;
633208c
+        }
633208c
+
633208c
+        return g_strdup_printf ("vt%d", vt);
32ae6ba
+}
32ae6ba
+
32ae6ba
 /**
32ae6ba
  * gdm_server_start:
32ae6ba
  * @disp: Pointer to a GdmDisplay structure
32ae6ba
@@ -675,8 +727,18 @@ gdm_server_start (GdmServer *server)
32ae6ba
 {
32ae6ba
         gboolean res;
32ae6ba
 
32ae6ba
-        /* fork X server process */
32ae6ba
-        res = gdm_server_spawn (server, NULL);
633208c
+        if (should_force_display_on_active_vt ()) {
32ae6ba
+                char *vt;
32ae6ba
+
633208c
+                g_free (server->priv->command);
633208c
+                server->priv->command = g_strdup (X_SERVER " -nr -verbose");
32ae6ba
+                vt = get_active_vt_as_string ();
633208c
+                res = gdm_server_spawn (server, vt);
32ae6ba
+                g_free (vt);
633208c
+        } else {
633208c
+                /* fork X server process */
633208c
+                res = gdm_server_spawn (server, NULL);
633208c
+        }
32ae6ba
 
32ae6ba
         return res;
32ae6ba
 }
32ae6ba
diff --git a/data/Makefile.am b/data/Makefile.am
32ae6ba
index 30e1f55..400c43d 100644
32ae6ba
--- a/data/Makefile.am
32ae6ba
+++ b/data/Makefile.am
32ae6ba
@@ -13,6 +13,7 @@ predir = $(gdmconfdir)/PreSession
32ae6ba
 postlogindir = $(gdmconfdir)/PostLogin
32ae6ba
 workingdir = $(GDM_WORKING_DIR)
32ae6ba
 xauthdir = $(GDM_XAUTH_DIR)
32ae6ba
+spooldir = $(GDM_SPOOL_DIR)
32ae6ba
 
32ae6ba
 if OS_SOLARIS
32ae6ba
    DISTRO_XSESSION=$(srcdir)/Xsession.solaris
32ae6ba
@@ -132,6 +133,7 @@ uninstall-hook:
32ae6ba
 	-rf \
32ae6ba
 	$(DESTDIR)$(workingdir)/.gconf.mandatory \
32ae6ba
 	$(DESTDIR)$(xauthdir)
aa6967b
+	$(DESTDIR)$(spooldir)
32ae6ba
 
32ae6ba
 install-data-hook: gdm.conf-custom Xsession Init PostSession PreSession gconf.path
32ae6ba
 	if test '!' -d $(DESTDIR)$(gdmconfdir); then \
32ae6ba
@@ -219,6 +221,12 @@ install-data-hook: gdm.conf-custom Xsession Init PostSession PreSession gconf.pa
32ae6ba
 		chown root:gdm $(DESTDIR)$(workingdir) || : ; \
32ae6ba
 	fi
32ae6ba
 
aa6967b
+	if test '!' -d $(DESTDIR)$(spooldir); then \
aa6967b
+		$(mkinstalldirs) $(DESTDIR)$(spooldir); \
1de4f90
+		chmod 775 $(DESTDIR)$(spooldir); \
aa6967b
+		chown root:gdm $(DESTDIR)$(spooldir) || : ; \
aa6967b
+	fi
32ae6ba
+
32ae6ba
 	$(INSTALL_DATA) $(srcdir)/gconf.path $(DESTDIR)$(workingdir)/.gconf.path
32ae6ba
 	gconftool-2 --direct --config-source=xml:merged:$(DESTDIR)$(workingdir)/.gconf.mandatory --recursive-unset /
32ae6ba
 	gconftool-2 --direct --config-source=xml:merged:$(DESTDIR)$(workingdir)/.gconf.mandatory --load $(srcdir)/session-setup.entries