Can't start X twice

Konstantinos Koukopoulos kouk at noc.uoa.gr
Mon Nov 7 13:17:08 UTC 2005


A bit of debugging info:

ktrace output of X failing to bind to a stale /tmp/.X11-unix/X socket:

 52016 Xorg     CALL  nlstat(0x81caca5,0xbfbfe930)
 52016 Xorg     NAMI  "/tmp/.X11-unix"
 52016 Xorg     RET   nlstat 0
 52016 Xorg     CALL  unlink(0xbfbfeac0)
 52016 Xorg     NAMI  "/tmp/.X11-unix/X0"
 52016 Xorg     RET   unlink -1 errno 2 No such file or directory
 52016 Xorg     CALL  bind(0x4,0xbfbfeabe,0x12)
 52016 Xorg     NAMI  "/tmp/.X11-unix/X"
 52016 Xorg     RET   bind -1 errno 48 Address already in use
 52016 Xorg     CALL  write(0x2,0x820bb40,0xb)
 52016 Xorg     GIO   fd 2 wrote 11 bytes
       "_XSERVTrans"
 52016 Xorg     RET   write 11/0xb
 52016 Xorg     CALL  write(0,0x820bb40,0xb)
 52016 Xorg     GIO   fd 0 wrote 11 bytes
       "_XSERVTrans"
 52016 Xorg     RET   write 11/0xb
 52016 Xorg     CALL  write(0x2,0x820bb40,0x3b)
 52016 Xorg     GIO   fd 2 wrote 59 bytes
       "SocketUNIXCreateListener: ...SocketCreateListener() failed

As you can see first it attempts to unlink a possibly stale socket 
called /tmp/.X11-unix/X0 and then it attempts to bind to /tmp/.X11-unix/X.

Here is the related excerpt from the Xorg source 
(http://cvs.freedesktop.org/xorg/xc/lib/xtrans/Xtranssock.c?rev=1.10&view=markup):

[...]
    sockname.sun_family = AF_UNIX;

    if (port && *port) {
        if (set_sun_path(port, UNIX_PATH, sockname.sun_path) != 0) {
            PRMSG (1, "SocketUNIXCreateListener: path too long\n", 0, 0, 0);
            return TRANS_CREATE_LISTENER_FAILED;
        }
    } else {
        sprintf (sockname.sun_path, "%s%ld", UNIX_PATH, (long)getpid());
    }

#if defined(BSD44SOCKETS) && !defined(Lynx)
    sockname.sun_len = strlen(sockname.sun_path);
    namelen = SUN_LEN(&sockname);
#else
    namelen = strlen(sockname.sun_path) + sizeof(sockname.sun_family);
#endif

    unlink (sockname.sun_path);

    if ((status = TRANS(SocketCreateListener) (ciptr,
        (struct sockaddr *) &sockname, namelen, flags)) < 0)
    {
        PRMSG (1,
    "SocketUNIXCreateListener: ...SocketCreateListener() failed\n",
            0, 0, 0);
        (void) umask (oldUmask);
        return status;
    }
[...]

So the call to unlink happens with the correct path "/tmp/.X11-unix/X0" (as is 
evident by the ktrace data). When the same argument is supplied to 
SocketCreateListener the zero on the end get's lopped off, probably due to a 
miscalculation of namelen. The BDS44SOCKETS conditional looks suspicious so 
my first guess is that BSD44SOCKETS isn't getting defined on gnu/kfreebsd, 
whereas it should. But as I checked out on the Xorg cvsweb the gnu.cf 
configuration file does indeed specify HasBSD44Sockets. Perhaps then 
BSD44SOCKETS should not be defined, or perhaps this is unrelated.

Btw a quick google turned up this message by Robert Millan, back in 2003:
http://lists.gnu.org/archive/html/bug-hurd/2003-05/msg00140.html



More information about the Glibc-bsd-devel mailing list