I just switched from POSIX to SysV because the limit is much higher on SysV (1024 vs 10). But I still need an higher limit. The limit should be changed at runtime, because it depends on the data the user chooses.
Using POSIX, it was possible to increase the limit but it was necessary to run the code as root every time and I cannot do that.
Is there a way to increase the limit in SysV?
As SYSV IPC are considered deprecated, it is a pity to design brand new applications with thoses old fashioned services.
POSIX message queues are based on a file system. It is usually mounted on /dev/mqueue:
A message queue is created with mq_open(). The attr parameter provides the ability to set some attributes:
According to the documentation, the /proc/sys/fs/mqueue/msg_max file defines the ceiling value for the maximum number of messages in a queue. In Linux 5.4, its default value is DFLT_MSGMAX (10) and its upper limit is HARD_MSGMAX (65536).
The defaults values are defined in the Linux source code (cf. /include/linux/ipc_namespace.h):
Here is an example program which creates a message queue. It receives as parameters the message queue name and the maximum number of messages in the queue:
At execution time we can verify that, by default, we can't go above 10 messages for the queue:
Let's change the ceiling value from 10 to 256 for msg_max:
Now it is possible to create message queues with up to 256 messages:
But as you say, increasing the ceiling value requires super user rights. It could be possible to create a "setuid helper" which increases the ceiling value. For example, the following program sets the ceiling value passed as parameter:
We can build it, change its owner/group to root and add the setuid bit:
Then, it is possible to run this program from a non super user account to change the ceiling value of msg_max:
Note: some file systems are mounted with the
nosuidoption to prevent users from introducing privileged programs.