version 1.15, 2001/08/13 15:10:21 |
version 1.16, 2001/09/28 01:44:37 |
|
|
/* $OpenBSD$ */ |
/* $OpenBSD$ */ |
/* $NetBSD: ipcs.c,v 1.10.6.1 1996/06/07 01:53:47 thorpej Exp $ */ |
/* $NetBSD: ipcs.c,v 1.25 2000/06/16 03:58:20 simonb Exp $ */ |
|
|
|
/*- |
|
* Copyright (c) 2000 The NetBSD Foundation, Inc. |
|
* All rights reserved. |
|
* |
|
* This code is derived from software contributed to The NetBSD Foundation |
|
* by Simon Burge. |
|
* |
|
* 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 the NetBSD |
|
* Foundation, Inc. and its contributors. |
|
* 4. Neither the name of The NetBSD Foundation nor the names of its |
|
* contributors may be used to endorse or promote products derived |
|
* from this software without specific prior written permission. |
|
* |
|
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS |
|
* ``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 FOUNDATION OR CONTRIBUTORS |
|
* 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. |
|
*/ |
|
|
/* |
/* |
* Copyright (c) 1994 SigmaSoft, Th. Lockert <tholo@sigmasoft.com> |
* Copyright (c) 1994 SigmaSoft, Th. Lockert <tholo@sigmasoft.com> |
* All rights reserved. |
* All rights reserved. |
|
|
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
*/ |
*/ |
|
|
#include <sys/types.h> |
|
#include <sys/param.h> |
#include <sys/param.h> |
#include <sys/time.h> |
#include <sys/sysctl.h> |
#include <sys/proc.h> |
|
#define _KERNEL |
#define _KERNEL |
#include <sys/ipc.h> |
#include <sys/ipc.h> |
#include <sys/sem.h> |
#include <sys/sem.h> |
|
|
|
|
#include <err.h> |
#include <err.h> |
#include <fcntl.h> |
#include <fcntl.h> |
#include <kvm.h> |
|
#include <pwd.h> |
|
#include <grp.h> |
#include <grp.h> |
|
#include <kvm.h> |
#include <limits.h> |
#include <limits.h> |
#include <nlist.h> |
#include <nlist.h> |
#include <paths.h> |
#include <paths.h> |
|
#include <pwd.h> |
#include <stdio.h> |
#include <stdio.h> |
#include <stdlib.h> |
#include <stdlib.h> |
#include <string.h> |
#include <string.h> |
|
#include <time.h> |
#include <unistd.h> |
#include <unistd.h> |
|
|
void usage __P((void)); |
void cvt_time(time_t, char *, size_t); |
|
char *fmt_perm(mode_t); |
|
void ipcs_kvm(void); |
|
int main(int, char **); |
|
void msg_sysctl(void); |
|
void sem_sysctl(void); |
|
void shm_sysctl(void); |
|
void show_msginfo(time_t, time_t, time_t, int, key_t, mode_t, uid_t, |
|
gid_t, uid_t, gid_t, u_long, u_long, u_long, pid_t, pid_t); |
|
void show_msginfo_hdr(void); |
|
void show_msgtotal(struct msginfo *); |
|
void show_seminfo_hdr(void); |
|
void show_seminfo(time_t, time_t, int, key_t, mode_t, uid_t, gid_t, |
|
uid_t, gid_t, int16_t); |
|
void show_semtotal(struct seminfo *); |
|
void show_shminfo(time_t, time_t, time_t, int, key_t, mode_t, uid_t, |
|
gid_t, uid_t, gid_t, u_int32_t, int, pid_t, pid_t); |
|
void show_shminfo_hdr(void); |
|
void show_shmtotal(struct shminfo *); |
|
__dead void usage(void); |
|
|
extern char *__progname; /* from crt0.o */ |
char * |
|
fmt_perm(mode_t mode) |
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 kvm_t *kd; |
|
|
|
char * |
|
fmt_perm(mode) |
|
u_short mode; |
|
{ |
{ |
static char buffer[100]; |
static char buffer[12]; |
|
|
buffer[0] = '-'; |
buffer[0] = '-'; |
buffer[1] = '-'; |
buffer[1] = '-'; |
|
|
} |
} |
|
|
void |
void |
cvt_time(t, buf) |
cvt_time(time_t t, char *buf, size_t buflen) |
time_t t; |
|
char *buf; |
|
{ |
{ |
struct tm *tm; |
struct tm *tm; |
|
|
if (t == 0) { |
if (t == 0) |
strcpy(buf, "no-entry"); |
(void)strlcpy(buf, "no-entry", buflen); |
} else { |
else { |
tm = localtime(&t); |
tm = localtime(&t); |
sprintf(buf, "%2d:%02d:%02d", |
(void)snprintf(buf, buflen, "%2d:%02d:%02d", |
tm->tm_hour, tm->tm_min, tm->tm_sec); |
tm->tm_hour, tm->tm_min, tm->tm_sec); |
} |
} |
} |
} |
|
|
#define PID 8 |
#define PID 8 |
#define TIME 16 |
#define TIME 16 |
|
|
|
char *core = NULL, *namelist = NULL; |
|
int display = SHMINFO | MSGINFO | SEMINFO; |
|
int option = 0; |
|
|
int |
int |
main(argc, argv) |
main(int argc, char **argv) |
int argc; |
|
char *argv[]; |
|
{ |
{ |
struct semid_ds *sema; |
int ch; |
struct seminfo seminfo; |
|
int semu; |
|
struct msginfo msginfo; |
|
struct msqid_ds *msqids; |
|
struct shminfo shminfo; |
|
struct shmid_ds *shmsegs; |
|
int display = SHMINFO | MSGINFO | SEMINFO; |
|
int option = 0; |
|
char *core = NULL, *namelist = NULL; |
|
int i; |
|
|
|
while ((i = getopt(argc, argv, "MmQqSsabC:cN:optT")) != -1) |
while ((ch = getopt(argc, argv, "MmQqSsabC:cN:optT")) != -1) |
switch (i) { |
switch (ch) { |
case 'M': |
case 'M': |
display = SHMTOTAL; |
display = SHMTOTAL; |
break; |
break; |
|
|
default: |
default: |
usage(); |
usage(); |
} |
} |
/* |
|
* Discard setgid privileges if not the running kernel so that bad |
if (argc - optind > 0) |
* guys can't print interesting stuff from kernel memory. |
usage(); |
*/ |
|
if (namelist != NULL || core != NULL) { |
if (namelist == NULL && core == NULL) { |
setegid(getgid()); |
if (display & (MSGINFO | MSGTOTAL)) |
setgid(getgid()); |
msg_sysctl(); |
|
if (display & (SHMINFO | SHMTOTAL)) |
|
shm_sysctl(); |
|
if (display & (SEMINFO | SEMTOTAL)) |
|
sem_sysctl(); |
|
} else |
|
ipcs_kvm(); |
|
|
|
exit(0); |
|
} |
|
|
|
void |
|
show_msgtotal(struct msginfo *msginfo) |
|
{ |
|
|
|
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); |
|
} |
|
|
|
void |
|
show_shmtotal(struct shminfo *shminfo) |
|
{ |
|
|
|
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); |
|
} |
|
|
|
void |
|
show_semtotal(struct seminfo *seminfo) |
|
{ |
|
|
|
printf("seminfo:\n"); |
|
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); |
|
} |
|
|
|
void |
|
show_msginfo_hdr(void) |
|
{ |
|
|
|
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"); |
|
} |
|
|
|
void |
|
show_msginfo(time_t stime, time_t rtime, time_t ctime, int ipcid, key_t key, |
|
mode_t mode, uid_t uid, gid_t gid, uid_t cuid, gid_t cgid, |
|
u_long cbytes, u_long qnum, u_long qbytes, pid_t lspid, |
|
pid_t lrpid) |
|
{ |
|
char stime_buf[100], rtime_buf[100], ctime_buf[100]; |
|
|
|
if (option & TIME) { |
|
cvt_time(stime, stime_buf, sizeof(stime_buf)); |
|
cvt_time(rtime, rtime_buf, sizeof(rtime_buf)); |
|
cvt_time(ctime, ctime_buf, sizeof(ctime_buf)); |
} |
} |
if ((kd = kvm_open(namelist, core, NULL, O_RDONLY, "ipcs")) == NULL) |
|
exit(1); |
|
|
|
setegid(getgid()); |
printf("q %6d %10ld %s %8s %8s", ipcid, key, fmt_perm(mode), |
setgid(getgid()); |
user_from_uid(uid, 0), group_from_gid(gid, 0)); |
|
|
|
if (option & CREATOR) |
|
printf(" %8s %8s", user_from_uid(cuid, 0), |
|
group_from_gid(cgid, 0)); |
|
|
|
if (option & OUTSTANDING) |
|
printf(" %6lu %5lu", cbytes, qnum); |
|
|
|
if (option & BIGGEST) |
|
printf(" %6lu", qbytes); |
|
|
|
if (option & PID) |
|
printf(" %5d %5d", lspid, lrpid); |
|
|
|
if (option & TIME) |
|
printf(" %s %s %s", stime_buf, rtime_buf, ctime_buf); |
|
|
|
printf("\n"); |
|
} |
|
|
|
void |
|
show_shminfo_hdr(void) |
|
{ |
|
|
|
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"); |
|
} |
|
|
|
void |
|
show_shminfo(time_t atime, time_t dtime, time_t ctime, int ipcid, key_t key, |
|
mode_t mode, uid_t uid, gid_t gid, uid_t cuid, gid_t cgid, |
|
u_int32_t nattch, int segsz, pid_t cpid, pid_t lpid) |
|
{ |
|
char atime_buf[100], dtime_buf[100], ctime_buf[100]; |
|
|
|
if (option & TIME) { |
|
cvt_time(atime, atime_buf, sizeof(atime_buf)); |
|
cvt_time(dtime, dtime_buf, sizeof(dtime_buf)); |
|
cvt_time(ctime, ctime_buf, sizeof(ctime_buf)); |
|
} |
|
|
|
printf("m %6d %10ld %s %8s %8s", ipcid, key, fmt_perm(mode), |
|
user_from_uid(uid, 0), group_from_gid(gid, 0)); |
|
|
|
if (option & CREATOR) |
|
printf(" %8s %8s", user_from_uid(cuid, 0), |
|
group_from_gid(cgid, 0)); |
|
|
|
if (option & OUTSTANDING) |
|
printf(" %6d", nattch); |
|
|
|
if (option & BIGGEST) |
|
printf(" %7d", segsz); |
|
|
|
if (option & PID) |
|
printf(" %5d %5d", cpid, lpid); |
|
|
|
if (option & TIME) |
|
printf(" %s %s %s", |
|
atime_buf, |
|
dtime_buf, |
|
ctime_buf); |
|
|
|
printf("\n"); |
|
} |
|
|
|
void |
|
show_seminfo_hdr(void) |
|
{ |
|
|
|
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"); |
|
} |
|
|
|
void |
|
show_seminfo(time_t otime, time_t ctime, int ipcid, key_t key, mode_t mode, |
|
uid_t uid, gid_t gid, uid_t cuid, gid_t cgid, int16_t nsems) |
|
{ |
|
char ctime_buf[100], otime_buf[100]; |
|
|
|
if (option & TIME) { |
|
cvt_time(otime, otime_buf, sizeof(otime_buf)); |
|
cvt_time(ctime, ctime_buf, sizeof(ctime_buf)); |
|
} |
|
|
|
printf("s %6d %10ld %s %8s %8s", ipcid, key, fmt_perm(mode), |
|
user_from_uid(uid, 0), group_from_gid(gid, 0)); |
|
|
|
if (option & CREATOR) |
|
printf(" %8s %8s", user_from_uid(cuid, 0), |
|
group_from_gid(cgid, 0)); |
|
|
|
if (option & BIGGEST) |
|
printf(" %5d", nsems); |
|
|
|
if (option & TIME) |
|
printf(" %s %s", otime_buf, ctime_buf); |
|
|
|
printf("\n"); |
|
} |
|
|
|
void |
|
msg_sysctl(void) |
|
{ |
|
struct msg_sysctl_info *msgsi; |
|
char *buf; |
|
int mib[3]; |
|
size_t len; |
|
int i, valid; |
|
|
|
mib[0] = CTL_KERN; |
|
mib[1] = KERN_SYSVMSG; |
|
len = sizeof(valid); |
|
if (sysctl(mib, 2, &valid, &len, NULL, NULL) < 0) { |
|
warn("sysctl(KERN_SYSVMSG)"); |
|
return; |
|
} |
|
if (!valid) { |
|
warnx("SVID messages facility not configured in the system"); |
|
return; |
|
} |
|
|
|
mib[0] = CTL_KERN; |
|
mib[1] = KERN_SYSVIPC_INFO; |
|
mib[2] = KERN_SYSVIPC_MSG_INFO; |
|
|
|
if (!(display & MSGINFO)) { |
|
/* totals only */ |
|
len = sizeof(struct msginfo); |
|
} else { |
|
if (sysctl(mib, 3, NULL, &len, NULL, NULL) < 0) { |
|
warn("sysctl(KERN_SYSVIPC_MSG_INFO)"); |
|
return; |
|
} |
|
} |
|
|
|
if ((buf = malloc(len)) == NULL) |
|
err(1, "malloc"); |
|
msgsi = (struct msg_sysctl_info *)buf; |
|
if (sysctl(mib, 3, msgsi, &len, NULL, NULL) < 0) { |
|
warn("sysctl(KERN_SYSVIPC_MSG_INFO)"); |
|
return; |
|
} |
|
|
|
if (display & MSGTOTAL) |
|
show_msgtotal(&msgsi->msginfo); |
|
|
|
if (display & MSGINFO) { |
|
show_msginfo_hdr(); |
|
for (i = 0; i < msgsi->msginfo.msgmni; i++) { |
|
struct msqid_ds *msqptr = &msgsi->msgids[i]; |
|
if (msqptr->msg_qbytes != 0) |
|
show_msginfo(msqptr->msg_stime, |
|
msqptr->msg_rtime, |
|
msqptr->msg_ctime, |
|
IXSEQ_TO_IPCID(i, msqptr->msg_perm), |
|
msqptr->msg_perm.key, |
|
msqptr->msg_perm.mode, |
|
msqptr->msg_perm.uid, |
|
msqptr->msg_perm.gid, |
|
msqptr->msg_perm.cuid, |
|
msqptr->msg_perm.cgid, |
|
msqptr->msg_cbytes, |
|
msqptr->msg_qnum, |
|
msqptr->msg_qbytes, |
|
msqptr->msg_lspid, |
|
msqptr->msg_lrpid); |
|
} |
|
printf("\n"); |
|
} |
|
} |
|
|
|
void |
|
shm_sysctl(void) |
|
{ |
|
struct shm_sysctl_info *shmsi; |
|
char *buf; |
|
int mib[3]; |
|
size_t len; |
|
int i /*, valid */; |
|
long valid; |
|
|
|
mib[0] = CTL_KERN; |
|
mib[1] = KERN_SYSVSHM; |
|
len = sizeof(valid); |
|
if (sysctl(mib, 2, &valid, &len, NULL, NULL) < 0) { |
|
warn("sysctl(KERN_SYSVSHM)"); |
|
return; |
|
} |
|
if (!valid) { |
|
warnx("SVID shared memory facility not configured in " |
|
"the system"); |
|
return; |
|
} |
|
|
|
mib[0] = CTL_KERN; |
|
mib[1] = KERN_SYSVIPC_INFO; |
|
mib[2] = KERN_SYSVIPC_SHM_INFO; |
|
|
|
if (!(display & SHMINFO)) { |
|
/* totals only */ |
|
len = sizeof(struct shminfo); |
|
} else { |
|
if (sysctl(mib, 3, NULL, &len, NULL, NULL) < 0) { |
|
warn("sysctl(KERN_SYSVIPC_SHM_INFO)"); |
|
return; |
|
} |
|
} |
|
|
|
if ((buf = malloc(len)) == NULL) |
|
err(1, "malloc"); |
|
shmsi = (struct shm_sysctl_info *)buf; |
|
if (sysctl(mib, 3, shmsi, &len, NULL, NULL) < 0) { |
|
warn("sysctl(KERN_SYSVIPC_SHM_INFO)"); |
|
return; |
|
} |
|
|
|
if (display & SHMTOTAL) |
|
show_shmtotal(&shmsi->shminfo); |
|
|
|
if (display & SHMINFO) { |
|
show_shminfo_hdr(); |
|
for (i = 0; i < shmsi->shminfo.shmmni; i++) { |
|
struct shmid_ds *shmptr = &shmsi->shmids[i]; |
|
if (shmptr->shm_perm.mode & 0x0800) |
|
show_shminfo(shmptr->shm_atime, |
|
shmptr->shm_dtime, |
|
shmptr->shm_ctime, |
|
IXSEQ_TO_IPCID(i, shmptr->shm_perm), |
|
shmptr->shm_perm.key, |
|
shmptr->shm_perm.mode, |
|
shmptr->shm_perm.uid, |
|
shmptr->shm_perm.gid, |
|
shmptr->shm_perm.cuid, |
|
shmptr->shm_perm.cgid, |
|
shmptr->shm_nattch, |
|
shmptr->shm_segsz, |
|
shmptr->shm_cpid, |
|
shmptr->shm_lpid); |
|
} |
|
printf("\n"); |
|
} |
|
} |
|
|
|
void |
|
sem_sysctl(void) |
|
{ |
|
struct sem_sysctl_info *semsi; |
|
char *buf; |
|
int mib[3]; |
|
size_t len; |
|
int i, valid; |
|
|
|
mib[0] = CTL_KERN; |
|
mib[1] = KERN_SYSVSEM; |
|
len = sizeof(valid); |
|
if (sysctl(mib, 2, &valid, &len, NULL, NULL) < 0) { |
|
warn("sysctl(KERN_SYSVSEM)"); |
|
return; |
|
} |
|
if (!valid) { |
|
warnx("SVID shared memory facility not configured in " |
|
"the system"); |
|
return; |
|
} |
|
|
|
mib[0] = CTL_KERN; |
|
mib[1] = KERN_SYSVIPC_INFO; |
|
mib[2] = KERN_SYSVIPC_SEM_INFO; |
|
|
|
if (!(display & SEMINFO)) { |
|
/* totals only */ |
|
len = sizeof(struct seminfo); |
|
} else { |
|
if (sysctl(mib, 3, NULL, &len, NULL, NULL) < 0) { |
|
warn("sysctl(KERN_SYSVIPC_SEM_INFO)"); |
|
return; |
|
} |
|
} |
|
|
|
if ((buf = malloc(len)) == NULL) |
|
err(1, "malloc"); |
|
semsi = (struct sem_sysctl_info *)buf; |
|
if (sysctl(mib, 3, semsi, &len, NULL, NULL) < 0) { |
|
warn("sysctl(KERN_SYSVIPC_SEM_INFO)"); |
|
return; |
|
} |
|
|
|
if (display & SEMTOTAL) |
|
show_semtotal(&semsi->seminfo); |
|
|
|
if (display & SEMINFO) { |
|
show_seminfo_hdr(); |
|
for (i = 0; i < semsi->seminfo.semmni; i++) { |
|
struct semid_ds *semaptr = &semsi->semids[i]; |
|
if ((semaptr->sem_perm.mode & SEM_ALLOC) != 0) |
|
show_seminfo(semaptr->sem_otime, |
|
semaptr->sem_ctime, |
|
IXSEQ_TO_IPCID(i, semaptr->sem_perm), |
|
semaptr->sem_perm.key, |
|
semaptr->sem_perm.mode, |
|
semaptr->sem_perm.uid, |
|
semaptr->sem_perm.gid, |
|
semaptr->sem_perm.cuid, |
|
semaptr->sem_perm.cgid, |
|
semaptr->sem_nsems); |
|
} |
|
printf("\n"); |
|
} |
|
} |
|
|
|
void |
|
ipcs_kvm(void) |
|
{ |
|
struct msginfo msginfo; |
|
struct msqid_ds *msqids; |
|
struct seminfo seminfo; |
|
struct semid_ds *sema; |
|
struct shminfo shminfo; |
|
struct shmid_ds *shmsegs; |
|
kvm_t *kd; |
|
char errbuf[_POSIX2_LINE_MAX]; |
|
int i; |
|
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} |
|
}; |
|
|
|
if ((kd = kvm_openfiles(namelist, core, NULL, O_RDONLY, |
|
errbuf)) == NULL) |
|
errx(1, "can't open kvm: %s", errbuf); |
|
|
switch (kvm_nlist(kd, symbols)) { |
switch (kvm_nlist(kd, symbols)) { |
case 0: |
case 0: |
break; |
break; |
case -1: |
case -1: |
errx(1, "unable to read kernel symbol table."); |
errx(1, "%s: unable to read symbol table.", |
|
namelist == NULL ? _PATH_UNIX : namelist); |
|
/* NOTREACHED */ |
default: |
default: |
#ifdef notdef /* they'll be told more civilly later */ |
#ifdef notdef /* they'll be told more civilly later */ |
warnx("nlist failed"); |
warnx("nlist failed"); |
for (i = 0; symbols[i].n_name != NULL; i++) |
for (i = 0; symbols[i].n_name != NULL; i++) |
if (symbols[i].n_value == 0) |
if (symbols[i].n_value == 0) |
warnx("symbol %s not found", |
warnx("symbol %s not found", symbols[i].n_name); |
symbols[i].n_name); |
|
break; |
|
#endif |
#endif |
|
break; |
} |
} |
|
|
if ((display & (MSGINFO | MSGTOTAL)) && |
if ((display & (MSGINFO | MSGTOTAL)) && |
(kvm_read(kd, symbols[X_MSGINFO].n_value, |
(kvm_read(kd, symbols[X_MSGINFO].n_value, |
&msginfo, sizeof(msginfo)) == sizeof(msginfo))) { |
&msginfo, sizeof(msginfo)) == sizeof(msginfo))) { |
|
|
if (display & MSGTOTAL) { |
if (display & MSGTOTAL) |
printf("msginfo:\n"); |
show_msgtotal(&msginfo); |
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) { |
if (display & MSGINFO) { |
struct msqid_ds *xmsqids; |
struct msqid_ds *xmsqids; |
|
|
|
|
errx(1, "kvm_read (msqids): %s", |
errx(1, "kvm_read (msqids): %s", |
kvm_geterr(kd)); |
kvm_geterr(kd)); |
|
|
printf("Message Queues:\n"); |
show_msginfo_hdr(); |
printf("T ID KEY MODE OWNER GROUP"); |
for (i = 0; i < msginfo.msgmni; i++) { |
if (option & CREATOR) |
struct msqid_ds *msqptr = &xmsqids[i]; |
printf(" CREATOR CGROUP"); |
if (msqptr->msg_qbytes != 0) |
if (option & OUTSTANDING) |
show_msginfo(msqptr->msg_stime, |
printf(" CBYTES QNUM"); |
msqptr->msg_rtime, |
if (option & BIGGEST) |
msqptr->msg_ctime, |
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 %10ld %s %8s %8s", |
|
IXSEQ_TO_IPCID(i, msqptr->msg_perm), |
IXSEQ_TO_IPCID(i, msqptr->msg_perm), |
msqptr->msg_perm.key, |
msqptr->msg_perm.key, |
fmt_perm(msqptr->msg_perm.mode), |
msqptr->msg_perm.mode, |
user_from_uid(msqptr->msg_perm.uid, 0), |
msqptr->msg_perm.uid, |
group_from_gid(msqptr->msg_perm.gid, 0)); |
msqptr->msg_perm.gid, |
|
msqptr->msg_perm.cuid, |
if (option & CREATOR) |
msqptr->msg_perm.cgid, |
printf(" %8s %8s", |
msqptr->msg_cbytes, |
user_from_uid(msqptr->msg_perm.cuid, 0), |
msqptr->msg_qnum, |
group_from_gid(msqptr->msg_perm.cgid, 0)); |
msqptr->msg_qbytes, |
|
msqptr->msg_lspid, |
if (option & OUTSTANDING) |
msqptr->msg_lrpid); |
printf(" %6lu %6lu", |
|
msqptr->msg_cbytes, |
|
msqptr->msg_qnum); |
|
|
|
if (option & BIGGEST) |
|
printf(" %6lu", |
|
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("\n"); |
printf("\n"); |
} |
} |
} else |
} else { |
if (display & (MSGINFO | MSGTOTAL)) { |
if (display & (MSGINFO | MSGTOTAL)) { |
fprintf(stderr, |
warnx("SVID messages facility not configured in " |
"SVID messages facility not configured in the system\n"); |
"the system"); |
} |
} |
|
} |
if ((display & (SHMINFO | SHMTOTAL)) && |
if ((display & (SHMINFO | SHMTOTAL)) && |
(kvm_read(kd, symbols[X_SHMINFO].n_value, &shminfo, |
(kvm_read(kd, symbols[X_SHMINFO].n_value, &shminfo, |
sizeof(shminfo)) == sizeof(shminfo))) { |
sizeof(shminfo)) == sizeof(shminfo))) { |
|
|
if (display & SHMTOTAL) { |
if (display & SHMTOTAL) |
printf("shminfo:\n"); |
show_shmtotal(&shminfo); |
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) { |
if (display & SHMINFO) { |
struct shmid_ds *xshmids; |
struct shmid_ds *xshmids; |
|
|
|
|
errx(1, "kvm_read (shmsegs): %s", |
errx(1, "kvm_read (shmsegs): %s", |
kvm_geterr(kd)); |
kvm_geterr(kd)); |
|
|
printf("Shared Memory:\n"); |
show_shminfo_hdr(); |
printf("T ID KEY MODE OWNER GROUP"); |
for (i = 0; i < shminfo.shmmni; i++) { |
if (option & CREATOR) |
struct shmid_ds *shmptr = &xshmids[i]; |
printf(" CREATOR CGROUP"); |
if (shmptr->shm_perm.mode & 0x0800) |
if (option & OUTSTANDING) |
show_shminfo(shmptr->shm_atime, |
printf(" NATTCH"); |
shmptr->shm_dtime, |
if (option & BIGGEST) |
shmptr->shm_ctime, |
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 %10ld %s %8s %8s", |
|
IXSEQ_TO_IPCID(i, shmptr->shm_perm), |
IXSEQ_TO_IPCID(i, shmptr->shm_perm), |
shmptr->shm_perm.key, |
shmptr->shm_perm.key, |
fmt_perm(shmptr->shm_perm.mode), |
shmptr->shm_perm.mode, |
user_from_uid(shmptr->shm_perm.uid, 0), |
shmptr->shm_perm.uid, |
group_from_gid(shmptr->shm_perm.gid, 0)); |
shmptr->shm_perm.gid, |
|
shmptr->shm_perm.cuid, |
if (option & CREATOR) |
shmptr->shm_perm.cgid, |
printf(" %8s %8s", |
shmptr->shm_nattch, |
user_from_uid(shmptr->shm_perm.cuid, 0), |
shmptr->shm_segsz, |
group_from_gid(shmptr->shm_perm.cgid, 0)); |
shmptr->shm_cpid, |
|
shmptr->shm_lpid); |
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"); |
printf("\n"); |
} |
} |
} else |
} else |
if (display & (SHMINFO | SHMTOTAL)) { |
if (display & (SHMINFO | SHMTOTAL)) { |
fprintf(stderr, |
warnx("SVID shared memory facility not configured in " |
"SVID shared memory facility not configured in the system\n"); |
"the system"); |
} |
} |
if ((display & (SEMINFO | SEMTOTAL)) && |
if ((display & (SEMINFO | SEMTOTAL)) && |
(kvm_read(kd, symbols[X_SEMINFO].n_value, &seminfo, |
(kvm_read(kd, symbols[X_SEMINFO].n_value, &seminfo, |
sizeof(seminfo)) == sizeof(seminfo))) { |
sizeof(seminfo)) == sizeof(seminfo))) { |
struct semid_ds *xsema; |
struct semid_ds *xsema; |
|
|
if (display & SEMTOTAL) { |
if (display & SEMTOTAL) |
printf("seminfo:\n"); |
show_semtotal(&seminfo); |
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 (display & SEMINFO) { |
if (kvm_read(kd, symbols[X_SEMA].n_value, &sema, |
if (kvm_read(kd, symbols[X_SEMA].n_value, &sema, |
sizeof(sema)) != sizeof(sema)) |
sizeof(sema)) != sizeof(sema)) |
|
|
errx(1, "kvm_read (sema): %s", |
errx(1, "kvm_read (sema): %s", |
kvm_geterr(kd)); |
kvm_geterr(kd)); |
|
|
printf("Semaphores:\n"); |
show_seminfo_hdr(); |
printf("T ID KEY MODE OWNER GROUP"); |
for (i = 0; i < seminfo.semmni; i++) { |
if (option & CREATOR) |
struct semid_ds *semaptr = &xsema[i]; |
printf(" CREATOR CGROUP"); |
if ((semaptr->sem_perm.mode & SEM_ALLOC) != 0) |
if (option & BIGGEST) |
show_seminfo(semaptr->sem_otime, |
printf(" NSEMS"); |
semaptr->sem_ctime, |
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]; |
|
|
|
cvt_time(semaptr->sem_otime, otime_buf); |
|
cvt_time(semaptr->sem_ctime, ctime_buf); |
|
|
|
printf("s %6d %10ld %s %8s %8s", |
|
IXSEQ_TO_IPCID(i, semaptr->sem_perm), |
IXSEQ_TO_IPCID(i, semaptr->sem_perm), |
semaptr->sem_perm.key, |
semaptr->sem_perm.key, |
fmt_perm(semaptr->sem_perm.mode), |
semaptr->sem_perm.mode, |
user_from_uid(semaptr->sem_perm.uid, 0), |
semaptr->sem_perm.uid, |
group_from_gid(semaptr->sem_perm.gid, 0)); |
semaptr->sem_perm.gid, |
|
semaptr->sem_perm.cuid, |
if (option & CREATOR) |
semaptr->sem_perm.cgid, |
printf(" %8s %8s", |
semaptr->sem_nsems); |
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("\n"); |
printf("\n"); |
} |
} |
} else |
} else |
if (display & (SEMINFO | SEMTOTAL)) { |
if (display & (SEMINFO | SEMTOTAL)) { |
fprintf(stderr, "SVID semaphores facility not configured in the system\n"); |
warnx("SVID semaphores facility not configured in " |
|
"the system"); |
} |
} |
kvm_close(kd); |
kvm_close(kd); |
|
|
exit(0); |
|
} |
} |
|
|
void |
void |
usage() |
usage(void) |
{ |
{ |
|
extern char *__progname; |
|
|
fprintf(stderr, |
fprintf(stderr, |
"usage: %s [-abcmopqst] [-C corefile] [-N namelist]\n", |
"usage: %s [-abcmopqstMQST] [-C corefile] [-N namelist]\n", |
__progname); |
__progname); |
exit(1); |
exit(1); |
} |
} |