mq_open - unable to create message queue.

I'm trying to use message queues on Sun OS 5.6 with Workshop 5 C++. The following command should create one for me:

mqd_t q = mq_open("my_q", O_CREATE | O_RDWR)

This returns -1 and errno is 16 (Invalid argument). If I use "/my_q", it still returns -1 but the error code is 0. Is there a special queue name that I should be using? Any help would be appreciated,

Bruce Edgerton

[409 byte] By [] at [2007-11-25 23:41:24]
# 1
I solved the problem myself, thank you. I missed the solution within the documentation. For mq_opwn with O_CREAT, you must supplu the additional parameters mode and attribute, I used 644 and 0 in this case and all was well.
at 2007-7-5 18:49:02 > top of Java-index,Development Tools,Solaris and Linux Development Tools...
# 2

I did same thing as above description on Solaris 2.6 and WorkShop 4.0 C++. It returns -1 and errno is 16 (Invalid argument). I did use "/my_q" as name for message queue. Here is my code:

open_flags = O_CREAT|O_RDWR;

mqfd = mq_open("/myipc",O_CREAT|O_RDWR,644,0);

if (mqfd == (mqd_t)-1)

{

perror("mq_open failure from main");

exit(0);

};

Anything wrong? Please help

Howard

wanghoward at 2007-7-5 18:49:02 > top of Java-index,Development Tools,Solaris and Linux Development Tools...
# 3

Howard,

Your piece of code should work as it is, but the error you

report is confusing. Errno 16 is actually EBUSY which is

"Mount device busy". The "Invalid argument" error has an errno

code of 22.

Here is a sample piece of code that worked fine:

<pre>

#include <stdio.h>

#include <mqueue.h>

#include <errno.h>

main(int argc, char **argv)

{

mqd_tmqfd;

mqfd = mq_open("/my_mq", O_CREAT|O_RDWR, 644, 0);

if (mqfd == (mqd_t)-1)

{

perror("mq_open failure from main");

printf("Errno = %d\n",errno);

exit(0);

}

else

{

printf("Message Queue opened successfully (%d)\n", (int)mqfd);

}

}

</PRE>



If you still have problems, then try running your program with

truss to see what's going wrong. You can also check the files

which mq_open creates on the file system. On Solaris 2.6,

three files are created in /tmp for every message queues:

<pre>

ls -la /tmp

-rw-rw-1 guestss-ts132632 Aug 14 11:10 /tmp/.MQDmy_mq

-rw-rw-rw-1 guestss-ts 0 Aug 14 11:10 /tmp/.MQLmy_mq

--w-r--1 guestss-ts 0 Aug 14 11:10 /tmp/.MQPmy_mq

</pre>


Regards,

Caryl

Sun Developer Technical Support

carylt at 2007-7-5 18:49:02 > top of Java-index,Development Tools,Solaris and Linux Development Tools...