We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 3049

Summary: SDL_Init(SDL_INIT_VIDEO) - XDM authorization key matches an existing client!
Product: SDL Reporter: malferit
Component: videoAssignee: Ryan C. Gordon <icculus>
Status: RESOLVED FIXED QA Contact: Sam Lantinga <slouken>
Severity: normal    
Priority: P2    
Version: 2.0.4   
Hardware: x86   
OS: Linux   

Description malferit 2015-07-05 22:08:20 UTC
Hello, I began a little program with SDL2 on Linux in C, and when I call SDL_Init(SDL_INIT_VIDEO) I get an error and this is printed in the console:

XDM authorization key matches an existing client!

I searched through Internet, and found that some people suggest to run 'xhost +' or to specify this in /etc/X11/xdm/xdm-config:

DisplayManager*authName:        MIT-MAGIC-COOKIE-1

I don't think an end user needs to know that...

But what bothered me is that first I started this little program in Pascal using the Freepascal compiler and it works. In freepascal you only use some thin header bindings in Pascal and then it links with the dynamic SDL library, so I don't understood why it worked with Freepascal and not in C.

I run ldd to the two generated applications:

Application in C:

	linux-gate.so.1 (0xffffe000)
	libSDL2-2.0.so.0 => /usr/lib/libSDL2-2.0.so.0 (0xb76ac000)
	libpthread.so.0 => /lib/libpthread.so.0 (0xb766e000)
	libc.so.6 => /lib/libc.so.6 (0xb74e2000)
	libm.so.6 => /lib/libm.so.6 (0xb74a0000)
	libdl.so.2 => /lib/libdl.so.2 (0xb749a000)
	librt.so.1 => /lib/librt.so.1 (0xb7491000)
	/lib/ld-linux.so.2 (0xb77b3000)

Application compiled with Freepascal:

	linux-gate.so.1 (0xffffe000)
	libSDL2-2.0.so.0 => /usr/lib/libSDL2-2.0.so.0 (0xb762a000)
	libX11.so.6 => /usr/lib/libX11.so.6 (0xb74f3000)
	libc.so.6 => /lib/libc.so.6 (0xb7367000)
	libm.so.6 => /lib/libm.so.6 (0xb7325000)
	libdl.so.2 => /lib/libdl.so.2 (0xb731f000)
	libpthread.so.0 => /lib/libpthread.so.0 (0xb7305000)
	librt.so.1 => /lib/librt.so.1 (0xb72fc000)
	libxcb.so.1 => /usr/lib/libxcb.so.1 (0xb72dc000)
	libXau.so.6 => /usr/lib/libXau.so.6 (0xb72d9000)
	libXdmcp.so.6 => /usr/lib/libXdmcp.so.6 (0xb72d3000)
	/lib/ld-linux.so.2 (0xb7755000)

It seems that Freepascal is linking with libX11, libxcb, libXau and libXdmcp .

Linking my C application with libxcb solved the problem (linking with libXau and/or libXdmcp without libxcb didn't work). Linking with X11 links all the other libraries and works as well.

So I fill this bug report mainly to let you know about this. I don't know if it is a problem that can be solved on the libSDL side or not, but at least I hope it will help.

Thank you very much.
Comment 1 Ryan C. Gordon 2015-07-09 05:26:40 UTC
I can't believe I have to request this about a Linux problem, but...does rebooting help? Everything I've read about this error says it's confused system state that gets wiped out by a reboot (killing the X server isn't enough, apparently).

--ryan.
Comment 2 malferit 2015-07-09 17:41:48 UTC
Hello Ryan.

No, rebooting makes no difference. Compiling without linking X11 always gives the same error. Linking with X11 always works.

Maybe the problem is related to me using the plain XDM for login instead of KDM or GDM that probably most Linux users are using today.

I don't understand why linking with X11 works. If you want me to do some tests, even compiling a special version of the SDL library or something, let me know.

I am going to test this disabling XDM (using startx at console) or using that MIT_MAGIC_COOKIE-1 and I'll let you know...
Comment 3 malferit 2015-07-09 18:09:25 UTC
Hi, some tests:

1. Disabled XDM. Login in console and running 'startx'. The program works without having to link with X11.

2. Enabled XDM. Added 'DisplayManager*authName: MIT-MAGIC-COOKIE-1' to /etc/X11/xdm/xdm-config.The program works without having to link with X11.

3. Enabled XDM without 'DisplayManager*authName: MIT-MAGIC-COOKIE-1' in /etc/X11/xdm/xdm-config . I get the authentication error unless I link with X11.
Comment 4 malferit 2016-08-04 09:35:14 UTC
Hi, I come back to this again :)

This time I tested with 2.0.4 .

I saw that you already had a workaround in the file SDL_x11video.c :

#if defined(__osf__) && defined(SDL_VIDEO_DRIVER_X11_DYNAMIC)
    /* On Tru64 if linking without -lX11, it fails and you get following message.
     * Xlib: connection to ":0.0" refused by server
     * Xlib: XDM authorization key matches an existing client!
     *
     * It succeeds if retrying 1 second later
     * or if running xhost +localhost on shell.
     */
    if (data->display == NULL) {
        SDL_Delay(1000);
        data->display = X11_XOpenDisplay(display);
    }
#endif

I recompiled SDL changing the first line to:

#if defined(SDL_VIDEO_DRIVER_X11_DYNAMIC)

to enable that workaround for me. With that, it worked ok. The message 'XDM authorization key matches an existing client!' is still printed on the console, but after one second the program launches.

It seems that this happens if you use the XDM. Perhaps this workaround can be enabled not only for __osf__ ?

Thank you very much.
Comment 5 Sam Lantinga 2017-08-12 23:49:22 UTC
This workaround is enabled for all platforms:
https://hg.libsdl.org/SDL/rev/1017272c981f

I still don't know why linking with X11 matters... ?