POSIX shared memory and semaphores permissions set incorrectly by open calls

Viewed 6637

I'm trying to create a shared memory which will be used by several processes, which will not necessarily be started by the same user, so I create the segment with the following line:

fd = shm_open(SHARE_MEM_NAME,O_RDWR | O_CREAT,0606);

however, when I check out the permissions of the file created in /dev/shm they are:

-rw----r-- 1 lmccauslin lmccauslin 1784 2012-08-10 17:11 /dev/shm/CubeConfigShare not -rw----rw- as I'd expected.

the permissions for /dev/shm are lrwxrwxrwx.

The exact same thing happens with the semaphore created similarly.

kernel version: 3.0.0-23-generic

glibc version: EGLIBC 2.13-20ubuntu5.1

Anyone got any ideas?

2 Answers

From what I 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 /etc/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.

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.
You can also look at shared memory limits:

------ Shared Memory Limits --------
max number of segments = 4096
max seg size (kbytes) = 18014398509465599 max total shared memory (kbytes) = 18446744073642442748
min seg size (bytes) = 1

Related