From 6294a526602447291dca25fa16f336f4dcca6e21 Mon Sep 17 00:00:00 2001 From: dfr Date: Tue, 13 Sep 1994 16:59:29 +0000 Subject: Imported the NetBSD version which acts a lot more like the SYSV program. Obtained from: NetBSD --- usr.bin/ipcs/Makefile | 10 +- usr.bin/ipcs/ipcs.1 | 151 ++++++++++ usr.bin/ipcs/ipcs.c | 770 ++++++++++++++++++++++++++++---------------------- 3 files changed, 593 insertions(+), 338 deletions(-) create mode 100644 usr.bin/ipcs/ipcs.1 (limited to 'usr.bin/ipcs') diff --git a/usr.bin/ipcs/Makefile b/usr.bin/ipcs/Makefile index 8ca86fc..eab4100 100644 --- a/usr.bin/ipcs/Makefile +++ b/usr.bin/ipcs/Makefile @@ -1,9 +1,9 @@ -# @(#)Makefile 5.2 (Berkeley) 5/11/90 +# $Id: Makefile,v 1.6 1994/06/18 21:09:40 cgd Exp $ PROG= ipcs -NOMAN= noman -BINMODE = 2555 -BINGRP = kmem -CFLAGS=-g +BINGRP= kmem +BINMODE= 2555 +DPADD+= ${LIBKVM} +LDADD+= -lkvm .include diff --git a/usr.bin/ipcs/ipcs.1 b/usr.bin/ipcs/ipcs.1 new file mode 100644 index 0000000..b62eeea --- /dev/null +++ b/usr.bin/ipcs/ipcs.1 @@ -0,0 +1,151 @@ +.\" +.\" Copyright (c) 1994 SigmaSoft, Th. Lockert +.\" All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by SigmaSoft, Th. Lockert. +.\" 3. The name of the author may not be used to endorse or promote products +.\" derived from this software without specific prior written permission +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR +.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES +.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, +.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT +.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +.\" +.\" $Id: ipcs.1,v 1.2 1994/06/18 22:28:58 cgd Exp $ +.\" +.Dd June 18, 1994 +.Dt "IPCS" 1 +.Os NetBSD 0.9c +.Sh NAME +.Nm ipcs +.Nd report System V interprocess communication facilities status +.Sh SYNOPSIS +.Nm ipcs +.Op Fl abcmopqstMQST +.Op Fl C Ar system +.Op Fl N Ar core +.Sh DESCRIPTION +The +.Nm ipcs +program provides information on System V interprocess communication +(IPC) facilities on the system. +.Pp +The options are as follows: +.Bl -tag -width Ds +.It Fl a +Show the maximum amount of information possible when +displaying active semaphores, message queues, +and shared memory segments. +(This is shorthand for specifying the +.Fl b , +.Fl c , +.Fl o , +.Fl p , +and +.Fl t +options.) +.It Fl b +Show the maximum allowed sizes for active semaphores, message queues, +and shared memory segments. The +.Dq maximum allowed size +is the maximum number of bytes in a message on a message queue, +the size of a shared memory segment, +or the number number of semaphores in a set of semaphores. +.It Fl c +Show the creator's name and group for active semaphores, message queues, +and shared memory segments. +.It Fl m +Display information about active shared memory segments. +.It Fl o +Show outstanding usage for active message queues, +and shared memory segments. The +.Dq outstanding usage +is the number of messages in a message queue, or the number +of processes attached to a shared memory segment. +.It Fl p +Show the process ID information for active semaphores, message queues, +and shared memory segments. The +.Dq process ID information +is the last process to send a message to or receive a message from +a message queue, +the process that created a semaphore, or the last process to attach +or detach a shared memory segment. +.It Fl q +Display information about active message queues. +.It Fl s +Display information about active semaphores. +.It Fl t +Show access times for active semaphores, message queues, +and shared memory segments. The access times is the time +of the last control operation on an IPC object, +the last send or receive of a message, +the last attach or detach of a shared memory segment, +or the last operation on a semaphore. +.It Fl C Ar system +Extract the name list from the specified system instead of the +default +.Dq Pa /kernel . +.It Fl M +Display system information about shared memory. +.It Fl N Ar core +Extract values associated with the name list from the specified +core instead of the default +.Dq Pa /dev/kmem . +and semaphores. +.It Fl Q +Display system information about messages queues. +.It Fl S +Display system information about semaphores. +.It Fl T +Display system information about shared memory, message queues +.El +.Pp +If none of the +.Fl M , +.Fl m , +.Fl Q , +.Fl q , +.Fl S , +or +.Fl s +options are specified, information about all active IPC facilities is +listed. +.Sh RESTRICTIONS +System data structures may change while +.Nm ipcs +is running; the output of +.Nm ipcs +is not guaranteed to be consistent. +.Sh BUGS +This manual page is woefully incomplete, because it does not +at all attempt to explain the information printed by +.Nm ipcs . +.Sh FILES +.Bl -tag -width /etc/passwd -compact +.It Pa /dev/kmem +default kernel memory +.It Pa /kernel +default system name list +.El +.Sh SEE ALSO +.Xr ipcrm 1 +.Sh AUTHOR +.Bl -tag +Thorsten Lockert +.El diff --git a/usr.bin/ipcs/ipcs.c b/usr.bin/ipcs/ipcs.c index a32ad7e..37e217c 100644 --- a/usr.bin/ipcs/ipcs.c +++ b/usr.bin/ipcs/ipcs.c @@ -1,16 +1,44 @@ /* - * Simplified implementation of SYSV ipcs. + * Copyright (c) 1994 SigmaSoft, Th. Lockert + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * $Id: ipcs.c,v 1.6 1994/06/18 22:05:08 cgd Exp $ */ -#include #include #include #include +#include #include +#include +#include +#include -#include #include #include +#include #include #define KERNEL #include @@ -18,357 +46,433 @@ #include #include -#define SHMSEG_FREE 0x0200 -#define SHMSEG_REMOVED 0x0400 -#define SHMSEG_ALLOCATED 0x0800 -#define SHMSEG_WANTED 0x1000 +int semconfig __P((int,...)); +void usage __P((void)); + +static struct nlist symbols[] = { + {"_sema"}, +#define X_SEMA 0 + {"_seminfo"}, +#define X_SEMINFO 1 + {"_semu"}, +#define X_SEMU 2 + {"_msginfo"}, +#define X_MSGINFO 3 + {"_msqids"}, +#define X_MSQIDS 4 + {"_shminfo"}, +#define X_SHMINFO 5 + {"_shmsegs"}, +#define X_SHMSEGS 6 + {NULL} +}; -static kmem_fd; +static kvm_t *kd; -getsymbol(struct nlist *symbols, char *symname, void *dptr, int len) +char * +fmt_perm(mode) + u_short mode; { - int i, rlen; - - for ( i = 0; symbols[i].n_name != NULL; i += 1 ) { - if ( strcmp(symbols[i].n_name,symname) == 0 ) { - break; - } - } - - if ( symbols[i].n_name == NULL ) { - fprintf(stderr,"ipcs(getsymbol): symbol %s not in local symbols list\n", - symname); - exit(1); - } - - if ( symbols[i].n_value == NULL ) { - fprintf(stderr,"ipcs(getsymbol): symbol %s not in %s\n", - symname,_PATH_UNIX); - return(0); - } - - if ( kmem_fd == 0 ) { - kmem_fd = open("/dev/kmem",0); - if ( kmem_fd < 0 ) { - perror("ipcs(getsymbol(open /dev/kmem))"); - exit(1); - } - } - - lseek(kmem_fd,symbols[i].n_value,SEEK_SET); - if ( (rlen = read(kmem_fd,dptr,len)) != len ) { - fprintf(stderr,"ipcs(getsymbol): can't fetch symbol %s from /dev/kmem\n",symname); - exit(1); - } - return(1); + static char buffer[100]; + + buffer[0] = '-'; + buffer[1] = '-'; + buffer[2] = ((mode & 0400) ? 'r' : '-'); + buffer[3] = ((mode & 0200) ? 'w' : '-'); + buffer[4] = ((mode & 0100) ? 'a' : '-'); + buffer[5] = ((mode & 0040) ? 'r' : '-'); + buffer[6] = ((mode & 0020) ? 'w' : '-'); + buffer[7] = ((mode & 0010) ? 'a' : '-'); + buffer[8] = ((mode & 0004) ? 'r' : '-'); + buffer[9] = ((mode & 0002) ? 'w' : '-'); + buffer[10] = ((mode & 0001) ? 'a' : '-'); + buffer[11] = '\0'; + return (&buffer[0]); } void -getlocation(void *addr, void *dptr, int len) -{ - int i, rlen; - - if ( kmem_fd == 0 ) { - kmem_fd = open("/dev/kmem",0); - if ( kmem_fd < 0 ) { - perror("ipcs(getlocation(open /dev/kmem))"); - exit(1); - } - } - - lseek(kmem_fd,(long)addr,SEEK_SET); - if ( (rlen = read(kmem_fd,dptr,len)) != len ) { - fprintf(stderr,"ipcs(getlocation): can't fetch location %08x from /dev/kmem\n",addr); - exit(1); - } -} - -char * -fmt_perm(ushort mode) +cvt_time(t, buf) + time_t t; + char *buf; { - static char buffer[100]; - - buffer[0] = '-'; - buffer[1] = '-'; - buffer[2] = ((mode & 0400) ? 'r' : '-'); - buffer[3] = ((mode & 0200) ? 'w' : '-'); - buffer[4] = ((mode & 0100) ? 'a' : '-'); - buffer[5] = ((mode & 0040) ? 'r' : '-'); - buffer[6] = ((mode & 0020) ? 'w' : '-'); - buffer[7] = ((mode & 0010) ? 'a' : '-'); - buffer[8] = ((mode & 0004) ? 'r' : '-'); - buffer[9] = ((mode & 0002) ? 'w' : '-'); - buffer[10] = ((mode & 0001) ? 'a' : '-'); - buffer[11] = '\0'; - return(&buffer[0]); -} + struct tm *tm; -void -cvt_time(time_t t,char *buf) -{ - struct tm tms; - static char *months[] = {"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"}; - if ( t == 0 ) { - strcpy(buf,""); - } else { - tms = *localtime(&t); - if ( t > time(0) - 6 * 30 * 24 * 3600 ) { /* less than about 6 months ago? */ - sprintf(buf,"%s %2d %2d:%2d", - months[tms.tm_mon],tms.tm_mday,tms.tm_hour,tms.tm_min); + if (t == 0) { + strcpy(buf, "no-entry"); } else { - sprintf(buf,"%s %2d %5d", - months[tms.tm_mon],tms.tm_mday,tms.tm_year+1900); + tm = localtime(&t); + sprintf(buf, "%2d:%02d:%02d", + tm->tm_hour, tm->tm_min, tm->tm_sec); } - } } - -main() +#define SHMINFO 1 +#define SHMTOTAL 2 +#define MSGINFO 4 +#define MSGTOTAL 8 +#define SEMINFO 16 +#define SEMTOTAL 32 + +#define BIGGEST 1 +#define CREATOR 2 +#define OUTSTANDING 4 +#define PID 8 +#define TIME 16 + +int +main(argc, argv) + int argc; + char *argv[]; { - static struct nlist symbols[] = { - { "_sema" }, - { "_seminfo" }, - { "_semu" }, - { "_msginfo" }, - { "_msqids" }, - { "_shminfo" }, - { "_shmsegs" }, - { NULL } - }; - int i; - int show_sem_values = 1; - int show_undo_values = 1; - - switch ( nlist(_PATH_UNIX,&symbols[0]) ) { - case 0: break; - case -1: - fprintf(stderr,"ipcs: can't open %s - bye!\n",_PATH_UNIX); - exit(1); - default: - fprintf(stderr,"ipcs: nlist failed\n"); - for ( i = 0; symbols[i].n_name != NULL; i += 1 ) { - if ( symbols[i].n_value == 0 ) { - fprintf(stderr,"\tsymbol %s not found\n",symbols[i].n_name); - } - } - break; - } - - /* - for ( i = 0; symbols[i].n_name != NULL; i += 1 ) { - fprintf(stderr,"\t%s : %08x\n",symbols[i].n_name,symbols[i].n_value); - } - */ - - if ( getsymbol(symbols,"_shminfo",&shminfo,sizeof(shminfo)) ) { - struct shmid_ds* xshm; -struct shminfo { - int shmmax, /* max shared memory segment size (bytes) */ - shmmin, /* min shared memory segment size (bytes) */ - shmmni, /* max number of shared memory identifiers */ - shmseg, /* max shared memory segments per process */ - shmall; /* max amount of shared memory (pages) */ -}; - printf("shminfo:\n"); - printf("\tshmmax: %6d\t(max size of a shared memory segment)\n", shminfo.shmmax); - printf("\tshmmin: %6d\t(min size of a shared memory segment)\n", shminfo.shmmin); - printf("\tshmmni: %6d\t(max # of shared memory segments)\n", shminfo.shmmni); - printf("\tshmseg: %6d\t(max # of shared memory segments per process)\n", shminfo.shmseg); - printf("\tshmall: %6d\t(# of shared memory pages available)\n", shminfo.shmall); - - getsymbol(symbols, "_shmsegs", &shmsegs, sizeof(shmsegs)); - xshm = malloc(sizeof(struct shmid_ds) * shminfo.shmmni); - getlocation(shmsegs,xshm,sizeof(struct shmid_ds) * shminfo.shmmni); - for ( i = 0; i < shminfo.shmmni; i += 1 ) { - if ( (xshm[i].shm_perm.mode & SHMSEG_ALLOCATED) != 0 ) { - char ctime_buf[100], atime_buf[100]; - struct shmid_ds* shmaptr = &xshm[i]; - cvt_time(shmaptr->shm_ctime,ctime_buf); - cvt_time(shmaptr->shm_atime,atime_buf); - - printf("\nshma id: %d key: 0x%08x:\n", - IXSEQ_TO_IPCID(i,shmaptr->shm_perm), - shmaptr->shm_perm.key); - - printf(" cuid: %6d cgid: %6d ctime: %s\n", - shmaptr->shm_perm.cuid,shmaptr->shm_perm.cgid,ctime_buf); - - printf(" uid: %6d gid: %6d atime: %s\n", - shmaptr->shm_perm.uid,shmaptr->shm_perm.gid,atime_buf); - - printf(" size: %6d attach:%6d perm: %s\n", - shmaptr->shm_segsz,shmaptr->shm_nattch,fmt_perm(shmaptr->shm_perm.mode)); - } - } - } - - if ( getsymbol(symbols,"_seminfo",&seminfo,sizeof(seminfo)) ) { - struct semid_ds *xsema; - - printf("\nseminfo:\n"); - printf("\tsemmap: %6d\t(# of entries in semaphore map)\n",seminfo.semmap); - printf("\tsemmni: %6d\t(# of semaphore identifiers)\n",seminfo.semmni); - printf("\tsemmns: %6d\t(# of semaphores in system)\n",seminfo.semmns); - printf("\tsemmnu: %6d\t(# of undo structures in system)\n",seminfo.semmnu); - printf("\tsemmsl: %6d\t(max # of semaphores per id)\n",seminfo.semmsl); - printf("\tsemopm: %6d\t(max # of operations per semop call)\n",seminfo.semopm); - printf("\tsemume: %6d\t(max # of undo entries per process)\n",seminfo.semume); - printf("\tsemusz: %6d\t(size in bytes of undo structure)\n",seminfo.semusz); - printf("\tsemvmx: %6d\t(semaphore maximum value)\n",seminfo.semvmx); - printf("\tsemaem: %6d\t(adjust on exit max value)\n",seminfo.semaem); - - /* - * Lock out other users of the semaphore facility - */ - - if ( semconfig(SEM_CONFIG_FREEZE) != 0 ) { - perror("semconfig"); - fprintf(stderr,"Can't lock semaphore facility - winging it...\n"); + int display = SHMINFO | MSGINFO | SEMINFO; + int option = 0; + char *core = NULL, *namelist = NULL; + int i; + + while ((i = getopt(argc, argv, "MmQqSsabC:cN:optT")) != EOF) + switch (i) { + case 'M': + display = SHMTOTAL; + break; + case 'm': + display = SHMINFO; + break; + case 'Q': + display = MSGTOTAL; + break; + case 'q': + display = MSGINFO; + break; + case 'S': + display = SEMTOTAL; + break; + case 's': + display = SEMINFO; + break; + case 'T': + display = SHMTOTAL | MSGTOTAL | SEMTOTAL; + break; + case 'a': + option |= BIGGEST | CREATOR | OUTSTANDING | PID | TIME; + break; + case 'b': + option |= BIGGEST; + break; + case 'C': + core = optarg; + break; + case 'c': + option |= CREATOR; + break; + case 'N': + namelist = optarg; + break; + case 'o': + option |= OUTSTANDING; + break; + case 'p': + option |= PID; + break; + case 't': + option |= TIME; + break; + default: + usage(); + } + if ((kd = kvm_open(namelist, core, NULL, O_RDONLY, "ipcs")) == NULL) + exit(1); + + switch (kvm_nlist(kd, symbols)) { + case 0: + break; + case -1: + errx(1, "unable to read kernel symbol table."); + default: +#ifdef notdef /* they'll be told more civilly later */ + warnx("nlist failed"); + for (i = 0; symbols[i].n_name != NULL; i++) + if (symbols[i].n_value == 0) + warnx("symbol %s not found", + symbols[i].n_name); + break; +#endif } - getsymbol(symbols,"_sema",&sema,sizeof(sema)); - xsema = malloc(sizeof(struct semid_ds) * seminfo.semmni); - getlocation(sema,xsema,sizeof(struct semid_ds) * seminfo.semmni); - - for ( i = 0; i < seminfo.semmni; i += 1 ) { - if ( (xsema[i].sem_perm.mode & SEM_ALLOC) != 0 ) { - char ctime_buf[100], otime_buf[100]; - struct semid_ds *semaptr = &xsema[i]; - cvt_time(semaptr->sem_ctime,ctime_buf); - cvt_time(semaptr->sem_otime,otime_buf); - - printf("\nsema id: %d key: 0x%08x:\n", - IXSEQ_TO_IPCID(i,semaptr->sem_perm), - semaptr->sem_perm.key); - - printf(" cuid: %6d cgid: %6d ctime: %s\n", - semaptr->sem_perm.cuid,semaptr->sem_perm.cgid,ctime_buf); - - printf(" uid: %6d gid: %6d otime: %s\n", - semaptr->sem_perm.uid,semaptr->sem_perm.gid,otime_buf); - - printf(" nsems: %6d perm: %s\n", - semaptr->sem_nsems,fmt_perm(semaptr->sem_perm.mode)); - - if ( show_sem_values ) { - int j, value; - union semun junk; - for ( j = 0; j < semaptr->sem_nsems; j += 1 ) { - if ( (value = semctl( IXSEQ_TO_IPCID(i,semaptr->sem_perm), j, GETVAL, junk )) < 0 ) { - printf("can't get semaphore values\n"); - break; - } - if ( j % 5 == 0 ) { - if ( j == 0 ) { - printf(" values: {"); - } else { - printf("\n"); - printf(" "); - } + if ((display & (MSGINFO | MSGTOTAL)) && + kvm_read(kd, symbols[X_MSGINFO].n_value, &msginfo, sizeof(msginfo))) { + + if (display & MSGTOTAL) { + printf("msginfo:\n"); + printf("\tmsgmax: %6d\t(max characters in a message)\n", + msginfo.msgmax); + printf("\tmsgmni: %6d\t(# of message queues)\n", + msginfo.msgmni); + printf("\tmsgmnb: %6d\t(max characters in a message queue)\n", + msginfo.msgmnb); + printf("\tmsgtql: %6d\t(max # of messages in system)\n", + msginfo.msgtql); + printf("\tmsgssz: %6d\t(size of a message segment)\n", + msginfo.msgssz); + printf("\tmsgseg: %6d\t(# of message segments in system)\n\n", + msginfo.msgseg); + } + if (display & MSGINFO) { + struct msqid_ds *xmsqids; + + kvm_read(kd, symbols[X_MSQIDS].n_value, &msqids, sizeof(msqids)); + xmsqids = malloc(sizeof(struct msqid_ds) * msginfo.msgmni); + kvm_read(kd, (u_long) msqids, xmsqids, sizeof(struct msqid_ds) * msginfo.msgmni); + + printf("Message Queues:\n"); + printf("T ID KEY MODE OWNER GROUP"); + if (option & CREATOR) + printf(" CREATOR CGROUP"); + if (option & OUTSTANDING) + printf(" CBYTES QNUM"); + if (option & BIGGEST) + printf(" QBYTES"); + if (option & PID) + printf(" LSPID LRPID"); + if (option & TIME) + printf(" STIME RTIME CTIME"); + printf("\n"); + for (i = 0; i < msginfo.msgmni; i += 1) { + if (xmsqids[i].msg_qbytes != 0) { + char stime_buf[100], rtime_buf[100], + ctime_buf[100]; + struct msqid_ds *msqptr = &xmsqids[i]; + + cvt_time(msqptr->msg_stime, stime_buf); + cvt_time(msqptr->msg_rtime, rtime_buf); + cvt_time(msqptr->msg_ctime, ctime_buf); + + printf("q %6d %10d %s %8s %8s", + IXSEQ_TO_IPCID(i, msqptr->msg_perm), + msqptr->msg_perm.key, + fmt_perm(msqptr->msg_perm.mode), + user_from_uid(msqptr->msg_perm.uid, 0), + group_from_gid(msqptr->msg_perm.gid, 0)); + + if (option & CREATOR) + printf(" %8s %8s", + user_from_uid(msqptr->msg_perm.cuid, 0), + group_from_gid(msqptr->msg_perm.cgid, 0)); + + if (option & OUTSTANDING) + printf(" %6d %6d", + msqptr->msg_cbytes, + msqptr->msg_qnum); + + if (option & BIGGEST) + printf(" %6d", + msqptr->msg_qbytes); + + if (option & PID) + printf(" %6d %6d", + msqptr->msg_lspid, + msqptr->msg_lrpid); + + if (option & TIME) + printf("%s %s %s", + stime_buf, + rtime_buf, + ctime_buf); + + printf("\n"); + } } - printf(" %d",value); - if ( j == semaptr->sem_nsems - 1 ) { - printf(" }\n"); - } else { - printf(", "); + printf("\n"); + } + } else + if (display & (MSGINFO | MSGTOTAL)) { + fprintf(stderr, + "SVID messages facility not configured in the system\n"); + } + if ((display & (SHMINFO | SHMTOTAL)) && + kvm_read(kd, symbols[X_SHMINFO].n_value, &shminfo, sizeof(shminfo))) { + if (display & SHMTOTAL) { + printf("shminfo:\n"); + printf("\tshmmax: %7d\t(max shared memory segment size)\n", + shminfo.shmmax); + printf("\tshmmin: %7d\t(min shared memory segment size)\n", + shminfo.shmmin); + printf("\tshmmni: %7d\t(max number of shared memory identifiers)\n", + shminfo.shmmni); + printf("\tshmseg: %7d\t(max shared memory segments per process)\n", + shminfo.shmseg); + printf("\tshmall: %7d\t(max amount of shared memory in pages)\n\n", + shminfo.shmall); + } + if (display & SHMINFO) { + struct shmid_ds *xshmids; + + kvm_read(kd, symbols[X_SHMSEGS].n_value, &shmsegs, sizeof(shmsegs)); + xshmids = malloc(sizeof(struct shmid_ds) * msginfo.msgmni); + kvm_read(kd, (u_long) shmsegs, xshmids, sizeof(struct shmid_ds) * + shminfo.shmmni); + + printf("Shared Memory:\n"); + printf("T ID KEY MODE OWNER GROUP"); + if (option & CREATOR) + printf(" CREATOR CGROUP"); + if (option & OUTSTANDING) + printf(" NATTCH"); + if (option & BIGGEST) + printf(" SEGSZ"); + if (option & PID) + printf(" CPID LPID"); + if (option & TIME) + printf(" ATIME DTIME CTIME"); + printf("\n"); + for (i = 0; i < shminfo.shmmni; i += 1) { + if (xshmids[i].shm_perm.mode & 0x0800) { + char atime_buf[100], dtime_buf[100], + ctime_buf[100]; + struct shmid_ds *shmptr = &xshmids[i]; + + cvt_time(shmptr->shm_atime, atime_buf); + cvt_time(shmptr->shm_dtime, dtime_buf); + cvt_time(shmptr->shm_ctime, ctime_buf); + + printf("m %6d %10d %s %8s %8s", + IXSEQ_TO_IPCID(i, shmptr->shm_perm), + shmptr->shm_perm.key, + fmt_perm(shmptr->shm_perm.mode), + user_from_uid(shmptr->shm_perm.uid, 0), + group_from_gid(shmptr->shm_perm.gid, 0)); + + if (option & CREATOR) + printf(" %8s %8s", + user_from_uid(shmptr->shm_perm.cuid, 0), + group_from_gid(shmptr->shm_perm.cgid, 0)); + + if (option & OUTSTANDING) + printf(" %6d", + shmptr->shm_nattch); + + if (option & BIGGEST) + printf(" %6d", + shmptr->shm_segsz); + + if (option & PID) + printf(" %6d %6d", + shmptr->shm_cpid, + shmptr->shm_lpid); + + if (option & TIME) + printf("%s %s %s", + atime_buf, + dtime_buf, + ctime_buf); + + printf("\n"); + } } - } + printf("\n"); } - - } - - } - - if ( show_undo_values ) { - int j; - int *ksemu, *semu; - int semu_size; - int got_one_undo = 0; - - semu = 0; - semu_size = (int)SEMU(seminfo.semmnu); - semu = (int *)malloc( semu_size ); - getsymbol(symbols,"_semu",&ksemu,sizeof(ksemu)); - getlocation(ksemu,semu,semu_size); - - printf("\nsem undos:\n"); - for ( j = 0; j < seminfo.semmnu; j += 1 ) { - struct sem_undo *suptr; - int k; - - suptr = SEMU(j); - if ( suptr->un_proc != NULL ) { - struct proc proc; - getlocation(suptr->un_proc,&proc,sizeof(proc)); - got_one_undo = 1; - printf(" pid %d: semid semnum adjval\n",proc.p_pid); - for ( k = 0; k < suptr->un_cnt; k += 1 ) { - printf(" %10d %5d %6d\n", - IXSEQ_TO_IPCID(suptr->un_ent[k].un_id,xsema[suptr->un_ent[k].un_id].sem_perm), - suptr->un_ent[k].un_num, - suptr->un_ent[k].un_adjval); - } + } else + if (display & (SHMINFO | SHMTOTAL)) { + fprintf(stderr, + "SVID shared memory facility not configured in the system\n"); } - } - if ( !got_one_undo ) { - printf(" none allocated\n"); - } - } - - (void)semconfig(SEM_CONFIG_THAW); - - } else { - fprintf(stderr,"SVID semaphores facility not configured in the system\n"); - } - - if ( getsymbol(symbols,"_msginfo",&msginfo,sizeof(msginfo)) ) { - struct msqid_ds *xmsqids; - - printf("\nmsginfo:\n"); - printf("\tmsgmax: %6d\t(max characters in a message)\n",msginfo.msgmax); - printf("\tmsgmni: %6d\t(# of message queues)\n",msginfo.msgmni); - printf("\tmsgmnb: %6d\t(max characters in a message queue)\n",msginfo.msgmnb); - printf("\tmsgtql: %6d\t(max # of messages in system)\n",msginfo.msgtql); - printf("\tmsgssz: %6d\t(size of a message segment)\n",msginfo.msgssz); - printf("\tmsgseg: %6d\t(# of message segments in system)\n",msginfo.msgseg); - - getsymbol(symbols,"_msqids",&msqids,sizeof(msqids)); - xmsqids = malloc(sizeof(struct msqid_ds) * msginfo.msgmni); - getlocation(msqids,xmsqids,sizeof(struct msqid_ds) * msginfo.msgmni); - - for ( i = 0; i < msginfo.msgmni; i += 1 ) { - if ( xmsqids[i].msg_qbytes != 0 ) { - char stime_buf[100], rtime_buf[100], ctime_buf[100]; - struct msqid_ds *msqptr = &xmsqids[i]; - - cvt_time(msqptr->msg_stime,stime_buf); - cvt_time(msqptr->msg_rtime,rtime_buf); - cvt_time(msqptr->msg_ctime,ctime_buf); - - printf("\nmsgq id: %d key: 0x%08x\n", - IXSEQ_TO_IPCID(i,msqptr->msg_perm), - msqptr->msg_perm.key); - - printf(" cuid: %6d cgid: %6d ctime: %s\n", - msqptr->msg_perm.cuid,msqptr->msg_perm.cgid,ctime_buf); - - printf(" uid: %6d gid: %6d\n", - msqptr->msg_perm.uid,msqptr->msg_perm.gid); - - printf(" lspid: %6d stime: %s\n", - msqptr->msg_lspid,stime_buf); + if ((display & (SEMINFO | SEMTOTAL)) && + kvm_read(kd, symbols[X_SEMINFO].n_value, &seminfo, sizeof(seminfo))) { + struct semid_ds *xsema; + + if (display & SEMTOTAL) { + printf("seminfo:\n"); + printf("\tsemmap: %6d\t(# of entries in semaphore map)\n", + seminfo.semmap); + printf("\tsemmni: %6d\t(# of semaphore identifiers)\n", + seminfo.semmni); + printf("\tsemmns: %6d\t(# of semaphores in system)\n", + seminfo.semmns); + printf("\tsemmnu: %6d\t(# of undo structures in system)\n", + seminfo.semmnu); + printf("\tsemmsl: %6d\t(max # of semaphores per id)\n", + seminfo.semmsl); + printf("\tsemopm: %6d\t(max # of operations per semop call)\n", + seminfo.semopm); + printf("\tsemume: %6d\t(max # of undo entries per process)\n", + seminfo.semume); + printf("\tsemusz: %6d\t(size in bytes of undo structure)\n", + seminfo.semusz); + printf("\tsemvmx: %6d\t(semaphore maximum value)\n", + seminfo.semvmx); + printf("\tsemaem: %6d\t(adjust on exit max value)\n\n", + seminfo.semaem); + } + if (display & SEMINFO) { + if (semconfig(SEM_CONFIG_FREEZE) != 0) { + perror("semconfig"); + fprintf(stderr, + "Can't lock semaphore facility - winging it...\n"); + } + kvm_read(kd, symbols[X_SEMA].n_value, &sema, sizeof(sema)); + xsema = malloc(sizeof(struct semid_ds) * seminfo.semmni); + kvm_read(kd, (u_long) sema, xsema, sizeof(struct semid_ds) * seminfo.semmni); + + printf("Semaphores:\n"); + printf("T ID KEY MODE OWNER GROUP"); + if (option & CREATOR) + printf(" CREATOR CGROUP"); + if (option & BIGGEST) + printf(" NSEMS"); + if (option & TIME) + printf(" OTIME CTIME"); + printf("\n"); + for (i = 0; i < seminfo.semmni; i += 1) { + if ((xsema[i].sem_perm.mode & SEM_ALLOC) != 0) { + char ctime_buf[100], otime_buf[100]; + struct semid_ds *semaptr = &xsema[i]; + int j, value; + union semun junk; + + cvt_time(semaptr->sem_otime, otime_buf); + cvt_time(semaptr->sem_ctime, ctime_buf); + + printf("s %6d %10d %s %8s %8s", + IXSEQ_TO_IPCID(i, semaptr->sem_perm), + semaptr->sem_perm.key, + fmt_perm(semaptr->sem_perm.mode), + user_from_uid(semaptr->sem_perm.uid, 0), + group_from_gid(semaptr->sem_perm.gid, 0)); + + if (option & CREATOR) + printf(" %8s %8s", + user_from_uid(semaptr->sem_perm.cuid, 0), + group_from_gid(semaptr->sem_perm.cgid, 0)); + + if (option & BIGGEST) + printf(" %6d", + semaptr->sem_nsems); + + if (option & TIME) + printf("%s %s", + otime_buf, + ctime_buf); + + printf("\n"); + } + } - printf(" lrpid: %6d qnum: %6d rtime: %s\n", - msqptr->msg_lrpid,msqptr->msg_qnum,rtime_buf); + (void) semconfig(SEM_CONFIG_THAW); - printf(" cbytes:%6d qbytes:%6d perm: %s\n", - msqptr->msg_cbytes,msqptr->msg_qbytes,fmt_perm(msqptr->msg_perm.mode)); + printf("\n"); + } + } else + if (display & (SEMINFO | SEMTOTAL)) { + fprintf(stderr, "SVID semaphores facility not configured in the system\n"); + } + kvm_close(kd); - } - } + exit(0); +} - } else { - fprintf(stderr,"SVID messages facility not configured in the system\n"); - } +void +usage() +{ - exit(0); + fprintf(stderr, + "usage: ipcs [-abcmopqst] [-C corefile] [-N namelist]\n"); + exit(1); } -- cgit v1.1