mkfifo 文件权限未正确执行

发布于 2024-08-03 08:02:46 字数 250 浏览 2 评论 0原文

我的 C 程序中的以下行应提供“所有/组/所有者”读写权限,

mkfifo("/tmp/dumbPipe", 0666)

但是一旦我执行代码并检查未设置写入位的权限,我最终会得到“

prw-r--r-- 

所有者是相同的”,是吗?因为我在 tmp 目录中创建管道,所以出现问题?当我从 cmd 行运行 chmod 666 时,所有权限都得到正确设置。

The following line in my C program should provided All/Group/Owner read and write permissions

mkfifo("/tmp/dumbPipe", 0666)

But once I execute the code and check out the permission non of the write bits were set, I end up with

prw-r--r-- 

The owners are the same, Is it a problem since I'm creating the pipe in the tmp directory? When I run chmod 666 from the cmd line all the permissions get set correctly.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

久随 2024-08-10 08:02:46

这是一篇没有评论的帖子,只是引用手册。简洁等

引用自 man 3 mkfifo:

按照通常的方式由进程的umask修改:创建的文件的权限是(mode & ~umask)。

引自 man 2 umask

进程 umask 的典型默认值为 S_IWGRP | S_IWOTH(八进制 022)。在通常情况下,模式参数为
open(2) 指定为:

<前><代码> S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH

(八进制 0666)创建新文件时,生成的文件的权限将为:

S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH

(因为 0666 & ~022 = 0644;即 rw-r--r--)。

This is a no-comments post, just quoting manuals. Brievity etc.

Quote from man 3 mkfifo:

It is modified by the process's umask in the usual way: the permissions of the created file are (mode & ~umask).

Quote from man 2 umask

The typical default value for the process umask is S_IWGRP | S_IWOTH (octal 022). In the usual case where the mode argument to
open(2) is specified as:

      S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH

  (octal 0666) when creating a new file, the permissions on the resulting file will be:

      S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH

  (because 0666 & ~022 = 0644; i.e., rw-r--r--).
凑诗 2024-08-10 08:02:46

萨拉姆,
我知道为时已晚,但对于其他用户,我选择写此评论
即使你精确的0666作为权限,你也应该知道还有一个因素叫做“进程的文件模式创建”,所以问题是:

如何更改当前进程文件模式的创建?

答案:在程序开头使用 umask(permission) - 并给予 0000 作为权限

http://www.cyberciti.biz/tips/understanding-linux-unix-umask-value-usage.html

这应该有帮助。

Salam,
I know it is to late but for other users I choose to write this comment
Even if you precise 0666 as permission, you should know that there is an another factor that is called " process's file mode creation ", so the question is :

how to change current process file mode creation ?

Answer : use umask(permission) at beginning of your program - and give 0000 as permission

http://www.cyberciti.biz/tips/understanding-linux-unix-umask-value-usage.html

this should help .

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文