udev: define a generic helper to print messages about unknown users and groups

We cannot just use %m, because strerror returns a confusing error message
for ESRCH or ENOEXEC. udev code was doing a good job, but the error handling
was very verbose. Let's encapsulate the customized error messages in a
helper.

No functional change, except that the error messages have a slightly different
form now. The old messages were a bit better, but we don't have as much
flexibility in the new scheme. "Failed to resolve user 'foo': Unknown user"
should be good enough.
This commit is contained in:
Zbigniew Jędrzejewski-Szmek
2025-11-18 16:23:29 +01:00
parent 00ed239a7b
commit 6e6e96f628
3 changed files with 30 additions and 31 deletions
+8 -1
View File
@@ -10,7 +10,8 @@
#include "basic-forward.h"
/* Users managed by systemd-homed. See https://systemd.io/UIDS-GIDS for details how this range fits into the rest of the world */
/* Users managed by systemd-homed. See https://systemd.io/UIDS-GIDS for details
* how this range fits into the rest of the world. */
#define HOME_UID_MIN ((uid_t) 60001)
#define HOME_UID_MAX ((uid_t) 60513)
@@ -18,6 +19,12 @@
#define MAP_UID_MIN ((uid_t) 60514)
#define MAP_UID_MAX ((uid_t) 60577)
/* A helper to print an error message when user or group resolution fails.
* Note that we can't use ({ … }) to define a temporary variable, so errnum is
* evaluated multiple times. */
#define STRERROR_USER(errnum) ((errnum) == -ESRCH ? "Unknown user" : (errnum) == -ENOEXEC ? "Not a system user" : STRERROR(errnum))
#define STRERROR_GROUP(errnum) ((errnum) == -ESRCH ? "Unknown group" : (errnum) == -ENOEXEC ? "Not a system group" : STRERROR(errnum))
bool uid_is_valid(uid_t uid) _const_;
static inline bool gid_is_valid(gid_t gid) {