A question about XOpenDisplay fail

Jamey Sharp jamey at minilop.net
Thu Apr 29 13:03:48 PDT 2010


On Tue, Apr 27, 2010 at 11:50 PM, Ma, Qingyu (GE Healthcare)
<Qingyu.Ma at ge.com> wrote:
> I'm developing a system, which uses fvwm as WM. Two fvwm are executed to
> implement two separated screens. My process is displayed on one
> screen(DISPLAY). It calls XOpenDisplay(NULL) to get one Display connection
> to be used as display image, and another Display to be used as toggle
> keyboard led (whenever keyboard led state is changed, a new Display is
> opened and closed). The function is OK. But when I was doing monkey and
> cycle test, there is a very very little possibility that my process may
> crash. I looked through my code, and found a bug which was that I didn't
> check the return value of XOpenDisplay, and use it directly . I have checked
> that a NULL Display will cause process crash in following code. It's just my
> analysis and guess, I'm not sure whether it does be the root cause. And, by
> now, the cycle and monkey cannot re-occur the issue.
>
> So, I want to get some information from you to help to reach the root cause.
> What will cause XOpenDisplay return NULL? How can I simulate the case?(When
> my process is executed, I'm sure the XWindow and fvwm have been booted up.)

The general answer is that XOpenDisplay returns NULL when it fails to
connect to the X server. One reason for that could be that it couldn't
allocate memory. The generally more common reason is that connecting
the socket failed.

You can test that you're handling NULL correctly by unsetting the
DISPLAY environment variable, or by passing an empty string to
XOpenDisplay.

Since you're seeing a rare transient failure, and assuming you're
using a version of libX11 built with XCB support, I'd guess you're
hitting this bug:

https://bugs.freedesktop.org/show_bug.cgi?id=5960

It doesn't sound like you actually need more than one connection in
your application. I'd recommend using the same Display for everything.
If you really need separate connections, you may be better off opening
both early in your program, and not closing them until exit.

Hope that helps,
Jamey



More information about the xorg mailing list