Correct way to handle fork/exec errors with DBusServer

Avery Pennarun apenwarr at gmail.com
Thu Jan 8 09:58:55 PST 2009


On Thu, Jan 8, 2009 at 11:44 AM, John Palmieri <johnp at redhat.com> wrote:
> An issue with fork that we run into is that if you exit your child before exec'ing the DBusServer socket is cleaned up
> and the socket file is unlinked on the disk (assuming you are not using abstract sockets).  On exec the socket is
> closed and DBusServer does not run the cleanup code path which is the correct behaviour.
>
> The biggest issue here is if exec fails (such as the executable not being found or permission denied) the child exits
> and takes down the socket with it.  We fixed this using _exit() instead of exit().  Is this correct or is there a better
> way of handling this?

As Havoc mentioned, it's a little weird that this would matter if you
don't have anything registered with atexit().

I've written lots of programs in C++, however, where global
destructors are run automatically at exit(), and this can cause all
sorts of problems when you use fork().

Anyway, the correct solution is indeed to just run _exit() in all but
one of the family of processes, and exit() only when the very last one
dies.

Have fun,

Avery


More information about the dbus mailing list