[Xcb] closing xcb connection after fork() call

Jamey Sharp jamey at minilop.net
Tue Mar 5 10:02:48 PST 2013


On Tue, Mar 05, 2013 at 08:37:10AM +0100, Rémi Denis-Courmont wrote:
> On Mon, 4 Mar 2013 20:22:19 -0500, Micah Nordland <mpnordland at gmail.com>
> wrote:
> > Should I call xcb_disconnect on the xcb_connection_t after I've
> > forked, or should I get at the file descriptor using
> > xcb_get_file_descriptor() and just close() it? What I'm trying to do
> > is have my application launch another app using the double fork()
> > trick.
> 
> The XCB sockets are created with close-on-exec, so you do not need to
> care. The XCB socket will be automatically closed and the XCB memory
> will be freed through process overlay once you call exec().

I'd forgotten this detail, thanks for the correct answer.

> In my understanding, as XCB uses POSIX threads internally, XCB
> functions cannot be used safely after fork() returns zero.

As a minor detail: XCB does not create any threads. However, none of its
internal state has any guarantees about consistency after fork. So yeah,
calling XCB functions across fork is not recommended.

Jamey
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 198 bytes
Desc: Digital signature
URL: <http://lists.freedesktop.org/archives/xcb/attachments/20130305/e71fdcef/attachment.pgp>


More information about the Xcb mailing list