【问题标题】:shm_open not setting group write accessshm_open 未设置组写访问权限
【发布时间】:2018-12-06 16:04:29
【问题描述】:

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

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

返回值很好,我希望在 /dev/shm 中找到类似以下内容

-rwxrwx--- 1 root   group     4096 Jun 27 19:08 somekey

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

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

【问题讨论】:

    标签: linux file-permissions shared-memory


    【解决方案1】:

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

    对象的权限位根据mode的低9位设置,除了那些在进程文件模式创建掩码中设置的位(见umask(2))被清除为新的对象。

    它只是 umask 做它的工作,就像它为一个普通的 open 做的一样。

    【讨论】:

      【解决方案2】:

      您的问题与以下线程重复

      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);
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2018-08-22
        • 2017-10-22
        • 2015-01-24
        • 2014-09-23
        • 1970-01-01
        • 2021-02-12
        • 2013-01-06
        • 2012-07-19
        相关资源
        最近更新 更多