views:

342

answers:

3

Hi I have 2 processes P1 and P2. P1 is running as root, and is creating a semaphore with the following call:

semget (key, 1, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH | IPC_CREAT);

and am trying to get the handle to the same semaphore in another process P2, which is running under the normal user's context. In this process, the semget call succeeds, but semop calls fail with "Permission Denied" (Errno = 13).

Any pointers would be of great help.

~ps7

A: 

What is the language we are talking about?

I think there is some error in importing the S_ constants, so that they are null and make no effect.

What about a brute test with the bit mask as is? Try use directly IPC_CREAT | 0666

my 2 cents :)

AlberT
A: 

"Permission denied"/EACCES is, of course, consistent with unprivileged process P2 trying to semget an extant semaphore for which it lacks access. So, perhaps there is already an extant semaphore under that key which lacks the needed S_IWOTH|S_IROTH permissions. (Perhaps a remnant from an early version of P1?)

What does ipcs -s say the semaphore's permissions are? What happens if you add IPC_EXCL to your semget call in P1? Will it fail?

pilcrow
A: 

Use S_IRUSR and S_IWUSR specify read and write permissions for the owner of the shared memory segment, and S_IROTH and S_IWOTH specify read and write permissions for others flags as the third arguement in the shmget().

IPC_CREATE only guarantees that the new shared memory segment should be created corresponding to the key value. Usually shmget() fails if the the segment specified with the key value exists.

Sachin Chourasiya