diff options
author | David Zeuthen <davidz@redhat.com> | 2007-03-03 21:35:55 -0500 |
---|---|---|
committer | David Zeuthen <davidz@redhat.com> | 2007-03-03 21:35:55 -0500 |
commit | e58d6361eb14817c216ce2475ec4503f25d87b8d (patch) | |
tree | 0a2bb152f9c30c920f71b1daa4b40243f73efe2d | |
parent | 61dea57bbe4c47479505e550325214013df8248b (diff) | |
download | hal-e58d6361eb14817c216ce2475ec4503f25d87b8d.tar.gz |
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.
-rw-r--r-- | hald/hald_runner.c | 81 | ||||
-rw-r--r-- | hald/hald_runner.h | 18 | ||||
-rw-r--r-- | hald/mmap_cache.c | 18 |
3 files changed, 92 insertions, 25 deletions
diff --git a/hald/hald_runner.c b/hald/hald_runner.c index 2fe0da5e..fd4514e5 100644 --- a/hald/hald_runner.c +++ b/hald/hald_runner.c @@ -612,18 +612,15 @@ hald_runner_start (HalDevice * device, const gchar * command_line, } 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, void *user_data) g_free (hb); - dbus_pending_call_unref (pending); - goto out; malformed: @@ -678,13 +673,24 @@ call_notify (DBusPendingCall * pending, void *user_data) 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 * device, 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 4dc1267f..c89eeee1 100644 --- a/hald/hald_runner.h +++ b/hald/hald_runner.h @@ -64,11 +64,19 @@ hald_runner_start (HalDevice *device, const gchar *command_line, char **extra_en /* 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 31bf9272..73716618 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!")); } |