From owner-svn-src-stable-9@FreeBSD.ORG Sat May 17 16:27:00 2014 Return-Path: Delivered-To: svn-src-stable-9@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id F3827382; Sat, 17 May 2014 16:26:59 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id E065721E4; Sat, 17 May 2014 16:26:59 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.8/8.14.8) with ESMTP id s4HGQx4l019298; Sat, 17 May 2014 16:26:59 GMT (envelope-from kib@svn.freebsd.org) Received: (from kib@localhost) by svn.freebsd.org (8.14.8/8.14.8/Submit) id s4HGQx2X019297; Sat, 17 May 2014 16:26:59 GMT (envelope-from kib@svn.freebsd.org) Message-Id: <201405171626.s4HGQx2X019297@svn.freebsd.org> From: Konstantin Belousov Date: Sat, 17 May 2014 16:26:59 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-9@freebsd.org Subject: svn commit: r266325 - stable/9/lib/libc/gen X-SVN-Group: stable-9 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-9@freebsd.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: SVN commit messages for only the 9-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 17 May 2014 16:27:00 -0000 Author: kib Date: Sat May 17 16:26:59 2014 New Revision: 266325 URL: http://svnweb.freebsd.org/changeset/base/266325 Log: MFC r246872 (by davidxu): Simplify code by using flag O_EXLOCK. Modified: stable/9/lib/libc/gen/sem_new.c Directory Properties: stable/9/lib/libc/ (props changed) Modified: stable/9/lib/libc/gen/sem_new.c ============================================================================== --- stable/9/lib/libc/gen/sem_new.c Sat May 17 16:22:25 2014 (r266324) +++ stable/9/lib/libc/gen/sem_new.c Sat May 17 16:26:59 2014 (r266325) @@ -198,15 +198,11 @@ _sem_open(const char *name, int flags, . goto error; } - fd = _open(path, flags|O_RDWR|O_CLOEXEC, mode); + fd = _open(path, flags|O_RDWR|O_CLOEXEC|O_EXLOCK, mode); if (fd == -1) goto error; - if (flock(fd, LOCK_EX) == -1) + if (_fstat(fd, &sb)) goto error; - if (_fstat(fd, &sb)) { - flock(fd, LOCK_UN); - goto error; - } if (sb.st_size < sizeof(sem_t)) { sem_t tmp; @@ -214,10 +210,8 @@ _sem_open(const char *name, int flags, . tmp._kern._has_waiters = 0; tmp._kern._count = value; tmp._kern._flags = USYNC_PROCESS_SHARED | SEM_NAMED; - if (_write(fd, &tmp, sizeof(tmp)) != sizeof(tmp)) { - flock(fd, LOCK_UN); + if (_write(fd, &tmp, sizeof(tmp)) != sizeof(tmp)) goto error; - } } flock(fd, LOCK_UN); sem = (sem_t *)mmap(NULL, sizeof(sem_t), PROT_READ|PROT_WRITE,