]>
git.saurik.com Git - apple/file_cmds.git/blob - ipcrm/ipcrm.c
2 * Copyright (c) 1994 Adam Glass
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by Adam Glass.
16 * 4. The name of the Author may not be used to endorse or promote products
17 * derived from this software without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY Adam Glass ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL Adam Glass BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 static const char rcsid
[] =
34 "$Id: ipcrm.c,v 1.3 2005/02/03 07:31:33 josborne Exp $";
43 #include <sys/types.h>
49 #define IPC_TO_STR(x) (x == 'Q' ? "msq" : (x == 'M' ? "shm" : "sem"))
50 #define IPC_TO_STRING(x) (x == 'Q' ? "message queue" : \
51 (x == 'M' ? "shared memory segment" : "semaphore"))
57 fprintf(stderr
, "%s\n%s\n",
58 "usage: ipcrm [-q msqid] [-m shmid] [-s semid]",
59 " [-Q msgkey] [-M shmkey] [-S semkey] ...");
72 return msgctl(id
, IPC_RMID
, NULL
);
80 id
= shmget(key
, 0, 0);
84 return shmctl(id
, IPC_RMID
, NULL
);
94 id
= semget(key
, 0, 0);
98 return semctl(id
, 0, IPC_RMID
, arg
);
101 void not_configured()
111 int c
, result
, errflg
, target_id
;
116 signal(SIGSYS
, not_configured
);
117 while ((c
= getopt(argc
, argv
, ":q:m:s:Q:M:S:")) != -1) {
124 target_id
= strtol(optarg
, &en
, 0);
126 warnx("%s: '%s' is not a number",
127 IPC_TO_STRING(toupper(c
)), optarg
);
131 result
= msgrm(0, target_id
);
133 result
= shmrm(0, target_id
);
135 result
= semrm(0, target_id
);
139 warn("%sid(%d): ", IPC_TO_STR(toupper(c
)), target_id
);
141 warnx("%ss are not configured in the running kernel",
142 IPC_TO_STRING(toupper(c
)));
148 target_key
= strtol(optarg
, &en
, 0);
150 warnx("%s: '%s' is not a number", IPC_TO_STRING(c
), optarg
);
153 if (target_key
== IPC_PRIVATE
) {
154 warnx("can't remove private %ss", IPC_TO_STRING(c
));
158 result
= msgrm(target_key
, 0);
160 result
= shmrm(target_key
, 0);
162 result
= semrm(target_key
, 0);
166 warn("%s key(%d): ", IPC_TO_STRING(c
), target_key
);
168 warnx("%ss are not configured in the running kernel",
173 fprintf(stderr
, "option -%c requires an argument\n", optopt
);
176 fprintf(stderr
, "unrecognized option: -%c\n", optopt
);
181 if (optind
!= argc
) {
182 fprintf(stderr
, "unknown argument: %s\n", argv
[optind
]);