2009-01-18 04:02:41 +03:00
|
|
|
/* $NetBSD: ipcs.c,v 1.42 2009/01/18 01:10:34 lukem Exp $ */
|
2000-06-03 07:58:44 +04:00
|
|
|
|
|
|
|
/*-
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
1994-12-24 19:46:18 +03:00
|
|
|
|
1993-11-14 19:17:55 +03:00
|
|
|
/*
|
1994-06-19 02:05:08 +04:00
|
|
|
* Copyright (c) 1994 SigmaSoft, Th. Lockert <tholo@sigmasoft.com>
|
|
|
|
* All rights reserved.
|
1993-11-14 19:17:55 +03:00
|
|
|
*
|
1994-06-19 02:05:08 +04:00
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* 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.
|
1993-11-14 19:17:55 +03:00
|
|
|
*/
|
|
|
|
|
2007-12-15 19:32:05 +03:00
|
|
|
#include <sys/cdefs.h>
|
1993-11-14 19:17:55 +03:00
|
|
|
#include <sys/param.h>
|
2000-06-03 07:58:44 +04:00
|
|
|
#include <sys/sysctl.h>
|
2008-04-13 00:49:22 +04:00
|
|
|
#include <sys/inttypes.h>
|
1993-11-14 19:17:55 +03:00
|
|
|
#include <sys/ipc.h>
|
|
|
|
#include <sys/sem.h>
|
|
|
|
#include <sys/shm.h>
|
|
|
|
#include <sys/msg.h>
|
1996-06-07 05:26:38 +04:00
|
|
|
|
|
|
|
#include <err.h>
|
|
|
|
#include <fcntl.h>
|
1997-10-19 07:23:46 +04:00
|
|
|
#include <grp.h>
|
1996-06-07 05:26:38 +04:00
|
|
|
#include <kvm.h>
|
|
|
|
#include <limits.h>
|
|
|
|
#include <nlist.h>
|
|
|
|
#include <paths.h>
|
1997-10-19 07:23:46 +04:00
|
|
|
#include <pwd.h>
|
1996-06-07 05:26:38 +04:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
1998-04-02 01:10:30 +04:00
|
|
|
#include <time.h>
|
1996-06-07 05:26:38 +04:00
|
|
|
#include <unistd.h>
|
1993-11-14 19:17:55 +03:00
|
|
|
|
2006-04-29 00:35:15 +04:00
|
|
|
#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
|
|
|
|
|
|
|
|
static char *core = NULL, *namelist = NULL;
|
|
|
|
static int display = 0;
|
|
|
|
static int option = 0;
|
|
|
|
|
|
|
|
static void cvt_time(time_t, char *, size_t);
|
|
|
|
static char *fmt_perm(u_short);
|
|
|
|
static void ipcs_kvm(void);
|
|
|
|
static void msg_sysctl(void);
|
|
|
|
static void sem_sysctl(void);
|
|
|
|
static void shm_sysctl(void);
|
|
|
|
static void show_msginfo(time_t, time_t, time_t, int, u_int64_t, mode_t,
|
|
|
|
uid_t, gid_t, uid_t, gid_t, u_int64_t, u_int64_t, u_int64_t, pid_t, pid_t);
|
|
|
|
static void show_msginfo_hdr(void);
|
|
|
|
static void show_msgtotal(struct msginfo *);
|
|
|
|
static void show_seminfo_hdr(void);
|
|
|
|
static void show_seminfo(time_t, time_t, int, u_int64_t, mode_t, uid_t,
|
|
|
|
gid_t, uid_t, gid_t, int16_t);
|
|
|
|
static void show_semtotal(struct seminfo *);
|
|
|
|
static void show_shminfo(time_t, time_t, time_t, int, u_int64_t, mode_t,
|
|
|
|
uid_t, gid_t, uid_t, gid_t, u_int32_t, u_int64_t, pid_t, pid_t);
|
|
|
|
static void show_shminfo_hdr(void);
|
|
|
|
static void show_shmtotal(struct shminfo *);
|
2007-12-15 22:44:37 +03:00
|
|
|
static void usage(void) __dead;
|
2006-04-29 00:35:15 +04:00
|
|
|
static void unconfsem(void);
|
|
|
|
static void unconfmsg(void);
|
|
|
|
static void unconfshm(void);
|
|
|
|
|
|
|
|
static void
|
|
|
|
unconfsem(void)
|
|
|
|
{
|
|
|
|
warnx("SVID semaphores facility not configured in the system");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
unconfmsg(void)
|
|
|
|
{
|
|
|
|
warnx("SVID messages facility not configured in the system");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
unconfshm(void)
|
|
|
|
{
|
|
|
|
warnx("SVID shared memory facility not configured in the system");
|
|
|
|
}
|
|
|
|
|
|
|
|
static char *
|
2000-06-03 07:58:44 +04:00
|
|
|
fmt_perm(u_short mode)
|
1993-11-14 19:17:55 +03:00
|
|
|
{
|
1998-07-06 14:16:40 +04:00
|
|
|
static char buffer[12];
|
1993-11-14 19:17:55 +03:00
|
|
|
|
|
|
|
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]);
|
|
|
|
}
|
|
|
|
|
2006-04-29 00:35:15 +04:00
|
|
|
static void
|
2000-06-03 07:58:44 +04:00
|
|
|
cvt_time(time_t t, char *buf, size_t buflen)
|
1993-11-14 19:17:55 +03:00
|
|
|
{
|
1994-06-19 01:09:40 +04:00
|
|
|
struct tm *tm;
|
1993-11-14 19:17:55 +03:00
|
|
|
|
2003-07-12 17:23:55 +04:00
|
|
|
if (t == 0)
|
|
|
|
(void)strlcpy(buf, "no-entry", buflen);
|
|
|
|
else {
|
1994-06-19 01:09:40 +04:00
|
|
|
tm = localtime(&t);
|
1997-02-11 11:43:23 +03:00
|
|
|
(void)snprintf(buf, buflen, "%2d:%02d:%02d",
|
1994-06-19 01:09:40 +04:00
|
|
|
tm->tm_hour, tm->tm_min, tm->tm_sec);
|
1993-11-14 19:17:55 +03:00
|
|
|
}
|
|
|
|
}
|
1994-06-19 01:09:40 +04:00
|
|
|
int
|
2000-06-03 07:58:44 +04:00
|
|
|
main(int argc, char *argv[])
|
1993-11-14 19:17:55 +03:00
|
|
|
{
|
2000-06-03 07:58:44 +04:00
|
|
|
int i;
|
2005-02-21 07:32:55 +03:00
|
|
|
time_t now;
|
2000-06-03 07:58:44 +04:00
|
|
|
|
1997-10-19 07:23:46 +04:00
|
|
|
while ((i = getopt(argc, argv, "MmQqSsabC:cN:optT")) != -1)
|
1994-06-19 01:09:40 +04:00
|
|
|
switch (i) {
|
|
|
|
case 'M':
|
2004-03-21 13:02:12 +03:00
|
|
|
display |= SHMTOTAL;
|
1994-06-19 01:09:40 +04:00
|
|
|
break;
|
|
|
|
case 'm':
|
2004-03-21 13:02:12 +03:00
|
|
|
display |= SHMINFO;
|
1994-06-19 01:09:40 +04:00
|
|
|
break;
|
|
|
|
case 'Q':
|
2004-03-21 13:02:12 +03:00
|
|
|
display |= MSGTOTAL;
|
1994-06-19 01:09:40 +04:00
|
|
|
break;
|
|
|
|
case 'q':
|
2004-03-21 13:02:12 +03:00
|
|
|
display |= MSGINFO;
|
1994-06-19 01:09:40 +04:00
|
|
|
break;
|
|
|
|
case 'S':
|
2004-03-21 13:02:12 +03:00
|
|
|
display |= SEMTOTAL;
|
1994-06-19 01:09:40 +04:00
|
|
|
break;
|
|
|
|
case 's':
|
2004-03-21 13:02:12 +03:00
|
|
|
display |= SEMINFO;
|
1994-06-19 01:09:40 +04:00
|
|
|
break;
|
|
|
|
case 'T':
|
2004-03-21 13:02:12 +03:00
|
|
|
display |= SHMTOTAL | MSGTOTAL | SEMTOTAL;
|
1994-06-19 01:09:40 +04:00
|
|
|
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:
|
1994-06-19 01:20:28 +04:00
|
|
|
usage();
|
1994-06-19 01:09:40 +04:00
|
|
|
}
|
1996-06-07 05:26:38 +04:00
|
|
|
|
2000-06-03 08:12:48 +04:00
|
|
|
if (argc - optind > 0)
|
|
|
|
usage();
|
|
|
|
|
2006-04-29 00:35:15 +04:00
|
|
|
(void)time(&now);
|
|
|
|
(void)printf("IPC status from %s as of %s\n",
|
|
|
|
/* and extra \n from ctime(3) */
|
2005-02-21 07:32:55 +03:00
|
|
|
core == NULL ? "<running system>" : core, ctime(&now));
|
|
|
|
|
2004-03-21 13:02:12 +03:00
|
|
|
if (display == 0)
|
|
|
|
display = SHMINFO | MSGINFO | SEMINFO;
|
|
|
|
|
2000-06-16 07:51:00 +04:00
|
|
|
if (core == NULL) {
|
2000-06-03 07:58:44 +04:00
|
|
|
if (display & (MSGINFO | MSGTOTAL))
|
|
|
|
msg_sysctl();
|
|
|
|
if (display & (SHMINFO | SHMTOTAL))
|
|
|
|
shm_sysctl();
|
|
|
|
if (display & (SEMINFO | SEMTOTAL))
|
|
|
|
sem_sysctl();
|
|
|
|
} else
|
|
|
|
ipcs_kvm();
|
2006-04-29 00:35:15 +04:00
|
|
|
return 0;
|
2000-06-03 07:58:44 +04:00
|
|
|
}
|
|
|
|
|
2006-04-29 00:35:15 +04:00
|
|
|
static void
|
2000-06-03 07:58:44 +04:00
|
|
|
show_msgtotal(struct msginfo *msginfo)
|
|
|
|
{
|
2006-04-29 00:35:15 +04:00
|
|
|
(void)printf("msginfo:\n");
|
|
|
|
(void)printf("\tmsgmax: %6d\t(max characters in a message)\n",
|
2000-06-03 07:58:44 +04:00
|
|
|
msginfo->msgmax);
|
2006-04-29 00:35:15 +04:00
|
|
|
(void)printf("\tmsgmni: %6d\t(# of message queues)\n",
|
2000-06-03 07:58:44 +04:00
|
|
|
msginfo->msgmni);
|
2006-04-29 00:35:15 +04:00
|
|
|
(void)printf("\tmsgmnb: %6d\t(max characters in a message queue)\n",
|
2000-06-03 07:58:44 +04:00
|
|
|
msginfo->msgmnb);
|
2006-04-29 00:35:15 +04:00
|
|
|
(void)printf("\tmsgtql: %6d\t(max # of messages in system)\n",
|
2000-06-03 07:58:44 +04:00
|
|
|
msginfo->msgtql);
|
2006-04-29 00:35:15 +04:00
|
|
|
(void)printf("\tmsgssz: %6d\t(size of a message segment)\n",
|
2000-06-03 07:58:44 +04:00
|
|
|
msginfo->msgssz);
|
2006-04-29 00:35:15 +04:00
|
|
|
(void)printf("\tmsgseg: %6d\t(# of message segments in system)\n\n",
|
2000-06-03 07:58:44 +04:00
|
|
|
msginfo->msgseg);
|
|
|
|
}
|
|
|
|
|
2006-04-29 00:35:15 +04:00
|
|
|
static void
|
2000-06-03 07:58:44 +04:00
|
|
|
show_shmtotal(struct shminfo *shminfo)
|
|
|
|
{
|
2006-04-29 00:35:15 +04:00
|
|
|
(void)printf("shminfo:\n");
|
2008-04-13 00:49:22 +04:00
|
|
|
(void)printf("\tshmmax: %" PRIu64 "\t(max shared memory segment size)\n",
|
2000-06-03 07:58:44 +04:00
|
|
|
shminfo->shmmax);
|
2006-04-29 00:35:15 +04:00
|
|
|
(void)printf("\tshmmin: %7d\t(min shared memory segment size)\n",
|
2000-06-03 07:58:44 +04:00
|
|
|
shminfo->shmmin);
|
2006-04-29 00:35:15 +04:00
|
|
|
(void)printf("\tshmmni: %7d\t(max number of shared memory identifiers)\n",
|
2000-06-03 07:58:44 +04:00
|
|
|
shminfo->shmmni);
|
2006-04-29 00:35:15 +04:00
|
|
|
(void)printf("\tshmseg: %7d\t(max shared memory segments per process)\n",
|
2000-06-03 07:58:44 +04:00
|
|
|
shminfo->shmseg);
|
2006-04-29 00:35:15 +04:00
|
|
|
(void)printf("\tshmall: %7d\t(max amount of shared memory in pages)\n\n",
|
2000-06-03 07:58:44 +04:00
|
|
|
shminfo->shmall);
|
|
|
|
}
|
|
|
|
|
2006-04-29 00:35:15 +04:00
|
|
|
static void
|
2000-06-03 07:58:44 +04:00
|
|
|
show_semtotal(struct seminfo *seminfo)
|
|
|
|
{
|
2006-04-29 00:35:15 +04:00
|
|
|
(void)printf("seminfo:\n");
|
|
|
|
(void)printf("\tsemmap: %6d\t(# of entries in semaphore map)\n",
|
2000-06-03 07:58:44 +04:00
|
|
|
seminfo->semmap);
|
2006-04-29 00:35:15 +04:00
|
|
|
(void)printf("\tsemmni: %6d\t(# of semaphore identifiers)\n",
|
2000-06-03 07:58:44 +04:00
|
|
|
seminfo->semmni);
|
2006-04-29 00:35:15 +04:00
|
|
|
(void)printf("\tsemmns: %6d\t(# of semaphores in system)\n",
|
2000-06-03 07:58:44 +04:00
|
|
|
seminfo->semmns);
|
2006-04-29 00:35:15 +04:00
|
|
|
(void)printf("\tsemmnu: %6d\t(# of undo structures in system)\n",
|
2000-06-03 07:58:44 +04:00
|
|
|
seminfo->semmnu);
|
2006-04-29 00:35:15 +04:00
|
|
|
(void)printf("\tsemmsl: %6d\t(max # of semaphores per id)\n",
|
2000-06-03 07:58:44 +04:00
|
|
|
seminfo->semmsl);
|
2006-04-29 00:35:15 +04:00
|
|
|
(void)printf("\tsemopm: %6d\t(max # of operations per semop call)\n",
|
2000-06-03 07:58:44 +04:00
|
|
|
seminfo->semopm);
|
2006-04-29 00:35:15 +04:00
|
|
|
(void)printf("\tsemume: %6d\t(max # of undo entries per process)\n",
|
2000-06-03 07:58:44 +04:00
|
|
|
seminfo->semume);
|
2006-04-29 00:35:15 +04:00
|
|
|
(void)printf("\tsemusz: %6d\t(size in bytes of undo structure)\n",
|
2000-06-03 07:58:44 +04:00
|
|
|
seminfo->semusz);
|
2006-04-29 00:35:15 +04:00
|
|
|
(void)printf("\tsemvmx: %6d\t(semaphore maximum value)\n",
|
2000-06-03 07:58:44 +04:00
|
|
|
seminfo->semvmx);
|
2006-04-29 00:35:15 +04:00
|
|
|
(void)printf("\tsemaem: %6d\t(adjust on exit max value)\n\n",
|
2000-06-03 07:58:44 +04:00
|
|
|
seminfo->semaem);
|
|
|
|
}
|
|
|
|
|
2006-04-29 00:35:15 +04:00
|
|
|
static void
|
2000-06-03 07:58:44 +04:00
|
|
|
show_msginfo_hdr(void)
|
|
|
|
{
|
2006-04-29 00:35:15 +04:00
|
|
|
(void)printf("Message Queues:\n");
|
|
|
|
(void)printf("T ID KEY MODE OWNER GROUP");
|
2000-06-03 07:58:44 +04:00
|
|
|
if (option & CREATOR)
|
2006-04-29 00:35:15 +04:00
|
|
|
(void)printf(" CREATOR CGROUP");
|
2000-06-03 07:58:44 +04:00
|
|
|
if (option & OUTSTANDING)
|
2006-04-29 00:35:15 +04:00
|
|
|
(void)printf(" CBYTES QNUM");
|
2000-06-03 07:58:44 +04:00
|
|
|
if (option & BIGGEST)
|
2006-04-29 00:35:15 +04:00
|
|
|
(void)printf(" QBYTES");
|
2000-06-03 07:58:44 +04:00
|
|
|
if (option & PID)
|
2006-04-29 00:35:15 +04:00
|
|
|
(void)printf(" LSPID LRPID");
|
2000-06-03 07:58:44 +04:00
|
|
|
if (option & TIME)
|
2006-04-29 00:35:15 +04:00
|
|
|
(void)printf(" STIME RTIME CTIME");
|
|
|
|
(void)printf("\n");
|
2000-06-03 07:58:44 +04:00
|
|
|
}
|
|
|
|
|
2006-04-29 00:35:15 +04:00
|
|
|
static void
|
|
|
|
show_msginfo(time_t s_time, time_t r_time, time_t c_time, int ipcid,
|
|
|
|
u_int64_t key,
|
2000-06-03 07:58:44 +04:00
|
|
|
mode_t mode, uid_t uid, gid_t gid, uid_t cuid, gid_t cgid,
|
|
|
|
u_int64_t cbytes, u_int64_t qnum, u_int64_t qbytes, pid_t lspid,
|
|
|
|
pid_t lrpid)
|
|
|
|
{
|
2006-04-29 00:35:15 +04:00
|
|
|
char s_time_buf[100], r_time_buf[100], c_time_buf[100];
|
2000-06-03 07:58:44 +04:00
|
|
|
|
|
|
|
if (option & TIME) {
|
2006-04-29 00:35:15 +04:00
|
|
|
cvt_time(s_time, s_time_buf, sizeof(s_time_buf));
|
|
|
|
cvt_time(r_time, r_time_buf, sizeof(r_time_buf));
|
|
|
|
cvt_time(c_time, c_time_buf, sizeof(c_time_buf));
|
2000-06-03 07:58:44 +04:00
|
|
|
}
|
|
|
|
|
2006-04-29 00:35:15 +04:00
|
|
|
(void)printf("q %9d %10lld %s %8s %8s", ipcid, (long long)key, fmt_perm(mode),
|
2000-06-03 07:58:44 +04:00
|
|
|
user_from_uid(uid, 0), group_from_gid(gid, 0));
|
|
|
|
|
|
|
|
if (option & CREATOR)
|
2006-04-29 00:35:15 +04:00
|
|
|
(void)printf(" %8s %8s", user_from_uid(cuid, 0),
|
2000-06-03 07:58:44 +04:00
|
|
|
group_from_gid(cgid, 0));
|
|
|
|
|
|
|
|
if (option & OUTSTANDING)
|
2006-04-29 00:35:15 +04:00
|
|
|
(void)printf(" %6lld %5lld", (long long)cbytes, (long long)qnum);
|
2000-06-03 07:58:44 +04:00
|
|
|
|
|
|
|
if (option & BIGGEST)
|
2006-04-29 00:35:15 +04:00
|
|
|
(void)printf(" %6lld", (long long)qbytes);
|
2000-06-03 07:58:44 +04:00
|
|
|
|
|
|
|
if (option & PID)
|
2006-04-29 00:35:15 +04:00
|
|
|
(void)printf(" %5d %5d", lspid, lrpid);
|
2000-06-03 07:58:44 +04:00
|
|
|
|
|
|
|
if (option & TIME)
|
2006-04-29 00:35:15 +04:00
|
|
|
(void)printf(" %s %s %s", s_time_buf, r_time_buf, c_time_buf);
|
2000-06-03 07:58:44 +04:00
|
|
|
|
2006-04-29 00:35:15 +04:00
|
|
|
(void)printf("\n");
|
2000-06-03 07:58:44 +04:00
|
|
|
}
|
|
|
|
|
2006-04-29 00:35:15 +04:00
|
|
|
static void
|
2000-06-03 07:58:44 +04:00
|
|
|
show_shminfo_hdr(void)
|
|
|
|
{
|
2006-04-29 00:35:15 +04:00
|
|
|
(void)printf("Shared Memory:\n");
|
|
|
|
(void)printf("T ID KEY MODE OWNER GROUP");
|
2000-06-03 07:58:44 +04:00
|
|
|
if (option & CREATOR)
|
2006-04-29 00:35:15 +04:00
|
|
|
(void)printf(" CREATOR CGROUP");
|
2000-06-03 07:58:44 +04:00
|
|
|
if (option & OUTSTANDING)
|
2006-04-29 00:35:15 +04:00
|
|
|
(void)printf(" NATTCH");
|
2000-06-03 07:58:44 +04:00
|
|
|
if (option & BIGGEST)
|
2006-04-29 00:35:15 +04:00
|
|
|
(void)printf(" SEGSZ");
|
2000-06-03 07:58:44 +04:00
|
|
|
if (option & PID)
|
2006-04-29 00:35:15 +04:00
|
|
|
(void)printf(" CPID LPID");
|
2000-06-03 07:58:44 +04:00
|
|
|
if (option & TIME)
|
2006-04-29 00:35:15 +04:00
|
|
|
(void)printf(" ATIME DTIME CTIME");
|
|
|
|
(void)printf("\n");
|
2000-06-03 07:58:44 +04:00
|
|
|
}
|
|
|
|
|
2006-04-29 00:35:15 +04:00
|
|
|
static void
|
|
|
|
show_shminfo(time_t atime, time_t dtime, time_t c_time, int ipcid, u_int64_t key,
|
2000-06-03 07:58:44 +04:00
|
|
|
mode_t mode, uid_t uid, gid_t gid, uid_t cuid, gid_t cgid,
|
|
|
|
u_int32_t nattch, u_int64_t segsz, pid_t cpid, pid_t lpid)
|
|
|
|
{
|
2006-04-29 00:35:15 +04:00
|
|
|
char atime_buf[100], dtime_buf[100], c_time_buf[100];
|
2000-06-03 07:58:44 +04:00
|
|
|
|
|
|
|
if (option & TIME) {
|
|
|
|
cvt_time(atime, atime_buf, sizeof(atime_buf));
|
|
|
|
cvt_time(dtime, dtime_buf, sizeof(dtime_buf));
|
2006-04-29 00:35:15 +04:00
|
|
|
cvt_time(c_time, c_time_buf, sizeof(c_time_buf));
|
2000-06-03 07:58:44 +04:00
|
|
|
}
|
|
|
|
|
2006-04-29 00:35:15 +04:00
|
|
|
(void)printf("m %9d %10lld %s %8s %8s", ipcid, (long long)key, fmt_perm(mode),
|
2000-06-03 07:58:44 +04:00
|
|
|
user_from_uid(uid, 0), group_from_gid(gid, 0));
|
|
|
|
|
|
|
|
if (option & CREATOR)
|
2006-04-29 00:35:15 +04:00
|
|
|
(void)printf(" %8s %8s", user_from_uid(cuid, 0),
|
2000-06-03 07:58:44 +04:00
|
|
|
group_from_gid(cgid, 0));
|
|
|
|
|
|
|
|
if (option & OUTSTANDING)
|
2006-04-29 00:35:15 +04:00
|
|
|
(void)printf(" %6d", nattch);
|
2000-06-03 07:58:44 +04:00
|
|
|
|
|
|
|
if (option & BIGGEST)
|
2006-04-29 00:35:15 +04:00
|
|
|
(void)printf(" %7llu", (long long)segsz);
|
2000-06-03 07:58:44 +04:00
|
|
|
|
|
|
|
if (option & PID)
|
2006-04-29 00:35:15 +04:00
|
|
|
(void)printf(" %5d %5d", cpid, lpid);
|
2000-06-03 07:58:44 +04:00
|
|
|
|
|
|
|
if (option & TIME)
|
2006-04-29 00:35:15 +04:00
|
|
|
(void)printf(" %s %s %s",
|
2000-06-03 07:58:44 +04:00
|
|
|
atime_buf,
|
|
|
|
dtime_buf,
|
2006-04-29 00:35:15 +04:00
|
|
|
c_time_buf);
|
2000-06-03 07:58:44 +04:00
|
|
|
|
2006-04-29 00:35:15 +04:00
|
|
|
(void)printf("\n");
|
2000-06-03 07:58:44 +04:00
|
|
|
}
|
|
|
|
|
2006-04-29 00:35:15 +04:00
|
|
|
static void
|
2000-06-03 07:58:44 +04:00
|
|
|
show_seminfo_hdr(void)
|
|
|
|
{
|
2006-04-29 00:35:15 +04:00
|
|
|
(void)printf("Semaphores:\n");
|
|
|
|
(void)printf("T ID KEY MODE OWNER GROUP");
|
2000-06-03 07:58:44 +04:00
|
|
|
if (option & CREATOR)
|
2006-04-29 00:35:15 +04:00
|
|
|
(void)printf(" CREATOR CGROUP");
|
2000-06-03 07:58:44 +04:00
|
|
|
if (option & BIGGEST)
|
2006-04-29 00:35:15 +04:00
|
|
|
(void)printf(" NSEMS");
|
2000-06-03 07:58:44 +04:00
|
|
|
if (option & TIME)
|
2006-04-29 00:35:15 +04:00
|
|
|
(void)printf(" OTIME CTIME");
|
|
|
|
(void)printf("\n");
|
2000-06-03 07:58:44 +04:00
|
|
|
}
|
|
|
|
|
2006-04-29 00:35:15 +04:00
|
|
|
static void
|
|
|
|
show_seminfo(time_t otime, time_t c_time, int ipcid, u_int64_t key, mode_t mode,
|
2000-06-03 07:58:44 +04:00
|
|
|
uid_t uid, gid_t gid, uid_t cuid, gid_t cgid, int16_t nsems)
|
|
|
|
{
|
2006-04-29 00:35:15 +04:00
|
|
|
char c_time_buf[100], otime_buf[100];
|
2000-06-03 07:58:44 +04:00
|
|
|
|
|
|
|
if (option & TIME) {
|
|
|
|
cvt_time(otime, otime_buf, sizeof(otime_buf));
|
2006-04-29 00:35:15 +04:00
|
|
|
cvt_time(c_time, c_time_buf, sizeof(c_time_buf));
|
2000-06-03 07:58:44 +04:00
|
|
|
}
|
|
|
|
|
2006-04-29 00:35:15 +04:00
|
|
|
(void)printf("s %9d %10lld %s %8s %8s", ipcid, (long long)key, fmt_perm(mode),
|
2000-06-03 07:58:44 +04:00
|
|
|
user_from_uid(uid, 0), group_from_gid(gid, 0));
|
|
|
|
|
|
|
|
if (option & CREATOR)
|
2006-04-29 00:35:15 +04:00
|
|
|
(void)printf(" %8s %8s", user_from_uid(cuid, 0),
|
2000-06-03 07:58:44 +04:00
|
|
|
group_from_gid(cgid, 0));
|
|
|
|
|
|
|
|
if (option & BIGGEST)
|
2006-04-29 00:35:15 +04:00
|
|
|
(void)printf(" %5d", nsems);
|
2000-06-03 07:58:44 +04:00
|
|
|
|
|
|
|
if (option & TIME)
|
2006-04-29 00:35:15 +04:00
|
|
|
(void)printf(" %s %s", otime_buf, c_time_buf);
|
2000-06-03 07:58:44 +04:00
|
|
|
|
2006-04-29 00:35:15 +04:00
|
|
|
(void)printf("\n");
|
2000-06-03 07:58:44 +04:00
|
|
|
}
|
|
|
|
|
2006-04-29 00:35:15 +04:00
|
|
|
static void
|
2000-06-03 07:58:44 +04:00
|
|
|
msg_sysctl(void)
|
|
|
|
{
|
|
|
|
struct msg_sysctl_info *msgsi;
|
2006-04-29 00:35:15 +04:00
|
|
|
void *buf;
|
2006-11-26 00:40:04 +03:00
|
|
|
int mib[4];
|
2000-06-03 07:58:44 +04:00
|
|
|
size_t len;
|
|
|
|
int i, valid;
|
|
|
|
|
|
|
|
mib[0] = CTL_KERN;
|
2006-11-26 00:40:04 +03:00
|
|
|
mib[1] = KERN_SYSVIPC;
|
|
|
|
mib[2] = KERN_SYSVIPC_MSG;
|
2000-06-03 07:58:44 +04:00
|
|
|
len = sizeof(valid);
|
2006-11-26 00:40:04 +03:00
|
|
|
if (sysctl(mib, 3, &valid, &len, NULL, 0) < 0) {
|
|
|
|
warn("sysctl(KERN_SYSVIPC_MSG)");
|
2000-06-03 07:58:44 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!valid) {
|
2006-04-29 00:35:15 +04:00
|
|
|
unconfmsg();
|
2000-06-03 07:58:44 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mib[0] = CTL_KERN;
|
2006-11-26 00:40:04 +03:00
|
|
|
mib[1] = KERN_SYSVIPC;
|
|
|
|
mib[2] = KERN_SYSVIPC_INFO;
|
|
|
|
mib[3] = KERN_SYSVIPC_MSG_INFO;
|
2000-06-03 07:58:44 +04:00
|
|
|
|
|
|
|
if (!(display & MSGINFO)) {
|
|
|
|
/* totals only */
|
|
|
|
len = sizeof(struct msginfo);
|
|
|
|
} else {
|
2006-11-26 00:40:04 +03:00
|
|
|
if (sysctl(mib, 4, NULL, &len, NULL, 0) < 0) {
|
2006-04-29 00:35:15 +04:00
|
|
|
warn("sysctl(KERN_SYSVIPC_MSG_INFO)");
|
2000-06-03 07:58:44 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((buf = malloc(len)) == NULL)
|
|
|
|
err(1, "malloc");
|
|
|
|
msgsi = (struct msg_sysctl_info *)buf;
|
2006-11-26 00:40:04 +03:00
|
|
|
if (sysctl(mib, 4, msgsi, &len, NULL, 0) < 0) {
|
2006-04-29 00:35:15 +04:00
|
|
|
warn("sysctl(KERN_SYSVIPC_MSG_INFO)");
|
|
|
|
goto done;
|
2000-06-03 07:58:44 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (display & MSGTOTAL)
|
|
|
|
show_msgtotal(&msgsi->msginfo);
|
|
|
|
|
|
|
|
if (display & MSGINFO) {
|
|
|
|
show_msginfo_hdr();
|
|
|
|
for (i = 0; i < msgsi->msginfo.msgmni; i++) {
|
|
|
|
struct msgid_ds_sysctl *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);
|
|
|
|
}
|
2006-04-29 00:35:15 +04:00
|
|
|
(void)printf("\n");
|
2000-06-03 07:58:44 +04:00
|
|
|
}
|
2006-04-29 00:35:15 +04:00
|
|
|
done:
|
|
|
|
free(buf);
|
2000-06-03 07:58:44 +04:00
|
|
|
}
|
|
|
|
|
2006-04-29 00:35:15 +04:00
|
|
|
static void
|
2000-06-03 07:58:44 +04:00
|
|
|
shm_sysctl(void)
|
|
|
|
{
|
|
|
|
struct shm_sysctl_info *shmsi;
|
2006-04-29 00:35:15 +04:00
|
|
|
void *buf;
|
2006-11-26 00:40:04 +03:00
|
|
|
int mib[4];
|
2000-06-03 07:58:44 +04:00
|
|
|
size_t len;
|
2009-01-18 04:02:41 +03:00
|
|
|
uint32_t i;
|
2000-06-03 07:58:44 +04:00
|
|
|
long valid;
|
|
|
|
|
|
|
|
mib[0] = CTL_KERN;
|
2006-11-26 00:40:04 +03:00
|
|
|
mib[1] = KERN_SYSVIPC;
|
|
|
|
mib[2] = KERN_SYSVIPC_SHM;
|
2000-06-03 07:58:44 +04:00
|
|
|
len = sizeof(valid);
|
2006-11-26 00:40:04 +03:00
|
|
|
if (sysctl(mib, 3, &valid, &len, NULL, 0) < 0) {
|
|
|
|
warn("sysctl(KERN_SYSVIPC_SHM)");
|
2000-06-03 07:58:44 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!valid) {
|
2006-04-29 00:35:15 +04:00
|
|
|
unconfshm();
|
2000-06-03 07:58:44 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mib[0] = CTL_KERN;
|
2006-11-26 00:40:04 +03:00
|
|
|
mib[1] = KERN_SYSVIPC;
|
|
|
|
mib[2] = KERN_SYSVIPC_INFO;
|
|
|
|
mib[3] = KERN_SYSVIPC_SHM_INFO;
|
2000-06-03 07:58:44 +04:00
|
|
|
|
|
|
|
if (!(display & SHMINFO)) {
|
|
|
|
/* totals only */
|
|
|
|
len = sizeof(struct shminfo);
|
|
|
|
} else {
|
2006-11-26 00:40:04 +03:00
|
|
|
if (sysctl(mib, 4, NULL, &len, NULL, 0) < 0) {
|
2006-04-29 00:35:15 +04:00
|
|
|
warn("sysctl(KERN_SYSVIPC_SHM_INFO)");
|
2000-06-03 07:58:44 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((buf = malloc(len)) == NULL)
|
|
|
|
err(1, "malloc");
|
|
|
|
shmsi = (struct shm_sysctl_info *)buf;
|
2006-11-26 00:40:04 +03:00
|
|
|
if (sysctl(mib, 4, shmsi, &len, NULL, 0) < 0) {
|
2006-04-29 00:35:15 +04:00
|
|
|
warn("sysctl(KERN_SYSVIPC_SHM_INFO)");
|
|
|
|
goto done;
|
2000-06-03 07:58:44 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (display & SHMTOTAL)
|
|
|
|
show_shmtotal(&shmsi->shminfo);
|
|
|
|
|
|
|
|
if (display & SHMINFO) {
|
|
|
|
show_shminfo_hdr();
|
|
|
|
for (i = 0; i < shmsi->shminfo.shmmni; i++) {
|
|
|
|
struct shmid_ds_sysctl *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);
|
|
|
|
}
|
2006-04-29 00:35:15 +04:00
|
|
|
(void)printf("\n");
|
2000-06-03 07:58:44 +04:00
|
|
|
}
|
2006-04-29 00:35:15 +04:00
|
|
|
done:
|
|
|
|
free(buf);
|
2000-06-03 07:58:44 +04:00
|
|
|
}
|
|
|
|
|
2006-04-29 00:35:15 +04:00
|
|
|
static void
|
2000-06-03 07:58:44 +04:00
|
|
|
sem_sysctl(void)
|
|
|
|
{
|
|
|
|
struct sem_sysctl_info *semsi;
|
2006-04-29 00:35:15 +04:00
|
|
|
void *buf;
|
2006-11-26 00:40:04 +03:00
|
|
|
int mib[4];
|
2000-06-03 07:58:44 +04:00
|
|
|
size_t len;
|
|
|
|
int i, valid;
|
|
|
|
|
|
|
|
mib[0] = CTL_KERN;
|
2006-11-26 00:40:04 +03:00
|
|
|
mib[1] = KERN_SYSVIPC;
|
|
|
|
mib[2] = KERN_SYSVIPC_SEM;
|
2000-06-03 07:58:44 +04:00
|
|
|
len = sizeof(valid);
|
2006-11-26 00:40:04 +03:00
|
|
|
if (sysctl(mib, 3, &valid, &len, NULL, 0) < 0) {
|
|
|
|
warn("sysctl(KERN_SYSVIPC_SEM)");
|
2000-06-03 07:58:44 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!valid) {
|
2006-04-29 00:35:15 +04:00
|
|
|
unconfsem();
|
2000-06-03 07:58:44 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mib[0] = CTL_KERN;
|
2006-11-26 00:40:04 +03:00
|
|
|
mib[1] = KERN_SYSVIPC;
|
|
|
|
mib[2] = KERN_SYSVIPC_INFO;
|
|
|
|
mib[3] = KERN_SYSVIPC_SEM_INFO;
|
2000-06-03 07:58:44 +04:00
|
|
|
|
|
|
|
if (!(display & SEMINFO)) {
|
|
|
|
/* totals only */
|
|
|
|
len = sizeof(struct seminfo);
|
|
|
|
} else {
|
2006-11-26 00:40:04 +03:00
|
|
|
if (sysctl(mib, 4, NULL, &len, NULL, 0) < 0) {
|
2006-04-29 00:35:15 +04:00
|
|
|
warn("sysctl(KERN_SYSVIPC_SEM_INFO)");
|
2000-06-03 07:58:44 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((buf = malloc(len)) == NULL)
|
|
|
|
err(1, "malloc");
|
|
|
|
semsi = (struct sem_sysctl_info *)buf;
|
2006-11-26 00:40:04 +03:00
|
|
|
if (sysctl(mib, 4, semsi, &len, NULL, 0) < 0) {
|
2006-04-29 00:35:15 +04:00
|
|
|
warn("sysctl(KERN_SYSVIPC_SEM_INFO)");
|
|
|
|
goto done;
|
2000-06-03 07:58:44 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (display & SEMTOTAL)
|
|
|
|
show_semtotal(&semsi->seminfo);
|
|
|
|
|
|
|
|
if (display & SEMINFO) {
|
|
|
|
show_seminfo_hdr();
|
|
|
|
for (i = 0; i < semsi->seminfo.semmni; i++) {
|
|
|
|
struct semid_ds_sysctl *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);
|
|
|
|
}
|
2006-04-29 00:35:15 +04:00
|
|
|
(void)printf("\n");
|
2000-06-03 07:58:44 +04:00
|
|
|
}
|
2006-04-29 00:35:15 +04:00
|
|
|
done:
|
|
|
|
free(buf);
|
2000-06-03 07:58:44 +04:00
|
|
|
}
|
|
|
|
|
2006-10-22 20:17:44 +04:00
|
|
|
static struct nlist symbols[] = {
|
|
|
|
{ .n_name = "_sema" },
|
|
|
|
#define X_SEMA 0
|
|
|
|
{ .n_name = "_seminfo" },
|
|
|
|
#define X_SEMINFO 1
|
|
|
|
{ .n_name = "_semu" },
|
|
|
|
#define X_SEMU 2
|
|
|
|
{ .n_name = "_msginfo" },
|
|
|
|
#define X_MSGINFO 3
|
|
|
|
{ .n_name = "_msqids" },
|
|
|
|
#define X_MSQIDS 4
|
|
|
|
{ .n_name = "_shminfo" },
|
|
|
|
#define X_SHMINFO 5
|
|
|
|
{ .n_name = "_shmsegs" },
|
|
|
|
#define X_SHMSEGS 6
|
|
|
|
{ .n_name = NULL }
|
|
|
|
};
|
|
|
|
|
2006-04-29 00:35:15 +04:00
|
|
|
static void
|
2000-06-03 07:58:44 +04:00
|
|
|
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];
|
2009-01-18 04:02:41 +03:00
|
|
|
int32_t i;
|
|
|
|
uint32_t u;
|
1996-06-07 05:26:38 +04:00
|
|
|
|
|
|
|
if ((kd = kvm_openfiles(namelist, core, NULL, O_RDONLY,
|
|
|
|
errbuf)) == NULL)
|
|
|
|
errx(1, "can't open kvm: %s", errbuf);
|
1994-06-19 01:09:40 +04:00
|
|
|
|
1998-07-06 11:50:18 +04:00
|
|
|
|
1994-06-19 01:09:40 +04:00
|
|
|
switch (kvm_nlist(kd, symbols)) {
|
1993-11-14 19:17:55 +03:00
|
|
|
case 0:
|
|
|
|
break;
|
|
|
|
case -1:
|
1996-06-07 05:26:38 +04:00
|
|
|
errx(1, "%s: unable to read symbol table.",
|
|
|
|
namelist == NULL ? _PATH_UNIX : namelist);
|
2000-06-03 07:58:44 +04:00
|
|
|
/* NOTREACHED */
|
1993-11-14 19:17:55 +03:00
|
|
|
default:
|
1994-06-19 01:20:28 +04:00
|
|
|
#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);
|
|
|
|
#endif
|
2000-06-03 07:58:44 +04:00
|
|
|
break;
|
1993-11-14 19:17:55 +03:00
|
|
|
}
|
|
|
|
|
1994-06-19 01:09:40 +04:00
|
|
|
if ((display & (MSGINFO | MSGTOTAL)) &&
|
1996-06-07 05:26:38 +04:00
|
|
|
(kvm_read(kd, symbols[X_MSGINFO].n_value,
|
|
|
|
&msginfo, sizeof(msginfo)) == sizeof(msginfo))) {
|
1994-06-19 01:09:40 +04:00
|
|
|
|
2000-06-03 07:58:44 +04:00
|
|
|
if (display & MSGTOTAL)
|
|
|
|
show_msgtotal(&msginfo);
|
|
|
|
|
1994-06-19 01:09:40 +04:00
|
|
|
if (display & MSGINFO) {
|
|
|
|
struct msqid_ds *xmsqids;
|
|
|
|
|
1996-06-07 05:26:38 +04:00
|
|
|
if (kvm_read(kd, symbols[X_MSQIDS].n_value,
|
|
|
|
&msqids, sizeof(msqids)) != sizeof(msqids))
|
|
|
|
errx(1, "kvm_read (%s): %s",
|
|
|
|
symbols[X_MSQIDS].n_name, kvm_geterr(kd));
|
|
|
|
|
|
|
|
xmsqids = malloc(sizeof(struct msqid_ds) *
|
|
|
|
msginfo.msgmni);
|
|
|
|
|
2009-01-18 04:02:41 +03:00
|
|
|
if ((size_t)kvm_read(kd, (u_long)msqids, xmsqids,
|
1996-06-07 05:26:38 +04:00
|
|
|
sizeof(struct msqid_ds) * msginfo.msgmni) !=
|
|
|
|
sizeof(struct msqid_ds) * msginfo.msgmni)
|
|
|
|
errx(1, "kvm_read (msqids): %s",
|
|
|
|
kvm_geterr(kd));
|
1994-06-19 01:09:40 +04:00
|
|
|
|
2000-06-03 07:58:44 +04:00
|
|
|
show_msginfo_hdr();
|
|
|
|
for (i = 0; i < msginfo.msgmni; i++) {
|
|
|
|
struct msqid_ds *msqptr = &xmsqids[i];
|
|
|
|
if (msqptr->msg_qbytes != 0)
|
|
|
|
show_msginfo(msqptr->msg_stime,
|
|
|
|
msqptr->msg_rtime,
|
|
|
|
msqptr->msg_ctime,
|
1994-06-19 01:09:40 +04:00
|
|
|
IXSEQ_TO_IPCID(i, msqptr->msg_perm),
|
2006-04-29 00:35:15 +04:00
|
|
|
(u_int64_t)msqptr->msg_perm._key,
|
2000-06-03 07:58:44 +04:00
|
|
|
msqptr->msg_perm.mode,
|
|
|
|
msqptr->msg_perm.uid,
|
|
|
|
msqptr->msg_perm.gid,
|
|
|
|
msqptr->msg_perm.cuid,
|
|
|
|
msqptr->msg_perm.cgid,
|
2006-04-29 00:35:15 +04:00
|
|
|
(u_int64_t)msqptr->_msg_cbytes,
|
|
|
|
(u_int64_t)msqptr->msg_qnum,
|
|
|
|
(u_int64_t)msqptr->msg_qbytes,
|
2000-06-03 07:58:44 +04:00
|
|
|
msqptr->msg_lspid,
|
|
|
|
msqptr->msg_lrpid);
|
1994-06-19 01:09:40 +04:00
|
|
|
}
|
2006-04-29 00:35:15 +04:00
|
|
|
(void)printf("\n");
|
|
|
|
free(xmsqids);
|
1994-06-19 01:09:40 +04:00
|
|
|
}
|
|
|
|
} else
|
2006-04-29 00:35:15 +04:00
|
|
|
if (display & (MSGINFO | MSGTOTAL))
|
|
|
|
unconfmsg();
|
1994-06-19 01:09:40 +04:00
|
|
|
if ((display & (SHMINFO | SHMTOTAL)) &&
|
1996-06-07 05:26:38 +04:00
|
|
|
(kvm_read(kd, symbols[X_SHMINFO].n_value, &shminfo,
|
|
|
|
sizeof(shminfo)) == sizeof(shminfo))) {
|
|
|
|
|
2000-06-03 07:58:44 +04:00
|
|
|
if (display & SHMTOTAL)
|
|
|
|
show_shmtotal(&shminfo);
|
|
|
|
|
1994-06-19 01:09:40 +04:00
|
|
|
if (display & SHMINFO) {
|
|
|
|
struct shmid_ds *xshmids;
|
|
|
|
|
1996-06-07 05:26:38 +04:00
|
|
|
if (kvm_read(kd, symbols[X_SHMSEGS].n_value, &shmsegs,
|
|
|
|
sizeof(shmsegs)) != sizeof(shmsegs))
|
|
|
|
errx(1, "kvm_read (%s): %s",
|
|
|
|
symbols[X_SHMSEGS].n_name, kvm_geterr(kd));
|
|
|
|
|
|
|
|
xshmids = malloc(sizeof(struct shmid_ds) *
|
1996-07-20 03:58:33 +04:00
|
|
|
shminfo.shmmni);
|
1996-06-07 05:26:38 +04:00
|
|
|
|
2009-01-18 04:02:41 +03:00
|
|
|
if ((size_t)kvm_read(kd, (u_long)shmsegs, xshmids,
|
1996-06-07 05:26:38 +04:00
|
|
|
sizeof(struct shmid_ds) * shminfo.shmmni) !=
|
|
|
|
sizeof(struct shmid_ds) * shminfo.shmmni)
|
|
|
|
errx(1, "kvm_read (shmsegs): %s",
|
|
|
|
kvm_geterr(kd));
|
1994-06-19 01:09:40 +04:00
|
|
|
|
2000-06-03 07:58:44 +04:00
|
|
|
show_shminfo_hdr();
|
2009-01-18 04:02:41 +03:00
|
|
|
for (u = 0; u < shminfo.shmmni; u++) {
|
|
|
|
struct shmid_ds *shmptr = &xshmids[u];
|
2000-06-03 07:58:44 +04:00
|
|
|
if (shmptr->shm_perm.mode & 0x0800)
|
|
|
|
show_shminfo(shmptr->shm_atime,
|
|
|
|
shmptr->shm_dtime,
|
|
|
|
shmptr->shm_ctime,
|
2009-01-18 04:02:41 +03:00
|
|
|
IXSEQ_TO_IPCID(u, shmptr->shm_perm),
|
2006-04-29 00:35:15 +04:00
|
|
|
(u_int64_t)shmptr->shm_perm._key,
|
2000-06-03 07:58:44 +04:00
|
|
|
shmptr->shm_perm.mode,
|
|
|
|
shmptr->shm_perm.uid,
|
|
|
|
shmptr->shm_perm.gid,
|
|
|
|
shmptr->shm_perm.cuid,
|
|
|
|
shmptr->shm_perm.cgid,
|
|
|
|
shmptr->shm_nattch,
|
2006-04-29 00:35:15 +04:00
|
|
|
(u_int64_t)shmptr->shm_segsz,
|
2000-06-03 07:58:44 +04:00
|
|
|
shmptr->shm_cpid,
|
|
|
|
shmptr->shm_lpid);
|
1994-06-19 01:09:40 +04:00
|
|
|
}
|
2006-04-29 00:35:15 +04:00
|
|
|
(void)printf("\n");
|
|
|
|
free(xshmids);
|
1994-06-19 01:09:40 +04:00
|
|
|
}
|
|
|
|
} else
|
2006-04-29 00:35:15 +04:00
|
|
|
if (display & (SHMINFO | SHMTOTAL))
|
|
|
|
unconfshm();
|
1994-06-19 01:09:40 +04:00
|
|
|
if ((display & (SEMINFO | SEMTOTAL)) &&
|
1996-06-07 05:26:38 +04:00
|
|
|
(kvm_read(kd, symbols[X_SEMINFO].n_value, &seminfo,
|
|
|
|
sizeof(seminfo)) == sizeof(seminfo))) {
|
1994-06-19 01:09:40 +04:00
|
|
|
struct semid_ds *xsema;
|
1993-11-14 19:17:55 +03:00
|
|
|
|
2000-06-03 07:58:44 +04:00
|
|
|
if (display & SEMTOTAL)
|
|
|
|
show_semtotal(&seminfo);
|
|
|
|
|
1994-06-19 01:09:40 +04:00
|
|
|
if (display & SEMINFO) {
|
1996-06-07 05:26:38 +04:00
|
|
|
if (kvm_read(kd, symbols[X_SEMA].n_value, &sema,
|
|
|
|
sizeof(sema)) != sizeof(sema))
|
|
|
|
errx(1, "kvm_read (%s): %s",
|
|
|
|
symbols[X_SEMA].n_name, kvm_geterr(kd));
|
|
|
|
|
|
|
|
xsema = malloc(sizeof(struct semid_ds) *
|
|
|
|
seminfo.semmni);
|
|
|
|
|
2009-01-18 04:02:41 +03:00
|
|
|
if ((size_t)kvm_read(kd, (u_long)sema, xsema,
|
1996-06-07 05:26:38 +04:00
|
|
|
sizeof(struct semid_ds) * seminfo.semmni) !=
|
|
|
|
sizeof(struct semid_ds) * seminfo.semmni)
|
|
|
|
errx(1, "kvm_read (sema): %s",
|
|
|
|
kvm_geterr(kd));
|
1994-06-19 01:09:40 +04:00
|
|
|
|
2000-06-03 07:58:44 +04:00
|
|
|
show_seminfo_hdr();
|
|
|
|
for (i = 0; i < seminfo.semmni; i++) {
|
|
|
|
struct semid_ds *semaptr = &xsema[i];
|
|
|
|
if ((semaptr->sem_perm.mode & SEM_ALLOC) != 0)
|
|
|
|
show_seminfo(semaptr->sem_otime,
|
|
|
|
semaptr->sem_ctime,
|
1994-06-19 01:09:40 +04:00
|
|
|
IXSEQ_TO_IPCID(i, semaptr->sem_perm),
|
2006-04-29 00:35:15 +04:00
|
|
|
(u_int64_t)semaptr->sem_perm._key,
|
2000-06-03 07:58:44 +04:00
|
|
|
semaptr->sem_perm.mode,
|
|
|
|
semaptr->sem_perm.uid,
|
|
|
|
semaptr->sem_perm.gid,
|
|
|
|
semaptr->sem_perm.cuid,
|
|
|
|
semaptr->sem_perm.cgid,
|
|
|
|
semaptr->sem_nsems);
|
1993-11-14 19:17:55 +03:00
|
|
|
}
|
|
|
|
|
2006-04-29 00:35:15 +04:00
|
|
|
(void)printf("\n");
|
|
|
|
free(xsema);
|
1993-11-14 19:17:55 +03:00
|
|
|
}
|
1994-06-19 01:09:40 +04:00
|
|
|
} else
|
2006-04-29 00:35:15 +04:00
|
|
|
if (display & (SEMINFO | SEMTOTAL))
|
|
|
|
unconfsem();
|
|
|
|
(void)kvm_close(kd);
|
1993-11-14 19:17:55 +03:00
|
|
|
}
|
1994-06-19 01:20:28 +04:00
|
|
|
|
2006-04-29 00:35:15 +04:00
|
|
|
static void
|
2000-06-03 07:58:44 +04:00
|
|
|
usage(void)
|
1994-06-19 01:20:28 +04:00
|
|
|
{
|
|
|
|
|
2006-04-29 00:35:15 +04:00
|
|
|
(void)fprintf(stderr,
|
|
|
|
"Usage: %s [-abcmopqstMQST] [-C corefile] [-N namelist]\n",
|
2001-02-20 02:03:42 +03:00
|
|
|
getprogname());
|
1994-06-19 01:20:28 +04:00
|
|
|
exit(1);
|
|
|
|
}
|