1/*
2 * Copyright (c) 2003, Intel Corporation. All rights reserved.
3 * Created by:  crystal.xiong 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 *  mq_notify() test plan:
11 *  mq_notify() will fail with EBADF if the mqdes argument is not a
12 *  valid message queue descriptor.
13 *
14 *  2/17/2004   call mq_close and mq_unlink before exit to release mq
15 *		resources
16 */
17
18#include <stdio.h>
19#include <errno.h>
20#include <mqueue.h>
21#include <fcntl.h>
22#include <signal.h>
23#include <sys/stat.h>
24#include <sys/types.h>
25#include <unistd.h>
26#include "posixtest.h"
27
28#define TEST "8-1"
29#define FUNCTION "mq_notify"
30#define ERROR_PREFIX "unexpected error: " FUNCTION " " TEST ": "
31
32#define NAMESIZE	50
33
34void mqclean(mqd_t queue, const char *qname)
35{
36	mq_close(queue);
37	mq_unlink(qname);
38}
39
40int main()
41{
42	char mqname[NAMESIZE];
43	mqd_t mqdes;
44	struct sigevent notification;
45
46	sprintf(mqname, "/" FUNCTION "_" TEST "_%d", getpid());
47
48	mqdes = mq_open(mqname, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR, 0);
49	if (mqdes == (mqd_t)-1) {
50		perror(ERROR_PREFIX "mq_open()");
51		return PTS_UNRESOLVED;
52	}
53	mqdes = mqdes + 1;
54
55	if (mq_unlink(mqname) != 0) {
56		perror(ERROR_PREFIX "mq_unlink()");
57		return PTS_UNRESOLVED;
58	}
59
60	notification.sigev_notify = SIGEV_SIGNAL;
61	notification.sigev_signo = SIGUSR1;
62
63	if (mq_notify(mqdes, &notification) == -1) {
64		if (EBADF == errno) {
65			printf("Test PASSED \n");
66			mqclean(mqdes, mqname);
67			return PTS_PASS;
68		}
69		else {
70			printf("errno != EBADF \n");
71			mqclean(mqdes, mqname);
72			printf("Test FAILED \n");
73			return PTS_FAIL;
74		}
75	}
76	else {
77		printf("Test FAILED \n");
78		mqclean(mqdes, mqname);
79		return PTS_FAIL;
80	}
81}
82