1
0
mirror of https://github.com/systemd/systemd.git synced 2025-02-02 13:47:27 +03:00

Use hashmap_ensure_replace()

Use the new function `hashmap_ensure_replace()` where we're using
`hashmap_ensure_allocated()` and `hashmap_ensure_replace()`.

Signed-off-by: Matteo Croce <teknoraver@meta.com>
This commit is contained in:
Matteo Croce 2024-06-28 17:19:26 +02:00
parent afb1fe36b8
commit e1226a9b48
3 changed files with 3 additions and 18 deletions

View File

@ -2805,13 +2805,8 @@ int unit_watch_pidref(Unit *u, const PidRef *pid, bool exclusive) {
new_array[n] = u;
new_array[n+1] = NULL;
/* Make sure the hashmap is allocated */
r = hashmap_ensure_allocated(&u->manager->watch_pids_more, &pidref_hash_ops_free);
if (r < 0)
return r;
/* Add or replace the old array */
r = hashmap_replace(u->manager->watch_pids_more, old_pid ?: pid, new_array);
r = hashmap_ensure_replace(&u->manager->watch_pids_more, &pidref_hash_ops_free, old_pid ?: pid, new_array);
if (r < 0)
return r;

View File

@ -166,11 +166,7 @@ static int hwdb_add_property(sd_hwdb *hwdb, const struct trie_value_entry_f *ent
}
}
r = ordered_hashmap_ensure_allocated(&hwdb->properties, &string_hash_ops);
if (r < 0)
return r;
r = ordered_hashmap_replace(hwdb->properties, key, (void *)entry);
r = ordered_hashmap_ensure_replace(&hwdb->properties, &string_hash_ops, key, (void *) entry);
if (r < 0)
return r;

View File

@ -86,15 +86,9 @@ static unsigned broadcast_group_get_ref(sd_netlink *nl, unsigned group) {
}
static int broadcast_group_set_ref(sd_netlink *nl, unsigned group, unsigned n_ref) {
int r;
assert(nl);
r = hashmap_ensure_allocated(&nl->broadcast_group_refs, NULL);
if (r < 0)
return r;
return hashmap_replace(nl->broadcast_group_refs, UINT_TO_PTR(group), UINT_TO_PTR(n_ref));
return hashmap_ensure_replace(&nl->broadcast_group_refs, NULL, UINT_TO_PTR(group), UINT_TO_PTR(n_ref));
}
static int broadcast_group_join(sd_netlink *nl, unsigned group) {