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
This commit is contained in:
Jilles Tjoelker 2012-04-09 14:17:22 +00:00
parent ac5b109f31
commit 5844994b1e
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=234057

View File

@ -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);
}
}
}