34a0d8f
From a4e9b92e2449b4c8f8654a0eaf0f1ca6627da1fc Mon Sep 17 00:00:00 2001
34a0d8f
From: Peter Hutterer <peter.hutterer@redhat.com>
34a0d8f
Date: Mon, 20 Oct 2008 12:19:55 +1030
34a0d8f
Subject: [PATCH] config: don't add duplicate devices through HAL.
34a0d8f
34a0d8f
If HAL is restarted, the device list is send to the server again, leading
34a0d8f
first to duplicate devices (and thus duplicate events), and later to a
34a0d8f
FatalError "Too many input devices."
34a0d8f
34a0d8f
dev->config_info contains the UDI for the device. If the UDI of a new devices
34a0d8f
is equal to one we already have in the device list, just ignore it.
34a0d8f
---
34a0d8f
 config/hal.c |   27 +++++++++++++++++++++++++++
34a0d8f
 1 files changed, 27 insertions(+), 0 deletions(-)
34a0d8f
34a0d8f
diff --git a/config/hal.c b/config/hal.c
34a0d8f
index 0e0505b..639e0ec 100644
34a0d8f
--- a/config/hal.c
34a0d8f
+++ b/config/hal.c
34a0d8f
@@ -166,6 +166,26 @@ get_prop_string_array(LibHalContext *hal_ctx, const char *udi, const char *prop)
34a0d8f
     return ret;
34a0d8f
 }
34a0d8f
 
34a0d8f
+static BOOL
34a0d8f
+device_is_duplicate(char *config_info)
34a0d8f
+{
34a0d8f
+    DeviceIntPtr dev;
34a0d8f
+
34a0d8f
+    for (dev = inputInfo.devices; dev; dev = dev->next)
34a0d8f
+    {
34a0d8f
+        if (dev->config_info && (strcmp(dev->config_info, config_info) == 0))
34a0d8f
+            return TRUE;
34a0d8f
+    }
34a0d8f
+
34a0d8f
+    for (dev = inputInfo.off_devices; dev; dev = dev->next)
34a0d8f
+    {
34a0d8f
+        if (dev->config_info && (strcmp(dev->config_info, config_info) == 0))
34a0d8f
+            return TRUE;
34a0d8f
+    }
34a0d8f
+
34a0d8f
+    return FALSE;
34a0d8f
+}
34a0d8f
+
34a0d8f
 static void
34a0d8f
 device_added(LibHalContext *hal_ctx, const char *udi)
34a0d8f
 {
34a0d8f
@@ -227,6 +247,13 @@ device_added(LibHalContext *hal_ctx, const char *udi)
34a0d8f
     }
34a0d8f
     sprintf(config_info, "hal:%s", udi);
34a0d8f
 
34a0d8f
+    /* Check for duplicate devices */
34a0d8f
+    if (device_is_duplicate(config_info))
34a0d8f
+    {
34a0d8f
+        LogMessage(X_WARNING, "config/hal: device %s already added. Ignoring.\n", name);
34a0d8f
+        goto unwind;
34a0d8f
+    }
34a0d8f
+
34a0d8f
     /* ok, grab options from hal.. iterate through all properties
34a0d8f
     * and lets see if any of them are options that we can add */
34a0d8f
     set = libhal_device_get_all_properties(hal_ctx, udi, &error);
34a0d8f
-- 
34a0d8f
1.6.0.1
34a0d8f