aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Hibma <n_hibma@FreeBSD.org>2002-06-23 19:23:46 +0000
committerNick Hibma <n_hibma@FreeBSD.org>2002-06-23 19:23:46 +0000
commit074dccd5458714d89cccb2c0e8f09f2b34fc8e94 (patch)
treed4f3dad50318a48b583be18687183dee9edd5bdf
parentbefd9c61ce8360b73054e444e737b3eee3e78fe1 (diff)
Notes
-rw-r--r--lib/libutil/pw_util.c13
1 files changed, 9 insertions, 4 deletions
diff --git a/lib/libutil/pw_util.c b/lib/libutil/pw_util.c
index 72c472301d78..444140dd613b 100644
--- a/lib/libutil/pw_util.c
+++ b/lib/libutil/pw_util.c
@@ -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);