From owner-svn-src-all@FreeBSD.ORG Thu Dec 27 14:09:51 2012 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 3FE48EC6; Thu, 27 Dec 2012 14:09:51 +0000 (UTC) (envelope-from bapt@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) by mx1.freebsd.org (Postfix) with ESMTP id 097688FC0C; Thu, 27 Dec 2012 14:09:51 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.5/8.14.5) with ESMTP id qBRE9oVJ092288; Thu, 27 Dec 2012 14:09:50 GMT (envelope-from bapt@svn.freebsd.org) Received: (from bapt@localhost) by svn.freebsd.org (8.14.5/8.14.5/Submit) id qBRE9ogT092286; Thu, 27 Dec 2012 14:09:50 GMT (envelope-from bapt@svn.freebsd.org) Message-Id: <201212271409.qBRE9ogT092286@svn.freebsd.org> From: Baptiste Daroussin Date: Thu, 27 Dec 2012 14:09:50 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r244735 - head/lib/libutil X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 27 Dec 2012 14:09:51 -0000 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 {