1994-09-13 15:27:02 +00:00
|
|
|
/*
|
1994-09-13 16:59:29 +00:00
|
|
|
* Copyright (c) 1994 SigmaSoft, Th. Lockert <tholo@sigmasoft.com>
|
|
|
|
* 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.
|
1994-09-13 15:27:02 +00:00
|
|
|
*/
|
|
|
|
|
2002-06-30 05:25:07 +00:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
1997-07-15 09:55:59 +00:00
|
|
|
|
2007-12-18 09:39:47 +00:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/proc.h>
|
|
|
|
#define _KERNEL
|
|
|
|
#include <sys/sem.h>
|
|
|
|
#include <sys/shm.h>
|
|
|
|
#include <sys/msg.h>
|
|
|
|
#undef _KERNEL
|
|
|
|
|
1997-07-15 09:55:59 +00:00
|
|
|
#include <err.h>
|
|
|
|
#include <fcntl.h>
|
2002-02-19 00:05:59 +00:00
|
|
|
#include <grp.h>
|
1997-07-15 09:55:59 +00:00
|
|
|
#include <kvm.h>
|
2001-05-31 22:30:39 +00:00
|
|
|
#include <limits.h>
|
2002-02-19 00:05:59 +00:00
|
|
|
#include <pwd.h>
|
1994-09-13 15:27:02 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2001-06-24 19:50:42 +00:00
|
|
|
#include <string.h>
|
1994-09-13 15:27:02 +00:00
|
|
|
#include <unistd.h>
|
|
|
|
|
2007-12-25 00:52:24 +00:00
|
|
|
#include "ipc.h"
|
1994-09-19 10:24:38 +00:00
|
|
|
|
2002-03-30 16:46:04 +00:00
|
|
|
char *fmt_perm(u_short);
|
|
|
|
void cvt_time(time_t, char *);
|
2002-03-22 01:22:50 +00:00
|
|
|
void usage(void);
|
2004-03-24 04:01:43 +00:00
|
|
|
uid_t user2uid(char *username);
|
2007-12-25 00:52:24 +00:00
|
|
|
|
2007-12-18 09:39:47 +00:00
|
|
|
void print_kmsqtotal(struct msginfo msginfo);
|
|
|
|
void print_kmsqheader(int option);
|
|
|
|
void print_kmsqptr(int i, int option, struct msqid_kernel *kmsqptr);
|
|
|
|
void print_kshmtotal(struct shminfo shminfo);
|
|
|
|
void print_kshmheader(int option);
|
|
|
|
void print_kshmptr(int i, int option, struct shmid_kernel *kshmptr);
|
|
|
|
void print_ksemtotal(struct seminfo seminfo);
|
|
|
|
void print_ksemheader(int option);
|
|
|
|
void print_ksemptr(int i, int option, struct semid_kernel *ksemaptr);
|
1994-09-13 16:59:29 +00:00
|
|
|
|
|
|
|
char *
|
2005-02-10 09:13:20 +00:00
|
|
|
fmt_perm(u_short mode)
|
1994-09-13 15:27:02 +00:00
|
|
|
{
|
1994-09-13 16:59:29 +00:00
|
|
|
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]);
|
1994-09-13 15:27:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2005-02-10 09:13:20 +00:00
|
|
|
cvt_time(time_t t, char *buf)
|
1994-09-13 15:27:02 +00:00
|
|
|
{
|
1994-09-13 16:59:29 +00:00
|
|
|
struct tm *tm;
|
1994-09-13 15:27:02 +00:00
|
|
|
|
1994-09-13 16:59:29 +00:00
|
|
|
if (t == 0) {
|
|
|
|
strcpy(buf, "no-entry");
|
1994-09-13 15:27:02 +00:00
|
|
|
} else {
|
1994-09-13 16:59:29 +00:00
|
|
|
tm = localtime(&t);
|
|
|
|
sprintf(buf, "%2d:%02d:%02d",
|
|
|
|
tm->tm_hour, tm->tm_min, tm->tm_sec);
|
1994-09-13 15:27:02 +00:00
|
|
|
}
|
|
|
|
}
|
1994-09-13 16:59:29 +00:00
|
|
|
|
|
|
|
#define BIGGEST 1
|
|
|
|
#define CREATOR 2
|
|
|
|
#define OUTSTANDING 4
|
|
|
|
#define PID 8
|
|
|
|
#define TIME 16
|
|
|
|
|
|
|
|
int
|
2005-02-10 09:13:20 +00:00
|
|
|
main(int argc, char *argv[])
|
1994-09-13 15:27:02 +00:00
|
|
|
{
|
1994-09-13 16:59:29 +00:00
|
|
|
int display = SHMINFO | MSGINFO | SEMINFO;
|
|
|
|
int option = 0;
|
2004-03-24 04:01:43 +00:00
|
|
|
char *core = NULL, *user = NULL, *namelist = NULL;
|
2001-05-31 22:30:39 +00:00
|
|
|
char kvmoferr[_POSIX2_LINE_MAX]; /* Error buf for kvm_openfiles. */
|
1994-09-13 16:59:29 +00:00
|
|
|
int i;
|
2007-12-18 09:39:47 +00:00
|
|
|
uid_t uid = 0;
|
1994-09-13 16:59:29 +00:00
|
|
|
|
2004-03-24 04:01:43 +00:00
|
|
|
while ((i = getopt(argc, argv, "MmQqSsabC:cN:optTu:y")) != -1)
|
1994-09-13 16:59:29 +00:00
|
|
|
switch (i) {
|
|
|
|
case 'a':
|
|
|
|
option |= BIGGEST | CREATOR | OUTSTANDING | PID | TIME;
|
|
|
|
break;
|
|
|
|
case 'b':
|
|
|
|
option |= BIGGEST;
|
|
|
|
break;
|
|
|
|
case 'C':
|
|
|
|
core = optarg;
|
|
|
|
break;
|
|
|
|
case 'c':
|
|
|
|
option |= CREATOR;
|
|
|
|
break;
|
2007-12-18 09:39:47 +00:00
|
|
|
case 'M':
|
|
|
|
display = SHMTOTAL;
|
|
|
|
break;
|
|
|
|
case 'm':
|
|
|
|
display = SHMINFO;
|
|
|
|
break;
|
1994-09-13 16:59:29 +00:00
|
|
|
case 'N':
|
|
|
|
namelist = optarg;
|
|
|
|
break;
|
|
|
|
case 'o':
|
|
|
|
option |= OUTSTANDING;
|
|
|
|
break;
|
|
|
|
case 'p':
|
|
|
|
option |= PID;
|
|
|
|
break;
|
2007-12-18 09:39:47 +00:00
|
|
|
case 'Q':
|
|
|
|
display = MSGTOTAL;
|
|
|
|
break;
|
|
|
|
case 'q':
|
|
|
|
display = MSGINFO;
|
|
|
|
break;
|
|
|
|
case 'S':
|
|
|
|
display = SEMTOTAL;
|
|
|
|
break;
|
|
|
|
case 's':
|
|
|
|
display = SEMINFO;
|
|
|
|
break;
|
2007-12-25 00:52:24 +00:00
|
|
|
case 'T':
|
|
|
|
display = SHMTOTAL | MSGTOTAL | SEMTOTAL;
|
|
|
|
break;
|
1994-09-13 16:59:29 +00:00
|
|
|
case 't':
|
|
|
|
option |= TIME;
|
|
|
|
break;
|
2004-03-24 04:01:43 +00:00
|
|
|
case 'u':
|
|
|
|
user = optarg;
|
|
|
|
uid = user2uid(user);
|
|
|
|
break;
|
2007-12-18 09:39:47 +00:00
|
|
|
case 'y':
|
|
|
|
use_sysctl = 0;
|
|
|
|
break;
|
1994-09-13 16:59:29 +00:00
|
|
|
default:
|
|
|
|
usage();
|
|
|
|
}
|
1996-05-30 02:18:44 +00:00
|
|
|
|
|
|
|
/*
|
2001-05-31 22:30:39 +00:00
|
|
|
* If paths to the exec file or core file were specified, we
|
|
|
|
* aren't operating on the running kernel, so we can't use
|
|
|
|
* sysctl.
|
1996-05-30 02:18:44 +00:00
|
|
|
*/
|
|
|
|
if (namelist != NULL || core != NULL)
|
2001-05-31 22:30:39 +00:00
|
|
|
use_sysctl = 0;
|
|
|
|
|
|
|
|
if (!use_sysctl) {
|
|
|
|
kd = kvm_openfiles(namelist, core, NULL, O_RDONLY, kvmoferr);
|
|
|
|
if (kd == NULL)
|
|
|
|
errx(1, "kvm_openfiles: %s", kvmoferr);
|
|
|
|
switch (kvm_nlist(kd, symbols)) {
|
|
|
|
case 0:
|
|
|
|
break;
|
|
|
|
case -1:
|
|
|
|
errx(1, "unable to read kernel symbol table");
|
|
|
|
default:
|
2002-03-30 16:46:04 +00:00
|
|
|
break;
|
2001-05-31 22:30:39 +00:00
|
|
|
}
|
1994-09-13 15:27:02 +00:00
|
|
|
}
|
|
|
|
|
2001-05-31 22:30:39 +00:00
|
|
|
kget(X_MSGINFO, &msginfo, sizeof(msginfo));
|
|
|
|
if ((display & (MSGINFO | MSGTOTAL))) {
|
2007-12-18 09:39:47 +00:00
|
|
|
if (display & MSGTOTAL)
|
|
|
|
print_kmsqtotal(msginfo);
|
|
|
|
|
1994-09-13 16:59:29 +00:00
|
|
|
if (display & MSGINFO) {
|
2004-11-12 13:33:55 +00:00
|
|
|
struct msqid_kernel *kxmsqids;
|
|
|
|
size_t kxmsqids_len;
|
2001-05-31 22:30:39 +00:00
|
|
|
|
2007-12-18 09:39:47 +00:00
|
|
|
kxmsqids_len =
|
|
|
|
sizeof(struct msqid_kernel) * msginfo.msgmni;
|
2004-11-12 13:33:55 +00:00
|
|
|
kxmsqids = malloc(kxmsqids_len);
|
|
|
|
kget(X_MSQIDS, kxmsqids, kxmsqids_len);
|
1994-09-13 16:59:29 +00:00
|
|
|
|
2007-12-18 09:39:47 +00:00
|
|
|
print_kmsqheader(option);
|
|
|
|
|
1994-09-13 16:59:29 +00:00
|
|
|
for (i = 0; i < msginfo.msgmni; i += 1) {
|
2004-11-12 13:33:55 +00:00
|
|
|
if (kxmsqids[i].u.msg_qbytes != 0) {
|
2007-12-18 09:39:47 +00:00
|
|
|
if (user &&
|
|
|
|
uid != kxmsqids[i].u.msg_perm.uid)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
print_kmsqptr(i, option, &kxmsqids[i]);
|
1994-09-13 16:59:29 +00:00
|
|
|
}
|
2007-12-18 09:39:47 +00:00
|
|
|
|
1994-09-13 15:27:02 +00:00
|
|
|
}
|
2007-12-18 09:39:47 +00:00
|
|
|
|
1994-09-13 16:59:29 +00:00
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
if (display & (MSGINFO | MSGTOTAL)) {
|
|
|
|
fprintf(stderr,
|
2007-12-18 09:39:47 +00:00
|
|
|
"SVID messages facility "
|
|
|
|
"not configured in the system\n");
|
1994-09-13 16:59:29 +00:00
|
|
|
}
|
2001-05-31 22:30:39 +00:00
|
|
|
|
|
|
|
kget(X_SHMINFO, &shminfo, sizeof(shminfo));
|
|
|
|
if ((display & (SHMINFO | SHMTOTAL))) {
|
2007-12-18 09:39:47 +00:00
|
|
|
|
|
|
|
if (display & SHMTOTAL)
|
|
|
|
print_kshmtotal(shminfo);
|
|
|
|
|
1994-09-13 16:59:29 +00:00
|
|
|
if (display & SHMINFO) {
|
2004-11-12 13:33:55 +00:00
|
|
|
struct shmid_kernel *kxshmids;
|
|
|
|
size_t kxshmids_len;
|
1994-09-13 16:59:29 +00:00
|
|
|
|
2007-12-18 09:39:47 +00:00
|
|
|
kxshmids_len =
|
|
|
|
sizeof(struct shmid_kernel) * shminfo.shmmni;
|
2004-11-12 13:33:55 +00:00
|
|
|
kxshmids = malloc(kxshmids_len);
|
|
|
|
kget(X_SHMSEGS, kxshmids, kxshmids_len);
|
1994-09-13 16:59:29 +00:00
|
|
|
|
2007-12-18 09:39:47 +00:00
|
|
|
print_kshmheader(option);
|
|
|
|
|
1994-09-13 16:59:29 +00:00
|
|
|
for (i = 0; i < shminfo.shmmni; i += 1) {
|
2004-11-12 13:33:55 +00:00
|
|
|
if (kxshmids[i].u.shm_perm.mode & 0x0800) {
|
2007-12-18 09:39:47 +00:00
|
|
|
if (user &&
|
|
|
|
uid != kxshmids[i].u.shm_perm.uid)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
print_kshmptr(i, option, &kxshmids[i]);
|
1994-09-13 16:59:29 +00:00
|
|
|
}
|
1994-09-13 15:27:02 +00:00
|
|
|
}
|
1994-09-13 16:59:29 +00:00
|
|
|
printf("\n");
|
1994-09-13 15:27:02 +00:00
|
|
|
}
|
1994-09-13 16:59:29 +00:00
|
|
|
} else
|
|
|
|
if (display & (SHMINFO | SHMTOTAL)) {
|
|
|
|
fprintf(stderr,
|
2007-12-18 09:39:47 +00:00
|
|
|
"SVID shared memory facility "
|
|
|
|
"not configured in the system\n");
|
1994-09-13 15:27:02 +00:00
|
|
|
}
|
2001-05-31 22:30:39 +00:00
|
|
|
|
|
|
|
kget(X_SEMINFO, &seminfo, sizeof(seminfo));
|
|
|
|
if ((display & (SEMINFO | SEMTOTAL))) {
|
2004-11-12 13:33:55 +00:00
|
|
|
struct semid_kernel *kxsema;
|
|
|
|
size_t kxsema_len;
|
1994-09-13 16:59:29 +00:00
|
|
|
|
2007-12-18 09:39:47 +00:00
|
|
|
if (display & SEMTOTAL)
|
|
|
|
print_ksemtotal(seminfo);
|
|
|
|
|
1994-09-13 16:59:29 +00:00
|
|
|
if (display & SEMINFO) {
|
2007-12-18 09:39:47 +00:00
|
|
|
kxsema_len =
|
|
|
|
sizeof(struct semid_kernel) * seminfo.semmni;
|
2004-11-12 13:33:55 +00:00
|
|
|
kxsema = malloc(kxsema_len);
|
|
|
|
kget(X_SEMA, kxsema, kxsema_len);
|
1994-09-13 16:59:29 +00:00
|
|
|
|
2007-12-18 09:39:47 +00:00
|
|
|
print_ksemheader(option);
|
|
|
|
|
1994-09-13 16:59:29 +00:00
|
|
|
for (i = 0; i < seminfo.semmni; i += 1) {
|
2007-12-25 00:52:24 +00:00
|
|
|
if ((kxsema[i].u.sem_perm.mode & SEM_ALLOC)
|
|
|
|
!= 0) {
|
2007-12-18 09:39:47 +00:00
|
|
|
if (user &&
|
|
|
|
uid != kxsema[i].u.sem_perm.uid)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
print_ksemptr(i, option, &kxsema[i]);
|
|
|
|
|
1994-09-13 16:59:29 +00:00
|
|
|
}
|
|
|
|
}
|
1994-09-13 15:27:02 +00:00
|
|
|
|
1994-09-13 16:59:29 +00:00
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
if (display & (SEMINFO | SEMTOTAL)) {
|
2007-12-18 09:39:47 +00:00
|
|
|
fprintf(stderr,
|
|
|
|
"SVID semaphores facility "
|
|
|
|
"not configured in the system\n");
|
1994-09-13 16:59:29 +00:00
|
|
|
}
|
2007-12-18 09:39:47 +00:00
|
|
|
|
2001-05-31 22:30:39 +00:00
|
|
|
if (!use_sysctl)
|
|
|
|
kvm_close(kd);
|
1994-09-13 15:27:02 +00:00
|
|
|
|
1994-09-13 16:59:29 +00:00
|
|
|
exit(0);
|
|
|
|
}
|
1994-09-13 15:27:02 +00:00
|
|
|
|
2007-12-18 09:39:47 +00:00
|
|
|
void
|
|
|
|
print_kmsqtotal(struct msginfo msginfo)
|
|
|
|
{
|
|
|
|
|
|
|
|
printf("msginfo:\n");
|
|
|
|
printf("\tmsgmax: %12d\t(max characters in a message)\n",
|
|
|
|
msginfo.msgmax);
|
|
|
|
printf("\tmsgmni: %12d\t(# of message queues)\n",
|
|
|
|
msginfo.msgmni);
|
|
|
|
printf("\tmsgmnb: %12d\t(max characters in a message queue)\n",
|
|
|
|
msginfo.msgmnb);
|
|
|
|
printf("\tmsgtql: %12d\t(max # of messages in system)\n",
|
|
|
|
msginfo.msgtql);
|
|
|
|
printf("\tmsgssz: %12d\t(size of a message segment)\n",
|
|
|
|
msginfo.msgssz);
|
|
|
|
printf("\tmsgseg: %12d\t(# of message segments in system)\n\n",
|
|
|
|
msginfo.msgseg);
|
|
|
|
}
|
|
|
|
|
2007-12-25 00:52:24 +00:00
|
|
|
void print_kmsqheader(int option)
|
|
|
|
{
|
2007-12-18 09:39:47 +00:00
|
|
|
|
|
|
|
printf("Message Queues:\n");
|
|
|
|
printf("T %12s %12s %-11s %-8s %-8s",
|
|
|
|
"ID", "KEY", "MODE", "OWNER", "GROUP");
|
|
|
|
if (option & CREATOR)
|
|
|
|
printf(" %-8s %-8s", "CREATOR", "CGROUP");
|
|
|
|
if (option & OUTSTANDING)
|
|
|
|
printf(" %20s %20s", "CBYTES", "QNUM");
|
|
|
|
if (option & BIGGEST)
|
|
|
|
printf(" %20s", "QBYTES");
|
|
|
|
if (option & PID)
|
|
|
|
printf(" %12s %12s", "LSPID", "LRPID");
|
|
|
|
if (option & TIME)
|
|
|
|
printf(" %-8s %-8s %-8s", "STIME", "RTIME", "CTIME");
|
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
print_kmsqptr(int i, int option, struct msqid_kernel *kmsqptr)
|
|
|
|
{
|
|
|
|
char stime_buf[100], rtime_buf[100], ctime_buf[100];
|
|
|
|
|
|
|
|
cvt_time(kmsqptr->u.msg_stime, stime_buf);
|
|
|
|
cvt_time(kmsqptr->u.msg_rtime, rtime_buf);
|
|
|
|
cvt_time(kmsqptr->u.msg_ctime, ctime_buf);
|
|
|
|
|
2007-12-25 00:52:24 +00:00
|
|
|
printf("q %12d %12d %s %-8s %-8s",
|
2007-12-18 09:39:47 +00:00
|
|
|
IXSEQ_TO_IPCID(i, kmsqptr->u.msg_perm),
|
|
|
|
(int)kmsqptr->u.msg_perm.key,
|
|
|
|
fmt_perm(kmsqptr->u.msg_perm.mode),
|
|
|
|
user_from_uid(kmsqptr->u.msg_perm.uid, 0),
|
|
|
|
group_from_gid(kmsqptr->u.msg_perm.gid, 0));
|
|
|
|
|
|
|
|
if (option & CREATOR)
|
2007-12-25 00:52:24 +00:00
|
|
|
printf(" %-8s %-8s",
|
2007-12-18 09:39:47 +00:00
|
|
|
user_from_uid(kmsqptr->u.msg_perm.cuid, 0),
|
|
|
|
group_from_gid(kmsqptr->u.msg_perm.cgid, 0));
|
|
|
|
|
|
|
|
if (option & OUTSTANDING)
|
|
|
|
printf(" %12lu %12lu",
|
|
|
|
kmsqptr->u.msg_cbytes,
|
|
|
|
kmsqptr->u.msg_qnum);
|
|
|
|
|
|
|
|
if (option & BIGGEST)
|
|
|
|
printf(" %20lu", kmsqptr->u.msg_qbytes);
|
|
|
|
|
|
|
|
if (option & PID)
|
|
|
|
printf(" %12d %12d",
|
|
|
|
kmsqptr->u.msg_lspid,
|
|
|
|
kmsqptr->u.msg_lrpid);
|
|
|
|
|
|
|
|
if (option & TIME)
|
|
|
|
printf(" %s %s %s",
|
|
|
|
stime_buf,
|
|
|
|
rtime_buf,
|
|
|
|
ctime_buf);
|
|
|
|
|
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
print_kshmtotal(struct shminfo shminfo)
|
|
|
|
{
|
|
|
|
|
|
|
|
printf("shminfo:\n");
|
2008-12-16 09:17:05 +00:00
|
|
|
printf("\tshmmax: %12lu\t(max shared memory segment size)\n",
|
2007-12-18 09:39:47 +00:00
|
|
|
shminfo.shmmax);
|
2008-12-16 09:17:05 +00:00
|
|
|
printf("\tshmmin: %12lu\t(min shared memory segment size)\n",
|
2007-12-18 09:39:47 +00:00
|
|
|
shminfo.shmmin);
|
2008-12-16 09:17:05 +00:00
|
|
|
printf("\tshmmni: %12lu\t(max number of shared memory identifiers)\n",
|
2007-12-18 09:39:47 +00:00
|
|
|
shminfo.shmmni);
|
2008-12-16 09:17:05 +00:00
|
|
|
printf("\tshmseg: %12lu\t(max shared memory segments per process)\n",
|
2007-12-18 09:39:47 +00:00
|
|
|
shminfo.shmseg);
|
2008-12-16 09:17:05 +00:00
|
|
|
printf("\tshmall: %12lu\t(max amount of shared memory in pages)\n\n",
|
2007-12-18 09:39:47 +00:00
|
|
|
shminfo.shmall);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
print_kshmheader(int option)
|
|
|
|
{
|
|
|
|
|
|
|
|
printf("Shared Memory:\n");
|
|
|
|
printf("T %12s %12s %-11s %-8s %-8s",
|
|
|
|
"ID", "KEY", "MODE", "OWNER", "GROUP");
|
|
|
|
if (option & CREATOR)
|
|
|
|
printf(" %-8s %-8s", "CREATOR", "CGROUP");
|
|
|
|
if (option & OUTSTANDING)
|
|
|
|
printf(" %12s", "NATTCH");
|
|
|
|
if (option & BIGGEST)
|
|
|
|
printf(" %12s", "SEGSZ");
|
|
|
|
if (option & PID)
|
|
|
|
printf(" %12s %12s", "CPID", "LPID");
|
|
|
|
if (option & TIME)
|
|
|
|
printf(" %-8s %-8s %-8s", "ATIME", "DTIME", "CTIME");
|
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
print_kshmptr(int i, int option, struct shmid_kernel *kshmptr)
|
|
|
|
{
|
|
|
|
char atime_buf[100], dtime_buf[100], ctime_buf[100];
|
|
|
|
|
|
|
|
cvt_time(kshmptr->u.shm_atime, atime_buf);
|
|
|
|
cvt_time(kshmptr->u.shm_dtime, dtime_buf);
|
|
|
|
cvt_time(kshmptr->u.shm_ctime, ctime_buf);
|
|
|
|
|
2007-12-25 00:52:24 +00:00
|
|
|
printf("m %12d %12d %s %-8s %-8s",
|
2007-12-18 09:39:47 +00:00
|
|
|
IXSEQ_TO_IPCID(i, kshmptr->u.shm_perm),
|
|
|
|
(int)kshmptr->u.shm_perm.key,
|
|
|
|
fmt_perm(kshmptr->u.shm_perm.mode),
|
|
|
|
user_from_uid(kshmptr->u.shm_perm.uid, 0),
|
|
|
|
group_from_gid(kshmptr->u.shm_perm.gid, 0));
|
|
|
|
|
|
|
|
if (option & CREATOR)
|
2007-12-25 00:52:24 +00:00
|
|
|
printf(" %-8s %-8s",
|
2007-12-18 09:39:47 +00:00
|
|
|
user_from_uid(kshmptr->u.shm_perm.cuid, 0),
|
|
|
|
group_from_gid(kshmptr->u.shm_perm.cgid, 0));
|
|
|
|
|
|
|
|
if (option & OUTSTANDING)
|
|
|
|
printf(" %12d",
|
|
|
|
kshmptr->u.shm_nattch);
|
|
|
|
|
|
|
|
if (option & BIGGEST)
|
2009-03-02 18:53:30 +00:00
|
|
|
printf(" %12zu",
|
2009-06-24 21:10:52 +00:00
|
|
|
kshmptr->u.shm_segsz);
|
2007-12-18 09:39:47 +00:00
|
|
|
|
|
|
|
if (option & PID)
|
|
|
|
printf(" %12d %12d",
|
|
|
|
kshmptr->u.shm_cpid,
|
|
|
|
kshmptr->u.shm_lpid);
|
|
|
|
|
|
|
|
if (option & TIME)
|
|
|
|
printf(" %s %s %s",
|
|
|
|
atime_buf,
|
|
|
|
dtime_buf,
|
|
|
|
ctime_buf);
|
|
|
|
|
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
print_ksemtotal(struct seminfo seminfo)
|
|
|
|
{
|
|
|
|
|
|
|
|
printf("seminfo:\n");
|
|
|
|
printf("\tsemmni: %12d\t(# of semaphore identifiers)\n",
|
|
|
|
seminfo.semmni);
|
|
|
|
printf("\tsemmns: %12d\t(# of semaphores in system)\n",
|
|
|
|
seminfo.semmns);
|
|
|
|
printf("\tsemmnu: %12d\t(# of undo structures in system)\n",
|
|
|
|
seminfo.semmnu);
|
|
|
|
printf("\tsemmsl: %12d\t(max # of semaphores per id)\n",
|
|
|
|
seminfo.semmsl);
|
|
|
|
printf("\tsemopm: %12d\t(max # of operations per semop call)\n",
|
|
|
|
seminfo.semopm);
|
|
|
|
printf("\tsemume: %12d\t(max # of undo entries per process)\n",
|
|
|
|
seminfo.semume);
|
|
|
|
printf("\tsemusz: %12d\t(size in bytes of undo structure)\n",
|
|
|
|
seminfo.semusz);
|
|
|
|
printf("\tsemvmx: %12d\t(semaphore maximum value)\n",
|
|
|
|
seminfo.semvmx);
|
|
|
|
printf("\tsemaem: %12d\t(adjust on exit max value)\n\n",
|
|
|
|
seminfo.semaem);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2007-12-25 00:52:24 +00:00
|
|
|
print_ksemheader(int option)
|
|
|
|
{
|
2007-12-18 09:39:47 +00:00
|
|
|
|
|
|
|
printf("Semaphores:\n");
|
|
|
|
printf("T %12s %12s %-11s %-8s %-8s",
|
|
|
|
"ID", "KEY", "MODE", "OWNER", "GROUP");
|
|
|
|
if (option & CREATOR)
|
|
|
|
printf(" %-8s %-8s", "CREATOR", "CGROUP");
|
|
|
|
if (option & BIGGEST)
|
|
|
|
printf(" %12s", "NSEMS");
|
|
|
|
if (option & TIME)
|
|
|
|
printf(" %-8s %-8s", "OTIME", "CTIME");
|
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
print_ksemptr(int i, int option, struct semid_kernel *ksemaptr)
|
|
|
|
{
|
|
|
|
char ctime_buf[100], otime_buf[100];
|
|
|
|
|
|
|
|
cvt_time(ksemaptr->u.sem_otime, otime_buf);
|
|
|
|
cvt_time(ksemaptr->u.sem_ctime, ctime_buf);
|
|
|
|
|
2007-12-25 00:52:24 +00:00
|
|
|
printf("s %12d %12d %s %-8s %-8s",
|
2007-12-18 09:39:47 +00:00
|
|
|
IXSEQ_TO_IPCID(i, ksemaptr->u.sem_perm),
|
|
|
|
(int)ksemaptr->u.sem_perm.key,
|
|
|
|
fmt_perm(ksemaptr->u.sem_perm.mode),
|
|
|
|
user_from_uid(ksemaptr->u.sem_perm.uid, 0),
|
|
|
|
group_from_gid(ksemaptr->u.sem_perm.gid, 0));
|
|
|
|
|
|
|
|
if (option & CREATOR)
|
2007-12-25 00:52:24 +00:00
|
|
|
printf(" %-8s %-8s",
|
2007-12-18 09:39:47 +00:00
|
|
|
user_from_uid(ksemaptr->u.sem_perm.cuid, 0),
|
|
|
|
group_from_gid(ksemaptr->u.sem_perm.cgid, 0));
|
|
|
|
|
|
|
|
if (option & BIGGEST)
|
|
|
|
printf(" %12d",
|
|
|
|
ksemaptr->u.sem_nsems);
|
|
|
|
|
|
|
|
if (option & TIME)
|
|
|
|
printf(" %s %s",
|
|
|
|
otime_buf,
|
|
|
|
ctime_buf);
|
|
|
|
|
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
|
2004-03-24 04:01:43 +00:00
|
|
|
uid_t
|
|
|
|
user2uid(char *username)
|
|
|
|
{
|
|
|
|
struct passwd *pwd;
|
|
|
|
uid_t uid;
|
|
|
|
char *r;
|
|
|
|
|
|
|
|
uid = strtoul(username, &r, 0);
|
|
|
|
if (!*r && r != username)
|
|
|
|
return (uid);
|
|
|
|
if ((pwd = getpwnam(username)) == NULL)
|
|
|
|
errx(1, "getpwnam failed: No such user");
|
|
|
|
endpwent();
|
|
|
|
return (pwd->pw_uid);
|
|
|
|
}
|
|
|
|
|
1994-09-13 16:59:29 +00:00
|
|
|
void
|
2005-02-10 09:13:20 +00:00
|
|
|
usage(void)
|
1994-09-13 16:59:29 +00:00
|
|
|
{
|
1994-09-13 15:27:02 +00:00
|
|
|
|
1994-09-13 16:59:29 +00:00
|
|
|
fprintf(stderr,
|
2007-12-18 09:39:47 +00:00
|
|
|
"usage: "
|
|
|
|
"ipcs [-abcmopqstyMQST] [-C corefile] [-N namelist] [-u user]\n");
|
1994-09-13 16:59:29 +00:00
|
|
|
exit(1);
|
1994-09-13 15:27:02 +00:00
|
|
|
}
|