xref: /onnv-gate/usr/src/cmd/ipcrm/ipcrm.c (revision 12185:435563b244c3)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*12185SKeerthi.Kondaka@Sun.COM  * Common Development and Distribution License (the "License").
6*12185SKeerthi.Kondaka@Sun.COM  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
210Sstevel@tonic-gate /*
22*12185SKeerthi.Kondaka@Sun.COM  * Copyright (c) 1988, 2010, Oracle and/or its affiliates. All rights reserved.
230Sstevel@tonic-gate  */
240Sstevel@tonic-gate 
250Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
260Sstevel@tonic-gate /*	  All Rights Reserved  	*/
270Sstevel@tonic-gate 
280Sstevel@tonic-gate 
290Sstevel@tonic-gate 
300Sstevel@tonic-gate /*
310Sstevel@tonic-gate  * ipcrm - IPC remove
320Sstevel@tonic-gate  *
330Sstevel@tonic-gate  * Remove specified message queues,
340Sstevel@tonic-gate  * semaphore sets and shared memory ids.
350Sstevel@tonic-gate  */
360Sstevel@tonic-gate 
370Sstevel@tonic-gate #include <sys/types.h>
380Sstevel@tonic-gate #include <sys/ipc.h>
390Sstevel@tonic-gate #include <sys/msg.h>
400Sstevel@tonic-gate #include <sys/sem.h>
410Sstevel@tonic-gate #include <sys/shm.h>
420Sstevel@tonic-gate #include <errno.h>
430Sstevel@tonic-gate #include <sys/ipc_impl.h>
440Sstevel@tonic-gate #include <zone.h>
450Sstevel@tonic-gate #include <stdio.h>
460Sstevel@tonic-gate #include <stdlib.h>
470Sstevel@tonic-gate #include <signal.h>
480Sstevel@tonic-gate #include <locale.h>
490Sstevel@tonic-gate 
500Sstevel@tonic-gate #define	NULL_MSG	((struct msqid_ds *)NULL)
510Sstevel@tonic-gate #define	NULL_SEM	((struct semid_ds *)NULL)
520Sstevel@tonic-gate #define	NULL_SHM	((struct shmid_ds *)NULL)
530Sstevel@tonic-gate 
540Sstevel@tonic-gate #define	USAGE	"usage: ipcrm [-z zone] [ [-q msqid] [-m shmid] " \
550Sstevel@tonic-gate "[-s semid]\n\t [-Q msgkey] [-M shmkey] [-S semkey] ... ]\n"
560Sstevel@tonic-gate 
570Sstevel@tonic-gate #define	IPC_KEYMATCH(perm, zoneid, key) \
580Sstevel@tonic-gate 	((perm).ipcx_key == (key) && (perm).ipcx_zoneid == (zoneid))
590Sstevel@tonic-gate 
600Sstevel@tonic-gate static char opts[] = "z:q:m:s:Q:M:S:";	/* allowable options for getopt */
610Sstevel@tonic-gate extern char	*optarg;	/* arg pointer for getopt */
620Sstevel@tonic-gate extern int	optind;		/* option index for getopt */
630Sstevel@tonic-gate 
640Sstevel@tonic-gate static zoneid_t zoneid;
650Sstevel@tonic-gate static int zflg;
660Sstevel@tonic-gate 
670Sstevel@tonic-gate static int *idlist, nids;
680Sstevel@tonic-gate 
690Sstevel@tonic-gate static void
oops(char * thing,char * arg)700Sstevel@tonic-gate oops(char *thing, char *arg)
710Sstevel@tonic-gate {
720Sstevel@tonic-gate 	char *e;
730Sstevel@tonic-gate 
740Sstevel@tonic-gate 	switch (errno) {
750Sstevel@tonic-gate 	case ENOENT:	/* key not found */
760Sstevel@tonic-gate 	case EINVAL:	/* id not found */
770Sstevel@tonic-gate 		e = "not found";
780Sstevel@tonic-gate 		break;
790Sstevel@tonic-gate 
800Sstevel@tonic-gate 	case EPERM:
810Sstevel@tonic-gate 		e = "permission denied";
820Sstevel@tonic-gate 		break;
830Sstevel@tonic-gate 	default:
840Sstevel@tonic-gate 		e = "unknown error";
850Sstevel@tonic-gate 	}
860Sstevel@tonic-gate 
870Sstevel@tonic-gate 	(void) fprintf(stderr, gettext("ipcrm: %s(%s): %s\n"), thing, arg, e);
880Sstevel@tonic-gate }
890Sstevel@tonic-gate 
900Sstevel@tonic-gate /* convert string to numeric key */
910Sstevel@tonic-gate static key_t
getkey(char * kp)920Sstevel@tonic-gate getkey(char *kp)
930Sstevel@tonic-gate {
940Sstevel@tonic-gate 	key_t k;
950Sstevel@tonic-gate 	char *tp;	/* will point to char that terminates strtol scan */
960Sstevel@tonic-gate 
97*12185SKeerthi.Kondaka@Sun.COM 	if ((k = (key_t)strtoul(kp, &tp, 0)) == IPC_PRIVATE || *tp != '\0') {
980Sstevel@tonic-gate 		(void) fprintf(stderr, gettext("ipcrm: illegal key: %s\n"),
990Sstevel@tonic-gate 		    kp);
1000Sstevel@tonic-gate 		return (0);
1010Sstevel@tonic-gate 	}
1020Sstevel@tonic-gate 	return (k);
1030Sstevel@tonic-gate }
1040Sstevel@tonic-gate 
1050Sstevel@tonic-gate /*
1060Sstevel@tonic-gate  * Gets list of all IPC ids (of a particular type) visible in the
1070Sstevel@tonic-gate  * caller's zone.  Returns number of ids retrieved.  On return, idlist
1080Sstevel@tonic-gate  * is set to point to an array of ids at least as large as the number
1090Sstevel@tonic-gate  * retrieved.
1100Sstevel@tonic-gate  */
1110Sstevel@tonic-gate static uint_t
getids(int (* idsfunc)(int *,uint_t,uint_t *))1120Sstevel@tonic-gate getids(int (*idsfunc)(int *, uint_t, uint_t *))
1130Sstevel@tonic-gate {
1140Sstevel@tonic-gate 	uint_t n;
1150Sstevel@tonic-gate 
1160Sstevel@tonic-gate 	for (;;) {
1170Sstevel@tonic-gate 		if (idsfunc(idlist, nids, &n) != 0)
1180Sstevel@tonic-gate 			goto err;	/* should never happen */
1190Sstevel@tonic-gate 		if (n <= nids)
1200Sstevel@tonic-gate 			break;
1210Sstevel@tonic-gate 		idlist = realloc(idlist, (nids = n) * sizeof (int));
1220Sstevel@tonic-gate 		if (idlist == NULL)
1230Sstevel@tonic-gate 			goto err;
1240Sstevel@tonic-gate 	}
1250Sstevel@tonic-gate 	return (n);
1260Sstevel@tonic-gate 
1270Sstevel@tonic-gate err:
1280Sstevel@tonic-gate 	perror("ipcrm");
1290Sstevel@tonic-gate 	exit(1);
1300Sstevel@tonic-gate 	/* NOTREACHED */
1310Sstevel@tonic-gate }
1320Sstevel@tonic-gate 
1330Sstevel@tonic-gate static int
msggetid(char * arg)1340Sstevel@tonic-gate msggetid(char *arg)
1350Sstevel@tonic-gate {
1360Sstevel@tonic-gate 	int id = atol(arg);
1370Sstevel@tonic-gate 	struct msqid_ds64 qds;
1380Sstevel@tonic-gate 
1390Sstevel@tonic-gate 	if (!zflg)
1400Sstevel@tonic-gate 		return (id);
1410Sstevel@tonic-gate 
1420Sstevel@tonic-gate 	if (msgctl64(id, IPC_STAT64, &qds) < 0) {
1430Sstevel@tonic-gate 		oops("msgctl", arg);
1440Sstevel@tonic-gate 		return (-1);
1450Sstevel@tonic-gate 	}
1460Sstevel@tonic-gate 	if (qds.msgx_perm.ipcx_zoneid != zoneid) {
1470Sstevel@tonic-gate 		/*
1480Sstevel@tonic-gate 		 * Not in right zone, pretend the call failed.
1490Sstevel@tonic-gate 		 * Message should be the same as that returned if
1500Sstevel@tonic-gate 		 * msggetid succeeds but the subsequent IPC_RMID fails
1510Sstevel@tonic-gate 		 * with EINVAL.
1520Sstevel@tonic-gate 		 */
1530Sstevel@tonic-gate 		errno = EINVAL;
1540Sstevel@tonic-gate 		oops("msgctl", arg);
1550Sstevel@tonic-gate 		return (-1);
1560Sstevel@tonic-gate 	}
1570Sstevel@tonic-gate 	return (id);
1580Sstevel@tonic-gate }
1590Sstevel@tonic-gate 
1600Sstevel@tonic-gate static int
msggetkey(char * kp)1610Sstevel@tonic-gate msggetkey(char *kp)
1620Sstevel@tonic-gate {
1630Sstevel@tonic-gate 	key_t k;
1640Sstevel@tonic-gate 	int id, i;
1650Sstevel@tonic-gate 	uint_t n;
1660Sstevel@tonic-gate 	struct msqid_ds64 qds;
1670Sstevel@tonic-gate 
1680Sstevel@tonic-gate 	if ((k = getkey(kp)) == 0)
1690Sstevel@tonic-gate 		return (-1);
1700Sstevel@tonic-gate 
1710Sstevel@tonic-gate 	if (!zflg) {
1720Sstevel@tonic-gate 		/* lookup in local zone is simple */
1730Sstevel@tonic-gate 		if ((id = msgget(k, 0)) == -1)
1740Sstevel@tonic-gate 			oops("msgget", kp);
1750Sstevel@tonic-gate 		return (id);
1760Sstevel@tonic-gate 	}
1770Sstevel@tonic-gate 
1780Sstevel@tonic-gate 	n = getids(msgids);
1790Sstevel@tonic-gate 
1800Sstevel@tonic-gate 	/* search for right key and zone combination */
1810Sstevel@tonic-gate 	for (i = 0; i < n; i++) {
1820Sstevel@tonic-gate 		id = idlist[i];
1830Sstevel@tonic-gate 		if (msgctl64(id, IPC_STAT64, &qds) < 0)
1840Sstevel@tonic-gate 			continue;
1850Sstevel@tonic-gate 		if (IPC_KEYMATCH(qds.msgx_perm, zoneid, k))
1860Sstevel@tonic-gate 			return (id);	/* found it, no need to look further */
1870Sstevel@tonic-gate 	}
1880Sstevel@tonic-gate 	(void) fprintf(stderr, gettext("ipcrm: unknown key: %s\n"), kp);
1890Sstevel@tonic-gate 	return (-1);
1900Sstevel@tonic-gate }
1910Sstevel@tonic-gate 
1920Sstevel@tonic-gate static int
semgetid(char * arg)1930Sstevel@tonic-gate semgetid(char *arg)
1940Sstevel@tonic-gate {
1950Sstevel@tonic-gate 	int id = atol(arg);
1960Sstevel@tonic-gate 	struct semid_ds64 sds;
1970Sstevel@tonic-gate 	union semun {
1980Sstevel@tonic-gate 		int val;
1990Sstevel@tonic-gate 		struct semid_ds64 *buf;
2000Sstevel@tonic-gate 		ushort_t *array;
2010Sstevel@tonic-gate 	} semarg;
2020Sstevel@tonic-gate 
2030Sstevel@tonic-gate 	if (!zflg)
2040Sstevel@tonic-gate 		return (id);
2050Sstevel@tonic-gate 
2060Sstevel@tonic-gate 	semarg.buf = &sds;
2070Sstevel@tonic-gate 	if (semctl64(id, 0, IPC_STAT64, semarg) < 0) {
2080Sstevel@tonic-gate 		oops("semctl", arg);
2090Sstevel@tonic-gate 		return (-1);
2100Sstevel@tonic-gate 	}
2110Sstevel@tonic-gate 	if (sds.semx_perm.ipcx_zoneid != zoneid) {
2120Sstevel@tonic-gate 		/*
2130Sstevel@tonic-gate 		 * Not in right zone, pretend the call failed.
2140Sstevel@tonic-gate 		 * Message should be the same as that returned if
2150Sstevel@tonic-gate 		 * semgetid succeeds but the subsequent IPC_RMID fails
2160Sstevel@tonic-gate 		 * with EINVAL.
2170Sstevel@tonic-gate 		 */
2180Sstevel@tonic-gate 		errno = EINVAL;
2190Sstevel@tonic-gate 		oops("semctl", arg);
2200Sstevel@tonic-gate 		return (-1);
2210Sstevel@tonic-gate 	}
2220Sstevel@tonic-gate 	return (id);
2230Sstevel@tonic-gate }
2240Sstevel@tonic-gate 
2250Sstevel@tonic-gate static int
semgetkey(char * kp)2260Sstevel@tonic-gate semgetkey(char *kp)
2270Sstevel@tonic-gate {
2280Sstevel@tonic-gate 	key_t k;
2290Sstevel@tonic-gate 	int id, i;
2300Sstevel@tonic-gate 	uint_t n;
2310Sstevel@tonic-gate 	struct semid_ds64 sds;
2320Sstevel@tonic-gate 	union semun {
2330Sstevel@tonic-gate 		int val;
2340Sstevel@tonic-gate 		struct semid_ds64 *buf;
2350Sstevel@tonic-gate 		ushort_t *array;
2360Sstevel@tonic-gate 	} semarg;
2370Sstevel@tonic-gate 
2380Sstevel@tonic-gate 	if ((k = getkey(kp)) == 0)
2390Sstevel@tonic-gate 		return (-1);
2400Sstevel@tonic-gate 
2410Sstevel@tonic-gate 	if (!zflg) {
2420Sstevel@tonic-gate 		/* lookup in local zone is simple */
2430Sstevel@tonic-gate 		if ((id = semget(k, 0, 0)) == -1)
2440Sstevel@tonic-gate 			oops("semget", kp);
2450Sstevel@tonic-gate 		return (id);
2460Sstevel@tonic-gate 	}
2470Sstevel@tonic-gate 
2480Sstevel@tonic-gate 	n = getids(semids);
2490Sstevel@tonic-gate 
2500Sstevel@tonic-gate 	semarg.buf = &sds;
2510Sstevel@tonic-gate 	/* search for right key and zone combination */
2520Sstevel@tonic-gate 	for (i = 0; i < n; i++) {
2530Sstevel@tonic-gate 		int id;
2540Sstevel@tonic-gate 		id = idlist[i];
2550Sstevel@tonic-gate 		if (semctl64(id, 0, IPC_STAT64, semarg) < 0)
2560Sstevel@tonic-gate 			continue;
2570Sstevel@tonic-gate 		if (IPC_KEYMATCH(sds.semx_perm, zoneid, k))
2580Sstevel@tonic-gate 			return (id);	/* found it, no need to look further */
2590Sstevel@tonic-gate 	}
2600Sstevel@tonic-gate 
2610Sstevel@tonic-gate 	(void) fprintf(stderr, gettext("ipcrm: unknown key: %s\n"), kp);
2620Sstevel@tonic-gate 	return (-1);
2630Sstevel@tonic-gate }
2640Sstevel@tonic-gate 
2650Sstevel@tonic-gate static int
shmgetid(char * arg)2660Sstevel@tonic-gate shmgetid(char *arg)
2670Sstevel@tonic-gate {
2680Sstevel@tonic-gate 	int id = atol(arg);
2690Sstevel@tonic-gate 	struct shmid_ds64 mds;
2700Sstevel@tonic-gate 
2710Sstevel@tonic-gate 	if (!zflg)
2720Sstevel@tonic-gate 		return (id);
2730Sstevel@tonic-gate 
2740Sstevel@tonic-gate 	if (shmctl64(id, IPC_STAT64, &mds) < 0) {
2750Sstevel@tonic-gate 		oops("shmctl", arg);
2760Sstevel@tonic-gate 		return (-1);
2770Sstevel@tonic-gate 	}
2780Sstevel@tonic-gate 	if (mds.shmx_perm.ipcx_zoneid != zoneid) {
2790Sstevel@tonic-gate 		/*
2800Sstevel@tonic-gate 		 * Not in right zone, pretend the call failed.
2810Sstevel@tonic-gate 		 * Message should be the same as that returned if
2820Sstevel@tonic-gate 		 * shmgetid succeeds but the subsequent IPC_RMID fails
2830Sstevel@tonic-gate 		 * with EINVAL.
2840Sstevel@tonic-gate 		 */
2850Sstevel@tonic-gate 		errno = EINVAL;
2860Sstevel@tonic-gate 		oops("shmctl", arg);
2870Sstevel@tonic-gate 		return (-1);
2880Sstevel@tonic-gate 	}
2890Sstevel@tonic-gate 	return (id);
2900Sstevel@tonic-gate }
2910Sstevel@tonic-gate 
2920Sstevel@tonic-gate static int
shmgetkey(char * kp)2930Sstevel@tonic-gate shmgetkey(char *kp)
2940Sstevel@tonic-gate {
2950Sstevel@tonic-gate 	key_t k;
2960Sstevel@tonic-gate 	int id, i;
2970Sstevel@tonic-gate 	uint_t n;
2980Sstevel@tonic-gate 	struct shmid_ds64 mds;
2990Sstevel@tonic-gate 
3000Sstevel@tonic-gate 	if ((k = getkey(kp)) == 0)
3010Sstevel@tonic-gate 		return (-1);
3020Sstevel@tonic-gate 
3030Sstevel@tonic-gate 	if (!zflg) {
3040Sstevel@tonic-gate 		/* lookup in local zone is simple */
3050Sstevel@tonic-gate 		if ((id = shmget(k, 0, 0)) == -1)
3060Sstevel@tonic-gate 			oops("shmget", kp);
3070Sstevel@tonic-gate 		return (id);
3080Sstevel@tonic-gate 	}
3090Sstevel@tonic-gate 
3100Sstevel@tonic-gate 	n = getids(shmids);
3110Sstevel@tonic-gate 
3120Sstevel@tonic-gate 	/* search for right key and zone combination */
3130Sstevel@tonic-gate 	for (i = 0; i < n; i++) {
3140Sstevel@tonic-gate 		int id;
3150Sstevel@tonic-gate 		id = idlist[i];
3160Sstevel@tonic-gate 		if (shmctl64(id, IPC_STAT64, &mds) < 0)
3170Sstevel@tonic-gate 			continue;
3180Sstevel@tonic-gate 		if (IPC_KEYMATCH(mds.shmx_perm, zoneid, k))
3190Sstevel@tonic-gate 			return (id);	/* found it, no need to look further */
3200Sstevel@tonic-gate 	}
3210Sstevel@tonic-gate 	(void) fprintf(stderr, gettext("ipcrm: unknown key: %s\n"), kp);
3220Sstevel@tonic-gate 	return (-1);
3230Sstevel@tonic-gate }
3240Sstevel@tonic-gate 
3250Sstevel@tonic-gate 
3260Sstevel@tonic-gate /* convert string containing zone name or id to a numeric id */
3270Sstevel@tonic-gate static zoneid_t
getzone(char * arg)3280Sstevel@tonic-gate getzone(char *arg)
3290Sstevel@tonic-gate {
3300Sstevel@tonic-gate 	zoneid_t zoneid;
3310Sstevel@tonic-gate 
3320Sstevel@tonic-gate 	if (zone_get_id(arg, &zoneid) != 0) {
3330Sstevel@tonic-gate 		(void) fprintf(stderr, gettext("ipcrm: unknown zone: %s\n"),
3340Sstevel@tonic-gate 		    arg);
3350Sstevel@tonic-gate 		exit(1);
3360Sstevel@tonic-gate 	}
3370Sstevel@tonic-gate 	return (zoneid);
3380Sstevel@tonic-gate }
3390Sstevel@tonic-gate 
3400Sstevel@tonic-gate int
main(int argc,char ** argv)3410Sstevel@tonic-gate main(int argc, char **argv)
3420Sstevel@tonic-gate {
3430Sstevel@tonic-gate 	int	o;		/* option flag */
3440Sstevel@tonic-gate 	int	err;		/* error count */
3450Sstevel@tonic-gate 	int	ipc_id;		/* id to remove */
3460Sstevel@tonic-gate 
3470Sstevel@tonic-gate 	(void) setlocale(LC_ALL, "");
3480Sstevel@tonic-gate 	(void) textdomain(TEXT_DOMAIN);
3490Sstevel@tonic-gate 	/*
3500Sstevel@tonic-gate 	 * If one or more of the IPC modules is not
3510Sstevel@tonic-gate 	 * included in the kernel, the corresponding
3520Sstevel@tonic-gate 	 * system calls will incur SIGSYS.  Ignoring
3530Sstevel@tonic-gate 	 * that signal makes the system call appear
3540Sstevel@tonic-gate 	 * to fail with errno == EINVAL, which can be
3550Sstevel@tonic-gate 	 * interpreted appropriately in oops().
3560Sstevel@tonic-gate 	 */
3570Sstevel@tonic-gate 
3580Sstevel@tonic-gate 	(void) signal(SIGSYS, SIG_IGN);
3590Sstevel@tonic-gate 
3600Sstevel@tonic-gate 	/*
3610Sstevel@tonic-gate 	 * If no -z argument is specified, only objects in the current
3620Sstevel@tonic-gate 	 * zone can be removed with keys.
3630Sstevel@tonic-gate 	 */
3640Sstevel@tonic-gate 	zoneid = getzoneid();
3650Sstevel@tonic-gate 
3660Sstevel@tonic-gate 	/*
3670Sstevel@tonic-gate 	 * Go through the options.  The first pass looks only for -z
3680Sstevel@tonic-gate 	 * since this option can affect the processing of keys.  The
3690Sstevel@tonic-gate 	 * second pass looks for the other options and ignores -z.
3700Sstevel@tonic-gate 	 */
3710Sstevel@tonic-gate 	err = 0;
3720Sstevel@tonic-gate 	while ((o = getopt(argc, argv, opts)) != EOF) {
3730Sstevel@tonic-gate 		switch (o) {
3740Sstevel@tonic-gate 		case 'z':
3750Sstevel@tonic-gate 			zflg++;
3760Sstevel@tonic-gate 			zoneid = getzone(optarg);
3770Sstevel@tonic-gate 			break;
3780Sstevel@tonic-gate 
3790Sstevel@tonic-gate 		case 'q':	/* skip the rest of the flags */
3800Sstevel@tonic-gate 		case 'm':
3810Sstevel@tonic-gate 		case 's':
3820Sstevel@tonic-gate 		case 'Q':
3830Sstevel@tonic-gate 		case 'M':
3840Sstevel@tonic-gate 		case 'S':
3850Sstevel@tonic-gate 			break;
3860Sstevel@tonic-gate 
3870Sstevel@tonic-gate 		case '?':	/* anything else is an error */
3880Sstevel@tonic-gate 		default:
3890Sstevel@tonic-gate 			err++;
3900Sstevel@tonic-gate 			break;
3910Sstevel@tonic-gate 		}
3920Sstevel@tonic-gate 	}
3930Sstevel@tonic-gate 
3940Sstevel@tonic-gate 	if (err || (optind < argc)) {
3950Sstevel@tonic-gate 		(void) fprintf(stderr, gettext(USAGE));
3960Sstevel@tonic-gate 		return (err);
3970Sstevel@tonic-gate 	}
3980Sstevel@tonic-gate 
3990Sstevel@tonic-gate 	if (zflg > 1) {
4000Sstevel@tonic-gate 		(void) fprintf(stderr,
4010Sstevel@tonic-gate 		    gettext("multiple -z options not allowed\n"));
4020Sstevel@tonic-gate 		(void) fprintf(stderr, gettext(USAGE));
4030Sstevel@tonic-gate 		return (1);
4040Sstevel@tonic-gate 	}
4050Sstevel@tonic-gate 
4060Sstevel@tonic-gate 	optind = 1;	/* rewind for pass 2 */
4070Sstevel@tonic-gate 	while ((o = getopt(argc, argv, opts)) != EOF) {
4080Sstevel@tonic-gate 		switch (o) {
4090Sstevel@tonic-gate 		case 'z':	/* zone identifier */
4100Sstevel@tonic-gate 			break;
4110Sstevel@tonic-gate 
4120Sstevel@tonic-gate 		case 'q':	/* message queue */
4130Sstevel@tonic-gate 			if ((ipc_id = msggetid(optarg)) < 0) {
4140Sstevel@tonic-gate 				err++;
4150Sstevel@tonic-gate 			} else if (msgctl(ipc_id, IPC_RMID, NULL_MSG) == -1) {
4160Sstevel@tonic-gate 				oops("msgctl", optarg);
4170Sstevel@tonic-gate 				err++;
4180Sstevel@tonic-gate 			}
4190Sstevel@tonic-gate 			break;
4200Sstevel@tonic-gate 
4210Sstevel@tonic-gate 		case 'm':	/* shared memory */
4220Sstevel@tonic-gate 			if ((ipc_id = shmgetid(optarg)) < 0) {
4230Sstevel@tonic-gate 				err++;
4240Sstevel@tonic-gate 			} else if (shmctl(ipc_id, IPC_RMID, NULL_SHM) == -1) {
4250Sstevel@tonic-gate 				oops("shmctl", optarg);
4260Sstevel@tonic-gate 				err++;
4270Sstevel@tonic-gate 			}
4280Sstevel@tonic-gate 			break;
4290Sstevel@tonic-gate 
4300Sstevel@tonic-gate 		case 's':	/* semaphores */
4310Sstevel@tonic-gate 			if ((ipc_id = semgetid(optarg)) < 0) {
4320Sstevel@tonic-gate 				err++;
4330Sstevel@tonic-gate 			} else if (semctl(ipc_id, 0, IPC_RMID, NULL_SEM) ==
4340Sstevel@tonic-gate 			    -1) {
4350Sstevel@tonic-gate 				oops("semctl", optarg);
4360Sstevel@tonic-gate 				err++;
4370Sstevel@tonic-gate 			}
4380Sstevel@tonic-gate 			break;
4390Sstevel@tonic-gate 
4400Sstevel@tonic-gate 		case 'Q':	/* message queue (by key) */
4410Sstevel@tonic-gate 			if ((ipc_id = msggetkey(optarg)) == -1) {
4420Sstevel@tonic-gate 				err++;
4430Sstevel@tonic-gate 				break;
4440Sstevel@tonic-gate 			}
4450Sstevel@tonic-gate 			if (msgctl(ipc_id, IPC_RMID, NULL_MSG) == -1) {
4460Sstevel@tonic-gate 				oops("msgctl", optarg);
4470Sstevel@tonic-gate 				err++;
4480Sstevel@tonic-gate 			}
4490Sstevel@tonic-gate 			break;
4500Sstevel@tonic-gate 
4510Sstevel@tonic-gate 		case 'M':	/* shared memory (by key) */
4520Sstevel@tonic-gate 			if ((ipc_id = shmgetkey(optarg)) == -1) {
4530Sstevel@tonic-gate 				err++;
4540Sstevel@tonic-gate 				break;
4550Sstevel@tonic-gate 			}
4560Sstevel@tonic-gate 			if (shmctl(ipc_id, IPC_RMID, NULL_SHM) == -1) {
4570Sstevel@tonic-gate 				oops("shmctl", optarg);
4580Sstevel@tonic-gate 				err++;
4590Sstevel@tonic-gate 			}
4600Sstevel@tonic-gate 			break;
4610Sstevel@tonic-gate 
4620Sstevel@tonic-gate 		case 'S':	/* semaphores (by key) */
4630Sstevel@tonic-gate 			if ((ipc_id = semgetkey(optarg)) == -1) {
4640Sstevel@tonic-gate 				err++;
4650Sstevel@tonic-gate 				break;
4660Sstevel@tonic-gate 			}
4670Sstevel@tonic-gate 			if (semctl(ipc_id, 0, IPC_RMID, NULL_SEM) == -1) {
4680Sstevel@tonic-gate 				oops("semctl", optarg);
4690Sstevel@tonic-gate 				err++;
4700Sstevel@tonic-gate 			}
4710Sstevel@tonic-gate 			break;
4720Sstevel@tonic-gate 		}
4730Sstevel@tonic-gate 	}
4740Sstevel@tonic-gate 	return (err);
4750Sstevel@tonic-gate }
476