chiark / gitweb /
sysusers: emit a bit more info at debug level when locking fails
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Mon, 29 Jan 2018 13:23:31 +0000 (14:23 +0100)
committerSven Eden <yamakuzure@gmx.net>
Wed, 30 May 2018 05:58:48 +0000 (07:58 +0200)
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.

src/basic/user-util.c
src/basic/user-util.h

index 78effacf8a0d99fe33635997038b79e55b0a9226..ecb1e5fc8dec898a5b4b24c6b3ee94fa0ff20678 100644 (file)
@@ -560,18 +560,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;
index 34816089764bff8e600ecc1384fd190ce7c91eef..6b2f1af52349cb7645b7be3e24fd80c2a93192c2 100644 (file)
@@ -71,6 +71,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"
+
 #if 0 /// UNNEEDED by elogind
 static inline bool uid_is_dynamic(uid_t uid) {
         return DYNAMIC_UID_MIN <= uid && uid <= DYNAMIC_UID_MAX;