I'm calling mq_open on linux 5.5.6 like so:
mq_open("/testing12345", O_RDWR | O_CREAT | O_NONBLOCK, 0777, & (struct mq_attr) {0, 10, 255, 0));
Note that I passed 0777 as the 3rd argument.
The function succeeds and the appropriate mqueue is created, after which I mount the mqueue filesystem from my shell:
mount -t mqueue none ./mqueue_dir
However, stat-ing the new mqueue's node reveals 0755 as the access bits:
stat -c %a ./mqueue_dir/testing12345
0755
Why is that? I clearly passed the 0777 constant when calling mq_open.
Reproducible example
compiled with 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;
}
Your "file creation mask" setting is almost certainly set to
022, thereby "masking" the0777you specified "down" to0755.Per the POSIX
umask()documentation (bolding mine):See also When is umask() useful?.
Effectively, in order to ensure the file(s) you create have a specific mode, you either have to blank out the file creation mask with
umask( 0 ), or you have to explicitly set the exact mode you want after you create the file. Since callingumask()affects the state of the entire process, it's almost always better to explicitly set the mode directly.