diff options
author | Rob Taylor <robtaylor@sultana.(none)> | 2008-03-06 13:49:21 +0000 |
---|---|---|
committer | Rob Taylor <rob.taylor@codethink.co.uk> | 2008-03-12 20:11:09 +0100 |
commit | 84bd77044698784c976d5a1c06c13f75ec900c17 (patch) | |
tree | 6ee23c0e94c5ccf7da3bd33d2b4bc799ffc359ae | |
parent | set 'linux.sysfs_path' as an indexed property (diff) | |
download | gentoo-hal-84bd77044698784c976d5a1c06c13f75ec900c17.tar.gz gentoo-hal-84bd77044698784c976d5a1c06c13f75ec900c17.tar.bz2 gentoo-hal-84bd77044698784c976d5a1c06c13f75ec900c17.zip |
compute udis that are unique in the gdl and tdl
Introduces hald_compute_udi which computes a udi thats unique in both the
tdl and gdl and uses it everywhere relvent. This is necessary when we're
processing events in parallel as otherwise its possible to get a race condition
with two devices added with the same name. As part of this patch,
hal_util_compute_udi grwos a varargs version and no longer makes the computer
udi unique. I've also added a hal_util_make_udi_unique for use in those places
where hal_util_compute_udi was only used to check a udi was unique when
inserting into the gdl.
-rw-r--r-- | hald/freebsd/hf-util.c | 2 | ||||
-rw-r--r-- | hald/hald.c | 29 | ||||
-rw-r--r-- | hald/hald.h | 2 | ||||
-rw-r--r-- | hald/hald_dbus.c | 2 | ||||
-rw-r--r-- | hald/linux/acpi.c | 6 | ||||
-rw-r--r-- | hald/linux/apm.c | 16 | ||||
-rw-r--r-- | hald/linux/blockdev.c | 48 | ||||
-rw-r--r-- | hald/linux/device.c | 354 | ||||
-rw-r--r-- | hald/linux/pmu.c | 16 | ||||
-rw-r--r-- | hald/solaris/devinfo.c | 8 | ||||
-rw-r--r-- | hald/solaris/devinfo_storage.c | 48 | ||||
-rw-r--r-- | hald/solaris/devinfo_usb.c | 16 | ||||
-rw-r--r-- | hald/util.c | 49 | ||||
-rw-r--r-- | hald/util.h | 4 |
14 files changed, 326 insertions, 274 deletions
diff --git a/hald/freebsd/hf-util.c b/hald/freebsd/hf-util.c index 8d6b07f3..fe9c9eed 100644 --- a/hald/freebsd/hf-util.c +++ b/hald/freebsd/hf-util.c @@ -292,7 +292,7 @@ hf_device_set_full_udi (HalDevice *device, const char *format, ...) requested_udi = g_strdup_vprintf(format, args); va_end(args); - hal_util_compute_udi(pending_gdl, actual_udi, sizeof(actual_udi), "%s", requested_udi); + hal_util_make_udi_unique (pending_gdl, actual_udi, sizeof(actual_udi), requested_udi); hf_pending_gdl_free(pending_gdl); g_free(requested_udi); diff --git a/hald/hald.c b/hald/hald.c index 8a160d51..a28d22e1 100644 --- a/hald/hald.c +++ b/hald/hald.c @@ -254,6 +254,35 @@ hald_get_tdl (void) return temporary_device_list; } +void +hald_compute_udi (gchar *dst, gsize dstsize, const gchar *format, ...) +{ + int i; + char buf[256]; + va_list args; + + va_start (args, format); + hal_util_compute_udi_valist (hald_get_gdl (), dst, dstsize, format, args); + va_end (args); + + if (hal_device_store_find (hald_get_gdl (), dst) == NULL && + hal_device_store_find (hald_get_tdl (), dst) == NULL) + goto out; + + for (i = 0; ; i++) { + g_snprintf (buf, sizeof(buf), "%s_%d", dst, i); + if (hal_device_store_find (hald_get_gdl (), buf) == NULL && + hal_device_store_find (hald_get_tdl (), buf) == NULL) { + g_strlcpy (dst, buf, dstsize); + goto out; + } + } + +out: + ; + +} + /** * usage: * diff --git a/hald/hald.h b/hald/hald.h index 1b60e034..7c55e628 100644 --- a/hald/hald.h +++ b/hald/hald.h @@ -47,6 +47,8 @@ extern PolKitContext *pk_context; HalDeviceStore *hald_get_gdl (void); HalDeviceStore *hald_get_tdl (void); +void hald_compute_udi (gchar *dst, gsize dstsize, const gchar *format, ...); + void property_atomic_update_begin (); void property_atomic_update_end (); diff --git a/hald/hald_dbus.c b/hald/hald_dbus.c index c56fe9e1..28195e1c 100644 --- a/hald/hald_dbus.c +++ b/hald/hald_dbus.c @@ -3854,7 +3854,7 @@ manager_commit_to_gdl (DBusConnection * connection, DBusMessage * message, dbus_ } /* sanity check & avoid races */ - hal_util_compute_udi (hald_get_gdl (), udi, sizeof udi, "%s", udi0); + hal_util_make_udi_unique (hald_get_gdl (), udi, sizeof udi, udi0); if (hal_device_store_find (hald_get_gdl (), udi)) { /* loose it */ diff --git a/hald/linux/acpi.c b/hald/linux/acpi.c index af5145cb..1c8a3e73 100644 --- a/hald/linux/acpi.c +++ b/hald/linux/acpi.c @@ -1006,9 +1006,9 @@ static gboolean acpi_generic_compute_udi (HalDevice *d, ACPIDevHandler *handler) { gchar udi[256]; - hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi), - "/org/freedesktop/Hal/devices/acpi_%s", - hal_util_get_last_element (hal_device_property_get_string (d, "linux.acpi_path"))); + hald_compute_udi (udi, sizeof (udi), + "/org/freedesktop/Hal/devices/acpi_%s", + hal_util_get_last_element (hal_device_property_get_string (d, "linux.acpi_path"))); hal_device_set_udi (d, udi); hal_device_property_set_string (d, "info.udi", udi); return TRUE; diff --git a/hald/linux/apm.c b/hald/linux/apm.c index 7b49fb25..06efe46f 100644 --- a/hald/linux/apm.c +++ b/hald/linux/apm.c @@ -348,16 +348,16 @@ apm_generic_compute_udi (HalDevice *d, APMDevHandler *handler) gchar udi[256]; if (handler->apm_type == APM_TYPE_BATTERY ) { - hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi), - "/org/freedesktop/Hal/devices/apm_battery"); - + hald_compute_udi (udi, sizeof (udi), + "/org/freedesktop/Hal/devices/apm_battery"); + } else if (handler->apm_type == APM_TYPE_AC_ADAPTER ) { - hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi), - "/org/freedesktop/Hal/devices/apm_ac_adapter"); + hald_compute_udi (udi, sizeof (udi), + "/org/freedesktop/Hal/devices/apm_ac_adapter"); } else { - hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi), - "/org/freedesktop/Hal/devices/apm_%d", - hal_device_property_get_int (d, "info.category")); + hald_compute_udi (udi, sizeof (udi), + "/org/freedesktop/Hal/devices/apm_%d", + hal_device_property_get_int (d, "info.category")); } hal_device_set_udi (d, udi); diff --git a/hald/linux/blockdev.c b/hald/linux/blockdev.c index decacff5..ffdda665 100644 --- a/hald/linux/blockdev.c +++ b/hald/linux/blockdev.c @@ -77,23 +77,23 @@ blockdev_compute_udi (HalDevice *d) uuid = hal_device_property_get_string (d, "volume.uuid"); if (uuid != NULL && strlen (uuid) > 0) { - hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi), - "/org/freedesktop/Hal/devices/volume_uuid_%s", uuid); + hald_compute_udi (udi, sizeof (udi), + "/org/freedesktop/Hal/devices/volume_uuid_%s", uuid); } else if (volumelabel != NULL && strlen (volumelabel) > 0) { - hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi), - "/org/freedesktop/Hal/devices/volume_label_%s", volumelabel); + hald_compute_udi (udi, sizeof (udi), + "/org/freedesktop/Hal/devices/volume_label_%s", volumelabel); } else if (hal_device_property_get_bool(d, "volume.is_disc") && hal_device_property_get_bool(d, "volume.disc.is_blank")) { /* this should be a empty CD/DVD */ - hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi), - "/org/freedesktop/Hal/devices/volume_empty_%s", - hal_device_property_get_string (d, "volume.disc.type")); + hald_compute_udi (udi, sizeof (udi), + "/org/freedesktop/Hal/devices/volume_empty_%s", + hal_device_property_get_string (d, "volume.disc.type")); } else { /* fallback to partition number, size */ - hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi), - "/org/freedesktop/Hal/devices/volume_part%d_size_%lld", - hal_device_property_get_int (d, "volume.partition.number"), - hal_device_property_get_uint64 (d, "volume.size")); + hald_compute_udi (udi, sizeof (udi), + "/org/freedesktop/Hal/devices/volume_part%d_size_%lld", + hal_device_property_get_int (d, "volume.partition.number"), + hal_device_property_get_uint64 (d, "volume.size")); } g_free(volumelabel); } else { @@ -108,22 +108,22 @@ blockdev_compute_udi (HalDevice *d) type = hal_device_property_get_string (d, "storage.drive_type"); if (serial != NULL) { - hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi), - "/org/freedesktop/Hal/devices/storage_serial_%s", - serial); + hald_compute_udi (udi, sizeof (udi), + "/org/freedesktop/Hal/devices/storage_serial_%s", + serial); } else if ((model != NULL) && (strlen(model) != 0) ) { - hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi), - "/org/freedesktop/Hal/devices/storage_model_%s", - model); + hald_compute_udi (udi, sizeof (udi), + "/org/freedesktop/Hal/devices/storage_model_%s", + model); } else if ((bus != NULL) && (type != NULL)){ - hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi), - "%s_storage_%s_%s", - hal_device_property_get_string (d, "storage.originating_device"), - bus, type); + hald_compute_udi (udi, sizeof (udi), + "%s_storage_%s_%s", + hal_device_property_get_string (d, "storage.originating_device"), + bus, type); } else { - hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi), - "%s_storage", - hal_device_property_get_string (d, "storage.originating_device")); + hald_compute_udi (udi, sizeof (udi), + "%s_storage", + hal_device_property_get_string (d, "storage.originating_device")); } } diff --git a/hald/linux/device.c b/hald/linux/device.c index 654d5e65..dde7c431 100644 --- a/hald/linux/device.c +++ b/hald/linux/device.c @@ -390,9 +390,9 @@ input_compute_udi (HalDevice *d) { gchar udi[256]; - hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi), - "%s_logicaldev_input", - hal_device_property_get_string (d, "info.parent")); + hald_compute_udi (udi, sizeof (udi), + "%s_logicaldev_input", + hal_device_property_get_string (d, "info.parent")); hal_device_set_udi (d, udi); hal_device_property_set_string (d, "info.udi", udi); @@ -470,18 +470,18 @@ bluetooth_compute_udi (HalDevice *d) gchar udi[256]; if (hal_device_has_capability (d, "bluetooth_acl")) { - hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi), - "/org/freedesktop/Hal/devices/bluetooth_acl_%0llx", - hal_device_property_get_uint64 (d, "bluetooth_acl.address")); + hald_compute_udi (udi, sizeof (udi), + "/org/freedesktop/Hal/devices/bluetooth_acl_%0llx", + hal_device_property_get_uint64 (d, "bluetooth_acl.address")); } else if (hal_device_has_capability (d, "bluetooth_sco")) { - hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi), - "/org/freedesktop/Hal/devices/bluetooth_acl_%0llx", - hal_device_property_get_uint64 (d, "bluetooth_acl.address")); + hald_compute_udi (udi, sizeof (udi), + "/org/freedesktop/Hal/devices/bluetooth_acl_%0llx", + hal_device_property_get_uint64 (d, "bluetooth_acl.address")); } else { - hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi), - "%s_bluetooth_hci_%0llx", - hal_device_property_get_string (d, "info.parent"), - hal_device_property_get_uint64 (d, "bluetooth_hci.address")); + hald_compute_udi (udi, sizeof (udi), + "%s_bluetooth_hci_%0llx", + hal_device_property_get_string (d, "info.parent"), + hal_device_property_get_uint64 (d, "bluetooth_hci.address")); } hal_device_set_udi (d, udi); hal_device_property_set_string (d, "info.udi", udi); @@ -650,9 +650,9 @@ net_compute_udi (HalDevice *d) /* Need to fall back to something else if mac not available. */ id = hal_util_get_last_element(hal_device_property_get_string(d, "net.originating_device")); } - hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi), - "/org/freedesktop/Hal/devices/net_%s", - id); + hald_compute_udi (udi, sizeof (udi), + "/org/freedesktop/Hal/devices/net_%s", + id); hal_device_set_udi (d, udi); hal_device_property_set_string (d, "info.udi", udi); return TRUE; @@ -687,9 +687,9 @@ scsi_generic_compute_udi (HalDevice *d) { gchar udi[256]; - hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi), - "%s_scsi_generic", - hal_device_property_get_string (d, "info.parent")); + hald_compute_udi (udi, sizeof (udi), + "%s_scsi_generic", + hal_device_property_get_string (d, "info.parent")); hal_device_set_udi (d, udi); hal_device_property_set_string (d, "info.udi", udi); return TRUE; @@ -811,9 +811,9 @@ scsi_host_compute_udi (HalDevice *d) { gchar udi[256]; - hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi), - "%s_scsi_host", - hal_device_property_get_string (d, "info.parent")); + hald_compute_udi (udi, sizeof (udi), + "%s_scsi_host", + hal_device_property_get_string (d, "info.parent")); hal_device_set_udi (d, udi); hal_device_property_set_string (d, "info.udi", udi); return TRUE; @@ -883,19 +883,19 @@ usbclass_compute_udi (HalDevice *d) gchar udi[256]; if (hal_device_has_capability (d, "hiddev")) { - hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi), - "%s_hiddev", - hal_device_property_get_string (d, "info.parent")); + hald_compute_udi (udi, sizeof (udi), + "%s_hiddev", + hal_device_property_get_string (d, "info.parent")); hal_device_set_udi (d, udi); hal_device_property_set_string (d, "info.udi", udi); } else if (hal_device_has_capability (d, "printer")) { const char *serial; serial = hal_device_property_get_string (d, "printer.serial"); - hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi), - "%s_printer_%s", - hal_device_property_get_string (d, "info.parent"), - serial != NULL ? serial : "noserial"); + hald_compute_udi (udi, sizeof (udi), + "%s_printer_%s", + hal_device_property_get_string (d, "info.parent"), + serial != NULL ? serial : "noserial"); hal_device_set_udi (d, udi); hal_device_property_set_string (d, "info.udi", udi); } @@ -932,8 +932,8 @@ usbraw_compute_udi (HalDevice *d) { gchar udi[256]; - hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi), "%s_usbraw", - hal_device_property_get_string (d, "info.parent")); + hald_compute_udi (udi, sizeof (udi), "%s_usbraw", + hal_device_property_get_string (d, "info.parent")); hal_device_set_udi (d, udi); hal_device_property_set_string (d, "info.udi", udi); @@ -983,8 +983,8 @@ video4linux_compute_udi (HalDevice *d) { gchar udi[256]; - hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi), "%s_video4linux", - hal_device_property_get_string (d, "info.parent")); + hald_compute_udi (udi, sizeof (udi), "%s_video4linux", + hal_device_property_get_string (d, "info.parent")); hal_device_set_udi (d, udi); hal_device_property_set_string (d, "info.udi", udi); @@ -1021,8 +1021,8 @@ dvb_compute_udi (HalDevice *d) { gchar udi[256]; - hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi), "%s_dvb", - hal_device_property_get_string (d, "info.parent")); + hald_compute_udi (udi, sizeof (udi), "%s_dvb", + hal_device_property_get_string (d, "info.parent")); hal_device_set_udi (d, udi); hal_device_property_set_string (d, "info.udi", udi); @@ -1312,41 +1312,41 @@ sound_compute_udi (HalDevice *d) if (hal_device_has_property(d, "sound.card")) { /* don't include card number as it may not be persistent across reboots */ - hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi), - "%s_sound_card_%i", - hal_device_property_get_string (d, "info.parent"), - hal_device_property_get_string (d, "sound.card")); + hald_compute_udi (udi, sizeof (udi), + "%s_sound_card_%i", + hal_device_property_get_string (d, "info.parent"), + hal_device_property_get_string (d, "sound.card")); } else if (hal_device_has_property(d, "alsa.card")) { /* don't include card number as it may not be persistent across reboots */ - hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi), - "%s_alsa_%s_%i", - hal_device_property_get_string (d, "info.parent"), - hal_device_property_get_string (d, "alsa.type"), - hal_device_property_get_int (d, "alsa.device")); + hald_compute_udi (udi, sizeof (udi), + "%s_alsa_%s_%i", + hal_device_property_get_string (d, "info.parent"), + hal_device_property_get_string (d, "alsa.type"), + hal_device_property_get_int (d, "alsa.device")); } else if (hal_device_has_property(d, "oss.card")) { /* don't include card number as it may not be persistent across reboots */ - hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi), - "%s_oss_%s_%i", - hal_device_property_get_string (d, "info.parent"), - hal_device_property_get_string (d, "oss.type"), - hal_device_property_get_int (d, "oss.device")); + hald_compute_udi (udi, sizeof (udi), + "%s_oss_%s_%i", + hal_device_property_get_string (d, "info.parent"), + hal_device_property_get_string (d, "oss.type"), + hal_device_property_get_int (d, "oss.device")); } else if (hal_device_has_property(d, "alsa.type")) { /* handle global ALSA devices */ - hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi), - "%s_alsa_%s", - hal_device_property_get_string (d, "info.parent"), - hal_device_property_get_string (d, "alsa.type")); + hald_compute_udi (udi, sizeof (udi), + "%s_alsa_%s", + hal_device_property_get_string (d, "info.parent"), + hal_device_property_get_string (d, "alsa.type")); } else if (hal_device_has_property(d, "oss.type")) { /* handle global OSS devices */ - hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi), - "%s_oss_%s", - hal_device_property_get_string (d, "info.parent"), - hal_device_property_get_string (d, "oss.type")); + hald_compute_udi (udi, sizeof (udi), + "%s_oss_%s", + hal_device_property_get_string (d, "info.parent"), + hal_device_property_get_string (d, "oss.type")); } else { /* fallback */ - hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi), "%s_sound_unknown", - hal_device_property_get_string (d, "info.parent")); - } + hald_compute_udi (udi, sizeof (udi), "%s_sound_unknown", + hal_device_property_get_string (d, "info.parent")); + } hal_device_set_udi (d, udi); hal_device_property_set_string (d, "info.udi", udi); @@ -1437,11 +1437,11 @@ serial_compute_udi (HalDevice *d) { gchar udi[256]; - hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi), - "%s_serial_%s_%d", - hal_device_property_get_string (d, "info.parent"), - hal_device_property_get_string (d, "serial.type"), - hal_device_property_get_int (d, "serial.port")); + hald_compute_udi (udi, sizeof (udi), + "%s_serial_%s_%d", + hal_device_property_get_string (d, "info.parent"), + hal_device_property_get_string (d, "serial.type"), + hal_device_property_get_int (d, "serial.port")); hal_device_set_udi (d, udi); hal_device_property_set_string (d, "info.udi", udi); @@ -1489,9 +1489,9 @@ tape_compute_udi (HalDevice *d) (d, "linux.sysfs_path")); if (!sysfs_name) return FALSE; - hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi), - "/org/freedesktop/Hal/devices/tape_%s", - sysfs_name); + hald_compute_udi (udi, sizeof (udi), + "/org/freedesktop/Hal/devices/tape_%s", + sysfs_name); hal_device_set_udi (d, udi); hal_device_property_set_string (d, "info.udi", udi); @@ -1536,9 +1536,9 @@ mmc_host_compute_udi (HalDevice *d) { gchar udi[256]; - hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi), - "%s_mmc_host", - hal_device_property_get_string (d, "info.parent")); + hald_compute_udi (udi, sizeof (udi), + "%s_mmc_host", + hal_device_property_get_string (d, "info.parent")); hal_device_set_udi (d, udi); hal_device_property_set_string (d, "info.udi", udi); return TRUE; @@ -1627,10 +1627,10 @@ pci_compute_udi (HalDevice *d) { gchar udi[256]; - hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi), - "/org/freedesktop/Hal/devices/pci_%x_%x", - hal_device_property_get_int (d, "pci.vendor_id"), - hal_device_property_get_int (d, "pci.product_id")); + hald_compute_udi (udi, sizeof (udi), + "/org/freedesktop/Hal/devices/pci_%x_%x", + hal_device_property_get_int (d, "pci.vendor_id"), + hal_device_property_get_int (d, "pci.product_id")); hal_device_set_udi (d, udi); hal_device_property_set_string (d, "info.udi", udi); @@ -1838,20 +1838,20 @@ usb_compute_udi (HalDevice *d) gchar udi[256]; if (hal_device_has_property (d, "usb.interface.number")) { - hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi), - "%s_if%d", - hal_device_property_get_string (d, "info.parent"), - hal_device_property_get_int (d, "usb.interface.number")); + hald_compute_udi (udi, sizeof (udi), + "%s_if%d", + hal_device_property_get_string (d, "info.parent"), + hal_device_property_get_int (d, "usb.interface.number")); hal_device_set_udi (d, udi); hal_device_property_set_string (d, "info.udi", udi); } else { - hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi), - "/org/freedesktop/Hal/devices/usb_device_%x_%x_%s", - hal_device_property_get_int (d, "usb_device.vendor_id"), - hal_device_property_get_int (d, "usb_device.product_id"), - hal_device_has_property (d, "usb_device.serial") ? - hal_device_property_get_string (d, "usb_device.serial") : - "noserial"); + hald_compute_udi (udi, sizeof (udi), + "/org/freedesktop/Hal/devices/usb_device_%x_%x_%s", + hal_device_property_get_int (d, "usb_device.vendor_id"), + hal_device_property_get_int (d, "usb_device.product_id"), + hal_device_has_property (d, "usb_device.serial") ? + hal_device_property_get_string (d, "usb_device.serial") : + "noserial"); hal_device_set_udi (d, udi); hal_device_property_set_string (d, "info.udi", udi); } @@ -1899,11 +1899,11 @@ ide_compute_udi (HalDevice *d) { gchar udi[256]; - hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi), - "%s_ide_%d_%d", - hal_device_property_get_string (d, "info.parent"), - hal_device_property_get_int (d, "ide.host"), - hal_device_property_get_int (d, "ide.channel")); + hald_compute_udi (udi, sizeof (udi), + "%s_ide_%d_%d", + hal_device_property_get_string (d, "info.parent"), + hal_device_property_get_int (d, "ide.host"), + hal_device_property_get_int (d, "ide.channel")); hal_device_set_udi (d, udi); hal_device_property_set_string (d, "info.udi", udi); @@ -1993,9 +1993,9 @@ pnp_compute_udi (HalDevice *d) { gchar udi[256]; - hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi), - "/org/freedesktop/Hal/devices/pnp_%s", - hal_device_property_get_string (d, "pnp.id")); + hald_compute_udi (udi, sizeof (udi), + "/org/freedesktop/Hal/devices/pnp_%s", + hal_device_property_get_string (d, "pnp.id")); hal_device_set_udi (d, udi); hal_device_property_set_string (d, "info.udi", udi); @@ -2045,9 +2045,9 @@ platform_compute_udi (HalDevice *d) { gchar udi[256]; - hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi), - "/org/freedesktop/Hal/devices/platform_%s", - hal_device_property_get_string (d, "platform.id")); + hald_compute_udi (udi, sizeof (udi), + "/org/freedesktop/Hal/devices/platform_%s", + hal_device_property_get_string (d, "platform.id")); hal_device_set_udi (d, udi); hal_device_property_set_string (d, "info.udi", udi); @@ -2105,10 +2105,10 @@ serio_compute_udi (HalDevice *d) { gchar udi[256]; - hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi), - "%s_%s", - hal_device_property_get_string (d, "info.parent"), - hal_device_property_get_string (d, "serio.description")); + hald_compute_udi (udi, sizeof (udi), + "%s_%s", + hal_device_property_get_string (d, "info.parent"), + hal_device_property_get_string (d, "serio.description")); hal_device_set_udi (d, udi); hal_device_property_set_string (d, "info.udi", udi); return TRUE; @@ -2183,10 +2183,10 @@ pcmcia_compute_udi (HalDevice *d) { gchar udi[256]; - hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi), - "/org/freedesktop/Hal/devices/pcmcia_%d_%d", - hal_device_property_get_int (d, "pcmcia.manfid1"), - hal_device_property_get_int (d, "pcmcia.manfid2")); + hald_compute_udi (udi, sizeof (udi), + "/org/freedesktop/Hal/devices/pcmcia_%d_%d", + hal_device_property_get_int (d, "pcmcia.manfid1"), + hal_device_property_get_int (d, "pcmcia.manfid2")); hal_device_set_udi (d, udi); hal_device_property_set_string (d, "info.udi", udi); return TRUE; @@ -2275,10 +2275,10 @@ scsi_compute_udi (HalDevice *d) { gchar udi[256]; - hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi), - "%s_scsi_device_lun%d", - hal_device_property_get_string (d, "info.parent"), - hal_device_property_get_int (d, "scsi.lun")); + hald_compute_udi (udi, sizeof (udi), + "%s_scsi_device_lun%d", + hal_device_property_get_string (d, "info.parent"), + hal_device_property_get_int (d, "scsi.lun")); hal_device_set_udi (d, udi); hal_device_property_set_string (d, "info.udi", udi); return TRUE; @@ -2369,10 +2369,10 @@ mmc_compute_udi (HalDevice *d) { gchar udi[256]; - hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi), - "%s_mmc_card_rca%d", - hal_device_property_get_string (d, "info.parent"), - hal_device_property_get_int (d, "mmc.rca")); + hald_compute_udi (udi, sizeof (udi), + "%s_mmc_card_rca%d", + hal_device_property_get_string (d, "info.parent"), + hal_device_property_get_int (d, "mmc.rca")); hal_device_set_udi (d, udi); hal_device_property_set_string (d, "info.udi", udi); return TRUE; @@ -2426,10 +2426,10 @@ sdio_compute_udi (HalDevice *d) { gchar udi[256]; - hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi), - "%s_sdio%d", - hal_device_property_get_string (d, "info.parent"), - hal_device_property_get_int (d, "sdio.card_id")); + hald_compute_udi (udi, sizeof (udi), + "%s_sdio%d", + hal_device_property_get_string (d, "info.parent"), + hal_device_property_get_int (d, "sdio.card_id")); hal_device_set_udi (d, udi); hal_device_property_set_string (d, "info.udi", udi); return TRUE; @@ -2488,9 +2488,9 @@ xen_compute_udi (HalDevice *d) { gchar udi[256]; - hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi), - "/org/freedesktop/Hal/devices/xen_%s", - hal_device_property_get_string (d, "xen.bus_id")); + hald_compute_udi (udi, sizeof (udi), + "/org/freedesktop/Hal/devices/xen_%s", + hal_device_property_get_string (d, "xen.bus_id")); hal_device_set_udi (d, udi); hal_device_property_set_string (d, "info.udi", udi); return TRUE; @@ -2569,9 +2569,9 @@ ieee1394_compute_udi (HalDevice *d) { gchar udi[256]; - hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi), - "/org/freedesktop/Hal/devices/ieee1394_guid_%0llx", - hal_device_property_get_uint64 (d, "ieee1394.guid")); + hald_compute_udi (udi, sizeof (udi), + "/org/freedesktop/Hal/devices/ieee1394_guid_%0llx", + hal_device_property_get_uint64 (d, "ieee1394.guid")); hal_device_set_udi (d, udi); hal_device_property_set_string (d, "info.udi", udi); return TRUE; @@ -2709,14 +2709,14 @@ firewire_compute_udi (HalDevice *d) gchar udi[256]; if (hal_device_has_capability (d, "ieee1394")) { - hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi), - "/org/freedesktop/Hal/devices/ieee1394_guid%0llx", - hal_device_property_get_uint64 (d, "ieee1394.guid")); + hald_compute_udi (udi, sizeof (udi), + "/org/freedesktop/Hal/devices/ieee1394_guid%0llx", + hal_device_property_get_uint64 (d, "ieee1394.guid")); } else { - hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi), - "%s_unit%d", - hal_device_property_get_string (d, "ieee1394_unit.originating_device"), - hal_device_property_get_int (d, "ieee1394_unit.unit_index")); + hald_compute_udi (udi, sizeof (udi), + "%s_unit%d", + hal_device_property_get_string (d, "ieee1394_unit.originating_device"), + hal_device_property_get_int (d, "ieee1394_unit.unit_index")); } hal_device_set_udi (d, udi); @@ -2870,10 +2870,10 @@ ccw_compute_udi (HalDevice *d) { gchar udi[256]; - hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi), - "/org/freedesktop/Hal/devices/ccw_%s", - hal_device_property_get_string - (d, "ccw.bus_id")); + hald_compute_udi (udi, sizeof (udi), + "/org/freedesktop/Hal/devices/ccw_%s", + hal_device_property_get_string + (d, "ccw.bus_id")); hal_device_set_udi (d, udi); hal_device_property_set_string (d, "info.udi", udi); return TRUE; @@ -3012,10 +3012,10 @@ ccwgroup_compute_udi (HalDevice *d) { gchar udi[256]; - hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi), - "/org/freedesktop/Hal/devices/ccwgroup_%s", - hal_device_property_get_string - (d, "ccwgroup.bus_id")); + hald_compute_udi (udi, sizeof (udi), + "/org/freedesktop/Hal/devices/ccwgroup_%s", + hal_device_property_get_string + (d, "ccwgroup.bus_id")); hal_device_set_udi (d, udi); hal_device_property_set_string (d, "info.udi", udi); return TRUE; @@ -3068,10 +3068,10 @@ iucv_compute_udi (HalDevice *d) { gchar udi[256]; - hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi), - "/org/freedesktop/Hal/devices/iucv_%s", - hal_device_property_get_string - (d, "iucv.bus_id")); + hald_compute_udi (udi, sizeof (udi), + "/org/freedesktop/Hal/devices/iucv_%s", + hal_device_property_get_string + (d, "iucv.bus_id")); hal_device_set_udi (d, udi); hal_device_property_set_string (d, "info.udi", udi); return TRUE; @@ -3110,9 +3110,9 @@ backlight_compute_udi (HalDevice *d) dir = hal_device_property_get_string (d, "linux.sysfs_path"); name = hal_util_get_last_element(dir); - hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi), - "%s_backlight", - hal_device_property_get_string (d, "info.parent")); + hald_compute_udi (udi, sizeof (udi), + "%s_backlight", + hal_device_property_get_string (d, "info.parent")); hal_device_set_udi (d, udi); hal_device_property_set_string (d, "info.udi", udi); return TRUE; @@ -3494,17 +3494,17 @@ power_supply_compute_udi (HalDevice *d) name = hal_util_get_last_element(dir); if (name) - hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi), - "%s_power_supply_%s_%s", - hal_device_property_get_string (d, "info.parent"), - hal_device_property_get_string (d, "info.category"), - name); + hald_compute_udi (udi, sizeof (udi), + "%s_power_supply_%s_%s", + hal_device_property_get_string (d, "info.parent"), + hal_device_property_get_string (d, "info.category"), + name); else - hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi), - "%s_power_supply_%s", - hal_device_property_get_string (d, "info.parent"), - hal_device_property_get_string (d, "info.category")); - + hald_compute_udi (udi, sizeof (udi), + "%s_power_supply_%s", + hal_device_property_get_string (d, "info.parent"), + hal_device_property_get_string (d, "info.category")); + hal_device_set_udi (d, udi); hal_device_property_set_string (d, "info.udi", udi); return TRUE; @@ -3553,11 +3553,11 @@ drm_compute_udi (HalDevice *d) name = hal_util_get_last_element(dir); /* generate e.g.: /org/freedesktop/Hal/devices/pci_8086_2a02_drm_i915_card0 */ - hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi), - "%s_drm_%s_%s", - hal_device_property_get_string (d, "info.parent"), - hal_device_property_get_string (d, "drm.dri_library"), - name); + hald_compute_udi (udi, sizeof (udi), + "%s_drm_%s_%s", + hal_device_property_get_string (d, "info.parent"), + hal_device_property_get_string (d, "drm.dri_library"), + name); hal_device_set_udi (d, udi); hal_device_property_set_string (d, "info.udi", udi); @@ -3601,9 +3601,9 @@ ps3_system_bus_compute_udi (HalDevice *d) { gchar udi[256]; - hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi), - "/org/freedesktop/Hal/devices/ps3_system_bus_%s", - hal_device_property_get_string (d, "ps3_system_bus.id")); + hald_compute_udi (udi, sizeof (udi), + "/org/freedesktop/Hal/devices/ps3_system_bus_%s", + hal_device_property_get_string (d, "ps3_system_bus.id")); hal_device_set_udi (d, udi); hal_device_property_set_string (d, "info.udi", udi); @@ -3646,9 +3646,9 @@ virtio_compute_udi (HalDevice *d) { gchar udi[256]; - hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi), - "/org/freedesktop/Hal/devices/virtio_%s", - hal_device_property_get_string (d, "virtio.id")); + hald_compute_udi (udi, sizeof (udi), + "/org/freedesktop/Hal/devices/virtio_%s", + hal_device_property_get_string (d, "virtio.id")); hal_device_set_udi (d, udi); hal_device_property_set_string (d, "info.udi", udi); @@ -3702,15 +3702,15 @@ vio_compute_udi (HalDevice *d) type = hal_device_property_get_string (d, "vio.type"); if (type) { - hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi), - "/org/freedesktop/Hal/devices/vio_%s_%s", - type, - hal_device_property_get_string (d, "vio.id")); + hald_compute_udi (udi, sizeof (udi), + "/org/freedesktop/Hal/devices/vio_%s_%s", + type, + hal_device_property_get_string (d, "vio.id")); } else { - hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi), - "/org/freedesktop/Hal/devices/vio_%s", - hal_device_property_get_string (d, "vio.id")); - } + hald_compute_udi (udi, sizeof (udi), + "/org/freedesktop/Hal/devices/vio_%s", + hal_device_property_get_string (d, "vio.id")); + } hal_device_set_udi (d, udi); hal_device_property_set_string (d, "info.udi", udi); @@ -3752,9 +3752,9 @@ pseudo_compute_udi (HalDevice *d) { gchar udi[256]; - hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi), - "/org/freedesktop/Hal/devices/pseudo", - hal_device_property_get_string (d, "platform.id")); + hald_compute_udi (udi, sizeof (udi), + "/org/freedesktop/Hal/devices/pseudo", + hal_device_property_get_string (d, "platform.id")); hal_device_set_udi (d, udi); hal_device_property_set_string (d, "info.udi", udi); diff --git a/hald/linux/pmu.c b/hald/linux/pmu.c index c080ed39..67ff7854 100644 --- a/hald/linux/pmu.c +++ b/hald/linux/pmu.c @@ -212,8 +212,8 @@ static gboolean pmu_lid_compute_udi (HalDevice *d, PMUDevHandler *handler) { gchar udi[256]; - hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi), - "/org/freedesktop/Hal/devices/pmu_lid"); + hald_compute_udi (udi, sizeof (udi), + "/org/freedesktop/Hal/devices/pmu_lid"); hal_device_set_udi (d, udi); hal_device_property_set_string (d, "info.udi", udi); return TRUE; @@ -223,8 +223,8 @@ static gboolean pmu_laptop_panel_compute_udi (HalDevice *d, PMUDevHandler *handler) { gchar udi[256]; - hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi), - "/org/freedesktop/Hal/devices/pmu_lcd"); + hald_compute_udi (udi, sizeof (udi), + "/org/freedesktop/Hal/devices/pmu_lcd"); hal_device_set_udi (d, udi); hal_device_property_set_string (d, "info.udi", udi); return TRUE; @@ -400,10 +400,10 @@ static gboolean pmu_generic_compute_udi (HalDevice *d, PMUDevHandler *handler) { gchar udi[256]; - hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi), - "/org/freedesktop/Hal/devices/pmu_%s_%d", - hal_util_get_last_element (hal_device_property_get_string (d, "linux.pmu_path")), - hal_device_property_get_int (d, "linux.pmu_type")); + hald_compute_udi (udi, sizeof (udi), + "/org/freedesktop/Hal/devices/pmu_%s_%d", + hal_util_get_last_element (hal_device_property_get_string (d, "linux.pmu_path")), + hal_device_property_get_int (d, "linux.pmu_type")); hal_device_set_udi (d, udi); hal_device_property_set_string (d, "info.udi", udi); return TRUE; diff --git a/hald/solaris/devinfo.c b/hald/solaris/devinfo.c index e82317f2..b6a2ddc6 100644 --- a/hald/solaris/devinfo.c +++ b/hald/solaris/devinfo.c @@ -95,10 +95,10 @@ devinfo_set_default_properties (HalDevice *d, HalDevice *parent, di_node_t node, hal_device_property_set_string (d, "info.parent", "/org/freedesktop/Hal/devices/local"); } - hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi), - "/org/freedesktop/Hal/devices%s_%d", - devfs_path, - di_instance (node)); + hald_compute_udi (udi, sizeof (udi), + "/org/freedesktop/Hal/devices%s_%d", + devfs_path, + di_instance (node)); hal_device_set_udi (d, udi); hal_device_property_set_string (d, "info.udi", udi); diff --git a/hald/solaris/devinfo_storage.c b/hald/solaris/devinfo_storage.c index 4e1e9b12..61f50aa2 100644 --- a/hald/solaris/devinfo_storage.c +++ b/hald/solaris/devinfo_storage.c @@ -209,8 +209,9 @@ devinfo_ide_storage_add(HalDevice *grampa, HalDevice *parent, di_node_t node, ch devinfo_set_default_properties (d, parent, node, devfs_path); hal_device_property_set_string (d, "info.category", "storage"); - hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi), - "%s/%s%d", hal_device_get_udi (parent), driver_name, di_instance (node)); + hald_compute_udi (udi, sizeof (udi), + "%s/%s%d", hal_device_get_udi (parent), + driver_name, di_instance (node)); hal_device_set_udi (d, udi); hal_device_property_set_string (d, "info.udi", udi); PROP_STR(d, node, s, "devid", "info.product"); @@ -255,10 +256,11 @@ devinfo_scsi_add(HalDevice *parent, di_node_t node, char *devfs_path, char *devi devinfo_set_default_properties (d, parent, node, devfs_path); hal_device_property_set_string (d, "info.subsystem", "scsi"); - hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi), - "%s/%s%d", hal_device_get_udi (parent), di_node_name(node), di_instance (node)); - hal_device_set_udi (d, udi); - hal_device_property_set_string (d, "info.udi", udi); + hald_compute_udi (udi, sizeof (udi), + "%s/%s%d", hal_device_get_udi (parent), + di_node_name(node), di_instance (node)); + hal_device_set_udi (d, udi); + hal_device_property_set_string (d, "info.udi", udi); hal_device_property_set_int (d, "scsi.host", hal_device_property_get_int (parent, "scsi_host.host")); @@ -285,10 +287,11 @@ devinfo_scsi_storage_add(HalDevice *grampa, HalDevice *parent, di_node_t node, c devinfo_set_default_properties (d, parent, node, devfs_path); hal_device_property_set_string (d, "info.category", "storage"); - hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi), - "%s/sd%d", hal_device_get_udi (parent), di_instance (node)); - hal_device_set_udi (d, udi); - hal_device_property_set_string (d, "info.udi", udi); + hald_compute_udi (udi, sizeof (udi), + "%s/sd%d", hal_device_get_udi (parent), + di_instance (node)); + hal_device_set_udi (d, udi); + hal_device_property_set_string (d, "info.udi", udi); PROP_STR(d, node, s, "inquiry-product-id", "info.product"); hal_device_add_capability (d, "storage"); @@ -542,12 +545,13 @@ devinfo_lofi_add_major(HalDevice *parent, di_node_t node, char *devfs_path, char devinfo_set_default_properties (d, parent, node, devfs_path); hal_device_property_set_string (d, "info.subsystem", "pseudo"); - hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi), - "%s/%s%d", hal_device_get_udi (parent), di_node_name(node), di_instance (node)); - hal_device_set_udi (d, udi); - hal_device_property_set_string (d, "info.udi", udi); + hald_compute_udi (udi, sizeof (udi), + "%s/%s%d", hal_device_get_udi (parent), + di_node_name(node), di_instance (node)); + hal_device_set_udi (d, udi); + hal_device_property_set_string (d, "info.udi", udi); - devinfo_add_enqueue (d, devfs_path, &devinfo_lofi_handler); + devinfo_add_enqueue (d, devfs_path, &devinfo_lofi_handler); } else { d = lofi_d; } @@ -939,14 +943,14 @@ devinfo_volume_add(HalDevice *parent, di_node_t node, devinfo_storage_minor_t *m devinfo_set_default_properties (d, parent, node, devfs_path); hal_device_property_set_string (d, "info.category", "volume"); - hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi), - "%s/%s", hal_device_get_udi (parent), slice); - hal_device_set_udi (d, udi); - hal_device_property_set_string (d, "info.udi", udi); - hal_device_property_set_string (d, "info.product", slice); + hald_compute_udi (udi, sizeof (udi), + "%s/%s", hal_device_get_udi (parent), slice); + hal_device_set_udi (d, udi); + hal_device_property_set_string (d, "info.udi", udi); + hal_device_property_set_string (d, "info.product", slice); - hal_device_add_capability (d, "volume"); - hal_device_add_capability (d, "block"); + hal_device_add_capability (d, "volume"); + hal_device_add_capability (d, "block"); hal_device_property_set_int (d, "block.major", major (dev)); hal_device_property_set_int (d, "block.minor", minor (dev)); hal_device_property_set_string (d, "block.device", devlink); diff --git a/hald/solaris/devinfo_usb.c b/hald/solaris/devinfo_usb.c index b0be81d8..fd3d37ec 100644 --- a/hald/solaris/devinfo_usb.c +++ b/hald/solaris/devinfo_usb.c @@ -119,11 +119,11 @@ devinfo_usb_if_add(HalDevice *parent, di_node_t node, gchar *devfs_path, int ifn devinfo_set_default_properties (d, parent, node, devfs_path); hal_device_property_set_string (d, "info.subsystem", "usb"); - hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi), - "%s_if%d", hal_device_get_udi (parent), ifnum); - hal_device_set_udi (d, udi); - hal_device_property_set_string (d, "info.udi", udi); - hal_device_property_set_string (d, "info.product", "USB Device Interface"); + hald_compute_udi (udi, sizeof (udi), + "%s_if%d", hal_device_get_udi (parent), ifnum); + hal_device_set_udi (d, udi); + hal_device_property_set_string (d, "info.udi", udi); + hal_device_property_set_string (d, "info.product", "USB Device Interface"); /* copy parent's usb_device.* properties */ hal_device_merge_with_rewrite (d, parent, "usb.", "usb_device."); @@ -209,9 +209,9 @@ devinfo_usb_scsa2usb_add(HalDevice *usbd, di_node_t node, gchar *devfs_path) hal_device_property_set_string (d, "info.category", "scsi_host"); hal_device_property_set_int (d, "scsi_host.host", 0); - hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi), - "%s/scsi_host%d", hal_device_get_udi (usbd), - hal_device_property_get_int (d, "scsi_host.host")); + hald_compute_udi (hald_get_gdl (), udi, sizeof (udi), + "%s/scsi_host%d", hal_device_get_udi (usbd), + hal_device_property_get_int (d, "scsi_host.host")); hal_device_set_udi (d, udi); hal_device_property_set_string (d, "info.udi", udi); hal_device_property_set_string (d, "info.product", "SCSI Host Adapter"); diff --git a/hald/util.c b/hald/util.c index 8f2dbec0..ee3cb37e 100644 --- a/hald/util.c +++ b/hald/util.c @@ -469,36 +469,49 @@ hal_util_set_double_from_file (HalDevice *d, const gchar *key, const gchar *dire } void -hal_util_compute_udi (HalDeviceStore *store, gchar *dst, gsize dstsize, const gchar *format, ...) +hal_util_make_udi_unique (HalDeviceStore *store, gchar *udi, gsize udisize, const char *original_udi) { - guint i; - va_list args; - gchar buf[256]; - - va_start (args, format); - g_vsnprintf (buf, sizeof (buf), format, args); - va_end (args); - - g_strcanon (buf, - "/_" - "abcdefghijklmnopqrstuvwxyz" - "ABCDEFGHIJKLMNOPQRSTUVWXYZ" - "1234567890", '_'); + int i; - g_strlcpy (dst, buf, dstsize); - if (hal_device_store_find (store, dst) == NULL) + if (hal_device_store_find (store, original_udi) == NULL) { + g_strlcpy (udi, original_udi, udisize); goto out; + } for (i = 0; ; i++) { - g_snprintf (dst, dstsize, "%s_%d", buf, i); - if (hal_device_store_find (store, dst) == NULL) + g_snprintf (udi, udisize, "%s_%d", original_udi, i); + if (hal_device_store_find (store, udi) == NULL) { goto out; + } } out: ; } +void +hal_util_compute_udi_valist (HalDeviceStore *store, gchar *dst, gsize dstsize, const gchar *format, va_list args) +{ + g_vsnprintf (dst, dstsize, format, args); + + g_strcanon (dst, + "/_" + "abcdefghijklmnopqrstuvwxyz" + "ABCDEFGHIJKLMNOPQRSTUVWXYZ" + "1234567890", '_'); +} + + +void +hal_util_compute_udi (HalDeviceStore *store, gchar *dst, gsize dstsize, const gchar *format, ...) +{ + va_list args; + + va_start (args, format); + hal_util_compute_udi_valist (store, dst, dstsize, format, args); + va_end (args); +} + gboolean hal_util_path_ascend (gchar *path) diff --git a/hald/util.h b/hald/util.h index 7530f034..4cf9524c 100644 --- a/hald/util.h +++ b/hald/util.h @@ -68,6 +68,10 @@ gboolean hal_util_set_bcd2_from_file (HalDevice *d, const gchar *key, const gcha gboolean hal_util_set_double_from_file (HalDevice *d, const gchar *key, const gchar *directory, const gchar *file); +void hal_util_make_udi_unique (HalDeviceStore *store, gchar *udi, gsize udisize, const char *original_udi); + +void hal_util_compute_udi_valist (HalDeviceStore *store, gchar *dst, gsize dstsize, const gchar *format, va_list args); + void hal_util_compute_udi (HalDeviceStore *store, gchar *dst, gsize dstsize, const gchar *format, ...); gboolean hal_util_path_ascend (gchar *path); |