summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authordavidxu <davidxu@FreeBSD.org>2013-02-16 06:07:07 +0000
committerdavidxu <davidxu@FreeBSD.org>2013-02-16 06:07:07 +0000
commit2fd1909d3a78ec1b44c47cf82d615bb9b8a12063 (patch)
treee0ddfca3f944dd6e6f2465e965fb702a9e2d3465 /lib
parent8261579eca2aee8b33c3aea62159bc66aaa49081 (diff)
downloadFreeBSD-src-2fd1909d3a78ec1b44c47cf82d615bb9b8a12063.zip
FreeBSD-src-2fd1909d3a78ec1b44c47cf82d615bb9b8a12063.tar.gz
Simplify code by using flag O_EXLOCK.
PR: kern/175674
Diffstat (limited to 'lib')
-rw-r--r--lib/libc/gen/sem_new.c12
1 files changed, 3 insertions, 9 deletions
diff --git a/lib/libc/gen/sem_new.c b/lib/libc/gen/sem_new.c
index b11d547..0393fac 100644
--- a/lib/libc/gen/sem_new.c
+++ b/lib/libc/gen/sem_new.c
@@ -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,
OpenPOWER on IntegriCloud