diff options
author | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2021-12-08 11:21:17 +0100 |
---|---|---|
committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2021-12-08 11:47:15 +0100 |
commit | 9a5af4b7ac16368ae14f26735657e93cce46f065 (patch) | |
tree | 631ed9f77d216ea69fb4b260be1096f6f3b9e594 /src/sysusers | |
parent | 64fe10957b9fdce55d59c2af101e004c93997419 (diff) | |
download | systemd-9a5af4b7ac16368ae14f26735657e93cce46f065.tar.gz |
sysusers: improve message about conflicting entries
Without any markup, the sentence could be quite confusing:
g user 55
g user 56
→
"Two or more conflicting lines for user configured"
It also wasn't clear which line is ignored.
Inspired by https://github.com/systemd/systemd/pull/21156.
Diffstat (limited to 'src/sysusers')
-rw-r--r-- | src/sysusers/sysusers.c | 30 |
1 files changed, 23 insertions, 7 deletions
diff --git a/src/sysusers/sysusers.c b/src/sysusers/sysusers.c index a2ffeb96c6..855096020d 100644 --- a/src/sysusers/sysusers.c +++ b/src/sysusers/sysusers.c @@ -38,12 +38,27 @@ #include "util.h" typedef enum ItemType { - ADD_USER = 'u', - ADD_GROUP = 'g', + ADD_USER = 'u', + ADD_GROUP = 'g', ADD_MEMBER = 'm', - ADD_RANGE = 'r', + ADD_RANGE = 'r', } ItemType; +static inline const char* item_type_to_string(ItemType t) { + switch (t) { + case ADD_USER: + return "user"; + case ADD_GROUP: + return "group"; + case ADD_MEMBER: + return "member"; + case ADD_RANGE: + return "range"; + default: + assert_not_reached(); + } +} + typedef struct Item { ItemType type; @@ -1150,7 +1165,7 @@ static int add_user(Item *i) { i->name, i->uid, i->gid); i->todo_user = true; - log_info("Creating user %s (%s) with UID " UID_FMT " and GID " GID_FMT ".", + log_info("Creating user '%s' (%s) with UID " UID_FMT " and GID " GID_FMT ".", i->name, strna(i->description), i->uid, i->gid); return 0; @@ -1320,7 +1335,7 @@ static int add_group(Item *i) { 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); + log_info("Creating group '%s' with GID " GID_FMT ".", i->name, i->gid); return 0; } @@ -1484,7 +1499,6 @@ static bool item_equal(Item *a, Item *b) { } static int parse_line(const char *fname, unsigned line, const char *buffer) { - _cleanup_free_ char *action = NULL, *name = NULL, *resolved_name = NULL, *id = NULL, *resolved_id = NULL, @@ -1749,7 +1763,9 @@ static int parse_line(const char *fname, unsigned line, const char *buffer) { if (existing) { /* Two identical items are fine */ if (!item_equal(existing, i)) - log_warning("Two or more conflicting lines for %s configured, ignoring.", i->name); + log_warning("%s:%u: conflict with earlier configuration for %s '%s', ignoring line.", + fname, line, + item_type_to_string(i->type), i->name); return 0; } |