1 #if HAVE_CONFIG_H
2 # include "config.h"
3 #endif
4
5 /* The program was written to address missing "ipcrm" command on Mac X
6 * It probes a range of System V shared memory id from 0 to MAXID
7 * and if exist, it attempts to delete them.
8 */
9 #if HAVE_SYS_TYPES_H
10 # include <sys/types.h>
11 #endif
12 #if HAVE_SYS_IPC_H
13 # include <sys/ipc.h>
14 #endif
15 #if HAVE_SYS_SHM_H
16 # include <sys/shm.h>
17 #endif
18 #if HAVE_SYS_PARAM_H
19 # include <sys/param.h>
20 #endif
21 #if HAVE_ERRNO_H
22 # include <errno.h>
23 #endif
24 #if HAVE_STDIO_H
25 # include <stdio.h>
26 #endif
27
28 #ifdef SUN
29 char *shmat();
30 #endif
31
32 #define MAXID 1000000
main(int argc,char ** argv)33 int main(int argc, char **argv)
34 {
35 int i;
36 for (i = 0; i < MAXID; i++) {
37 #if SIZEOF_VOIDP == SIZEOF_INT
38 int rc = (int) shmat(i, (char *) NULL, 0);
39 #elif SIZEOF_VOIDP == SIZEOF_LONG
40 long rc = (long) shmat(i, (char *) NULL, 0);
41 #elif SIZEOF_VOIDP == SIZEOF_LONGLONG
42 long long rc = (long long) shmat(i, (char *) NULL, 0);
43 #endif
44 if (rc < 0) {
45 continue;
46 }
47 printf("found %d\n", i);
48 shmdt((void *)rc);
49 /* delete segment id */
50 if (shmctl(i, IPC_RMID, (struct shmid_ds *)NULL)) {
51 printf("failed to remove shm id=%d\n", i);
52 }
53 }
54
55 return 0;
56 }
57