[PATCH xf86-video-nested] Do not error out if XShmAttach fails.

Nick Alcock nick.alcock at esperi.org.uk
Mon Oct 15 07:25:11 PDT 2012


It is normal for XShmAttach to fail with BadAccess if we are connected to a remote
X server.  Do not fail in this case.  (Largely copied from x11perf.)

Signed-off-by: Nick Alcock <nick.alcock at oracle.com>
---
 src/xlibclient.c | 24 +++++++++++++++++++++++-
 1 file changed, 23 insertions(+), 1 deletion(-)

diff --git a/src/xlibclient.c b/src/xlibclient.c
index 1aa3590..cadb87e 100644
--- a/src/xlibclient.c
+++ b/src/xlibclient.c
@@ -95,6 +95,18 @@ NestedClientValidDepth(int depth) {
     return TRUE;
 }
 
+static Bool hadShmError;
+static int (*origErrorHandler)(Display *, XErrorEvent *);
+
+static int ShmErrorHandler(Display *d, XErrorEvent *e) {
+    if(e->error_code == BadAccess) {
+	/* Probably a remote display.  Fall back to non-SHM. */
+        hadShmError = True;
+        return 0;
+    } else
+        return (*origErrorHandler)(d, e);
+}
+
 static Bool
 NestedClientTryXShm(NestedClientPrivatePtr pPriv, int scrnIndex, int width, int height, int depth) {
     int shmMajor, shmMinor;
@@ -147,11 +159,21 @@ NestedClientTryXShm(NestedClientPrivatePtr pPriv, int scrnIndex, int width, int
         return FALSE;
     }
 
+    XSync(pPriv->display, True);
+    hadShmError = False;
+    origErrorHandler = XSetErrorHandler(ShmErrorHandler);
     pPriv->img->data = pPriv->shminfo.shmaddr;
     pPriv->shminfo.readOnly = FALSE;
     XShmAttach(pPriv->display, &pPriv->shminfo);
+    XSync(pPriv->display, True);
+    XSetErrorHandler(origErrorHandler);
+    if (hadShmError) {
+        xf86DrvMsg(scrnIndex, X_ERROR, "XShmAttach failed.  Dropping XShm support.\n");
+        shmdt(pPriv->shminfo.shmaddr);
+        XDestroyImage(pPriv->img);
+        return FALSE;
+    }
     pPriv->usingShm = TRUE;
-
     return TRUE;
 }
 
-- 
1.7.12.1.157.geb3194e



More information about the xorg mailing list