rpms/xorg-x11-server/devel xserver-1.5.99.902-listen-for-hal.patch, NONE, 1.1 xorg-x11-server.spec, 1.399, 1.400

Peter Hutterer whot at fedoraproject.org
Tue Feb 10 04:14:58 UTC 2009


Author: whot

Update of /cvs/pkgs/rpms/xorg-x11-server/devel
In directory cvs1.fedora.phx.redhat.com:/tmp/cvs-serv23219

Modified Files:
	xorg-x11-server.spec 
Added Files:
	xserver-1.5.99.902-listen-for-hal.patch 
Log Message:
* Tue Feb 10 2009 Peter Hutterer <peter.hutterer at redhat.com> 1.5.99.902-6
- xserver-1.5.99.902-listen-for-hal.patch: listen for HAL startup
  notifications if it isn't running already.



xserver-1.5.99.902-listen-for-hal.patch:

--- NEW FILE xserver-1.5.99.902-listen-for-hal.patch ---
>From 9bd9e83179e863c8bd25da423d6c69f57c3317ba Mon Sep 17 00:00:00 2001
From: Peter Hutterer <peter.hutterer at who-t.net>
Date: Wed, 4 Feb 2009 11:50:18 +1000
Subject: [PATCH] config: if we can't connect to HAL, listen for a startup notification.

If HAL isn't available when we try to connect, the registered NameOwnerChanged
signal handler waits until HAL is available. Once we connected to HAL, we
unregister the signal handler again.
This allows HAL to be started in parallel or after the server has started.

Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
---
 config/hal.c |  111 ++++++++++++++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 105 insertions(+), 6 deletions(-)

diff --git a/config/hal.c b/config/hal.c
index 8dfbb07..36fa839 100644
--- a/config/hal.c
+++ b/config/hal.c
@@ -467,11 +467,10 @@ disconnect_hook(void *data)
     info->system_bus = NULL;
 }
 
-static void
-connect_hook(DBusConnection *connection, void *data)
+static BOOL
+connect_and_register(DBusConnection *connection, struct config_hal_info *info)
 {
     DBusError error;
-    struct config_hal_info *info = data;
     char **devices;
     int num_devices, i;
 
@@ -479,8 +478,10 @@ connect_hook(DBusConnection *connection, void *data)
 
     dbus_error_init(&error);
 
-    if (!info->hal_ctx)
-        info->hal_ctx = libhal_ctx_new();
+    if (info->hal_ctx)
+        return TRUE; /* already registered, pretend we did something */
+
+    info->hal_ctx = libhal_ctx_new();
     if (!info->hal_ctx) {
         LogMessage(X_ERROR, "config/hal: couldn't create HAL context\n");
         goto out_err;
@@ -512,7 +513,7 @@ connect_hook(DBusConnection *connection, void *data)
 
     dbus_error_free(&error);
 
-    return;
+    return TRUE;
 
 out_ctx2:
     if (!libhal_ctx_shutdown(info->hal_ctx, &error))
@@ -526,6 +527,104 @@ out_err:
     info->hal_ctx = NULL;
     info->system_bus = NULL;
 
+    return FALSE;
+}
+
+
+/**
+ * Handle NewOwnerChanged signals to deal with HAL startup at X server runtime.
+ *
+ * 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
+ownerchanged_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);
+        } else if (name && strcmp(name, "org.freedesktop.Hal") == 0) {
+
+            if (!old_owner || !strlen(old_owner)) {
+                DebugF("[config/hal] HAL startup detected.\n");
+                if (connect_and_register(connection, (struct config_hal_info*)data))
+                    dbus_connection_unregister_object_path(connection,
+                                                     "/org/freedesktop/DBus");
+                else
+                    ErrorF("[config/hal] Failed to connect to HAL bus.\n");
+            }
+
+            ret = DBUS_HANDLER_RESULT_HANDLED;
+        }
+        dbus_error_free(&error);
+    }
+
+    return ret;
+}
+
+/**
+ * Register a handler for the NameOwnerChanged signal.
+ */
+static BOOL
+listen_for_startup(DBusConnection *connection, void *data)
+{
+    DBusObjectPathVTable vtable = { .message_function = ownerchanged_handler, };
+    DBusError error;
+    const char MATCH_RULE[] = "sender='org.freedesktop.DBus',"
+                              "interface='org.freedesktop.DBus',"
+                              "type='signal',"
+                              "path='/org/freedesktop/DBus',"
+                              "member='NameOwnerChanged'";
+    int rc = FALSE;
+
+    dbus_error_init(&error);
+    dbus_bus_add_match(connection, MATCH_RULE, &error);
+    if (!dbus_error_is_set(&error)) {
+        if (dbus_connection_register_object_path(connection,
+                                                  "/org/freedesktop/DBus",
+                                                  &vtable,
+                                                  data))
+            rc = TRUE;
+        else
+            ErrorF("[config/hal] cannot register object path.\n");
+    } else {
+        ErrorF("[config/hal] couldn't add match rule: %s (%s)\n", error.name,
+                error.message);
+        ErrorF("[config/hal] cannot detect a HAL startup.\n");
+    }
+
+    dbus_error_free(&error);
+
+    return rc;
+}
+
+static void
+connect_hook(DBusConnection *connection, void *data)
+{
+    struct config_hal_info *info = data;
+
+    if (listen_for_startup(connection, data) &&
+        connect_and_register(connection, info))
+        dbus_connection_unregister_object_path(connection,
+                                               "/org/freedesktop/DBus");
+
     return;
 }
 
-- 
1.6.0.6



Index: xorg-x11-server.spec
===================================================================
RCS file: /cvs/pkgs/rpms/xorg-x11-server/devel/xorg-x11-server.spec,v
retrieving revision 1.399
retrieving revision 1.400
diff -u -r1.399 -r1.400
--- xorg-x11-server.spec	9 Feb 2009 00:44:59 -0000	1.399
+++ xorg-x11-server.spec	10 Feb 2009 04:14:28 -0000	1.400
@@ -19,7 +19,7 @@
 Summary:   X.Org X11 X server
 Name:      xorg-x11-server
 Version:   1.5.99.902
-Release:   5%{?dist}
+Release:   6%{?dist}
 URL:       http://www.x.org
 License:   MIT
 Group:     User Interface/X
@@ -82,6 +82,9 @@
 # nominated for 1.6 (FDO #19574)
 Patch6011: xserver-1.5.99.902-mediakeys-crash.patch
 
+# ensure HAL can start after X, upstream soon, not 1.6 yet.
+Patch6012: xserver-1.5.99.902-listen-for-hal.patch
+
 %define moduledir	%{_libdir}/xorg/modules
 %define drimoduledir	%{_libdir}/dri
 %define sdkdir		%{_includedir}/xorg
@@ -498,6 +501,10 @@
 
 
 %changelog
+* Tue Feb 10 2009 Peter Hutterer <peter.hutterer at redhat.com> 1.5.99.902-6
+- xserver-1.5.99.902-listen-for-hal.patch: listen for HAL startup
+  notifications if it isn't running already.
+
 * Mon Feb 09 2009 Peter Hutterer <peter.hutterer at redhat.com> 1.5.99.902-5
 - xserver-1.5.99.902-mediakeys-crash.patch: don't crash when multimedia keys
   are pressed (#483435)




More information about the fedora-extras-commits mailing list