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 if O_EXCL and O_CREAT are set and message queue name already
11 * exists, mq_open() fails.
12 */
13
14#include <stdio.h>
15#include <mqueue.h>
16#include <fcntl.h>
17#include <sys/stat.h>
18#include <sys/types.h>
19#include <unistd.h>
20#include <string.h>
21#include "posixtest.h"
22
23#define NAMESIZE 50
24
25int main()
26{
27        char qname[NAMESIZE];
28        mqd_t queue, queue2;
29
30        sprintf(qname, "/mq_open_15-1_%d", getpid());
31
32        queue = mq_open(qname, O_CREAT |O_RDWR, S_IRUSR | S_IWUSR, NULL);
33        if (queue == (mqd_t)-1) {
34                perror("mq_open() did not return success");
35		printf("Test UNRESOLVED\n");
36		return PTS_UNRESOLVED;
37        }
38
39	/*
40	 * Open queue qname again with O_CREAT and O_EXCL set
41	 */
42	queue2 = mq_open(qname, O_CREAT |O_EXCL|O_RDWR,
43			S_IRUSR | S_IWUSR, NULL);
44        if (queue2 != (mqd_t)-1) {
45                printf("mq_open() should have failed with O_CREAT and \n");
46                printf("O_EXCL on an already opened queue.\n");
47		printf("Test FAILED\n");
48		mq_close(queue);
49		mq_close(queue2);
50		mq_unlink(qname);
51                return PTS_FAIL;
52        }
53
54	mq_close(queue);
55	mq_unlink(qname);
56
57        printf("Test PASSED\n");
58        return PTS_PASS;
59}
60
61