hal: Branch 'master'

David Zeuthen david at kemper.freedesktop.org
Sat Mar 3 18:36:49 PST 2007


 hald/hald_runner.c |   81 +++++++++++++++++++++++++++++++++++++++++++++++------
 hald/hald_runner.h |   18 ++++++++---
 hald/mmap_cache.c  |   18 ++++-------
 3 files changed, 92 insertions(+), 25 deletions(-)

New commits:
diff-tree e58d6361eb14817c216ce2475ec4503f25d87b8d (from 61dea57bbe4c47479505e550325214013df8248b)
Author: David Zeuthen <davidz at redhat.com>
Date:   Sat Mar 3 21:35:55 2007 -0500

    generate the fdi cache synchronously
    
    This should avoid some "interesting" race conditions and reentrancy
    issues since iterating the mainloop might pop out new hotplug events.

diff --git a/hald/hald_runner.c b/hald/hald_runner.c
index 2fe0da5..fd4514e 100644
--- a/hald/hald_runner.c
+++ b/hald/hald_runner.c
@@ -612,18 +612,15 @@ hald_runner_start (HalDevice * device, c
 }
 
 static void
-call_notify (DBusPendingCall * pending, void *user_data)
+process_reply (DBusMessage *m, HelperData *hb)
 {
-	HelperData *hb = (HelperData *) user_data;
 	dbus_uint32_t exitt = HALD_RUN_SUCCESS;
 	dbus_int32_t return_code = 0;
-	DBusMessage *m;
 	GArray *error = NULL;
 	DBusMessageIter iter;
 
 	error = g_array_new (TRUE, FALSE, sizeof (char *));
 
-	m = dbus_pending_call_steal_reply (pending);
 	if (dbus_message_get_type (m) != DBUS_MESSAGE_TYPE_METHOD_RETURN)
 		goto malformed;
 
@@ -658,8 +655,6 @@ call_notify (DBusPendingCall * pending, 
 
 	g_free (hb);
 
-	dbus_pending_call_unref (pending);
-
 	goto out;
 
       malformed:
@@ -678,13 +673,24 @@ call_notify (DBusPendingCall * pending, 
 
 	g_free (hb);
 
-	dbus_pending_call_unref (pending);
-
       out:
 	if (method_run_notify)
 		method_run_notify (method_run_notify_userdata);
 }
 
+
+static void
+call_notify (DBusPendingCall * pending, void *user_data)
+{
+	HelperData *hb = (HelperData *) user_data;
+	DBusMessage *m;
+
+	m = dbus_pending_call_steal_reply (pending);
+	process_reply (m, hb);
+	dbus_pending_call_unref (pending);
+
+}
+
 /* Run a helper program using the commandline, with input as infomation on
  * stdin */
 void
@@ -732,7 +738,7 @@ hald_runner_run_method (HalDevice * devi
 	dbus_pending_call_set_notify (call, call_notify, hd, NULL);
 	dbus_message_unref (msg);
 	return;
-      error:
+error:
 	dbus_message_unref (msg);
 	g_free (hd);
 	cb (device, HALD_RUN_FAILED, 0, NULL, data1, data2);
@@ -748,6 +754,63 @@ hald_runner_run (HalDevice * device,
 				"", FALSE, timeout, cb, data1, data2);
 }
 
+void
+hald_runner_run_sync (HalDevice * device,
+		      const gchar * command_line, char **extra_env,
+		      guint timeout,
+		      HalRunTerminatedCB cb, gpointer data1, gpointer data2)
+{
+	DBusMessage *msg;
+	DBusMessage *reply;
+	DBusMessageIter iter;
+	HelperData *hd = NULL;
+	const char *input = "";
+	gboolean error_on_stderr = FALSE;
+	DBusError error;
+
+	msg = dbus_message_new_method_call ("org.freedesktop.HalRunner",
+					    "/org/freedesktop/HalRunner",
+					    "org.freedesktop.HalRunner",
+					    "Run");
+	if (msg == NULL)
+		DIE (("No memory"));
+	dbus_message_iter_init_append (msg, &iter);
+
+	if (!add_first_part (&iter, device, command_line, extra_env))
+		goto error;
+
+	dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &input);
+	dbus_message_iter_append_basic (&iter, DBUS_TYPE_BOOLEAN, &error_on_stderr);
+	dbus_message_iter_append_basic (&iter, DBUS_TYPE_UINT32, &timeout);
+
+	dbus_error_init (&error);
+	reply = dbus_connection_send_with_reply_and_block (runner_connection, msg, INT_MAX, &error);
+	if (reply == NULL) {
+		if (dbus_error_is_set (&error)) {
+			HAL_ERROR (("Error running '%s': %s: %s", command_line, error.name, error.message));
+		}
+		goto error;
+	}
+
+	hd = g_new0 (HelperData, 1);
+	hd->d = device;
+	hd->cb = cb;
+	hd->data1 = data1;
+	hd->data2 = data2;
+
+	/* this will free the HelperData and unref the reply (it's
+	 * used also by the async version) 
+	 */
+	process_reply (reply, hd);
+
+	dbus_message_unref (msg);
+	return;
+
+error:
+	dbus_message_unref (msg);
+	g_free (hd);
+	cb (device, HALD_RUN_FAILED, 0, NULL, data1, data2);
+}
 
 
 void
diff --git a/hald/hald_runner.h b/hald/hald_runner.h
index 4dc1267..c89eeee 100644
--- a/hald/hald_runner.h
+++ b/hald/hald_runner.h
@@ -64,11 +64,19 @@ hald_runner_start (HalDevice *device, co
 /* Run a helper program using the commandline, with input as infomation on
  * stdin */
 void
-hald_runner_run(HalDevice *device,
-               const gchar *command_line, char **extra_env, 
-               guint32 timeout,
-               HalRunTerminatedCB cb,
-               gpointer data1, gpointer data2);
+hald_runner_run (HalDevice *device,
+		 const gchar *command_line, char **extra_env, 
+		 guint32 timeout,
+		 HalRunTerminatedCB cb,
+		 gpointer data1, gpointer data2);
+
+void
+hald_runner_run_sync (HalDevice *device,
+		      const gchar *command_line, char **extra_env, 
+		      guint32 timeout,
+		      HalRunTerminatedCB cb,
+		      gpointer data1, gpointer data2);
+
 void
 hald_runner_run_method(HalDevice *device,                                                              
 		       const gchar *command_line, char **extra_env, 
diff --git a/hald/mmap_cache.c b/hald/mmap_cache.c
index 31bf927..7371661 100644
--- a/hald/mmap_cache.c
+++ b/hald/mmap_cache.c
@@ -171,22 +171,18 @@ regen_cache (void)
 
 	regen_cache_done = FALSE;
 
-	hald_runner_run (NULL, 
-			 "hald-generate-fdi-cache --force",
-			 extra_env,
-			 10000,
-			 regen_cache_cb,
-			 NULL,
-			 NULL);
+	hald_runner_run_sync (NULL, 
+			      "hald-generate-fdi-cache --force",
+			      extra_env,
+			      10000,
+			      regen_cache_cb,
+			      NULL,
+			      NULL);
 
 	for (n = 0; extra_env[n] != NULL; n++) {
 		g_free (extra_env[n]);
 	}
 
-	while (!regen_cache_done) {
-		g_main_context_iteration (NULL, TRUE);
-	}
-
 	if (!regen_cache_success) {
 		DIE (("fdi cache regeneration failed!"));
 	}


More information about the hal-commit mailing list