Sophie

Sophie

distrib > Mandriva > 2007.1 > x86_64 > by-pkgid > e9d7306cbb3d13290c9b1281bcbf9c3a > files > 3

x11-server-1.2.0-9.1mdv2007.1.src.rpm

From 44190d8a006e8916f46584fc7cc560a9befb68f8 Mon Sep 17 00:00:00 2001
From: Boiko <boiko@ageless.conectiva>
Date: Thu, 8 Jun 2006 14:28:13 -0300
Subject: [PATCH] find free VT

Try to find an empty VT to start the X server
---
 hw/xfree86/os-support/linux/lnx_init.c |   18 +++++++++++++++---
 1 files changed, 15 insertions(+), 3 deletions(-)

diff --git a/hw/xfree86/os-support/linux/lnx_init.c b/hw/xfree86/os-support/linux/lnx_init.c
index 9933c6f..a0de5ef 100644
--- a/hw/xfree86/os-support/linux/lnx_init.c
+++ b/hw/xfree86/os-support/linux/lnx_init.c
@@ -112,7 +112,6 @@ #endif
 	    xf86Info.vtno = VTnum;
 	    from = X_CMDLINE;
 	} else {
-
 	    i=0;
 	    while (tty0[i] != NULL) {
 		if ((fd = open(tty0[i],O_WRONLY,0)) >= 0)
@@ -133,10 +132,23 @@ #endif
                     FatalError("xf86OpenConsole: Cannot find the current"
                                " VT (%s)\n", strerror(errno));
             } else {
-	        if ((ioctl(fd, VT_OPENQRY, &xf86Info.vtno) < 0) ||
-		    (xf86Info.vtno == -1))
+		if ((ioctl(fd, VT_GETSTATE, &vts) < 0)) {
 		    FatalError("xf86OpenConsole: Cannot find a free VT: %s\n",
                                strerror(errno));
+		} else {
+		    for(xf86Info.vtno=7; xf86Info.vtno<13; xf86Info.vtno++) {
+			if (!(vts.v_state & (1 << xf86Info.vtno))) {
+			    break;
+			}
+		    }
+		    if (xf86Info.vtno == 13) {
+			if ((ioctl(fd, VT_OPENQRY, &xf86Info.vtno) < 0) ||
+			    (xf86Info.vtno == -1)) {
+			    FatalError("xf86OpenConsole: Cannot find a free VT\n");
+			}
+		    }
+		    ErrorF("Using vt %d\n", xf86Info.vtno);
+		}
             }
 	    close(fd);
 	}
-- 
1.4.0