LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 09-28-2006, 02:02 AM   #1
Mish
LQ Newbie
 
Registered: Sep 2006
Posts: 2

Rep: Reputation: 0
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
*/
 
Old 09-28-2006, 07:45 PM   #2
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,659
Blog Entries: 4

Rep: Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941
Are you certain that the named semaphore does not somehow already exist?

Anyhow, the Posix standard lists two possibilities for EACCES:
Quote:
  • Valid name specified but oflag permissions are denied, or...
  • the semaphore name specified does not exist and permission to create the named semaphore is denied.
"What makes the third system different from the other two?" Or, what makes you different from the point-of-view of the third system?
 
Old 09-28-2006, 08:16 PM   #3
Mish
LQ Newbie
 
Registered: Sep 2006
Posts: 2

Original Poster
Rep: Reputation: 0
Thanks for your help. Yeah, positive it didn't already exist. I tried using all different names and I had never created semaphores before.

This morning I found the solution to the problem... in a Unix forum respnse from 1997!

From what I now understand, POSIX semaphores are created in shared memory. So you need to make sure that users have rw permissions to /dev/shm for the semaphores to be created.

Then, as a handy option, put the following line in your fstab file to mount tmpfs:

none /dev/shm tmpfs defaults 0 0

So that when your machine is rebooted, the permissions are set right from the start.

That was the difference between my machines. Two of the three had /dev/shm set to drwxrwxrwx and the machine that would not allow creation of semaphores had it set to drwxr_xr_x.

Thanks to all those who may have looked into this problem.

Cheers
Michelle

Last edited by Mish; 09-28-2006 at 08:20 PM.
 
  


Reply

Tags
posix, semaphores



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
ln: creating symbolic link `/dev/dvd' to `/dev/hdc': Permission denied qazwsx27 Fedora 3 06-14-2005 02:09 PM
Posix file based process shared semaphores dragonman Programming 9 05-25-2005 04:44 PM
POSIX semaphores acting strangely spuzzzzzzz Programming 0 10-18-2004 09:10 PM
permission denied error endezeichen Linux - General 5 12-20-2003 06:59 PM
POSIX File-based Semaphores dragonman Linux - Newbie 1 11-17-2002 10:51 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:12 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration