FreeBSD Bugzilla – Attachment 142353 Details for
Bug 189353
POSIX sem_unlink does not actually unlink the semaphore in the process context
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
sem_test.c
sem_test.c (text/plain), 1.79 KB, created by
joris
on 2014-05-04 13:46:43 UTC
(
hide
)
Description:
sem_test.c
Filename:
MIME Type:
Creator:
joris
Created:
2014-05-04 13:46:43 UTC
Size:
1.79 KB
patch
obsolete
>#include <fcntl.h> >#include <sys/stat.h> >#include <sys/wait.h> >#include <sys/types.h> >#include <semaphore.h> > >#include <stdio.h> >#include <unistd.h> > >#include <err.h> >#include <errno.h> > > >int main() { > pid_t pid; > sem_t *sem1, *sem2; > int error, saved_errno, status; > int v1, v2; > int pd[2]; > char er[1]; > char ok[1]; > char buf[1]; > size_t size; > > *er = 'X'; > *ok = 'O'; > > if (pipe(pd) == -1) > err(1, "Cannot create sync pipe"); > > sem1 = sem_open("/test-sem", O_CREAT | O_EXCL, S_IRWXU, 1); > if (sem1 == SEM_FAILED) > err(1,"Cannot create test /test-sem semaphore"); > > char c = getchar(); > pid = fork(); > > if ( pid == -1) > err(1, "Unable to fork test process"); > > if (pid == 0) { > > close(pd[0]); > > error = sem_unlink("/test-sem"); > > if (error) { > perror("Cannot unlink semaphore /test-sem"); > goto error; > } > > sem2 = sem_open("/test-sem", O_CREAT | O_EXCL, S_IRWXU, 2); > > if (sem2 == SEM_FAILED) { > perror("Cannot re-create semaphore /test-sem"); > goto error; > } > > write(pd[1], ok, 1); > > error = wait(&status); > if (error && errno == EINTR) > goto error; > > return(status); >error: > write(pd[1], er, 1); > close(pd[1]); > error = wait(&status); > if (error && errno == EINTR) > goto error; > > errx(1, "TEST UNRESOLVED"); > > return(1); > > } else { > > close(pd[1]); > size = read(pd[0], buf, 1); > > if (size != 1) > err(2, "process 2 cannot wait for process 1"); > > if (*buf == *er) > errx(2, "Test error"); > else { > > sem2 = sem_open("/test-sem", 0); > > if (sem2 == SEM_FAILED) > err(2, "process 2 failed reopeing semaphore"); > > // sem_unlink("/test-sem"); > > sem_getvalue(sem1, &v1); > sem_getvalue(sem2, &v2); > printf("v1 = %d and v2 = %d\n", v1, v2); > if (v1 == v2) { > errx(2, "*** TEST FAILED. NOT POSIX ***"); > } else { > errx(0, "*** TEST SUCCESS. POSIX CONFORMANT ***"); > } > } > > } >} >
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 189353
:
142352
| 142353