shm_open 未设置组写入权限

shm_open not setting group write access

我正在像这样创建一个新的共享内存对象

  int fd = shm_open("somekey", O_CREAT | O_RDWR, S_IRWXU | S_IRWXG);

return 值很好,我希望在 /dev/shm

中找到类似以下内容
-rwxrwx--- 1 root   group     4096 Jun 27 19:08 somekey

但是文件中的写入权限丢失了,我不知道为什么。

-rwxr-x--- 1 root   group     4096 Jun 27 19:08 somekey

http://man7.org/linux/man-pages/man3/shm_open.3.html

the object's permission bits are set according to the low-order 9 bits of mode, except that those bits set in the process file mode creation mask (see umask(2)) are cleared for the new object.

这只是 umask 的工作,就像它对常规 open 所做的一样。

您的问题与以下线程重复

POSIX shared memory and semaphores permissions set incorrectly by open calls

mode_t old_umask = umask(0);

int fd = shm_open("somekey", O_CREAT | O_RDWR, S_IRWXU | S_IRWXG);

// restore old
umask(old_umask);