[PATCH] Daemonize consolekit only after it is registered on D-Bus
Scott James Remnant
scott at canonical.com
Thu Oct 2 04:38:06 PDT 2008
On Thu, 2008-10-02 at 00:30 -0400, Ray Strode wrote:
> On Wed, Oct 1, 2008 at 6:46 PM, Olivier Blin <blino at mandriva.com> wrote:
> > This patch moves the daemonize call only after consolekit is properly
> > registered on D-Bus, to avoid race conditions.
> ...
> > - if (! no_daemon && daemon (0, 0)) {
> > - g_error ("Could not daemonize: %s", g_strerror (errno));
> > - }
> > -
> > setup_debug_log (debug);
> >
> > connection = get_system_bus ();
> > @@ -331,6 +327,10 @@ main (int argc,
> > g_timeout_add (1000 * 30, (GSourceFunc) timed_exit_cb, loop);
> > }
> >
> > + if (! no_daemon && daemon (0, 0)) {
> > + g_error ("Could not daemonize: %s", g_strerror (errno));
> > + }
> > +
>
> As a general rule, it's not normally a good idea to call daemon()
> (which forks) late in startup. I don't know if the above patch would
> cause any specific problems in this case, but a better approach would
> be to create a pipe, fork immediately and have the parent wait on the
> pipe for the child to say "okay exit now". Then have the child write
> to/close the pipe when it's ready to go.
>
Really? Why?
It's been almost standard UNIX practice for decades now to fork() as one
of the very last operations you do - after any sockets, etc. are set up.
There are various reasons to do this, but most specifically, it means
that the process that spawned you can use your exit as a sign you're
ready - and any errors can be passed to that process by stderr and exit
code.
Scott
--
Scott James Remnant
scott at canonical.com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
Url : http://lists.freedesktop.org/archives/hal/attachments/20081002/6e06a6f4/attachment.pgp
More information about the hal
mailing list