1 #include <stdio.h>
2 #include <errno.h>
3 #include <sys/msg.h>
4
5 int
main(void)6 main(void)
7 {
8 int rc, id;
9 struct msqid_ds ds;
10
11 id = msgget(IPC_PRIVATE, 0600);
12 if (id < 0)
13 return 77;
14 printf("msgget\\(IPC_PRIVATE, 0600\\) += %d\n", id);
15
16 if (msgctl(id, IPC_STAT, &ds))
17 goto fail;
18 printf("msgctl\\(%d, (IPC_64\\|)?IPC_STAT, %p\\) += 0\n", id, &ds);
19
20 int max = msgctl(0, MSG_INFO, &ds);
21 if (max < 0)
22 goto fail;
23 printf("msgctl\\(0, (IPC_64\\|)?MSG_INFO, %p\\) += %d\n", &ds, max);
24
25 rc = msgctl(id, MSG_STAT, &ds);
26 if (rc != id) {
27 /*
28 * In linux < v2.6.24-rc1 the first argument must be
29 * an index in the kernel's internal array.
30 */
31 if (-1 != rc || EINVAL != errno)
32 goto fail;
33 printf("msgctl\\(%d, (IPC_64\\|)?MSG_STAT, %p\\) += -1 EINVAL \\(Invalid argument\\)\n", id, &ds);
34 } else {
35 printf("msgctl\\(%d, (IPC_64\\|)?MSG_STAT, %p\\) += %d\n", id, &ds, id);
36 }
37
38 rc = 0;
39 done:
40 if (msgctl(id, IPC_RMID, 0) < 0)
41 return 1;
42 printf("msgctl\\(%d, (IPC_64\\|)?IPC_RMID, 0\\) += 0\n", id);
43 return rc;
44
45 fail:
46 rc = 1;
47 goto done;
48 }
49