blob: ed2bfd6cb86480b18532023bf1e27450ca08b1b0 [file] [log] [blame]
Dmitry V. Levin12e24422015-01-12 16:08:59 +00001#include <stdio.h>
Dmitry V. Levin7230d0a2015-01-14 16:52:28 +00002#include <errno.h>
Dmitry V. Levin12e24422015-01-12 16:08:59 +00003#include <sys/msg.h>
4
5int
6main(void)
7{
Dmitry V. Levin7230d0a2015-01-14 16:52:28 +00008 int rc, id;
9 struct msqid_ds ds;
10
11 id = msgget(IPC_PRIVATE, 0600);
Dmitry V. Levin12e24422015-01-12 16:08:59 +000012 if (id < 0)
13 return 77;
14 printf("msgget\\(IPC_PRIVATE, 0600\\) += %d\n", id);
15
Dmitry V. Levin7230d0a2015-01-14 16:52:28 +000016 if (msgctl(id, IPC_STAT, &ds))
17 goto fail;
Andreas Schwab3aa45f32015-03-11 17:47:56 +010018 printf("msgctl\\(%d, (IPC_64\\|)?IPC_STAT, %p\\) += 0\n", id, &ds);
Dmitry V. Levin12e24422015-01-12 16:08:59 +000019
Dmitry V. Levin12e24422015-01-12 16:08:59 +000020 int max = msgctl(0, MSG_INFO, &ds);
21 if (max < 0)
22 goto fail;
Andreas Schwab3aa45f32015-03-11 17:47:56 +010023 printf("msgctl\\(0, (IPC_64\\|)?MSG_INFO, %p\\) += %d\n", &ds, max);
Dmitry V. Levin12e24422015-01-12 16:08:59 +000024
Dmitry V. Levin7230d0a2015-01-14 16:52:28 +000025 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;
Andreas Schwab3aa45f32015-03-11 17:47:56 +010033 printf("msgctl\\(%d, (IPC_64\\|)?MSG_STAT, %p\\) += -1 EINVAL \\(Invalid argument\\)\n", id, &ds);
Dmitry V. Levin7230d0a2015-01-14 16:52:28 +000034 } else {
Andreas Schwab3aa45f32015-03-11 17:47:56 +010035 printf("msgctl\\(%d, (IPC_64\\|)?MSG_STAT, %p\\) += %d\n", id, &ds, id);
Dmitry V. Levin7230d0a2015-01-14 16:52:28 +000036 }
Dmitry V. Levin12e24422015-01-12 16:08:59 +000037
38 rc = 0;
Dmitry V. Levin7230d0a2015-01-14 16:52:28 +000039done:
Dmitry V. Levin12e24422015-01-12 16:08:59 +000040 if (msgctl(id, IPC_RMID, 0) < 0)
41 return 1;
Andreas Schwab3aa45f32015-03-11 17:47:56 +010042 printf("msgctl\\(%d, (IPC_64\\|)?IPC_RMID, 0\\) += 0\n", id);
Dmitry V. Levin12e24422015-01-12 16:08:59 +000043 return rc;
Dmitry V. Levin7230d0a2015-01-14 16:52:28 +000044
45fail:
46 rc = 1;
47 goto done;
Dmitry V. Levin12e24422015-01-12 16:08:59 +000048}