Dmitry V. Levin | 12e2442 | 2015-01-12 16:08:59 +0000 | [diff] [blame] | 1 | #include <stdio.h> |
Dmitry V. Levin | 7230d0a | 2015-01-14 16:52:28 +0000 | [diff] [blame] | 2 | #include <errno.h> |
Dmitry V. Levin | 12e2442 | 2015-01-12 16:08:59 +0000 | [diff] [blame] | 3 | #include <sys/msg.h> |
| 4 | |
| 5 | int |
| 6 | main(void) |
| 7 | { |
Dmitry V. Levin | 7230d0a | 2015-01-14 16:52:28 +0000 | [diff] [blame] | 8 | int rc, id; |
| 9 | struct msqid_ds ds; |
| 10 | |
| 11 | id = msgget(IPC_PRIVATE, 0600); |
Dmitry V. Levin | 12e2442 | 2015-01-12 16:08:59 +0000 | [diff] [blame] | 12 | if (id < 0) |
| 13 | return 77; |
| 14 | printf("msgget\\(IPC_PRIVATE, 0600\\) += %d\n", id); |
| 15 | |
Dmitry V. Levin | 7230d0a | 2015-01-14 16:52:28 +0000 | [diff] [blame] | 16 | if (msgctl(id, IPC_STAT, &ds)) |
| 17 | goto fail; |
Andreas Schwab | 3aa45f3 | 2015-03-11 17:47:56 +0100 | [diff] [blame] | 18 | printf("msgctl\\(%d, (IPC_64\\|)?IPC_STAT, %p\\) += 0\n", id, &ds); |
Dmitry V. Levin | 12e2442 | 2015-01-12 16:08:59 +0000 | [diff] [blame] | 19 | |
Dmitry V. Levin | 12e2442 | 2015-01-12 16:08:59 +0000 | [diff] [blame] | 20 | int max = msgctl(0, MSG_INFO, &ds); |
| 21 | if (max < 0) |
| 22 | goto fail; |
Andreas Schwab | 3aa45f3 | 2015-03-11 17:47:56 +0100 | [diff] [blame] | 23 | 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] | 24 | |
Dmitry V. Levin | 7230d0a | 2015-01-14 16:52:28 +0000 | [diff] [blame] | 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; |
Andreas Schwab | 3aa45f3 | 2015-03-11 17:47:56 +0100 | [diff] [blame] | 33 | printf("msgctl\\(%d, (IPC_64\\|)?MSG_STAT, %p\\) += -1 EINVAL \\(Invalid argument\\)\n", id, &ds); |
Dmitry V. Levin | 7230d0a | 2015-01-14 16:52:28 +0000 | [diff] [blame] | 34 | } else { |
Andreas Schwab | 3aa45f3 | 2015-03-11 17:47:56 +0100 | [diff] [blame] | 35 | 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] | 36 | } |
Dmitry V. Levin | 12e2442 | 2015-01-12 16:08:59 +0000 | [diff] [blame] | 37 | |
| 38 | rc = 0; |
Dmitry V. Levin | 7230d0a | 2015-01-14 16:52:28 +0000 | [diff] [blame] | 39 | done: |
Dmitry V. Levin | 12e2442 | 2015-01-12 16:08:59 +0000 | [diff] [blame] | 40 | if (msgctl(id, IPC_RMID, 0) < 0) |
| 41 | return 1; |
Andreas Schwab | 3aa45f3 | 2015-03-11 17:47:56 +0100 | [diff] [blame] | 42 | printf("msgctl\\(%d, (IPC_64\\|)?IPC_RMID, 0\\) += 0\n", id); |
Dmitry V. Levin | 12e2442 | 2015-01-12 16:08:59 +0000 | [diff] [blame] | 43 | return rc; |
Dmitry V. Levin | 7230d0a | 2015-01-14 16:52:28 +0000 | [diff] [blame] | 44 | |
| 45 | fail: |
| 46 | rc = 1; |
| 47 | goto done; |
Dmitry V. Levin | 12e2442 | 2015-01-12 16:08:59 +0000 | [diff] [blame] | 48 | } |