summaryrefslogtreecommitdiffstats
path: root/libutil
diff options
context:
space:
mode:
authorBaptiste Daroussin <bapt@FreeBSD.org>2012-12-27 14:09:50 +0000
committerBaptiste Daroussin <bapt@FreeBSD.org>2012-12-27 14:09:50 +0000
commit758c4f17afd4a148f62b0b87647f242acf074aa9 (patch)
tree991f8117fe65f324796fb06a9a3268b9d65c4c0b /libutil
parent6f9e060eaafec4d7157f90f32e8d2d580fd73a71 (diff)
downloadpw-darwin-758c4f17afd4a148f62b0b87647f242acf074aa9.tar.gz
pw-darwin-758c4f17afd4a148f62b0b87647f242acf074aa9.tar.zst
pw-darwin-758c4f17afd4a148f62b0b87647f242acf074aa9.zip
Use flopen(3) instead of open(2) + flock(2)
Diffstat (limited to 'libutil')
-rw-r--r--libutil/gr_util.c6
-rw-r--r--libutil/pw_util.c7
2 files changed, 4 insertions, 9 deletions
diff --git a/libutil/gr_util.c b/libutil/gr_util.c
index be34395..6bf102f 100644
--- a/libutil/gr_util.c
+++ b/libutil/gr_util.c
@@ -106,10 +106,8 @@ gr_lock(void)
for (;;) {
struct stat st;
- lockfd = open(group_file, O_RDONLY, 0);
- if (lockfd < 0 || fcntl(lockfd, F_SETFD, 1) == -1)
- err(1, "%s", group_file);
- if (flock(lockfd, LOCK_EX|LOCK_NB) == -1) {
+ lockfd = flopen(group_file, O_RDONLY|O_NONBLOCK, 0);
+ if (lockfd == -1) {
if (errno == EWOULDBLOCK) {
errx(1, "the group file is busy");
} else {
diff --git a/libutil/pw_util.c b/libutil/pw_util.c
index 4bf3001..24c0263 100644
--- a/libutil/pw_util.c
+++ b/libutil/pw_util.c
@@ -179,11 +179,8 @@ pw_lock(void)
for (;;) {
struct stat st;
- lockfd = open(masterpasswd, O_RDONLY, 0);
- 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) == -1) {
+ lockfd = flopen(masterpasswd, O_RDONLY|O_NONBLOCK, 0);
+ if (lockfd == -1) {
if (errno == EWOULDBLOCK) {
errx(1, "the password db file is busy");
} else {