[PATCH 5/6] linux: Refactor VT switch on {re, }generation and shutdown

Adam Jackson ajax at redhat.com
Tue Aug 24 14:05:24 PDT 2010


This makes more things fatal than were fatal before, but that's correct;
if you need the VT, then failing to get it on regeneration means things
are about to go very very badly.

Signed-off-by: Adam Jackson <ajax at redhat.com>
---
 hw/xfree86/os-support/linux/lnx_init.c |   38 +++++++++++--------------------
 1 files changed, 14 insertions(+), 24 deletions(-)

diff --git a/hw/xfree86/os-support/linux/lnx_init.c b/hw/xfree86/os-support/linux/lnx_init.c
index 0762dca..d2759d5 100644
--- a/hw/xfree86/os-support/linux/lnx_init.c
+++ b/hw/xfree86/os-support/linux/lnx_init.c
@@ -55,6 +55,16 @@ drain_console(int fd, void *closure)
     tcflush(fd, TCIOFLUSH);
 }
 
+static void
+switch_to(int vt, const char *from)
+{
+    if (ioctl(xf86Info.consoleFd, VT_ACTIVATE, vt) < 0)
+        FatalError("%s: VT_ACTIVATE failed: %s\n", from, strerror(errno));
+
+    if (ioctl(xf86Info.consoleFd, VT_WAITACTIVE, vt) < 0)
+        FatalError("%s: VT_WAITACTIVE failed: %s\n", from, strerror(errno));
+}
+
 void
 xf86OpenConsole(void)
 {
@@ -170,13 +180,7 @@ xf86OpenConsole(void)
 	    /*
 	     * now get the VT.  This _must_ succeed, or else fail completely.
 	     */
-	    if (ioctl(xf86Info.consoleFd, VT_ACTIVATE, xf86Info.vtno) < 0)
-	        FatalError("xf86OpenConsole: VT_ACTIVATE failed: %s\n",
-		           strerror(errno));
-
-	    if (ioctl(xf86Info.consoleFd, VT_WAITACTIVE, xf86Info.vtno) < 0)
-	        FatalError("xf86OpenConsole: VT_WAITACTIVE failed: %s\n",
-			   strerror(errno));
+            switch_to(xf86Info.vtno, "xf86OpenConsole");
 
 	    if (ioctl(xf86Info.consoleFd, VT_GETMODE, &VT) < 0)
 	        FatalError("xf86OpenConsole: VT_GETMODE failed %s\n",
@@ -224,16 +228,8 @@ xf86OpenConsole(void)
     } else { 	/* serverGeneration != 1 */
         if (!ShareVTs && VTSwitch)
         {
-	    /*
-	     * now get the VT
-	     */
-	    if (ioctl(xf86Info.consoleFd, VT_ACTIVATE, xf86Info.vtno) < 0)
-	        xf86Msg(X_WARNING, "xf86OpenConsole: VT_ACTIVATE failed %s\n",
-		        strerror(errno));
-
-	    if (ioctl(xf86Info.consoleFd, VT_WAITACTIVE, xf86Info.vtno) < 0)
-	        xf86Msg(X_WARNING, "xf86OpenConsole: VT_WAITACTIVE failed %s\n",
-		        strerror(errno));
+	    /* now get the VT */
+            switch_to(xf86Info.vtno, "xf86OpenConsole");
         }
     }
 }
@@ -278,13 +274,7 @@ xf86CloseConsole(void)
          * Perform a switch back to the active VT when we were started
          */
         if (activeVT >= 0) {
-	    if (ioctl(xf86Info.consoleFd, VT_ACTIVATE, activeVT) < 0)
-	        xf86Msg(X_WARNING, "xf86CloseConsole: VT_ACTIVATE failed: %s\n",
-		        strerror(errno));
-	    if (ioctl(xf86Info.consoleFd, VT_WAITACTIVE, activeVT) < 0)
-		xf86Msg(X_WARNING,
-			"xf86CloseConsole: VT_WAITACTIVE failed: %s\n",
-			strerror(errno));
+            switch_to(activeVT, "xf86CloseConsole");
 	    activeVT = -1;
         }
     }
-- 
1.7.2.1



More information about the xorg-devel mailing list