PSA: fork() after gtk_init() is unsafe.

Alistair Buxton a.j.buxton at
Mon May 5 00:55:21 CEST 2014

Hi all,

It has recently come to my attention that a lot of the programs in
Xfce that have a daemon mode call gtk_init() before fork()ing. This is
unsafe, and when it goes wrong this will typically manifest as the
daemon hanging shortly after forking, and appearing to simply do
nothing at all.

Some examples of this bug:

I also suspect this might be the cause of all the weird thunar
crashes, but I have no evidence for this currently.

So you're probably going to say "but Al, those are all Xubuntu
specific bugs caused by Ubuntu modifications" - while this is true, we
believe the underlying cause of all of them is the fork() after
gtk_init(). The modded Gtk stuff in Ubuntu merely exposes the problem.

fork() after gtk_init() has always been problematic, and the only
reason it works is by luck - or at least, that is what our research
into the problem has told us. For example:

So if you're maintaining an application in Xfce that forks in order to
become a daemon, please do it as early on as possible. It isn't
necessary to call gtk_init() to parse arguments with glib, so ideally
you would parse for the "no-daemon" argument, possibly fork, then call
gtk_init, then do everything else. This is the order of operations in
the fix I proposed for xfce4-volumed-pulse. Note that the original
xfce4-volumed isn't affected by this bug, but potentially there could
be others I haven't mentioned.

Alistair Buxton
a.j.buxton at

More information about the Xfce4-dev mailing list