standards/189353: POSIX sem_unlink does not actually unlink the semaphore in the process context

Joris joris at giovannangeli.fr
Sun May 4 11:20:00 UTC 2014


>Number:         189353
>Category:       standards
>Synopsis:       POSIX sem_unlink does not actually unlink the semaphore in the process context
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-standards
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Sun May 04 11:20:00 UTC 2014
>Closed-Date:
>Last-Modified:
>Originator:     Joris
>Release:        freebsd 10
>Organization:
>Environment:
>Description:
When a posix sempahore is open, it is cached in the process address space. A call to sem_unlink does not invalidate the caching, and trying to reopen the semaphore with O_EXCL after calling sem_unlink fails with EEXIST.
>How-To-Repeat:
Here is a test case :

#include <fcntl.h>
#include <sys/stat.h>
#include <sys/wait.h>
#include <sys/types.h>
#include <semaphore.h>

#include <err.h>


int
main(int argc, char *argv[])
{
	sem_t *sem1, *sem2;
	int error;

	sem1 = sem_open("/test-sem1", O_CREAT | O_EXCL, S_IRWXU, 1);
	if (sem1 == SEM_FAILED)
		err(1,"Cannot create test /test-sem1 semaphore");

	error = sem_unlink("/test-sem1");

	if (error)
		err(1, "Cannot unlink semaphore /test-sem1");


	sem2 = sem_open("/test-sem1", O_CREAT | O_EXCL, S_IRWXU, 2);

	if (sem2 == SEM_FAILED)
		err(1, "Cannot re-create semaphore /test-sem1");

	error = sem_unlink("/test-sem1");

	if (error)
		err(1, "Cannot unlink semaphore /test-sem1");

	return(0);
}

>Fix:


>Release-Note:
>Audit-Trail:
>Unformatted:


More information about the freebsd-standards mailing list