after "rm -R /tmp/.X11-unix", nothing special happens?

4.6k views Asked by At

I'm learning something about X11. And I was wondering what would happen if I'd deleted the directory "/tmp/.X11-unix". I tried it but actually, nothing special happened. Every GUI app runs unaffected. Why ?

I thought X client communicated with X server through unix domain socket, and the socket pathname is "/tmp/.X11-unix/X0".

My os is Ubuntu 14.04.

Any help will be appreciated.

2

There are 2 answers

2
Thomas Dickey On

The X server creates the directory and opens the socket in that directory. Clients do not open the socket directly but use the connect function (which does reference the path of the socket device). The socket continues to exist as long as the X server process has it open. The clue is in this wording from the connect manual page:

The connect() system call connects the socket referred to by the file descriptor sockfd to the address specified by addr. The addrlen argument specifies the size of addr. The format of the address in addr is determined by the address space of the socket sockfd; see socket(2) for further details.

That is, the address given in the connect call is not necessarily a filesystem path that applications can test by other means but is simply something known to the kernel when applications ask to open the socket.

0
Meixner On

Just because an entry in the file system is deleted does not mean the file descriptor stops working.

When a GUI application is started it connects to /tmp/.X11-unix/X0 and gets a file descriptor. From now on it is using the file descriptor, /tmp/.X11-unix/X0 is no longer needed by this application and, therefore, if you delete it, nothing happens to running applications.

However, trying to start new applications would not work any longer.

Linux has an extension that allows using names that are not bound to the file system: abstract names, see unix(7) for a description. Since these do not use the file system it does not matter at all if the file system entry has been deleted.

It looks like X supports both types of sockets. So clients can choose which one they want to use. So after removing the socket from the file system new clients that use the abstract name can still be started whereas new clients that use the socket in the file system will fail to start. However, old clients will continue to run in both cases.