mirror of
https://gitlab.uni-freiburg.de/opensourcevdi/spice
synced 2025-12-31 02:41:52 +00:00
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 <ieidus@redhat.com>
This commit is contained in:
parent
aa1481378f
commit
e93ef13b8f
@ -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,12 @@ void Platform::init()
|
||||
THROW("open X display failed");
|
||||
}
|
||||
|
||||
connection_fd = ConnectionNumber(x_display);
|
||||
if (!getsockname(connection_fd, &sock_addr, &sock_len) &&
|
||||
XShmQueryExtension(x_display) && sock_addr.sa_family == AF_UNIX ) {
|
||||
x_shm_avail = true;
|
||||
}
|
||||
|
||||
vinfo = new XVisualInfo *[ScreenCount(x_display)];
|
||||
memset(vinfo, 0, sizeof(XVisualInfo *) * ScreenCount(x_display));
|
||||
fb_config = new GLXFBConfig *[ScreenCount(x_display)];
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
@ -31,6 +31,8 @@ public:
|
||||
|
||||
static void on_focus_in();
|
||||
static void on_focus_out();
|
||||
|
||||
static bool is_x_shm_avail();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
Loading…
Reference in New Issue
Block a user