From: Zbigniew Jędrzejewski-Szmek Date: Mon, 29 Jan 2018 13:23:31 +0000 (+0100) Subject: sysusers: emit a bit more info at debug level when locking fails X-Git-Tag: v238~147^2~7 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=d1e4b8fd963ba43190ec824a803819612ff80441;p=thirdparty%2Fsystemd.git sysusers: emit a bit more info at debug level when locking fails This is the first error message when running unprivileged, and the message is unspecific, so let's at least add some logging at debug level to make this less confusing. --- diff --git a/src/basic/user-util.c b/src/basic/user-util.c index 17a9b5a8f13..011b29ad023 100644 --- a/src/basic/user-util.c +++ b/src/basic/user-util.c @@ -553,18 +553,18 @@ int take_etc_passwd_lock(const char *root) { * awfully racy, and thus we just won't do them. */ if (root) - path = prefix_roota(root, "/etc/.pwd.lock"); + path = prefix_roota(root, ETC_PASSWD_LOCK_PATH); else - path = "/etc/.pwd.lock"; + path = ETC_PASSWD_LOCK_PATH; fd = open(path, O_WRONLY|O_CREAT|O_CLOEXEC|O_NOCTTY|O_NOFOLLOW, 0600); if (fd < 0) - return -errno; + return log_debug_errno(errno, "Cannot open %s: %m", path); r = fcntl(fd, F_SETLKW, &flock); if (r < 0) { safe_close(fd); - return -errno; + return log_debug_errno(errno, "Locking %s failed: %m", path); } return fd; diff --git a/src/basic/user-util.h b/src/basic/user-util.h index 5f0391f2b85..290d17a0c64 100644 --- a/src/basic/user-util.h +++ b/src/basic/user-util.h @@ -63,6 +63,8 @@ int take_etc_passwd_lock(const char *root); #define UID_NOBODY ((uid_t) 65534U) #define GID_NOBODY ((gid_t) 65534U) +#define ETC_PASSWD_LOCK_PATH "/etc/.pwd.lock" + static inline bool uid_is_dynamic(uid_t uid) { return DYNAMIC_UID_MIN <= uid && uid <= DYNAMIC_UID_MAX; } diff --git a/src/sysusers/sysusers.c b/src/sysusers/sysusers.c index 510d5fa59eb..288f6a16658 100644 --- a/src/sysusers/sysusers.c +++ b/src/sysusers/sysusers.c @@ -1841,7 +1841,7 @@ int main(int argc, char *argv[]) { lock = take_etc_passwd_lock(arg_root); if (lock < 0) { - log_error_errno(lock, "Failed to take lock: %m"); + log_error_errno(lock, "Failed to take /etc/passwd lock: %m"); goto finish; }