Unable to get Virtual Frame Buffer / Display (Xvfb) Information with xdpyinfo

Solution 1:

The obscure error message is because the client (xdpyinfo) doesn't have the correct authorization data.

As @TomSchober identified in the question, xvfb-run creates an authorization file with a path of the form /tmp/xvfb-run.XXXXXX/Xauthority and configures Xvfb to use that file. The clients need to use that file (rather than the default, which is ~/.Xauthority). This can be done by setting the XAUTHORITY environment variable:

DISPLAY=:99 XAUTHORITY=/tmp/xvfb-run.XXXXXX/Xauthority xdpyinfo

Here XXXXXX should be replaced to match the actual path. The path can be discovered by printing the arguments of the Xvfb process using pgrep -ax Xvfb and inspecting the value of the -auth option. Alternatively, xvfb-run has an option --auth-file that can be used to set the location of the Xauthority file (a warning will be printed if the file doesn't exist; you can ignore the warning, or create an empty file at that location beforehand).


An interesting observation that @TomSchober made in the question is that if you manually invoke the Xvfb command used by xvfb-run (that is, with the -auth option), it may be possible for clients to connect even if XAUTHORITY is not set. This is because xvfb-run adds an authorization entry to the Xauthority file before it runs Xvfb. If this entry is not added, and the file is empty/missing, Xvfb will allow clients to connect without requiring authorization (!). Xvfb only requires authorization if there is at least one entry in the Xauthority file. An authorization entry can be added manually using the following command:

XAUTHORITY=/path/to/Xauthority xauth source - <<EOF
add :99 . $(mcookie)
EOF