1/*
2 * Copyright (c) 2003, Intel Corporation. All rights reserved.
3 * Created by:  julie.n.fleischer REMOVE-THIS AT intel DOT com
4 * This file is licensed under the GPL license.  For the full content
5 * of this license, see the COPYING file at the top level of this
6 * source tree.
7 */
8
9/*
10 * Test that a message queue can be opened more than once for read-only
11 * in the same process.
12 *
13 * Note:  Just testing that it can be opened.  No tests that it truly
14 * is read-only (that's 7-1.c and 7-2.c)
15 */
16
17#include <stdio.h>
18#include <mqueue.h>
19#include <fcntl.h>
20#include <sys/stat.h>
21#include <sys/types.h>
22#include <unistd.h>
23#include <string.h>
24#include "posixtest.h"
25
26#define NAMESIZE 50
27
28int main()
29{
30        char qname[NAMESIZE];
31        mqd_t roqueue, roqueue2;
32
33        sprintf(qname, "/mq_open_7-3_%d", getpid());
34
35        roqueue = mq_open(qname, O_CREAT |O_RDONLY, S_IRUSR | S_IWUSR, NULL);
36        if (roqueue == (mqd_t)-1) {
37                perror("mq_open() for read-only queue did not return success");
38		printf("Test FAILED\n");
39                return PTS_FAIL;
40        }
41
42        roqueue2 = mq_open(qname, O_RDONLY, S_IRUSR | S_IWUSR, NULL);
43        if (roqueue2 == (mqd_t)-1) {
44                perror("Second mq_open() for rd-only queue didn't ret success");
45		printf("Test FAILED\n");
46                return PTS_FAIL;
47        }
48
49	mq_close(roqueue);
50	mq_close(roqueue2);
51	mq_unlink(qname);
52
53        printf("Test PASSED\n");
54        return PTS_PASS;
55}
56
57