]> git.cameronkatri.com Git - pw-darwin.git/commitdiff
Be more clear in error messages.
authorNick Hibma <n_hibma@FreeBSD.org>
Sun, 23 Jun 2002 19:23:46 +0000 (19:23 +0000)
committerNick Hibma <n_hibma@FreeBSD.org>
Sun, 23 Jun 2002 19:23:46 +0000 (19:23 +0000)
Distinguish between a held lock and a failed lock op.

If rpc.lockd is not running on a diskless client this makes clearer
what the problem is.

libutil/pw_util.c

index 72c472301d78f01e3f071d0aedbfa6d5345e68f2..444140dd613b6522e2b007ce1574c79077df48aa 100644 (file)
@@ -185,16 +185,21 @@ pw_lock(void)
                if (lockfd < 0 || fcntl(lockfd, F_SETFD, 1) == -1)
                        err(1, "%s", masterpasswd);
                /* XXX vulnerable to race conditions */
-               if (flock(lockfd, LOCK_EX|LOCK_NB))
-                       errx(1, "the password db file is busy");
+               if (flock(lockfd, LOCK_EX|LOCK_NB) == -1) {
+                       if (errno == EWOULDBLOCK) {
+                               errx(1, "the password db file is busy");
+                       } else {
+                               err(1, "could not lock the passwd file: ");
+                       }
+               }
 
                /*
                 * If the password file was replaced while we were trying to
                 * get the lock, our hardlink count will be 0 and we have to
                 * close and retry.
                 */
-               if (fstat(lockfd, &st) < 0)
-                       errx(1, "fstat() failed");
+               if (fstat(lockfd, &st) == -1)
+                       err(1, "fstat() failed: ");
                if (st.st_nlink != 0)
                        break;
                close(lockfd);