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

Steve Dodier-Lazaro sidnioulz at gmail.com
Mon May 5 02:17:14 CEST 2014


Thanks again Alistair for these reports!

I totally agree with you. Forking (rightfully) breaks DBus connections
among other things, and we can't tell who's been putting DBus in which of
the libs we're using -- better safe than sorry. :)


2014-05-04 23:55 GMT+01:00 Alistair Buxton <a.j.buxton at gmail.com>:

> 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:
>
> https://bugs.launchpad.net/ubuntu/+source/xfce4-volumed/+bug/1314782
>
> https://bugs.launchpad.net/ubuntu/+source/xfce4-settings/+bug/1239014
>
> https://bugs.launchpad.net/ubuntu/+source/xfce4-power-manager/+bug/973778
>
> https://bugs.launchpad.net/ubuntu/+source/xfce4-appfinder/+bug/1048805
>
> 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:
> http://lists.freedesktop.org/archives/dbus/2007-April/007496.html
>
> 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.
>
> Thanks,
> --
> Alistair Buxton
> a.j.buxton at gmail.com
> _______________________________________________
> Xfce4-dev mailing list
> Xfce4-dev at xfce.org
> https://mail.xfce.org/mailman/listinfo/xfce4-dev
>



-- 
Steve Dodier-Lazaro
PhD Student in Information Security
University College London
Free Software Developer
OpenPGP : 1B6B1670
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.xfce.org/pipermail/xfce4-dev/attachments/20140505/5af12fd9/attachment.html>


More information about the Xfce4-dev mailing list