栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

POSIX共享内存和信号灯权限因打开调用而设置不正确

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

POSIX共享内存和信号灯权限因打开调用而设置不正确

可能是

umask

援引的手册页

shm_open

   O_CREAT    Create  the  shared memory object if it does not exist.  The user and   group ownership of the object are taken from the corresponding effec‐   tive IDs of the calling process, and 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.  A set of macro constants which can  be  used  to   define  mode  is  listed  in open(2).  (Symbolic definitions of these   constants can be obtained by including <sys/stat.h>.)

因此,为了允许创建可全局写入的文件,您需要设置允许它的umask,例如:

umask(0);

进行这样的设置,

umask
将不再影响已创建文件的任何权限。但是,您应该注意,如果您随后创建另一个文件而未明确指定权限,那么该文件也是可写的。

因此,您可能只想暂时清除umask,然后将其还原:

#include <sys/types.h>#include <sys/stat.h>...void yourfunc(){    // store old    mode_t old_umask = umask(0);    int fd = shm_open(SHARE_MEM_NAME,O_RDWR | O_CREAT,0606);    // restore old    umask(old_umask);}


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/409013.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号