[PATCH] Daemonize consolekit only after it is registered on D-Bus

Ray Strode halfline at gmail.com
Wed Oct 1 21:30:22 PDT 2008


Hi,

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.

--Ray


More information about the hal mailing list