mirror of
https://github.com/freebsd/freebsd-src
synced 2024-09-06 17:18:32 +00:00
Use flopen(3) instead of open(2) + flock(2)
This commit is contained in:
parent
a68c6b5790
commit
98e79fb122
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=244735
|
@ -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 {
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in a new issue