Bug 497723 - forgot to restore callgrind output cleanup
[valgrind.git] / none / tests / mq.c
blob72c150d9a5a4511e3f3fa897790acccecefc7fd4
1 #include <sys/types.h>
2 #include <config.h>
3 #include <errno.h>
4 #include <stdio.h>
5 #include <stdlib.h>
6 #include <string.h>
7 #include <fcntl.h>
9 #if defined(HAVE_MQUEUE_H)
11 #include <mqueue.h>
13 #define MSGMAX 10
14 #define MSGSIZEMAX 1024
16 int main(int argc, char **argv)
18 struct mq_attr mqa, mqa2;
19 mqd_t mqdw;
20 mqd_t mqdr;
21 char buffer[MSGSIZEMAX];
22 unsigned int priority;
23 int len;
25 mqa.mq_maxmsg = MSGMAX;
26 mqa.mq_msgsize = MSGSIZEMAX;
28 if ((mqdw = mq_open("/valgrind-mqueue", O_CREAT|O_EXCL|O_WRONLY, 0600, &mqa)) < 0)
30 if (errno == ENOSYS)
31 exit(0);
32 perror("mq_open");
33 exit(1);
36 if ((mqdr = mq_open("/valgrind-mqueue", O_RDONLY)) < 0)
38 perror("mq_open");
39 mq_unlink("/valgrind-mqueue");
40 mq_close(mqdw);
41 exit(1);
44 if (mq_unlink("/valgrind-mqueue") < 0)
46 perror("mq_unlink");
47 mq_close(mqdw);
48 mq_close(mqdr);
49 exit(1);
52 if (mq_send(mqdw, "PING", 4, 0) < 0)
54 perror("mq_send");
55 mq_close(mqdr);
56 mq_close(mqdw);
57 exit(1);
60 if ((len = mq_receive(mqdr, buffer, sizeof(buffer), &priority)) < 0)
62 perror("mq_receive");
63 mq_close(mqdr);
64 mq_close(mqdw);
65 exit(1);
68 #if !defined(VGO_solaris)
69 /* On Solaris, there is no existing notification registration. */
70 if (mq_notify(mqdr, NULL) < 0)
72 perror("mq_notify");
73 mq_close(mqdr);
74 mq_close(mqdw);
75 exit(1);
77 #endif /* !VGO_solaris */
79 if (len != 4 || memcmp(buffer, "PING", 4) != 0)
81 fprintf(stderr, "Message corrupt!");
84 if (mq_getattr(mqdr, &mqa) < 0)
86 perror("mq_getattr");
87 mq_close(mqdr);
88 mq_close(mqdw);
89 exit(1);
92 mqa2 = mqa;
93 if (mq_setattr(mqdw, &mqa, &mqa2) < 0)
95 perror("mq_setattr");
96 mq_close(mqdr);
97 mq_close(mqdw);
98 exit(1);
101 if (mq_close(mqdr) < 0)
103 perror("mq_close");
104 mq_close(mqdw);
105 exit(1);
108 if (mq_close(mqdw) < 0)
110 perror("mq_close");
111 exit(1);
114 exit(0);
117 #else
119 int main(int argc, char **argv)
121 exit(0);
124 #endif