This is the mail archive of the cygwin mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Re: Cygwin 1.7 message queues - permission denied error still exists


Corinna Vinschen schrieb:
> On Sep 13 16:32, Christopher Faylor wrote:
>   
>> I just modified the test case from the original report:
>>
>>     
>>>>> cut here<<<
>>>>>           
>> >>> here was the test case which opens 2 queues un same process <<<
>>     
>>>>> cut here<<<
>>>>>           
>> It behaves the same on both linux and cygwin.
>>
>> Make sure that you've read:
>>
>> http://cygwin.com/faq/faq-nochunks.html#faq.programming.ipc
>>
>> And have cygserver running properly.
>>     
>
> Just FYI, running Cygserver is required only for XSI IPC.  The POSIX
> IPC functions are supposed to work without Cygserver.
>
>
> Corinna
>
>   
Hi,

there is another problem with the queues.
The mentioned test case opens two different queues in the same process.

But if you open the same queue in two different processes you get also a
permission denied error.

I add here some test case:
--- file: receiver.c -----------------------
#include <stdio.h>
#include <mqueue.h>
#include <fcntl.h>
#include <stdlib.h>
#include <assert.h>

int
main ()
{
  int i;
  const struct mq_attr attr = {.mq_flags = 0,.mq_maxmsg = 8,.mq_msgsize
= 4,.mq_curmsgs = 0};
  mqd_t mq = mq_open ("/demo", O_RDONLY | O_CREAT, 0644, &attr);
  if (mq == -1) {
    perror ("Receiver: mq_open");
    exit (1);
  }
  for (i = 1; i < 20; i++) {
    int r;
    ssize_t msg_size = mq_receive (mq, (char*)&r, sizeof (r), NULL);
    assert (msg_size == sizeof (int));
    if (msg_size == -1) {
      perror ("Receiver: mq_receive");
      exit (1);
    }
    printf ("%d. received %d\n", i, r);
  }
  mq_close (mq);

  return 0;
}
------------------------------------------
--- file: sender.c ----------------------
#include <stdio.h>
#include <mqueue.h>
#include <fcntl.h>
#include <stdlib.h>

int main (){
  int i;
  const struct mq_attr attr = {.mq_flags = 0,.mq_maxmsg = 8,.mq_msgsize
= 4,.mq_curmsgs = 0};
  mqd_t mq = mq_open ("/demo", O_WRONLY | O_CREAT, 0644, &attr);
  if (mq == -1) {
    perror ("Sender: mq_open");
    exit (1);
  }
  for (i = 1; i < 20; i++) {
    mqd_t mq_result = mq_send (mq, (char *) &i, sizeof (i), 1);
    if (mq_result == -1) {
      perror ("Sender: mq_send");
      exit (1);
    }
    printf ("Sent %d\n", i);
  }
  mq_close (mq);

  return 0;
}
-----------------------------------------
It just sends an integer from sender to receiver.

Compiled on linux with:
gcc -g -o receiver receiver.c -lrt
gcc -g -o sender sender.c -lrt

On Linux you can start them in any order in two terminal windows and get:
---------------------------
# ./sender
Sent 1
Sent 2
...
Sent 18
Sent 19
#
---------------------------
and
---------------------------
# ./receiver
1. received 1
2. received 2
...
18. received 18
19. received 19
#
---------------------------

However on cygwin it doesn't matter which of the processes you start
first, the second one will get a permission denied.
---------------------------
$ ./sender
Sent 1
Sent 2
Sent 3
Sent 4
Sent 5
Sent 6
Sent 7
Sent 8
--- it waits here to get free places in queue (when receiver is running)
---------------------------
But the receiver gets this:
---------------------------
$ ./receiver
Receiver: mq_open: Permission denied
---------------------------

Kind regards

René Liebscher

BTW:
Before someone asks for it:
---------------------------
$ uname -r
1.7.0(0.212/5/3)
$ uname -v
2009-09-11 01:25
---------------------------

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]