clients not using X abstract socket (Linux)?

Xavier Toth txtoth at gmail.com
Wed Sep 10 09:28:59 PDT 2008


I noticed that the socket file /tmp/.X11-unix/X0 is being created on
my Fedora 9 box despite the fact that the X server is creating an
abstract socket which I would have thought was the preferred method of
connecting to the server. I wrote a little test to connect to the
abstract socket but it fails with 'Connection refused'. netstat makes
it look like no clients are connected to the abstract socket. Any idea
what's happening here and why my test can't connect?

[tedx at comms ~]$ netstat -a | grep X0
unix  2      [ ACC ]     STREAM     LISTENING     83490  /tmp/.X11-unix/X0
unix  2      [ ACC ]     STREAM     LISTENING     83489  @/tmp/.X11-unix/X0
unix  3      [ ]         STREAM     CONNECTED     199104 /tmp/.X11-unix/X0
unix  3      [ ]         STREAM     CONNECTED     154799 /tmp/.X11-unix/X0
unix  3      [ ]         STREAM     CONNECTED     116710 /tmp/.X11-unix/X0
unix  3      [ ]         STREAM     CONNECTED     113614 /tmp/.X11-unix/X0
unix  3      [ ]         STREAM     CONNECTED     112608 /tmp/.X11-unix/X0
unix  3      [ ]         STREAM     CONNECTED     88839  /tmp/.X11-unix/X0
unix  3      [ ]         STREAM     CONNECTED     84751  /tmp/.X11-unix/X0
unix  3      [ ]         STREAM     CONNECTED     84746  /tmp/.X11-unix/X0
unix  3      [ ]         STREAM     CONNECTED     84674  /tmp/.X11-unix/X0
unix  3      [ ]         STREAM     CONNECTED     84623  /tmp/.X11-unix/X0
unix  3      [ ]         STREAM     CONNECTED     84556  /tmp/.X11-unix/X0
unix  3      [ ]         STREAM     CONNECTED     84525  /tmp/.X11-unix/X0
unix  3      [ ]         STREAM     CONNECTED     84509  /tmp/.X11-unix/X0
unix  3      [ ]         STREAM     CONNECTED     84395  /tmp/.X11-unix/X0
unix  4      [ ]         STREAM     CONNECTED     84350  /tmp/.X11-unix/X0
unix  5      [ ]         STREAM     CONNECTED     83673  /tmp/.X11-unix/X0

----------------------------------- Test code
--------------------------------------------------------------

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <netinet/in.h>

static int _open_unix(const char *file)
{
    int fd;
    struct sockaddr_un addr = { AF_UNIX };

    memset(&addr, 0, sizeof(addr));
    addr.sun_family = AF_UNIX;

    fd = socket(AF_UNIX, SOCK_STREAM, 0);
    if(fd == -1)
        return -1;

    /* try the abstract socket first */
    strcpy(addr.sun_path + 1, file);
    if(connect(fd, (struct sockaddr *) &addr, sizeof(addr)) != -1) {
        return fd;
    }
    else {
      printf("failed to connect to abstract X socket: %m\n");
    }

    strcpy(addr.sun_path, file);
    printf("socket name %s\n", addr.sun_path);
    if(connect(fd, (struct sockaddr *) &addr, sizeof(addr)) == -1)
        return -1;

    return fd;
}

static int _open(const int display)
{
    int fd;
    static const char base[] = "/tmp/.X11-unix/X";
    char file[sizeof(base) + 20];



    /* display specifies Unix socket */
    snprintf(file, sizeof(file), "%s%d", base, display);
    return  _open_unix(file);


    return fd;
}


int _argc_value;
char **_argv_value;

int main(int argc, char **argv)
{
  _open(0);
}



More information about the xorg mailing list