]> git.cameronkatri.com Git - pw-darwin.git/blobdiff - libutil/pw_util.c
Merge from head@274682
[pw-darwin.git] / libutil / pw_util.c
index 4bf3001ffe79b6f2e7b98c829b98ca51aa1460aa..befd1fb02d701ee9f8bf67f83077073139b36dc2 100644 (file)
@@ -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|O_CLOEXEC, 0);
+               if (lockfd == -1) {
                        if (errno == EWOULDBLOCK) {
                                errx(1, "the password db file is busy");
                        } else {