summaryrefslogtreecommitdiffstats
path: root/src/sysusers
diff options
context:
space:
mode:
authorSusant Sahani <ssahani@vmware.com>2021-01-18 21:37:39 +0100
committerSusant Sahani <ssahani@vmware.com>2021-01-18 21:37:39 +0100
commitf334debabbb70597e04a5f5318437e2ab6f9d22e (patch)
treec088cf4cb2754aebd2859616392a9f03a9f3e3a3 /src/sysusers
parentsd-netlink: use hashmap_ensure_put (diff)
downloadsystemd-f334debabbb70597e04a5f5318437e2ab6f9d22e.tar.xz
systemd-f334debabbb70597e04a5f5318437e2ab6f9d22e.zip
sysusers: use ordered_hashmap_ensure_put
Diffstat (limited to 'src/sysusers')
-rw-r--r--src/sysusers/sysusers.c24
1 files changed, 10 insertions, 14 deletions
diff --git a/src/sysusers/sysusers.c b/src/sysusers/sysusers.c
index 6b0acd529e..f0ec5085fc 100644
--- a/src/sysusers/sysusers.c
+++ b/src/sysusers/sysusers.c
@@ -1298,10 +1298,6 @@ static int add_implicit(void) {
if (!ordered_hashmap_get(users, *m)) {
_cleanup_(item_freep) Item *j = NULL;
- r = ordered_hashmap_ensure_allocated(&users, &item_hash_ops);
- if (r < 0)
- return log_oom();
-
j = new0(Item, 1);
if (!j)
return log_oom();
@@ -1311,22 +1307,20 @@ static int add_implicit(void) {
if (!j->name)
return log_oom();
- r = ordered_hashmap_put(users, j->name, j);
- if (r < 0)
+ r = ordered_hashmap_ensure_put(&users, &item_hash_ops, j->name, j);
+ if (r == -ENOMEM)
return log_oom();
+ if (r < 0)
+ return log_error_errno(r, "Failed to add implicit user '%s': %m", j->name);
log_debug("Adding implicit user '%s' due to m line", j->name);
- j = NULL;
+ TAKE_PTR(j);
}
if (!(ordered_hashmap_get(users, g) ||
ordered_hashmap_get(groups, g))) {
_cleanup_(item_freep) Item *j = NULL;
- r = ordered_hashmap_ensure_allocated(&groups, &item_hash_ops);
- if (r < 0)
- return log_oom();
-
j = new0(Item, 1);
if (!j)
return log_oom();
@@ -1336,12 +1330,14 @@ static int add_implicit(void) {
if (!j->name)
return log_oom();
- r = ordered_hashmap_put(groups, j->name, j);
- if (r < 0)
+ r = ordered_hashmap_ensure_put(&groups, &item_hash_ops, j->name, j);
+ if (r == -ENOMEM)
return log_oom();
+ if (r < 0)
+ return log_error_errno(r, "Failed to add implicit group '%s': %m", j->name);
log_debug("Adding implicit group '%s' due to m line", j->name);
- j = NULL;
+ TAKE_PTR(j);
}
}