blob: 2fd7d4f7d0f686e0ce7a241615e8bacc2ec04fc7 [file] [log] [blame]
Dmitry V. Levin38a34c92015-12-17 17:56:48 +00001/*
Dmitry V. Levin38a34c92015-12-17 17:56:48 +00002 * Copyright (c) 2015 Elvira Khabirova <lineprinter0@gmail.com>
Dmitry V. Levin3ba7fec2016-01-06 11:59:06 +00003 * Copyright (c) 2015-2016 Dmitry V. Levin <ldv@altlinux.org>
Dmitry V. Levin38a34c92015-12-17 17:56:48 +00004 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
Dmitry V. Levin3ba7fec2016-01-06 11:59:06 +000029#include "tests.h"
Dmitry V. Levin7230d0a2015-01-14 16:52:28 +000030#include <errno.h>
Dmitry V. Levin3ba7fec2016-01-06 11:59:06 +000031#include <stdio.h>
32#include <stdlib.h>
Dmitry V. Levin12e24422015-01-12 16:08:59 +000033#include <sys/msg.h>
34
Dmitry V. Levin3ba7fec2016-01-06 11:59:06 +000035static int id = -1;
36
37static void
38cleanup(void)
39{
40 msgctl(id, IPC_RMID, NULL);
41 printf("msgctl\\(%d, (IPC_64\\|)?IPC_RMID, NULL\\) += 0\n", id);
42 id = -1;
43}
44
Dmitry V. Levin12e24422015-01-12 16:08:59 +000045int
46main(void)
47{
Dmitry V. Levin3ba7fec2016-01-06 11:59:06 +000048 int rc;
Dmitry V. Levin7230d0a2015-01-14 16:52:28 +000049 struct msqid_ds ds;
50
51 id = msgget(IPC_PRIVATE, 0600);
Dmitry V. Levin12e24422015-01-12 16:08:59 +000052 if (id < 0)
Dmitry V. Levin3ba7fec2016-01-06 11:59:06 +000053 perror_msg_and_skip("msgget");
Dmitry V. Levin12e24422015-01-12 16:08:59 +000054 printf("msgget\\(IPC_PRIVATE, 0600\\) += %d\n", id);
Dmitry V. Levin3ba7fec2016-01-06 11:59:06 +000055 atexit(cleanup);
Dmitry V. Levin12e24422015-01-12 16:08:59 +000056
Dmitry V. Levin7230d0a2015-01-14 16:52:28 +000057 if (msgctl(id, IPC_STAT, &ds))
Dmitry V. Levin3ba7fec2016-01-06 11:59:06 +000058 perror_msg_and_skip("msgctl IPC_STAT");
Elvira Khabirovad0a61872015-08-18 02:01:26 +030059 printf("msgctl\\(%d, (IPC_64\\|)?IPC_STAT, \\{msg_perm=\\{uid=%u, gid=%u, "
60 "mode=%#o, key=%u, cuid=%u, cgid=%u\\}, msg_stime=%u, msg_rtime=%u, "
61 "msg_ctime=%u, msg_qnum=%u, msg_qbytes=%u, msg_lspid=%u, "
62 "msg_lrpid=%u\\}\\) += 0\n",
63 id, (unsigned) ds.msg_perm.uid, (unsigned) ds.msg_perm.gid,
64 (unsigned) ds.msg_perm.mode, (unsigned) ds.msg_perm.__key,
65 (unsigned) ds.msg_perm.cuid, (unsigned) ds.msg_perm.cgid,
66 (unsigned) ds.msg_stime, (unsigned) ds.msg_rtime,
67 (unsigned) ds.msg_ctime, (unsigned) ds.msg_qnum,
68 (unsigned) ds.msg_qbytes, (unsigned) ds.msg_lspid,
69 (unsigned) ds.msg_lrpid);
Dmitry V. Levin12e24422015-01-12 16:08:59 +000070
Dmitry V. Levin12e24422015-01-12 16:08:59 +000071 int max = msgctl(0, MSG_INFO, &ds);
72 if (max < 0)
Dmitry V. Levin3ba7fec2016-01-06 11:59:06 +000073 perror_msg_and_skip("msgctl MSG_INFO");
Andreas Schwab3aa45f32015-03-11 17:47:56 +010074 printf("msgctl\\(0, (IPC_64\\|)?MSG_INFO, %p\\) += %d\n", &ds, max);
Dmitry V. Levin12e24422015-01-12 16:08:59 +000075
Dmitry V. Levin7230d0a2015-01-14 16:52:28 +000076 rc = msgctl(id, MSG_STAT, &ds);
77 if (rc != id) {
78 /*
79 * In linux < v2.6.24-rc1 the first argument must be
80 * an index in the kernel's internal array.
81 */
82 if (-1 != rc || EINVAL != errno)
Dmitry V. Levin3ba7fec2016-01-06 11:59:06 +000083 perror_msg_and_skip("msgctl MSG_STAT");
84 printf("msgctl\\(%d, (IPC_64\\|)?MSG_STAT, %p\\) += -1 EINVAL \\(%m\\)\n", id, &ds);
Dmitry V. Levin7230d0a2015-01-14 16:52:28 +000085 } else {
Andreas Schwab3aa45f32015-03-11 17:47:56 +010086 printf("msgctl\\(%d, (IPC_64\\|)?MSG_STAT, %p\\) += %d\n", id, &ds, id);
Dmitry V. Levin7230d0a2015-01-14 16:52:28 +000087 }
Dmitry V. Levin12e24422015-01-12 16:08:59 +000088
Dmitry V. Levin3ba7fec2016-01-06 11:59:06 +000089 return 0;
Dmitry V. Levin12e24422015-01-12 16:08:59 +000090}