]> granicus.if.org Git - strace/blob - tests/ipc_shm.c
Mpersify RTC_* ioctl parser
[strace] / tests / ipc_shm.c
1 /*
2  * Copyright (c) 2015 Elvira Khabirova <lineprinter0@gmail.com>
3  * Copyright (c) 2015-2016 Dmitry V. Levin <ldv@altlinux.org>
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
29 #include "tests.h"
30 #include <errno.h>
31 #include <stdio.h>
32 #include <stdlib.h>
33 #include <sys/shm.h>
34
35 static int id = -1;
36
37 static void
38 cleanup(void)
39 {
40         shmctl(id, IPC_RMID, NULL);
41         printf("shmctl\\(%d, (IPC_64\\|)?IPC_RMID, NULL\\) += 0\n", id);
42         id = -1;
43 }
44
45 int
46 main(void)
47 {
48         int rc;
49         struct shmid_ds ds;
50
51         id = shmget(IPC_PRIVATE, 1, 0600);
52         if (id < 0)
53                 perror_msg_and_skip("shmget");
54         printf("shmget\\(IPC_PRIVATE, 1, 0600\\) += %d\n", id);
55         atexit(cleanup);
56
57         if (shmctl(id, IPC_STAT, &ds))
58                 perror_msg_and_skip("shmctl IPC_STAT");
59         printf("shmctl\\(%d, (IPC_64\\|)?IPC_STAT, \\{shm_perm=\\{uid=%u, gid=%u, "
60                 "mode=%#o, key=%u, cuid=%u, cgid=%u\\}, shm_segsz=%u, shm_cpid=%u, "
61                 "shm_lpid=%u, shm_nattch=%u, shm_atime=%u, shm_dtime=%u, "
62                 "shm_ctime=%u\\}\\) += 0\n",
63                 id, (unsigned) ds.shm_perm.uid, (unsigned) ds.shm_perm.gid,
64                 (unsigned) ds.shm_perm.mode, (unsigned) ds.shm_perm.__key,
65                 (unsigned) ds.shm_perm.cuid, (unsigned) ds.shm_perm.cgid,
66                 (unsigned) ds.shm_segsz, (unsigned) ds.shm_cpid,
67                 (unsigned) ds.shm_lpid, (unsigned) ds.shm_nattch,
68                 (unsigned) ds.shm_atime, (unsigned) ds.shm_dtime,
69                 (unsigned) ds. shm_ctime);
70
71         int max = shmctl(0, SHM_INFO, &ds);
72         if (max < 0)
73                 perror_msg_and_skip("shmctl SHM_INFO");
74         printf("shmctl\\(0, (IPC_64\\|)?SHM_INFO, %p\\) += %d\n", &ds, max);
75
76         rc = shmctl(id, SHM_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)
83                         perror_msg_and_skip("shmctl SHM_STAT");
84                 printf("shmctl\\(%d, (IPC_64\\|)?SHM_STAT, %p\\) += -1 EINVAL \\(%m\\)\n", id, &ds);
85         } else {
86                 printf("shmctl\\(%d, (IPC_64\\|)?SHM_STAT, %p\\) += %d\n", id, &ds, id);
87         }
88
89         return 0;
90 }