summaryrefslogtreecommitdiff
path: root/src/libsystemd/sd-device
diff options
context:
space:
mode:
authorDavid Herrmann <dh.herrmann@gmail.com>2015-06-14 16:51:35 +0200
committerDavid Herrmann <dh.herrmann@gmail.com>2015-06-14 16:56:02 +0200
commit8927b1dad2d4a7330174cb924090b4635a2547fb (patch)
treeaa730ee2822e083e988f7621fcafefd65006b844 /src/libsystemd/sd-device
parentaa75494ad5cdf7bede947212ad8c8356d78580fa (diff)
hashmap: fix iterators to not skip entries
Currently, the HASHMAP iterators stop at the first NULL entry in a hashmap. This is non-obvious and breaks users like sd-device, which legitimately store NULL values in a hashmap. Fix all the iterators by taking a pointer to the value storage, instead of returning it. The iterators now return a boolean that tells whether the end of the list was reached. Current users of HASHMAP_FOREACH() are *NOT* changed to explicitly check for NULL. If it turns out, there were users that inserted NULL into hashmaps, but didn't properly check for it during iteration, then we really want to find those and fix them.
Diffstat (limited to 'src/libsystemd/sd-device')
-rw-r--r--src/libsystemd/sd-device/sd-device.c33
1 files changed, 25 insertions, 8 deletions
diff --git a/src/libsystemd/sd-device/sd-device.c b/src/libsystemd/sd-device/sd-device.c
index 8e63b9ef56..b274f71093 100644
--- a/src/libsystemd/sd-device/sd-device.c
+++ b/src/libsystemd/sd-device/sd-device.c
@@ -1371,6 +1371,8 @@ _public_ int sd_device_get_usec_since_initialized(sd_device *device, uint64_t *u
}
_public_ const char *sd_device_get_tag_first(sd_device *device) {
+ void *v;
+
assert_return(device, NULL);
(void) device_read_db(device);
@@ -1378,10 +1380,13 @@ _public_ const char *sd_device_get_tag_first(sd_device *device) {
device->tags_iterator_generation = device->tags_generation;
device->tags_iterator = ITERATOR_FIRST;
- return set_iterate(device->tags, &device->tags_iterator);
+ set_iterate(device->tags, &device->tags_iterator, &v);
+ return v;
}
_public_ const char *sd_device_get_tag_next(sd_device *device) {
+ void *v;
+
assert_return(device, NULL);
(void) device_read_db(device);
@@ -1389,10 +1394,13 @@ _public_ const char *sd_device_get_tag_next(sd_device *device) {
if (device->tags_iterator_generation != device->tags_generation)
return NULL;
- return set_iterate(device->tags, &device->tags_iterator);
+ set_iterate(device->tags, &device->tags_iterator, &v);
+ return v;
}
_public_ const char *sd_device_get_devlink_first(sd_device *device) {
+ void *v;
+
assert_return(device, NULL);
(void) device_read_db(device);
@@ -1400,10 +1408,13 @@ _public_ const char *sd_device_get_devlink_first(sd_device *device) {
device->devlinks_iterator_generation = device->devlinks_generation;
device->devlinks_iterator = ITERATOR_FIRST;
- return set_iterate(device->devlinks, &device->devlinks_iterator);
+ set_iterate(device->devlinks, &device->devlinks_iterator, &v);
+ return v;
}
_public_ const char *sd_device_get_devlink_next(sd_device *device) {
+ void *v;
+
assert_return(device, NULL);
(void) device_read_db(device);
@@ -1411,7 +1422,8 @@ _public_ const char *sd_device_get_devlink_next(sd_device *device) {
if (device->devlinks_iterator_generation != device->devlinks_generation)
return NULL;
- return set_iterate(device->devlinks, &device->devlinks_iterator);
+ set_iterate(device->devlinks, &device->devlinks_iterator, &v);
+ return v;
}
static int device_properties_prepare(sd_device *device) {
@@ -1482,7 +1494,7 @@ _public_ const char *sd_device_get_property_first(sd_device *device, const char
device->properties_iterator_generation = device->properties_generation;
device->properties_iterator = ITERATOR_FIRST;
- value = ordered_hashmap_iterate(device->properties, &device->properties_iterator, (const void**)&key);
+ ordered_hashmap_iterate(device->properties, &device->properties_iterator, (void**)&value, (const void**)&key);
if (_value)
*_value = value;
@@ -1504,7 +1516,7 @@ _public_ const char *sd_device_get_property_next(sd_device *device, const char *
if (device->properties_iterator_generation != device->properties_generation)
return NULL;
- value = ordered_hashmap_iterate(device->properties, &device->properties_iterator, (const void**)&key);
+ ordered_hashmap_iterate(device->properties, &device->properties_iterator, (void**)&value, (const void**)&key);
if (_value)
*_value = value;
@@ -1562,6 +1574,7 @@ static int device_sysattrs_read_all(sd_device *device) {
}
_public_ const char *sd_device_get_sysattr_first(sd_device *device) {
+ void *v;
int r;
assert_return(device, NULL);
@@ -1576,16 +1589,20 @@ _public_ const char *sd_device_get_sysattr_first(sd_device *device) {
device->sysattrs_iterator = ITERATOR_FIRST;
- return set_iterate(device->sysattrs, &device->sysattrs_iterator);
+ set_iterate(device->sysattrs, &device->sysattrs_iterator, &v);
+ return v;
}
_public_ const char *sd_device_get_sysattr_next(sd_device *device) {
+ void *v;
+
assert_return(device, NULL);
if (!device->sysattrs_read)
return NULL;
- return set_iterate(device->sysattrs, &device->sysattrs_iterator);
+ set_iterate(device->sysattrs, &device->sysattrs_iterator, &v);
+ return v;
}
_public_ int sd_device_has_tag(sd_device *device, const char *tag) {