Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 4 May 2012 20:45:53 +0000 (UTC)
From:      Jilles Tjoelker <jilles@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-9@freebsd.org
Subject:   svn commit: r235035 - stable/9/lib/libc/gen
Message-ID:  <201205042045.q44Kjrs8022031@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: jilles
Date: Fri May  4 20:45:53 2012
New Revision: 235035
URL: http://svn.freebsd.org/changeset/base/235035

Log:
  MFC r234057: 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

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	Fri May  4 20:31:27 2012	(r235034)
+++ stable/9/lib/libc/gen/sem_new.c	Fri May  4 20:45:53 2012	(r235035)
@@ -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);
+			}
 		}
 	}
 



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201205042045.q44Kjrs8022031>