From 9faf682350db76ac4e73b1c33bb86c87556ad5aa Mon Sep 17 00:00:00 2001
From: Ray Strode <rstrode@redhat.com>
Date: Fri, 13 Sep 2013 17:17:16 -0400
Subject: [PATCH] xf86Init: trim out non-wayland capable servers from drive
 list

Otherwise they'll cause the server to crash when run in wayland mode.
---
 hw/xfree86/common/xf86Init.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/hw/xfree86/common/xf86Init.c b/hw/xfree86/common/xf86Init.c
index 2d3bb01..6282252 100644
--- a/hw/xfree86/common/xf86Init.c
+++ b/hw/xfree86/common/xf86Init.c
@@ -531,60 +531,69 @@ InitOutput(ScreenInfo * pScreenInfo, int argc, char **argv)
          */
 
         for (i = 0; i < xf86NumDrivers; i++) {
             xorgHWFlags flags = HW_IO;
 
             if (xf86DriverList[i]->Identify != NULL)
                 xf86DriverList[i]->Identify(0);
 
             if (xf86DriverList[i]->driverFunc)
                 xf86DriverList[i]->driverFunc(NULL,
                                               GET_REQUIRED_HW_INTERFACES,
                                               &flags);
 
             if (NEED_IO_ENABLED(flags))
                 want_hw_access = TRUE;
 
             if (!(flags & HW_SKIP_CONSOLE))
                 xorgHWOpenConsole = TRUE;
 
 	    if (xorgWayland) {
                 if (flags != HW_WAYLAND) {
                     xf86DeleteDriver(i);
                     continue;
                 }
 
                 want_hw_access = FALSE;
                 xorgHWOpenConsole = FALSE;
 	    }
         }
 
+        for (i = 0; i < xf86NumDrivers; i++) {
+                if (xf86DriverList[i] == NULL) {
+                        for (j = i; j < xf86NumDrivers; j++) {
+                            xf86DriverList[j] = xf86DriverList[j + 1];
+                        }
+                        xf86NumDrivers--;
+                }
+        }
+
         if (xorgHWOpenConsole)
             xf86OpenConsole();
         else
             xf86Info.dontVTSwitch = TRUE;
 
 	/* Enable full I/O access */
 	if (want_hw_access)
 	    xorgHWAccess = xf86EnableIO();
 
         if (xf86BusConfig() == FALSE)
             return;
 
         xf86PostProbe();
 
         /*
          * Sort the drivers to match the requested ording.  Using a slow
          * bubble sort.
          */
         for (j = 0; j < xf86NumScreens - 1; j++) {
             for (i = 0; i < xf86NumScreens - j - 1; i++) {
                 if (xf86Screens[i + 1]->confScreen->screennum <
                     xf86Screens[i]->confScreen->screennum) {
                     ScrnInfoPtr tmpScrn = xf86Screens[i + 1];
 
                     xf86Screens[i + 1] = xf86Screens[i];
                     xf86Screens[i] = tmpScrn;
                 }
             }
         }
         /* Fix up the indexes */
-- 
1.8.3.1

