diff options
author | Kazunobu Kuriyama <kazunobu.kuriyama@nifty.com> | 2015-08-24 13:44:20 +0900 |
---|---|---|
committer | Kazunobu Kuriyama <kazunobu.kuriyama@nifty.com> | 2015-08-28 19:37:09 +0900 |
commit | 91a19905b381bf3d17f4c4f81cf72d4eae853a85 (patch) | |
tree | ff192ba10f30a94cdf96b20d1751969d266e4ed3 /test | |
parent | 74f85d05402411c4f18bd431c919fa631a37a90d (diff) | |
download | xorg-lib-libxkbcommon-91a19905b381bf3d17f4c4f81cf72d4eae853a85.tar.gz |
test/x11comp: Fix contention between X11 and Xvfb on Mac OS X
- Abandon use of -displayfd.
- Have x11comp itself look for an unused X11 display number instead.
Diffstat (limited to 'test')
-rw-r--r-- | test/x11comp.c | 56 |
1 files changed, 31 insertions, 25 deletions
diff --git a/test/x11comp.c b/test/x11comp.c index 71928a6..bf5bbe7 100644 --- a/test/x11comp.c +++ b/test/x11comp.c @@ -39,23 +39,24 @@ main(void) struct xkb_keymap *keymap; xcb_connection_t *conn; int32_t device_id; - int pipefds[2]; int ret, status; - char displayfd[128], display[128]; + char display[512]; char *xkb_path; char *original, *dump; char *envp[] = { NULL }; - char *xvfb_argv[] = { "Xvfb", "-displayfd", displayfd, NULL }; + char *xvfb_argv[] = { "Xvfb", display, NULL }; pid_t xvfb_pid; char *xkbcomp_argv[] = { "xkbcomp", "-I", NULL /* xkb_path */, display, NULL }; pid_t xkbcomp_pid; + char *xhost; + int xdpy_current; + int xdpy_candidate; + /* * What all of this mess does is: - * 1. Launch Xvfb on the next available DISPLAY. Xvfb reports the - * display number to an fd passed with -displayfd once it's - * initialized. We pass a pipe there to read it. + * 1. Launch Xvfb on available DISPLAY. * 2. Make an xcb connection to this display. * 3. Launch xkbcomp to change the keymap of the new display (doing * this programmatically is major work [which we may yet do some @@ -65,30 +66,35 @@ main(void) * 6. Kill the server & clean up. */ - ret = pipe(pipefds); - assert(ret == 0); - - ret = snprintf(displayfd, sizeof(displayfd), "%d", pipefds[1]); - assert(ret >= 0 && ret < sizeof(displayfd)); - - ret = posix_spawnp(&xvfb_pid, "Xvfb", NULL, NULL, xvfb_argv, envp); + ret = xcb_parse_display(NULL, &xhost, &xdpy_current, NULL); + assert(ret != 0); + /* + * IANA assigns TCP port numbers from 6000 through 6063 to X11 + * clients. In addition, the current XCB implementaion shows + * that, when an X11 client tries to establish a TCP connetion, + * the port number needed is specified by adding 6000 to a given + * display number. So, one of reasonable ranges of xdpy_candidate + * is [0, 63]. + */ + for (xdpy_candidate = 63; xdpy_candidate >= 0; xdpy_candidate--) { + char *buf; + + if (xdpy_candidate == xdpy_current) { + continue; + } + snprintf(display, sizeof(display), "%s:%d", xhost, xdpy_candidate); + ret = posix_spawnp(&xvfb_pid, "Xvfb", NULL, NULL, xvfb_argv, envp); + if (ret == 0) { + break; + } + } if (ret != 0) { ret = SKIP_TEST; goto err_ctx; } - close(pipefds[1]); - - display[0] = ':'; - ret = read(pipefds[0], display + 1, sizeof(display) - 1); - if (ret <= 0 || 1 + ret >= sizeof(display) - 1) { - ret = SKIP_TEST; - goto err_xvfd; - } - if (display[ret] == '\n') - display[ret] = '\0'; - display[1 + ret] = '\0'; - close(pipefds[0]); + /* Wait for Xvfb fully waking up to accept a connection from a client. */ + sleep(1); conn = xcb_connect(display, NULL); if (xcb_connection_has_error(conn)) { |