0

I am on an IMX chip running a distro with yocto linux. In one of my apps, I am calling mq_open with flags O_CREAT | O_RDWR and mode as S_IROTH | S_IWOTH | S_IRGRP | S_IWGRP | S_IRUSR | S_IWUSR

However, the actual device node is having permissions:

root@NEW-Board:~# ls -l /dev/mqueue/my-ipc
-rw-r--r-- 1 root root 80 Nov 22 12:34 my-ipc

I would have expected the permissions to be -rw-rw-rw-. Whats happening here?

preetam
  • 1,451
  • 1
  • 17
  • 43
  • From the documentation: **The permissions settings are masked against the process umask.** – Barmar Nov 22 '21 at 20:53
  • Just like when you create a file. – Barmar Nov 22 '21 at 20:53
  • So umask applies for message queues. What about shared memory? – preetam Nov 22 '21 at 21:05
  • No, it doesn't apply to shared memory. From `umask(2)`: **The umask does not affect the permissions assigned to System V IPC objects created by the process (using msgget(2), semget(2), shmget(2)).** – Barmar Nov 22 '21 at 21:38
  • I used `fmode = umask(S_IRWXU | S_IRWXG | S_IRWXO); ` before mq_open and `umask(fmode)` after mq_open. It removed all permissions to `----------`. – preetam Nov 22 '21 at 21:53
  • `umask` is the list of permissions to *remove*. If you want the permissions to be exactly what you specified in `mq_open()`, use `umask(0)` – Barmar Nov 22 '21 at 22:10
  • That interesting. So thats why `~(S_IRWXU | S_IRWXG | S_IRWXO)` gave me `-rw-rw-rw-` – preetam Nov 22 '21 at 22:14
  • The man page is confusing when it says `umask() sets the calling process's file mode creation mask (umask) to mask & 0777` and later on goes on to say `Specifically, permissions in the umask are turned off from the mode argument to open(2) and mkdir(2)` – preetam Nov 22 '21 at 22:17
  • That's what I said. removed == turned off. – Barmar Nov 22 '21 at 22:17
  • How about putting an answer so that I can check it as valid answer ? – preetam Nov 22 '21 at 22:18

0 Answers0