我这样mq_open
打电话linux 5.5.6
:
mq_open("/testing12345", O_RDWR | O_CREAT | O_NONBLOCK, 0777, & (struct mq_attr) {0, 10, 255, 0));
请注意,我0777
作为第三个参数传递。
该函数成功并创建了适当的 mqueue,之后我从我的 shell 挂载 mqueue 文件系统:
mount -t mqueue none ./mqueue_dir
然而,统计新 mqueue 的节点显示0755
为访问位:
stat -c %a ./mqueue_dir/testing12345
0755
这是为什么?0777
我在调用 mq_open 时清楚地传递了常量。
可重现的例子
编译gcc -Wall -Werror -lrt a.c -o ./a
#include <fcntl.h>
#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
#include <mqueue.h>
#include <sys/types.h>
#include <sys/stat.h>
int main(void) {
const mqd_t descriptor = mq_open("/testing12345", O_RDWR | O_CREAT | O_NONBLOCK, 0777, & (struct mq_attr) {0, 10, 255, 0});
if(descriptor == -1) {
perror("parent: failed opening mqueue");
return EXIT_FAILURE;
}
sleep(30u);
mq_unlink("/testing123");
return EXIT_SUCCESS;
}