[PATCH] Wait for hald during initialization when necessary

Yan Li elliot.li.tech at gmail.com
Wed Jan 21 02:09:48 PST 2009


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


-- 
Li, Yan
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 197 bytes
Desc: Digital signature
URL: <http://lists.x.org/archives/xorg/attachments/20090121/80cd7b36/attachment.pgp>


More information about the xorg mailing list