Hi, this patch should fix the issues with remote X and spice.

This patch should fix the issues, it is made for the master branch,
I will see if it can be applied to 0.4 stable branch and if not will
make another one for that branch.


Thanks


>From 76d98ecb705153db049ae399cb7e39db10c73f75 Mon Sep 17 00:00:00 2001
From: Izik Eidus <[email protected]>
Date: Thu, 17 Dec 2009 20:45:09 +0200
Subject: [PATCH] spice: client: add checks to see if it is safe to use XShem.

Beacuse that XShem internal checks wont fail when using the spice client
from remote, we are adding check on the socket family to see if it is
unix domain socket and fail in case it is not.

Signed-off-by: Izik Eidus <[email protected]>
---
 client/x11/platform.cpp         |   22 ++++++++++++++++++++++
 client/x11/red_pixmap_cairo.cpp |    9 ++++++---
 client/x11/x_platform.h         |    2 ++
 3 files changed, 30 insertions(+), 3 deletions(-)

diff --git a/client/x11/platform.cpp b/client/x11/platform.cpp
index 1ac45ef..3536186 100644
--- a/client/x11/platform.cpp
+++ b/client/x11/platform.cpp
@@ -26,7 +26,9 @@
 #include <X11/extensions/render.h>
 #include <X11/extensions/XKB.h>
 #include <X11/extensions/Xrender.h>
+#include <X11/extensions/XShm.h>
 #include <unistd.h>
+#include <sys/socket.h>
 #include <sys/epoll.h>
 #include <sys/resource.h>
 #include <sys/types.h>
@@ -63,6 +65,7 @@
 #endif
 
 static Display* x_display = NULL;
+static bool x_shm_avail = false;
 static XVisualInfo **vinfo = NULL;
 static GLXFBConfig **fb_config = NULL;
 static XIM x_input_method = NULL;
@@ -185,6 +188,11 @@ Display* XPlatform::get_display()
     return x_display;
 }
 
+bool XPlatform::is_x_shm_avail()
+{
+    return x_shm_avail;
+}
+
 XVisualInfo** XPlatform::get_vinfo()
 {
     return vinfo;
@@ -2095,6 +2103,9 @@ void Platform::init()
 {
     int err, ev;
     int threads_enable;
+    int connection_fd;
+    socklen_t sock_len;
+    struct sockaddr sock_addr;
 
     DBG(0, "");
 
@@ -2107,6 +2118,17 @@ void Platform::init()
         THROW("open X display failed");
     }
 
+    connection_fd = ConnectionNumber(x_display);
+    if (getsockname(connection_fd, &sock_addr, &sock_len)) {
+        x_shm_avail = false;
+    } else {
+        if (XShmQueryExtension(x_display) && sock_addr.sa_family == AF_UNIX) {
+            x_shm_avail = true;
+        } else {
+            x_shm_avail = false;
+        }
+    }
+
     vinfo = new XVisualInfo *[ScreenCount(x_display)];
     memset(vinfo, 0, sizeof(XVisualInfo *) * ScreenCount(x_display));
     fb_config = new GLXFBConfig *[ScreenCount(x_display)];
diff --git a/client/x11/red_pixmap_cairo.cpp b/client/x11/red_pixmap_cairo.cpp
index d15c35c..795c8a0 100644
--- a/client/x11/red_pixmap_cairo.cpp
+++ b/client/x11/red_pixmap_cairo.cpp
@@ -36,6 +36,7 @@ RedPixmapCairo::RedPixmapCairo(int width, int height, 
RedPixmap::Format format,
     XShmSegmentInfo *shminfo = NULL;
     _data = NULL;
     XVisualInfo *vinfo = NULL;
+    bool using_shm = false;
 
 
     try {
@@ -45,7 +46,9 @@ RedPixmapCairo::RedPixmapCairo(int width, int height, 
RedPixmap::Format format,
             vinfo = XPlatform::get_vinfo()[win->get_screen_num()];
         }
 
-        if (vinfo && XShmQueryExtension(XPlatform::get_display())) {
+        using_shm = vinfo && XPlatform::is_x_shm_avail();
+
+        if (using_shm) {
             int depth;
 
             switch (format) {
@@ -146,14 +149,14 @@ RedPixmapCairo::RedPixmapCairo(int width, int height, 
RedPixmap::Format format,
         if (cairo_status(cairo) != CAIRO_STATUS_SUCCESS) {
             THROW("cairo create failed failed");
         }
-        if (!(vinfo && XShmQueryExtension(XPlatform::get_display()))) {
+        if (!using_shm) {
             ((PixelsSource_p*)get_opaque())->pixmap.cairo_surf = cairo_surf;
         } else {
             ((PixelsSource_p*)get_opaque())->x_shm_drawable.cairo_surf = 
cairo_surf;
         }
         ((RedDrawable_p*)get_opaque())->cairo = cairo;
     } catch (...) {
-        if (vinfo && XShmQueryExtension(XPlatform::get_display())) {
+        if (using_shm) {
             if (image) {
                 XDestroyImage(image);
             }
diff --git a/client/x11/x_platform.h b/client/x11/x_platform.h
index 3d3fd8f..8423e66 100644
--- a/client/x11/x_platform.h
+++ b/client/x11/x_platform.h
@@ -31,6 +31,8 @@ public:
 
     static void on_focus_in();
     static void on_focus_out();
+
+    static bool is_x_shm_avail();
 };
 
 #endif
-- 
1.6.5.2


------------------------------------------------------------------------------
This SF.Net email is sponsored by the Verizon Developer Community
Take advantage of Verizon's best-in-class app development support
A streamlined, 14 day to market process makes app distribution fast and easy
Join now and get one step closer to millions of Verizon customers
http://p.sf.net/sfu/verizon-dev2dev 
_______________________________________________
Spice-space-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/spice-space-devel

Reply via email to