Date: Fri, 6 Apr 2012 21:06:42 GMT From: Ion Gaztaņaga <igaztanaga@gmail.com> To: freebsd-gnats-submit@FreeBSD.org Subject: kern/166706: sem_open incorrectly returns the already opened named semaphore handle when O_EXCL is used Message-ID: <201204062106.q36L6gDC067777@red.freebsd.org> Resent-Message-ID: <201204062110.q36LA1Uf079631@freefall.freebsd.org>
next in thread | raw e-mail | index | archive | help
>Number: 166706 >Category: kern >Synopsis: sem_open incorrectly returns the already opened named semaphore handle when O_EXCL is used >Confidential: no >Severity: serious >Priority: medium >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Fri Apr 06 21:10:01 UTC 2012 >Closed-Date: >Last-Modified: >Originator: Ion Gaztaņaga >Release: 9.0 RELEASE >Organization: >Environment: FreeBSD pcbsd-5366 9.0 RELEASE FreeBSD 9.0 RELEASE (...) PCBSD amd64 >Description: POSIX states that if O_EXCL and O_CREAT are set, sem_open() fails if the semaphore name exists, even if the semaphore was already opened by the current process. The following test case shows the problem: #include <semaphore.h> #include <fcntl.h> #include <stdio.h> #include <semaphore.h> #include <fcntl.h> #include <stdio.h> int main() { sem_t *sem1, *sem2; sem_unlink("/testsem"); sem1 = sem_open("/testsem", O_CREAT|O_EXCL, 0644, 1); if(sem1 == SEM_FAILED){ return 1; } sem2 = sem_open("/testsem", O_CREAT|O_EXCL, 0644, 1); if(sem2 != SEM_FAILED){ printf("ERROR: semaphore already created O_EXCL should fail\n"); sem_close(sem2); sem_unlink("/testsem"); return 1; } printf("OK: semaphore already created, O_EXCL has failed\n"); sem_close(sem1); sem_unlink("/testsem"); return 0; } In FreeBSD 9 the test fails, whereas in FreeBSD 8 (FreeBSD pcbsd-4080 8.0-RELEASE-p2 FreeBSD 8.0-RELEASE-p2 (...) PCBSD i386) the test passes. >How-To-Repeat: Run the test case >Fix: >Release-Note: >Audit-Trail: >Unformatted:
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201204062106.q36L6gDC067777>