User and group error messages (#39783)

I'm using separate commit here because this changes are a bit finicky.
This commit is contained in:
Zbigniew Jędrzejewski-Szmek
2025-11-18 19:39:57 +01:00
committed by GitHub
13 changed files with 86 additions and 58 deletions
+11 -4
View File
@@ -2087,8 +2087,11 @@ static int build_environment(
assert(!c->user);
r = get_fixed_user("root", /* prefer_nss = */ false, &username, NULL, NULL, &home, &shell);
if (r < 0)
return log_debug_errno(r, "Failed to determine user credentials for root: %m");
if (r < 0) {
log_debug_errno(r, "Failed to determine credentials for user root: %s",
STRERROR_USER(r));
return ERRNO_IS_NEG_BAD_ACCOUNT(r) ? -EINVAL : r; /* Suppress confusing errno */
}
}
bool set_user_login_env = exec_context_get_set_login_environment(c);
@@ -5265,7 +5268,9 @@ int exec_invoke(
&username, &uid, &gid, &pwent_home, &shell);
if (r < 0) {
*exit_status = EXIT_USER;
return log_error_errno(r, "Failed to determine user credentials: %m");
log_error_errno(r, "Failed to determine credentials for user '%s': %s",
u, STRERROR_USER(r));
return ERRNO_IS_NEG_BAD_ACCOUNT(r) ? -EINVAL : r; /* Suppress confusing errno */
}
}
@@ -5273,7 +5278,9 @@ int exec_invoke(
r = get_fixed_group(context->group, &groupname, &gid);
if (r < 0) {
*exit_status = EXIT_GROUP;
return log_error_errno(r, "Failed to determine group credentials: %m");
log_error_errno(r, "Failed to determine credentials for group '%s': %s",
u, STRERROR_GROUP(r));
return ERRNO_IS_NEG_BAD_ACCOUNT(r) ? -EINVAL : r; /* Suppress confusing errno */
}
}
}
+6 -2
View File
@@ -348,7 +348,9 @@ static int scope_enter_start_chown(Scope *s) {
r = get_user_creds(&user, &uid, &gid, NULL, NULL, 0);
if (r < 0) {
log_unit_error_errno(UNIT(s), r, "Failed to resolve user \"%s\": %m", user);
log_unit_error_errno(UNIT(s), r,
"Failed to resolve user '%s': %s",
user, STRERROR_USER(r));
_exit(EXIT_USER);
}
}
@@ -358,7 +360,9 @@ static int scope_enter_start_chown(Scope *s) {
r = get_group_creds(&group, &gid, 0);
if (r < 0) {
log_unit_error_errno(UNIT(s), r, "Failed to resolve group \"%s\": %m", group);
log_unit_error_errno(UNIT(s), r,
"Failed to resolve group '%s': %s",
group, STRERROR_GROUP(r));
_exit(EXIT_GROUP);
}
}
+6 -2
View File
@@ -2056,7 +2056,9 @@ static int socket_chown(Socket *s, PidRef *ret_pid) {
r = get_user_creds(&user, &uid, &gid, NULL, NULL, 0);
if (r < 0) {
log_unit_error_errno(UNIT(s), r, "Failed to resolve user %s: %m", user);
log_unit_error_errno(UNIT(s), r,
"Failed to resolve user '%s': %s",
user, STRERROR_USER(r));
_exit(EXIT_USER);
}
}
@@ -2066,7 +2068,9 @@ static int socket_chown(Socket *s, PidRef *ret_pid) {
r = get_group_creds(&group, &gid, 0);
if (r < 0) {
log_unit_error_errno(UNIT(s), r, "Failed to resolve group %s: %m", group);
log_unit_error_errno(UNIT(s), r,
"Failed to resolve group '%s': %s",
group, STRERROR_GROUP(r));
_exit(EXIT_GROUP);
}
}