diff options
author | Jeremy Huddleston <jeremyhu@apple.com> | 2010-05-12 16:42:18 -0700 |
---|---|---|
committer | Jeremy Huddleston <jeremyhu@apple.com> | 2010-05-14 14:23:24 -0700 |
commit | f09c5299a381e2729e800a0ac43f1c0e371f65f6 (patch) | |
tree | 15151cf1614f18b888efcca0330b807f9a544221 /src | |
parent | fd82552d5c0ce1931f29006a0c36f5e03cf8577e (diff) | |
download | xorg-lib-libX11-f09c5299a381e2729e800a0ac43f1c0e371f65f6.tar.gz |
xcb: Add TCP fallback
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 <jeremyhu@apple.com>
Reviewed-by: Jamey Sharp <jamey@minilop.net>
Diffstat (limited to 'src')
-rw-r--r-- | src/OpenDis.c | 27 |
1 files changed, 23 insertions, 4 deletions
diff --git a/src/OpenDis.c b/src/OpenDis.c index 46e10268..2983b319 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,10 +164,29 @@ XOpenDisplay ( #if USE_XCB if(!_XConnectXCB(dpy, display, &fullname, &iscreen)) { + /* Try falling back on other transports if no transport specified */ + const char *slash = strrchr(display_name, '/'); + if(slash == NULL) { + const char *protocols[] = {"local", "unix", "tcp", "inet6", "inet", NULL}; + const char **s; + size_t buf_size = strlen(display_name) + 7; // max strlen + 2 (null + /) + char *buf = Xmalloc(buf_size * sizeof(char)); + + if(buf) { + for(s = protocols; buf && *s; s++) { + snprintf(buf, buf_size, "%s/%s", *s, display_name); + if(_XConnectXCB(dpy, buf, &fullname, &iscreen)) + goto fallback_success; + } + Xfree(buf); + } + } + dpy->display_name = fullname; OutOfMemory(dpy, NULL); return NULL; } +fallback_success: #else /* !USE_XCB */ if ((dpy->trans_conn = _X11TransConnectDisplay ( display_name, &fullname, &idisplay, |