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?
It’s probably
umask.Citing the manpage of
shm_open:So, in order to allow creating files which are world-writable, you’d need to set an umask permitting it, for example:
Set like this,
umaskwon’t affect any permissions on created files anymore. However, you should note that if you will then create another file without specifying permissions explicitly, it will be world-writable as well.Thus, you may want to clear the umask only temporarily, and then restore it: