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_CREAT is set and name has already been used to create
11 * a currently existing message queue, then the current call has no effect.
12 *
13 * Just test by calling O_CREAT again and ensure mq_send works again (i.e.,
14 * Basically just testing that using O_CREAT twice doesn't break anything.
15 * Otherwise, this assertion is basically untestable.)
16 */
17
18#include <stdio.h>
19#include <mqueue.h>
20#include <fcntl.h>
21#include <sys/stat.h>
22#include <sys/types.h>
23#include <unistd.h>
24#include <string.h>
25#include "posixtest.h"
26
27#define NAMESIZE 50
28#define MSGSTR "0123456789"
29
30int main()
31{
32        char qname[NAMESIZE];
33        const char *msgptr = MSGSTR;
34        mqd_t queue, queue2;
35
36        sprintf(qname, "/mq_open_11-1_%d", getpid());
37
38        queue = mq_open(qname, O_CREAT |O_RDWR, S_IRUSR | S_IWUSR, NULL);
39        if (queue == (mqd_t)-1) {
40                perror("mq_open() did not return success");
41		printf("Test FAILED\n");
42                return PTS_FAIL;
43        }
44
45        if (mq_send(queue, msgptr, strlen(msgptr), 1) != 0) {
46                perror("mq_send() first time did not return success");
47		printf("Test UNRESOLVED\n");
48		mq_close(queue);
49		mq_unlink(qname);
50		return PTS_UNRESOLVED;
51        }
52
53	/*
54	 * Second call should have no effect
55	 */
56        queue2 = mq_open(qname, O_CREAT |O_RDWR, S_IRUSR | S_IWUSR, NULL);
57        if (queue2 == (mqd_t)-1) {
58                perror("mq_open() second time did not return success");
59		printf("Test FAILED\n");
60		mq_close(queue);
61		mq_unlink(qname);
62                return PTS_FAIL;
63        }
64
65        if (mq_send(queue2, msgptr, strlen(msgptr), 1) != 0) {
66                perror("mq_send() did not return success second time");
67		printf("Test FAILED\n");
68		mq_close(queue);
69		mq_close(queue2);
70		mq_unlink(qname);
71                return PTS_FAIL;
72        }
73
74	mq_close(queue);
75	mq_close(queue2);
76	mq_unlink(qname);
77
78        printf("Test PASSED\n");
79        return PTS_PASS;
80}
81
82