bluetooth: Add device to hash before registration
authorGustavo Padovan <gustavo.padovan@collabora.co.uk>
Thu, 9 Aug 2012 21:57:25 +0000 (18:57 -0300)
committerPatrik Flykt <patrik.flykt@linux.intel.com>
Fri, 10 Aug 2012 14:10:10 +0000 (17:10 +0300)
During the connman_device_register() procedure a lookup to the
bluetooth_devices hash table happens, however the device is not on the
hash at this point and the look out fails.

If the registration fails, technology_disable() returns the Failed
message on D-Bus with the error status zero. That happens because we
don't have any device registered.

This patch moves the insertion of the device to before the device
registration.

plugins/bluetooth.c

index b06460a..2ab29a6 100644 (file)
@@ -660,6 +660,8 @@ static void adapter_properties_reply(DBusPendingCall *call, void *user_data)
        if (device != NULL)
                goto update;
 
+       g_hash_table_insert(bluetooth_devices, g_strdup(path), device);
+
        ether_aton_r(address, &addr);
 
        snprintf(ident, 13, "%02x%02x%02x%02x%02x%02x",
@@ -680,11 +682,10 @@ static void adapter_properties_reply(DBusPendingCall *call, void *user_data)
 
        if (connman_device_register(device) < 0) {
                connman_device_unref(device);
+               g_hash_table_remove(bluetooth_devices, path);
                goto done;
        }
 
-       g_hash_table_insert(bluetooth_devices, g_strdup(path), device);
-
 update:
        connman_device_set_string(device, "Address", address);
        connman_device_set_string(device, "Name", name);