summaryrefslogtreecommitdiffstats
path: root/lib/libc
diff options
context:
space:
mode:
authorjilles <jilles@FreeBSD.org>2012-04-09 14:17:22 +0000
committerjilles <jilles@FreeBSD.org>2012-04-09 14:17:22 +0000
commit7a3a1c55f2cf22cb72b26de09a4217c9a604abeb (patch)
tree64551716fb7a6bce2b9ba7e98c369e1676bd45fb /lib/libc
parentee116ad85c6fac2cea158c7afcccf60835267977 (diff)
downloadFreeBSD-src-7a3a1c55f2cf22cb72b26de09a4217c9a604abeb.zip
FreeBSD-src-7a3a1c55f2cf22cb72b26de09a4217c9a604abeb.tar.gz
sem_open: Make sure to fail an O_CREAT|O_EXCL open, even if that semaphore
is already open in this process. If the named semaphore is already open, sem_open() only increments a reference count and did not take the flags into account (which otherwise happens by passing them to open()). Add an extra check for O_CREAT|O_EXCL. PR: kern/166706 Reviewed by: davidxu MFC after: 10 days
Diffstat (limited to 'lib/libc')
-rw-r--r--lib/libc/gen/sem_new.c14
1 files changed, 10 insertions, 4 deletions
diff --git a/lib/libc/gen/sem_new.c b/lib/libc/gen/sem_new.c
index 222a465..b748b49 100644
--- a/lib/libc/gen/sem_new.c
+++ b/lib/libc/gen/sem_new.c
@@ -162,10 +162,16 @@ _sem_open(const char *name, int flags, ...)
_pthread_mutex_lock(&sem_llock);
LIST_FOREACH(ni, &sem_list, next) {
if (strcmp(name, ni->name) == 0) {
- ni->open_count++;
- sem = ni->sem;
- _pthread_mutex_unlock(&sem_llock);
- return (sem);
+ if ((flags & (O_CREAT|O_EXCL)) == (O_CREAT|O_EXCL)) {
+ _pthread_mutex_unlock(&sem_llock);
+ errno = EEXIST;
+ return (SEM_FAILED);
+ } else {
+ ni->open_count++;
+ sem = ni->sem;
+ _pthread_mutex_unlock(&sem_llock);
+ return (sem);
+ }
}
}
OpenPOWER on IntegriCloud