summaryrefslogtreecommitdiffstats
path: root/src/sysusers
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2021-01-19 08:46:41 +0100
committerGitHub <noreply@github.com>2021-01-19 08:46:41 +0100
commit7b5ed18779992a62ac705952b4dc63b783be93b8 (patch)
tree9936f750fb5f6019f4abf36fdd00c612eef340cc /src/sysusers
parentMerge pull request #18300 from yuwata/analyze-verify-18252 (diff)
parentudev: Use TAKE_PTR (diff)
downloadsystemd-7b5ed18779992a62ac705952b4dc63b783be93b8.tar.xz
systemd-7b5ed18779992a62ac705952b4dc63b783be93b8.zip
Merge pull request #18294 from ssahani/net-2
tree wide use ensure_put
Diffstat (limited to 'src/sysusers')
-rw-r--r--src/sysusers/sysusers.c22
1 files changed, 12 insertions, 10 deletions
diff --git a/src/sysusers/sysusers.c b/src/sysusers/sysusers.c
index f0ec5085fc..4f78e3d065 100644
--- a/src/sysusers/sysusers.c
+++ b/src/sysusers/sysusers.c
@@ -1043,13 +1043,15 @@ static int add_user(Item *i) {
i->uid = search_uid;
}
- r = ordered_hashmap_ensure_allocated(&todo_uids, NULL);
- if (r < 0)
+ r = ordered_hashmap_ensure_put(&todo_uids, NULL, UID_TO_PTR(i->uid), i);
+ if (r == -EEXIST)
+ return log_error_errno(r, "Requested user %s with uid " UID_FMT " and gid" GID_FMT " to be created is duplicated "
+ "or conflicts with another user.", i->name, i->uid, i->gid);
+ if (r == -ENOMEM)
return log_oom();
-
- r = ordered_hashmap_put(todo_uids, UID_TO_PTR(i->uid), i);
if (r < 0)
- return log_oom();
+ return log_error_errno(r, "Failed to store user %s with uid " UID_FMT " and gid " GID_FMT " to be created: %m",
+ i->name, i->uid, i->gid);
i->todo_user = true;
log_info("Creating user %s (%s) with uid " UID_FMT " and gid " GID_FMT ".", i->name, strna(i->description), i->uid, i->gid);
@@ -1212,13 +1214,13 @@ static int add_group(Item *i) {
i->gid = search_uid;
}
- r = ordered_hashmap_ensure_allocated(&todo_gids, NULL);
- if (r < 0)
+ r = ordered_hashmap_ensure_put(&todo_gids, NULL, GID_TO_PTR(i->gid), i);
+ if (r == -EEXIST)
+ return log_error_errno(r, "Requested group %s with gid "GID_FMT " to be created is duplicated or conflicts with another user.", i->name, i->gid);
+ if (r == -ENOMEM)
return log_oom();
-
- r = ordered_hashmap_put(todo_gids, GID_TO_PTR(i->gid), i);
if (r < 0)
- return log_oom();
+ return log_error_errno(r, "Failed to store group %s with gid " GID_FMT " to be created: %m", i->name, i->gid);
i->todo_group = true;
log_info("Creating group %s with gid " GID_FMT ".", i->name, i->gid);