]> git.ipfire.org Git - thirdparty/util-linux.git/blob - sys-utils/ipcrm.c
Imported from util-linux-2.9i tarball.
[thirdparty/util-linux.git] / sys-utils / ipcrm.c
1 /*
2 * krishna balasubramanian 1993
3 */
4
5 #include <stdio.h>
6 #include <stdlib.h>
7 #include <string.h>
8 #include <errno.h>
9
10 #include <sys/types.h>
11 #include <sys/ipc.h>
12 #include <sys/shm.h>
13 #include <sys/msg.h>
14 #include <sys/sem.h>
15 #if defined (__GNU_LIBRARY__) && !defined(_SEM_SEMUN_UNDEFINED)
16 /* union semun is defined by including <sys/sem.h> */
17 #else
18 /* according to X/OPEN we have to define it ourselves */
19 union semun {
20 int val;
21 struct semid_ds *buf;
22 unsigned short int *array;
23 struct seminfo *__buf;
24 };
25 #endif
26
27
28 int main(int argc, char **argv)
29 {
30 int id;
31 union semun arg;
32
33 arg.val = 0;
34
35 if (argc != 3 || strlen(argv[1]) < 3) {
36 printf ("usage: %s [shm | msg | sem] id\n", argv[0]);
37 exit (1);
38 }
39 id = atoi (argv[2]);
40 switch (argv[1][1]) {
41 case 'h':
42 if (!shmctl (id, IPC_RMID, NULL))
43 break;
44 perror ("shmctl ");
45 exit (1);
46
47 case 'e':
48 if (!semctl (id, 0, IPC_RMID, arg))
49 break;
50 perror ("semctl ");
51 exit (1);
52
53 case 's':
54 if (!msgctl (id, IPC_RMID, NULL))
55 break;
56 perror ("msgctl ");
57 exit (1);
58
59 default:
60 printf ("usage: %s [-shm | -msg | -sem] id\n", argv[0]);
61 exit (1);
62 }
63 printf ("resource deleted\n");
64 return 0;
65 }
66