I have trouble with creating a message queue on linux. The error I'm getting is "Invalid argument". Another thing I have to mansion is that the code is a part of Qt project.
Common mistakes are the name does not start with (/) and the number of arg is not correct, but I have checked those!
here is the code that I'm trying to run:
#define MQ_TEST_PATH "/test_queue"
#define MQ_MAX_MSG_SIZE 256
#define MQ_MAX_MSG_COUNT 20
struct mq_attr mqAttr;
mqAttr.mq_maxmsg = MQ_MAX_MSG_COUNT;
mqAttr.mq_msgsize = MQ_MAX_MSG_SIZE;
mq_unlink(MQ_TEST_PATH);
mode_t mode = S_IRUSR | S_IWUSR;
int oflags = O_WRONLY | O_CREAT | O_EXCL;
mqd_t mqd;
mqd = mq_open(MQ_TEST_PATH, oflags, mode, &mqAttr);
if(mqd < 0){
perror("Error on open");
qDebug()<<mqd;
return 0;
}
mq_close(mqd);
mq_unlink(MQ_TEST_PATH);
Output:
Error on open: Invalid argument
-1
man mq_open
EINVAL
O_CREAT
was specified inoflag
, andattr
was notNULL
, butattr->mq_maxmsg
orattr->mq_msqsize
was invalid. Both of these fields must be greater than zero. In a process that is unprivileged (does not have theCAP_SYS_RESOURCE
capability),attr->mq_maxmsg
must be less than or equal to themsg_max
limit
man mq_overview
> /proc/sys/fs/mqueue/msg_max
The default value for msg_max is 10.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With