From: Susant Sahani Date: Tue, 19 Jan 2021 04:56:25 +0000 (+0100) Subject: sysusers: use ordered_hashmap_ensure_put X-Git-Tag: v248-rc1~301^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1dfb93210f2dede4034c02c702aa7f348e3f5b73;p=thirdparty%2Fsystemd.git sysusers: use ordered_hashmap_ensure_put --- diff --git a/src/sysusers/sysusers.c b/src/sysusers/sysusers.c index 6b0acd529e4..ddaddebc4f2 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);