xf86OpenConsole: VT_WAITACTIVE failed: Interrupted system call

Keith Packard keithp at keithp.com
Sun Oct 7 12:55:02 PDT 2007


On Sun, 2007-10-07 at 12:00 -0700, Linus Torvalds wrote:

>        Fatal server error:
>        xf86OpenConsole: VT_WAITACTIVE failed: Interrupted system call

Here's a patch; please review. This covers all ioctl usage in
os-support/linux; the only unwrapped calls relate to MTRR or GART
ioctls, which are not subject to EINTR?

The SYSCALL macro is already defined in xf86_OSlib.h:

#define SYSCALL(call) while(((call) == -1) && (errno == EINTR))

# On branch master
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#	modified:   hw/xfree86/os-support/linux/lnx_apm.c
#	modified:   hw/xfree86/os-support/linux/lnx_font.c
#	modified:   hw/xfree86/os-support/linux/lnx_init.c
#	modified:   hw/xfree86/os-support/linux/lnx_jstk.c
#
diff --git a/hw/xfree86/os-support/linux/lnx_apm.c b/hw/xfree86/os-support/linux/lnx_apm.c
index 16ac80d..52b7b7a 100644
--- a/hw/xfree86/os-support/linux/lnx_apm.c
+++ b/hw/xfree86/os-support/linux/lnx_apm.c
@@ -24,6 +24,7 @@ extern PMClose lnxACPIOpen(void);
 #include <sys/stat.h>
 #include <fcntl.h>
 #include <errno.h>
+#include <xf86_OSlib.h>
  
 #define APM_PROC   "/proc/apm"
 #define APM_DEVICE "/dev/apm_bios"
@@ -99,16 +100,19 @@ lnxPMGetEventFromOs(int fd, pmEvent *events, int num)
 static pmWait
 lnxPMConfirmEventToOs(int fd, pmEvent event)
 {
+    int	ret;
     switch (event) {
     case XF86_APM_SYS_STANDBY:
     case XF86_APM_USER_STANDBY:
-        if (ioctl( fd, APM_IOC_STANDBY, NULL ))
+	SYSCALL (ret = ioctl( fd, APM_IOC_STANDBY, NULL ));
+        if (ret)
 	    return PM_FAILED;
 	return PM_CONTINUE;
     case XF86_APM_SYS_SUSPEND:
     case XF86_APM_CRITICAL_SUSPEND:
     case XF86_APM_USER_SUSPEND:
-	if (ioctl( fd, APM_IOC_SUSPEND, NULL )) {
+	SYSCALL (ret = ioctl( fd, APM_IOC_SUSPEND, NULL ));
+	if (ret) {
 	    /* I believe this is wrong (EE)
 	       EBUSY is sent when a device refuses to be suspended.
 	       In this case we still need to undo everything we have
diff --git a/hw/xfree86/os-support/linux/lnx_font.c b/hw/xfree86/os-support/linux/lnx_font.c
index e9a5b6a..9cede01 100644
--- a/hw/xfree86/os-support/linux/lnx_font.c
+++ b/hw/xfree86/os-support/linux/lnx_font.c
@@ -273,9 +273,9 @@ lnx_switchaway(void)
     Bool ret;
 
     /* temporarily switch to text mode */
-    ioctl(xf86Info.consoleFd, KDSETMODE, KD_TEXT);
+    SYSCALL (ioctl(xf86Info.consoleFd, KDSETMODE, KD_TEXT));
     ret = lnx_restorefont();
-    ioctl(xf86Info.consoleFd, KDSETMODE, KD_GRAPHICS);
+    SYSCALL (ioctl(xf86Info.consoleFd, KDSETMODE, KD_GRAPHICS));
     return ret;
 }
 
diff --git a/hw/xfree86/os-support/linux/lnx_init.c b/hw/xfree86/os-support/linux/lnx_init.c
index 4c36b7c..3213362 100644
--- a/hw/xfree86/os-support/linux/lnx_init.c
+++ b/hw/xfree86/os-support/linux/lnx_init.c
@@ -94,6 +94,7 @@ xf86OpenConsole(void)
     struct fb_var_screeninfo var;
     int fbfd;
 #endif
+    int ret;
     char *tty0[] = { "/dev/tty0", "/dev/vc/0", NULL };
     char *vcs[] = { "/dev/vc/%d", "/dev/tty%d", NULL };
 
@@ -126,13 +127,15 @@ xf86OpenConsole(void)
 
             if (ShareVTs)
             {
-                if (ioctl(fd, VT_GETSTATE, &vts) == 0)
+		SYSCALL (ret = ioctl(fd, VT_GETSTATE, &vts));
+                if (ret == 0)
                     xf86Info.vtno = vts.v_active;
                 else
                     FatalError("xf86OpenConsole: Cannot find the current"
                                " VT (%s)\n", strerror(errno));
             } else {
-	        if ((ioctl(fd, VT_OPENQRY, &xf86Info.vtno) < 0) ||
+		SYSCALL (ret = ioctl(fd, VT_OPENQRY, &xf86Info.vtno));
+	        if ((ret < 0) ||
 		    (xf86Info.vtno == -1))
 		    FatalError("xf86OpenConsole: Cannot find a free VT: %s\n",
                                strerror(errno));
@@ -151,7 +154,8 @@ xf86OpenConsole(void)
 	        FatalError("xf86OpenConsole: Cannot open %s (%s)\n",
 		           fb_dev_name, strerror(errno));
 
-	    if (ioctl(fbfd, FBIOGET_VSCREENINFO, &var) < 0)
+	    SYSCALL (ret = ioctl(fbfd, FBIOGET_VSCREENINFO, &var));
+	    if (ret < 0)
 	        FatalError("xf86OpenConsole: Unable to get screen info %s\n",
 		           strerror(errno));
         }
@@ -220,7 +224,8 @@ xf86OpenConsole(void)
 	 * Linux doesn't switch to an active vt after the last close of a vt,
 	 * so we do this ourselves by remembering which is active now.
 	 */
-	if (ioctl(xf86Info.consoleFd, VT_GETSTATE, &vts) < 0)
+	SYSCALL (ret = ioctl(xf86Info.consoleFd, VT_GETSTATE, &vts));
+	if (ret < 0)
 	    xf86Msg(X_WARNING,"xf86OpenConsole: VT_GETSTATE failed: %s\n",
 		    strerror(errno));
 	else
@@ -232,7 +237,7 @@ xf86OpenConsole(void)
 	     * Detach from the controlling tty to avoid char loss
 	     */
 	    if ((i = open("/dev/tty",O_RDWR)) >= 0) {
-		ioctl(i, TIOCNOTTY, 0);
+		SYSCALL (ioctl(i, TIOCNOTTY, 0));
 		close(i);
 	    }
 	}
@@ -246,15 +251,18 @@ xf86OpenConsole(void)
 	    /*
 	     * now get the VT.  This _must_ succeed, or else fail completely.
 	     */
-	    if (ioctl(xf86Info.consoleFd, VT_ACTIVATE, xf86Info.vtno) < 0)
+	    SYSCALL (ret = ioctl(xf86Info.consoleFd, VT_ACTIVATE, xf86Info.vtno));
+	    if (ret < 0)
 	        FatalError("xf86OpenConsole: VT_ACTIVATE failed: %s\n",
 		           strerror(errno));
 
-	    if (ioctl(xf86Info.consoleFd, VT_WAITACTIVE, xf86Info.vtno) < 0)
+	    SYSCALL (ret = ioctl(xf86Info.consoleFd, VT_WAITACTIVE, xf86Info.vtno));
+	    if (ret < 0)
 	        FatalError("xf86OpenConsole: VT_WAITACTIVE failed: %s\n",
 			   strerror(errno));
 
-	    if (ioctl(xf86Info.consoleFd, VT_GETMODE, &VT) < 0)
+	    SYSCALL (ret = ioctl(xf86Info.consoleFd, VT_GETMODE, &VT));
+	    if (ret < 0)
 	        FatalError("xf86OpenConsole: VT_GETMODE failed %s\n",
 		           strerror(errno));
 
@@ -264,11 +272,13 @@ xf86OpenConsole(void)
 	    VT.relsig = SIGUSR1;
 	    VT.acqsig = SIGUSR1;
 
-	    if (ioctl(xf86Info.consoleFd, VT_SETMODE, &VT) < 0)
+	    SYSCALL (ret = ioctl(xf86Info.consoleFd, VT_SETMODE, &VT));
+	    if (ret < 0)
 	        FatalError("xf86OpenConsole: VT_SETMODE VT_PROCESS failed: %s\n",
 		    strerror(errno));
 	
-	    if (ioctl(xf86Info.consoleFd, KDSETMODE, KD_GRAPHICS) < 0)
+	    SYSCALL (ret = ioctl(xf86Info.consoleFd, KDSETMODE, KD_GRAPHICS));
+	    if (ret < 0)
 	        FatalError("xf86OpenConsole: KDSETMODE KD_GRAPHICS failed %s\n",
 		           strerror(errno));
 
@@ -279,7 +289,8 @@ xf86OpenConsole(void)
 	    /* copy info to new console */
 	    var.yoffset=0;
 	    var.xoffset=0;
-	    if (ioctl(fbfd, FBIOPUT_VSCREENINFO, &var))
+	    SYSCALL (ret = ioctl(fbfd, FBIOPUT_VSCREENINFO, &var));
+	    if (ret < 0)
 	        FatalError("Unable to set screen info\n");
 	    close(fbfd);
 #endif
@@ -293,12 +304,14 @@ xf86OpenConsole(void)
 	    /*
 	     * now get the VT
 	     */
-	    if (ioctl(xf86Info.consoleFd, VT_ACTIVATE, xf86Info.vtno) < 0)
+	    SYSCALL (ret = ioctl(xf86Info.consoleFd, VT_ACTIVATE, xf86Info.vtno));
+	    if (ret < 0)
 	        xf86Msg(X_WARNING, "xf86OpenConsole: VT_ACTIVATE failed %s\n",
 		        strerror(errno));
         }
 
-	    if (ioctl(xf86Info.consoleFd, VT_WAITACTIVE, xf86Info.vtno) < 0)
+	    SYSCALL (ret = ioctl(xf86Info.consoleFd, VT_WAITACTIVE, xf86Info.vtno));
+	    if (ret < 0)
 	        xf86Msg(X_WARNING, "xf86OpenConsole: VT_WAITACTIVE failed %s\n",
 		        strerror(errno));
     }
@@ -309,6 +322,7 @@ void
 xf86CloseConsole()
 {
     struct vt_mode   VT;
+    int ret;
 #if defined(DO_OS_FONTRESTORE)
     struct vt_stat vts;
     int vtno = -1;
@@ -317,7 +331,8 @@ xf86CloseConsole()
     if (ShareVTs) return;
 
 #if defined(DO_OS_FONTRESTORE)
-    if (ioctl(xf86Info.consoleFd, VT_GETSTATE, &vts) < 0)
+    SYSCALL (ret = ioctl(xf86Info.consoleFd, VT_GETSTATE, &vts));
+    if (ret < 0)
 	xf86Msg(X_WARNING, "xf86CloseConsole: VT_GETSTATE failed: %s\n",
 		strerror(errno));
     else
@@ -325,17 +340,20 @@ xf86CloseConsole()
 #endif
 
     /* Back to text mode ... */
-    if (ioctl(xf86Info.consoleFd, KDSETMODE, KD_TEXT) < 0)
+    SYSCALL (ret = ioctl(xf86Info.consoleFd, KDSETMODE, KD_TEXT));
+    if (ret < 0)
 	xf86Msg(X_WARNING, "xf86CloseConsole: KDSETMODE failed: %s\n",
 		strerror(errno));
 	
-    if (ioctl(xf86Info.consoleFd, VT_GETMODE, &VT) < 0) 
+    SYSCALL (ret = ioctl(xf86Info.consoleFd, VT_GETMODE, &VT));
+    if (ret < 0) 
 	xf86Msg(X_WARNING, "xf86CloseConsole: VT_GETMODE failed: %s\n",
 		strerror(errno));
     else {
 	/* set dflt vt handling */
 	VT.mode = VT_AUTO;
-	if (ioctl(xf86Info.consoleFd, VT_SETMODE, &VT) < 0) 
+	SYSCALL (ret = ioctl(xf86Info.consoleFd, VT_SETMODE, &VT));
+	if (ret < 0) 
 	    xf86Msg(X_WARNING, "xf86CloseConsole: VT_SETMODE failed: %s\n",
 		    strerror(errno));
     }
@@ -346,10 +364,12 @@ xf86CloseConsole()
          * Perform a switch back to the active VT when we were started
          */
         if (activeVT >= 0) {
-	    if (ioctl(xf86Info.consoleFd, VT_ACTIVATE, activeVT) < 0)
+	    SYSCALL (ret = ioctl(xf86Info.consoleFd, VT_ACTIVATE, activeVT));
+	    if (ret < 0)
 	        xf86Msg(X_WARNING, "xf86CloseConsole: VT_ACTIVATE failed: %s\n",
 		        strerror(errno));
-	    if (ioctl(xf86Info.consoleFd, VT_WAITACTIVE, activeVT) < 0)
+	    SYSCALL (ret = ioctl(xf86Info.consoleFd, VT_WAITACTIVE, activeVT));
+	    if (ret < 0)
 		xf86Msg(X_WARNING,
 			"xf86CloseConsole: VT_WAITACTIVE failed: %s\n",
 			strerror(errno));
diff --git a/hw/xfree86/os-support/linux/lnx_jstk.c b/hw/xfree86/os-support/linux/lnx_jstk.c
index d77631b..80f72e8 100644
--- a/hw/xfree86/os-support/linux/lnx_jstk.c
+++ b/hw/xfree86/os-support/linux/lnx_jstk.c
@@ -61,6 +61,7 @@ xf86JoystickOn(char *name, int *timeout, int *centerX, int *centerY)
 {
   int			fd;
   struct js_status	js;
+  int			ret;
     
 #ifdef DEBUG
   ErrorF("xf86JoystickOn %s\n", name);
@@ -74,7 +75,8 @@ xf86JoystickOn(char *name, int *timeout, int *centerX, int *centerY)
     }
 
   if (*timeout == 0) {
-    if (ioctl (fd, JSIOCGTIMELIMIT, timeout) == -1) {
+    SYSCALL (ret = ioctl (fd, JSIOCGTIMELIMIT, timeout));
+    if (ret == -1) {
       Error("joystick JSIOCGTIMELIMIT ioctl");
     }
     else {
@@ -82,7 +84,8 @@ xf86JoystickOn(char *name, int *timeout, int *centerX, int *centerY)
     }
   }
   else {
-    if (ioctl(fd, JSIOCSTIMELIMIT, timeout) == -1) {
+    SYSCALL (ret = ioctl(fd, JSIOCSTIMELIMIT, timeout));
+    if (ret == -1) {
       Error("joystick JSIOCSTIMELIMIT ioctl");
     }
   }


-- 
keith.packard at intel.com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
URL: <http://lists.x.org/archives/xorg/attachments/20071007/0dfacb88/attachment.pgp>


More information about the xorg mailing list