Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 9 Apr 2012 14:20:18 GMT
From:      dfilter@FreeBSD.ORG (dfilter service)
To:        freebsd-bugs@FreeBSD.org
Subject:   Re: kern/166706: commit references a PR
Message-ID:  <201204091420.q39EKIK5022249@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help
The following reply was made to PR kern/166706; it has been noted by GNATS.

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: kern/166706: commit references a PR
Date: Mon,  9 Apr 2012 14:17:32 +0000 (UTC)

 Author: jilles
 Date: Mon Apr  9 14:17:22 2012
 New Revision: 234057
 URL: http://svn.freebsd.org/changeset/base/234057
 
 Log:
   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
 
 Modified:
   head/lib/libc/gen/sem_new.c
 
 Modified: head/lib/libc/gen/sem_new.c
 ==============================================================================
 --- head/lib/libc/gen/sem_new.c	Mon Apr  9 14:16:24 2012	(r234056)
 +++ head/lib/libc/gen/sem_new.c	Mon Apr  9 14:17:22 2012	(r234057)
 @@ -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);
 +			}
  		}
  	}
  
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 



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