[PATCH] Wait for hald during initialization when necessary

Peter Hutterer peter.hutterer at who-t.net
Wed Jan 21 04:41:17 PST 2009


On Wed, Jan 21, 2009 at 06:09:48PM +0800, Yan Li wrote:
> hald might not be ready when we need it, wait for it for a few seconds
> 
> Signed-off-by: Yan Li <yan.i.li at intel.com>
> ---
>  config/hal.c |   24 ++++++++++++++++++++----
>  1 files changed, 20 insertions(+), 4 deletions(-)
> 
> diff --git a/config/hal.c b/config/hal.c
> index 8dfbb07..bcc05bc 100644
> --- a/config/hal.c
> +++ b/config/hal.c
> @@ -32,6 +32,7 @@
>  #include <hal/libhal.h>
>  #include <string.h>
>  #include <sys/select.h>
> +#include <unistd.h>
>  
>  #include "input.h"
>  #include "inputstr.h"
> @@ -475,6 +476,10 @@ connect_hook(DBusConnection *connection, void *data)
>      char **devices;
>      int num_devices, i;
>  
> +    /* hald might not finish it's init yet, we'll wait for it for 2s */
> +    unsigned int wait_for_hal = 2 * 1000000;
> +    const unsigned int wait_for_hal_sleep_time = 100 * 1000;
> +
>      info->system_bus = connection;
>  
>      dbus_error_init(&error);
> @@ -490,11 +495,22 @@ connect_hook(DBusConnection *connection, void *data)
>          LogMessage(X_ERROR, "config/hal: couldn't associate HAL context with bus\n");
>          goto out_ctx;
>      }
> -    if (!libhal_ctx_init(info->hal_ctx, &error)) {
> -        LogMessage(X_ERROR, "config/hal: couldn't initialise context: %s (%s)\n",
> -               error.name, error.message);
> -        goto out_ctx;
> +
> +    /* hald might not be ready now, waiting for it for a few seconds */
> +    while (wait_for_hal >= wait_for_hal_sleep_time)
> +    {
> +	    if (libhal_ctx_init(info->hal_ctx, &error))
> +		    goto ctx_init_done;
> +
> +	    LogMessage(X_INFO, "config/hal: waiting for hald...\n");
> +	    usleep (wait_for_hal_sleep_time);
> +	    wait_for_hal -= wait_for_hal_sleep_time;
>      }
> +    LogMessage(X_ERROR, "config/hal: couldn't initialise context: %s (%s)\n",
> +               error.name, error.message);
> +    goto out_ctx;
> +
> +ctx_init_done:
>      if (!libhal_device_property_watch_all(info->hal_ctx, &error)) {
>          LogMessage(X_ERROR, "config/hal: couldn't watch all properties: %s (%s)\n",
>                 error.name, error.message);
> -- 
> 1.5.6.5
 
I think it'd be better to set a timer to fire off the reinitialization rather
than a simple usleep. Doing so allows us to finish the server initialization
without having to wait for hal. Any opinions?

Cheers,
  Peter



More information about the xorg mailing list