Date: Thu, 27 Dec 2012 14:09:50 +0000 (UTC) From: Baptiste Daroussin <bapt@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r244735 - head/lib/libutil Message-ID: <201212271409.qBRE9ogT092286@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: bapt Date: Thu Dec 27 14:09:50 2012 New Revision: 244735 URL: http://svnweb.freebsd.org/changeset/base/244735 Log: Use flopen(3) instead of open(2) + flock(2) Modified: head/lib/libutil/gr_util.c head/lib/libutil/pw_util.c Modified: head/lib/libutil/gr_util.c ============================================================================== --- head/lib/libutil/gr_util.c Thu Dec 27 13:21:37 2012 (r244734) +++ head/lib/libutil/gr_util.c Thu Dec 27 14:09:50 2012 (r244735) @@ -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 { Modified: head/lib/libutil/pw_util.c ============================================================================== --- head/lib/libutil/pw_util.c Thu Dec 27 13:21:37 2012 (r244734) +++ head/lib/libutil/pw_util.c Thu Dec 27 14:09:50 2012 (r244735) @@ -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 {
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201212271409.qBRE9ogT092286>