This is the mail archive of the
newlib@sources.redhat.com
mailing list for the newlib project.
Re: Message queue support
- From: "J. Johnston" <jjohnstn at redhat dot com>
- To: Jose Miguel Goncalves <jose dot goncalves at inov dot pt>
- Cc: newlib at sources dot redhat dot com
- Date: Fri, 27 Jun 2003 16:28:41 -0400
- Subject: Re: Message queue support
- Organization: Red Hat Inc.
- References: <3EF98C51.30208@inov.pt> <3EF9E64F.3090009@redhat.com> <3EFB4D6A.8080207@inov.pt> <3EFB8A3A.8010605@redhat.com> <3EFC64B7.5000601@inov.pt>
Thanks Jose,
The first part regarding the "created" flag is correct, however, I do not agree
with the 2nd part of your change. That code ensures that the creator of the shared memory file also
owns the semaphores. Once the "created" flag has been set correctly, it should work for
your test.
-- Jeff J.
Jose Miguel Goncalves wrote:
Jeff,
I have found another bug in mq_open(). When called more than once (for
the same queue) with O_CREAT flag set, it fails. Sugested patch:
===================================================================
RCS file: /cvs/src/src/newlib/libc/sys/linux/mq_open.c,v
retrieving revision 1.3
diff -p -u -r1.3 mq_open.c
--- mq_open.c 27 Jun 2003 00:00:48 -0000 1.3
+++ mq_open.c 27 Jun 2003 14:53:04 -0000
@@ -98,7 +98,8 @@ mq_open (const char *name, int oflag, ..
return (mqd_t)-1;
}
errno = saved_errno;
- created = 1;
+ if (fd >= 0)
+ created = 1;
}
if (fd < 0)
@@ -132,9 +133,12 @@ mq_open (const char *name, int oflag, ..
saved_errno = errno;
semid = semget (key, 6, IPC_CREAT | IPC_EXCL | mode);
errno = saved_errno;
- /* now that we have created the semaphore, we should initialize
it */
if (semid != -1)
+ /* now that we have created the semaphore, we should initialize
it */
semctl (semid, 0, SETVAL, arg);
+ else
+ /* semaphore already exists, so we get only it's id */
+ semid = semget (key, 6, 0);
}
else
{
Regards,
José Gonçalves
J. Johnston wrote:
Jose,
I found a serious problem with opening an existing queue for read
whereby the
read/write buffers were not being allocated. A patch has been
committed to the
sources. With that patch applied I was able to run your test case
successfully.
-- Jeff J.
Jose Miguel Goncalves wrote:
Jeff,
After setting up /dev/shm I could create a queue with mq_open(), and
send messages with mq_send(), but calling to mq_receive() returns
errors - "Bad address".
I attach the source code for the simple mqueue test application that
I'm using. I am compiling in a 2.4.21 linux kernel with:
$ gcc -static -nostdlib -g -Wall -D_REENTRANT
-I/usr/local/newlib/i686-pc-linux-gnu/include
/usr/local/newlib/i686-pc-linux-gnu/lib/crt0.o test_thread_queue.c
-L/usr/local/newlib/i686-pc-linux-gnu/lib -lpthread -lc -lgcc -o
test_thread_queue
The same source compiled in a Sun Solaris 8 machine (with native
support for pthreads and mqueues) works fine.
Regards,
José Gonçalves