[Xcb] [PATCH] Open the X11 socket with close-on-exec flag

Rémi Denis-Courmont remi at remlab.net
Sat Feb 13 03:49:10 PST 2010

Le samedi 13 février 2010 12:47:37 Julien Danjou, vous avez écrit :
> Rémi Denis-Courmont <remi at remlab.net> writes:
> > This saves the X11 connection from leaking into children processes.
> > On Linux, this is fully thread-safe using SOCK_CLOEXEC. On other
> > systems, there is a small race condition.
> Seems good to me, except I don't see if it's very useful, since there's
> already close on exec set when the socket go through
> xcb_connect_to_fd().

On Linux, that's not thread-safe. SOCK_CLOEXEC sets the flag atomically while 
allocating the descriptor from the process file table.
On other platforms, this patch merely shrinks the window of opportunity for 
the race, which cannot be fully fixed.

You have a point that the later close-on-exec setting becomes useless if 
called through xcb_connect() though.

Rémi Denis-Courmont

More information about the Xcb mailing list