xref: /freebsd/tests/sys/mqueue/mqtest1.c (revision e2340276fc734a1f0bd0d2cf16fcfba7936c9462)
1 
2 #include <err.h>
3 #include <errno.h>
4 #include <fcntl.h>
5 #include <mqueue.h>
6 #include <signal.h>
7 #include <stdio.h>
8 
9 #include "freebsd_test_suite/macros.h"
10 
11 #define MQNAME	"/mytstqueue1"
12 
13 int
14 main(void)
15 {
16 	struct mq_attr attr, attr2;
17 	struct sigevent sigev;
18 	mqd_t mq;
19 	int status;
20 
21 	PLAIN_REQUIRE_KERNEL_MODULE("mqueuefs", 0);
22 
23 	attr.mq_maxmsg  = 2;
24 	attr.mq_msgsize = 100;
25 	mq = mq_open(MQNAME, O_CREAT | O_RDWR | O_EXCL, 0666, &attr);
26 	if (mq == (mqd_t)-1)
27 		err(1, "mq_open");
28 	status = mq_unlink(MQNAME);
29 	if (status)
30 		err(1, "mq_unlink");
31 	status = mq_getattr(mq, &attr2);
32 	if (status)
33 		err(1, "mq_getattr");
34 	if (attr.mq_maxmsg != attr2.mq_maxmsg)
35 		err(1, "mq_maxmsg changed");
36 	if (attr.mq_msgsize != attr2.mq_msgsize)
37 		err(1, "mq_msgsize changed");
38 
39 	sigev.sigev_notify = SIGEV_SIGNAL;
40 	sigev.sigev_signo = SIGRTMIN;
41 	status = mq_notify(mq, &sigev);
42 	if (status)
43 		err(1, "mq_notify");
44 	status = mq_notify(mq, &sigev);
45 	if (status == 0)
46 		err(1, "mq_notify 2");
47 	else if (errno != EBUSY)
48 		err(1, "mq_notify 3");
49 	status = mq_notify(mq, NULL);
50 	if (status)
51 		err(1, "mq_notify 4");
52 	status = mq_close(mq);
53 	if (status)
54 		err(1, "mq_close");
55 	return (0);
56 }
57