Revision: 4505
          http://tigervnc.svn.sourceforge.net/tigervnc/?rev=4505&view=rev
Author:   ossman_
Date:     2011-06-17 08:35:22 +0000 (Fri, 17 Jun 2011)

Log Message:
-----------
Turns out that TXImage wasn't just being overly cautious with the custom error
handler; the shared memory extension is actually this broken so it will return
success all the way through even when you're on a remote connection where
things cannot possibly work.

Modified Paths:
--------------
    trunk/vncviewer/X11PixelBuffer.cxx

Modified: trunk/vncviewer/X11PixelBuffer.cxx
===================================================================
--- trunk/vncviewer/X11PixelBuffer.cxx  2011-06-17 07:35:56 UTC (rev 4504)
+++ trunk/vncviewer/X11PixelBuffer.cxx  2011-06-17 08:35:22 UTC (rev 4505)
@@ -140,11 +140,20 @@
   return xim->bytes_per_line / (getPF().bpp/8);
 }
 
+static bool caughtError;
 
+static int XShmAttachErrorHandler(Display *dpy, XErrorEvent *error)
+{
+  caughtError = true;
+  return 0;
+}
+
 int PlatformPixelBuffer::setupShm()
 {
   int major, minor;
   Bool pixmaps;
+  XErrorHandler old_handler;
+  Status status;
 
   if (!XShmQueryVersion(fl_display, &major, &minor, &pixmaps))
     return 0;
@@ -167,12 +176,27 @@
     goto free_shm;
 
   shminfo->readOnly = True;
+
+  // This is the only way we can detect that shared memory won't work
+  // (e.g. because we're accessing a remote X11 server)
+  caughtError = false;
+  old_handler = XSetErrorHandler(XShmAttachErrorHandler);
+
   XShmAttach(fl_display, shminfo);
+  XSync(fl_display, False);
 
+  XSetErrorHandler(old_handler);
+
+  if (caughtError)
+    goto free_shmaddr;
+
   vlog.debug("Using shared memory XImage");
 
   return 1;
 
+free_shmaddr:
+  shmdt(shminfo->shmaddr);
+
 free_shm:
   shmctl(shminfo->shmid, IPC_RMID, 0);
 


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

------------------------------------------------------------------------------
EditLive Enterprise is the world's most technically advanced content
authoring tool. Experience the power of Track Changes, Inline Image
Editing and ensure content is compliant with Accessibility Checking.
http://p.sf.net/sfu/ephox-dev2dev
_______________________________________________
Tigervnc-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tigervnc-commits

Reply via email to