[PATCH] Wait for hald during initialization when necessary
Peter Hutterer
peter.hutterer at who-t.net
Wed Jan 21 15:12:26 PST 2009
On Thu, Jan 22, 2009 at 09:48:13AM +1100, Daniel Stone wrote:
> Really, the ideal thing is to listen for the D-Bus signal that tells you
> that hald is running (when it claims a particular name on the bus).
I wrote that code a while ago but then ditched it because it didn't fix the
problem at hand. Anyone is free to pick it up and clean it up.
HAL restarts generate a NameOwnerChanged signal, one with new_owner unset (on
shutdown), and one with old_owner unset (on startup).
Note: this patch doesn't actually do anything but print to the log.
---
config/hal.c | 85 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 85 insertions(+), 0 deletions(-)
diff --git a/config/hal.c b/config/hal.c
index 6573efe..10b91bb 100644
--- a/config/hal.c
+++ b/config/hal.c
@@ -440,6 +440,89 @@ disconnect_hook(void *data)
info->system_bus = NULL;
}
+/**
+ * Handle NewOwnerChanged signals to deal with HAL restarts.
+ *
+ * NewOwnerChanged is send once when HAL shuts down, and once again when it
+ * comes back up. Message has three arguments, first is the name
+ * (org.freedesktop.Hal), the second one is the old owner, third one is new
+ * owner.
+ */
+static DBusHandlerResult
+restart_handler(DBusConnection *connection, DBusMessage *message, void *data)
+{
+ int ret = DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+
+ if (dbus_message_is_signal(message,
+ "org.freedesktop.DBus",
+ "NameOwnerChanged"))
+ {
+ DBusError error;
+ char *name, *old_owner, *new_owner;
+
+ dbus_error_init(&error);
+ dbus_message_get_args(message, &error,
+ DBUS_TYPE_STRING, &name,
+ DBUS_TYPE_STRING, &old_owner,
+ DBUS_TYPE_STRING, &new_owner,
+ DBUS_TYPE_INVALID);
+
+ if (dbus_error_is_set(&error))
+ {
+ ErrorF("[config/hal] failed to get NameOwnerChanged args: %s (%s)\n",
+ error.name, error.message);
+ dbus_error_free(&error);
+ } else if (name && strcmp(name, "org.freedesktop.Hal") == 0)
+ {
+ if (!old_owner || !strlen(old_owner))
+ ErrorF("[config/hal] HAL startup detected.\n");
+ else if (!new_owner || !strlen(new_owner))
+ ErrorF("[config/hal] HAL shutdown detected.\n");
+
+ return DBUS_HANDLER_RESULT_HANDLED;
+ }
+ }
+
+ return ret;
+}
+
+/**
+ * Set stuff up so we get notified on HAL restart.
+ */
+static void
+register_HALrestart(DBusConnection *connection)
+{
+ DBusObjectPathVTable vtable = { .message_function = restart_handler, };
+ DBusError error;
+
+#define MATCH_RULE "sender='org.freedesktop.DBus',interface='org.freedesktop.DBus',type='signal',path='/org/freedesktop/DBus',member='NameOwnerChanged'"
+
+ dbus_error_init(&error);
+ dbus_bus_add_match(connection, MATCH_RULE, &error);
+ if (dbus_error_is_set(&error))
+ {
+ ErrorF("[config/hal] couldn't add match rule: %s (%s)\n", error.name,
+ error.message);
+ ErrorF("[config/hal] we cannot deal with HAL restarts.\n");
+ goto err_match;
+ }
+
+ if (!dbus_connection_register_object_path(connection,
+ "/org/freedesktop/DBus",
+ &vtable,
+ NULL))
+ {
+ ErrorF("[config/hal] can't register object path.\n");
+ goto err_register;
+ }
+
+#undef MATCH_RULE
+
+err_match:
+err_register:
+ dbus_error_free(&error);
+}
+
static void
connect_hook(DBusConnection *connection, void *data)
{
@@ -483,6 +566,8 @@ connect_hook(DBusConnection *connection, void *data)
device_added(info->hal_ctx, devices[i]);
libhal_free_string_array(devices);
+ register_HALrestart(connection);
+
dbus_error_free(&error);
return;
--
1.5.4.3
More information about the xorg
mailing list