If we fail to connect to a UNIX socket and the transport isn't specified,
fallback on TCP.  This matches behavior with the xtrans codepath and the
Xlib spec.

http://lists.x.org/archives/xorg-devel/2010-April/007915.html

Signed-off-by: Jeremy Huddleston <[email protected]>
---
 src/OpenDis.c |   35 ++++++++++++++++++++++++++++-------
 1 files changed, 28 insertions(+), 7 deletions(-)

diff --git a/src/OpenDis.c b/src/OpenDis.c
index 46e1026..cd628f1 100644
--- a/src/OpenDis.c
+++ b/src/OpenDis.c
@@ -93,8 +93,8 @@ XOpenDisplay (
        register Display *dpy;          /* New Display object being created. */
        register int i;
        int j, k;                       /* random iterator indexes */
-#if !USE_XCB
        char *display_name;             /* pointer to display name */
+#if !USE_XCB
        int endian;                     /* to determine which endian. */
        xConnClientPrefix client;       /* client information */
        int idisplay;                   /* display number */
@@ -119,12 +119,13 @@ XOpenDisplay (
        long setuplength;       /* number of bytes in setup message */
        long usedbytes = 0;     /* number of bytes we have processed */
        unsigned long mask;
-       long int conn_buf_size;
-       char *xlib_buffer_size;
+       long int conn_buf_size;
+       char *xlib_buffer_size;
 
 #if !USE_XCB
        bzero((char *) &client, sizeof(client));
        bzero((char *) &prefix, sizeof(prefix));
+#endif /* !USE_XCB */
 
        /*
         * If the display specifier string supplied as an argument to this
@@ -140,7 +141,6 @@ XOpenDisplay (
                /* Display is non-NULL, copy the pointer */
                display_name = (char *)display;
        }
-#endif /* !USE_XCB */
 
 /*
  * Set the default error handlers.  This allows the global variables to
@@ -164,9 +164,30 @@ XOpenDisplay (
 
 #if USE_XCB
        if(!_XConnectXCB(dpy, display, &fullname, &iscreen)) {
-               dpy->display_name = fullname;
-               OutOfMemory(dpy, NULL);
-               return NULL;
+               /* Try falling back on TCP if no transport specified */
+               if(*display_name == ':') {
+                       size_t buf_size = strlen(display_name) + 10;
+                       char *buf = (char *)Xcalloc(buf_size, sizeof(char));
+
+                       if(!buf) {
+                               dpy->display_name = fullname;
+                               OutOfMemory(dpy, NULL);
+                               return NULL;
+                       }
+                       
+                       strcpy(buf, "localhost");
+                       strlcat(buf, display_name, buf_size);
+
+                       if(!_XConnectXCB(dpy, buf, &fullname, &iscreen)) {
+                               dpy->display_name = fullname;
+                               OutOfMemory(dpy, NULL);
+                               return NULL;
+                       }
+               } else {
+                       dpy->display_name = fullname;
+                       OutOfMemory(dpy, NULL);
+                       return NULL;
+               }
        }
 #else /* !USE_XCB */
        if ((dpy->trans_conn = _X11TransConnectDisplay (
-- 
1.5.6.6


_______________________________________________
[email protected]: X.Org development
Archives: http://lists.x.org/archives/xorg-devel
Info: http://lists.x.org/mailman/listinfo/xorg-devel

Reply via email to