diff options
author | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2020-04-29 08:47:51 +0200 |
---|---|---|
committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2020-05-06 16:54:06 +0200 |
commit | be32732168e07b7d52ec77fa67cf93a80a9a8293 (patch) | |
tree | 0feb0a006050702078fd41b5fea2eee9c4d00b08 /src/libsystemd | |
parent | 0894f08bf14b09ef0436ed11268d43dbcdd88ee7 (diff) | |
download | systemd-be32732168e07b7d52ec77fa67cf93a80a9a8293.tar.gz |
basic/set: let set_put_strdup() create the set with string hash ops
If we're using a set with _put_strdup(), most of the time we want to use
string hash ops on the set, and free the strings when done. This defines
the appropriate a new string_hash_ops_free structure to automatically free
the keys when removing the set, and makes set_put_strdup() and set_put_strdupv()
instantiate the set with those hash ops.
hashmap_put_strdup() was already doing something similar.
(It is OK to instantiate the set earlier, possibly with a different hash ops
structure. set_put_strdup() will then use the existing set. It is also OK
to call set_free_free() instead of set_free() on a set with
string_hash_ops_free, the effect is the same, we're just overriding the
override of the cleanup function.)
No functional change intended.
Diffstat (limited to 'src/libsystemd')
-rw-r--r-- | src/libsystemd/sd-device/device-enumerator.c | 8 | ||||
-rw-r--r-- | src/libsystemd/sd-device/sd-device.c | 24 |
2 files changed, 10 insertions, 22 deletions
diff --git a/src/libsystemd/sd-device/device-enumerator.c b/src/libsystemd/sd-device/device-enumerator.c index a1932f41f9..cd3d75c517 100644 --- a/src/libsystemd/sd-device/device-enumerator.c +++ b/src/libsystemd/sd-device/device-enumerator.c @@ -101,7 +101,7 @@ _public_ int sd_device_enumerator_add_match_subsystem(sd_device_enumerator *enum if (r < 0) return r; - r = set_put_strdup(*set, subsystem); + r = set_put_strdup(set, subsystem); if (r < 0) return r; @@ -192,7 +192,7 @@ _public_ int sd_device_enumerator_add_match_sysname(sd_device_enumerator *enumer if (r < 0) return r; - r = set_put_strdup(enumerator->match_sysname, sysname); + r = set_put_strdup(&enumerator->match_sysname, sysname); if (r < 0) return r; @@ -211,7 +211,7 @@ _public_ int sd_device_enumerator_add_match_tag(sd_device_enumerator *enumerator if (r < 0) return r; - r = set_put_strdup(enumerator->match_tag, tag); + r = set_put_strdup(&enumerator->match_tag, tag); if (r < 0) return r; @@ -242,7 +242,7 @@ int device_enumerator_add_match_parent_incremental(sd_device_enumerator *enumera if (r < 0) return r; - r = set_put_strdup(enumerator->match_parent, path); + r = set_put_strdup(&enumerator->match_parent, path); if (r < 0) return r; diff --git a/src/libsystemd/sd-device/sd-device.c b/src/libsystemd/sd-device/sd-device.c index 1f2451f8e1..24f34dc182 100644 --- a/src/libsystemd/sd-device/sd-device.c +++ b/src/libsystemd/sd-device/sd-device.c @@ -68,9 +68,9 @@ static sd_device *device_free(sd_device *device) { ordered_hashmap_free_free_free(device->properties); ordered_hashmap_free_free_free(device->properties_db); hashmap_free_free_free(device->sysattr_values); - set_free_free(device->sysattrs); - set_free_free(device->tags); - set_free_free(device->devlinks); + set_free(device->sysattrs); + set_free(device->tags); + set_free(device->devlinks); return mfree(device); } @@ -1078,11 +1078,7 @@ int device_add_tag(sd_device *device, const char *tag) { if (!is_valid_tag(tag)) return -EINVAL; - r = set_ensure_allocated(&device->tags, &string_hash_ops); - if (r < 0) - return r; - - r = set_put_strdup(device->tags, tag); + r = set_put_strdup(&device->tags, tag); if (r < 0) return r; @@ -1098,11 +1094,7 @@ int device_add_devlink(sd_device *device, const char *devlink) { assert(device); assert(devlink); - r = set_ensure_allocated(&device->devlinks, &string_hash_ops); - if (r < 0) - return r; - - r = set_put_strdup(device->devlinks, devlink); + r = set_put_strdup(&device->devlinks, devlink); if (r < 0) return r; @@ -1591,10 +1583,6 @@ static int device_sysattrs_read_all(sd_device *device) { if (!dir) return -errno; - r = set_ensure_allocated(&device->sysattrs, &string_hash_ops); - if (r < 0) - return r; - FOREACH_DIRENT_ALL(dent, dir, return -errno) { _cleanup_free_ char *path = NULL; struct stat statbuf; @@ -1613,7 +1601,7 @@ static int device_sysattrs_read_all(sd_device *device) { if (!(statbuf.st_mode & S_IRUSR)) continue; - r = set_put_strdup(device->sysattrs, dent->d_name); + r = set_put_strdup(&device->sysattrs, dent->d_name); if (r < 0) return r; } |