Dmitry V. Levin | 38a34c9 | 2015-12-17 17:56:48 +0000 | [diff] [blame] | 1 | /* |
Dmitry V. Levin | 38a34c9 | 2015-12-17 17:56:48 +0000 | [diff] [blame] | 2 | * Copyright (c) 2015 Elvira Khabirova <lineprinter0@gmail.com> |
Dmitry V. Levin | 3ba7fec | 2016-01-06 11:59:06 +0000 | [diff] [blame^] | 3 | * Copyright (c) 2015-2016 Dmitry V. Levin <ldv@altlinux.org> |
Dmitry V. Levin | 38a34c9 | 2015-12-17 17:56:48 +0000 | [diff] [blame] | 4 | * 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. Levin | 3ba7fec | 2016-01-06 11:59:06 +0000 | [diff] [blame^] | 29 | #include "tests.h" |
Dmitry V. Levin | 7230d0a | 2015-01-14 16:52:28 +0000 | [diff] [blame] | 30 | #include <errno.h> |
Dmitry V. Levin | 3ba7fec | 2016-01-06 11:59:06 +0000 | [diff] [blame^] | 31 | #include <stdio.h> |
| 32 | #include <stdlib.h> |
Dmitry V. Levin | 12e2442 | 2015-01-12 16:08:59 +0000 | [diff] [blame] | 33 | #include <sys/msg.h> |
| 34 | |
Dmitry V. Levin | 3ba7fec | 2016-01-06 11:59:06 +0000 | [diff] [blame^] | 35 | static int id = -1; |
| 36 | |
| 37 | static void |
| 38 | cleanup(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. Levin | 12e2442 | 2015-01-12 16:08:59 +0000 | [diff] [blame] | 45 | int |
| 46 | main(void) |
| 47 | { |
Dmitry V. Levin | 3ba7fec | 2016-01-06 11:59:06 +0000 | [diff] [blame^] | 48 | int rc; |
Dmitry V. Levin | 7230d0a | 2015-01-14 16:52:28 +0000 | [diff] [blame] | 49 | struct msqid_ds ds; |
| 50 | |
| 51 | id = msgget(IPC_PRIVATE, 0600); |
Dmitry V. Levin | 12e2442 | 2015-01-12 16:08:59 +0000 | [diff] [blame] | 52 | if (id < 0) |
Dmitry V. Levin | 3ba7fec | 2016-01-06 11:59:06 +0000 | [diff] [blame^] | 53 | perror_msg_and_skip("msgget"); |
Dmitry V. Levin | 12e2442 | 2015-01-12 16:08:59 +0000 | [diff] [blame] | 54 | printf("msgget\\(IPC_PRIVATE, 0600\\) += %d\n", id); |
Dmitry V. Levin | 3ba7fec | 2016-01-06 11:59:06 +0000 | [diff] [blame^] | 55 | atexit(cleanup); |
Dmitry V. Levin | 12e2442 | 2015-01-12 16:08:59 +0000 | [diff] [blame] | 56 | |
Dmitry V. Levin | 7230d0a | 2015-01-14 16:52:28 +0000 | [diff] [blame] | 57 | if (msgctl(id, IPC_STAT, &ds)) |
Dmitry V. Levin | 3ba7fec | 2016-01-06 11:59:06 +0000 | [diff] [blame^] | 58 | perror_msg_and_skip("msgctl IPC_STAT"); |
Elvira Khabirova | d0a6187 | 2015-08-18 02:01:26 +0300 | [diff] [blame] | 59 | 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. Levin | 12e2442 | 2015-01-12 16:08:59 +0000 | [diff] [blame] | 70 | |
Dmitry V. Levin | 12e2442 | 2015-01-12 16:08:59 +0000 | [diff] [blame] | 71 | int max = msgctl(0, MSG_INFO, &ds); |
| 72 | if (max < 0) |
Dmitry V. Levin | 3ba7fec | 2016-01-06 11:59:06 +0000 | [diff] [blame^] | 73 | perror_msg_and_skip("msgctl MSG_INFO"); |
Andreas Schwab | 3aa45f3 | 2015-03-11 17:47:56 +0100 | [diff] [blame] | 74 | printf("msgctl\\(0, (IPC_64\\|)?MSG_INFO, %p\\) += %d\n", &ds, max); |
Dmitry V. Levin | 12e2442 | 2015-01-12 16:08:59 +0000 | [diff] [blame] | 75 | |
Dmitry V. Levin | 7230d0a | 2015-01-14 16:52:28 +0000 | [diff] [blame] | 76 | 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. Levin | 3ba7fec | 2016-01-06 11:59:06 +0000 | [diff] [blame^] | 83 | perror_msg_and_skip("msgctl MSG_STAT"); |
| 84 | printf("msgctl\\(%d, (IPC_64\\|)?MSG_STAT, %p\\) += -1 EINVAL \\(%m\\)\n", id, &ds); |
Dmitry V. Levin | 7230d0a | 2015-01-14 16:52:28 +0000 | [diff] [blame] | 85 | } else { |
Andreas Schwab | 3aa45f3 | 2015-03-11 17:47:56 +0100 | [diff] [blame] | 86 | printf("msgctl\\(%d, (IPC_64\\|)?MSG_STAT, %p\\) += %d\n", id, &ds, id); |
Dmitry V. Levin | 7230d0a | 2015-01-14 16:52:28 +0000 | [diff] [blame] | 87 | } |
Dmitry V. Levin | 12e2442 | 2015-01-12 16:08:59 +0000 | [diff] [blame] | 88 | |
Dmitry V. Levin | 3ba7fec | 2016-01-06 11:59:06 +0000 | [diff] [blame^] | 89 | return 0; |
Dmitry V. Levin | 12e2442 | 2015-01-12 16:08:59 +0000 | [diff] [blame] | 90 | } |