- char *xhost = NULL;
- int xdpy_current;
- int xdpy_candidate;
-
- /*
- * What all of this mess does is:
- * 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
- * day for xkbcommon-x11] so we use xkbcomp for now).
- * 4. Download the keymap back from the display using xkbcommon-x11.
- * 5. Compare received keymap to the uploaded keymap.
- * 6. Kill the server & clean up.
- */
-
- 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--) {
- 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;
- }
- }
- free(xhost);
- if (ret != 0) {
- ret = SKIP_TEST;
- goto err_ctx;
- }
-
- /* Wait for Xvfb fully waking up to accept a connection from a client. */
- sleep(1);
-