|
permission denied error creating POSIX semaphores
Hi,
Can anyone tell me what area I should be looking in to solve a permission denied error when creating a POSIX semaphore?
I understand that the error means:
the semaphore already exists, and the permissions specified are denied OR the semaphore does not exist, and the permissions specified to create it are denied.
I have three Linux machines, all built with the RHEL 4 distro, using gcc -lrt to link and have the same user id & group id set.
(All three machines are from different vendors, not that the HW probably matters?).
I can create semaphores on two of the machines but not on the third. I am using the same code (NFS mounted machines). What could be set different on the machines that would cause the EACCES (permission denied) error on only one of them???Where/what exactly am I being denied permission to?
Here is my crude code:
/*
** seminit.c -- sets up a POSIX semaphore
*/
#include <sys/stat.h>
#include <sys/sem.h>
#include <stdio.h>
#include <stdlib.h>
#include <semaphore.h>
#include <errno.h>
#include <fcntl.h>
int main (int argc, char *argv[])
{
sem_t *mySem;
mySem=sem_open("/name1", O_CREAT | O_EXCL, 0666, 2);
if (mySem == SEM_FAILED)
{
/* Check the error value */
if (errno == EACCES)
{
/* Permission is denied */
printf("Error: EACCESS Permission denied\n");
}
else
{
/* Show the other error */
printf("Some other error");
/* return; */
}
}
else
{
/* Process created the semaphore */
int a1;
sem_wait(mySem);
printf("Sample data written\n");
sem_getvalue(mySem, &a1);
printf("Value of mySem=%d \n", a1);
sem_unlink("/name1");
sem_close(mySem);
exit(0);
}
}
/*
** End seminit.c
*/
|