summaryrefslogtreecommitdiffstats
path: root/usr.bin/ipcs
diff options
context:
space:
mode:
authoredwin <edwin@FreeBSD.org>2007-12-18 09:39:47 +0000
committeredwin <edwin@FreeBSD.org>2007-12-18 09:39:47 +0000
commit75ddc3d2357e981940f6ad3decedf198a76d1e2f (patch)
tree8cafe3e5799793255fd61a3b78f4bfab42754cf8 /usr.bin/ipcs
parentdbcd24960cd45cd568a2a1d25abd1e8c22d91cd1 (diff)
downloadFreeBSD-src-75ddc3d2357e981940f6ad3decedf198a76d1e2f.zip
FreeBSD-src-75ddc3d2357e981940f6ad3decedf198a76d1e2f.tar.gz
Stylify ipcs/ipcs.c and ipcrm/ipcrm in preparation of the upcoming
changes as proposed in bin/118292. Feel free to mention any I have missed, there is much to learn with regarding to style(9). Approved by: grog@
Diffstat (limited to 'usr.bin/ipcs')
-rw-r--r--usr.bin/ipcs/ipcs.c639
1 files changed, 354 insertions, 285 deletions
diff --git a/usr.bin/ipcs/ipcs.c b/usr.bin/ipcs/ipcs.c
index 9424e67..322f9a3 100644
--- a/usr.bin/ipcs/ipcs.c
+++ b/usr.bin/ipcs/ipcs.c
@@ -28,13 +28,25 @@
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
+#include <sys/types.h>
+#include <sys/param.h>
+#include <sys/time.h>
+#include <sys/proc.h>
+#include <sys/sysctl.h>
+#define _KERNEL
+#include <sys/ipc.h>
+#include <sys/sem.h>
+#include <sys/shm.h>
+#include <sys/msg.h>
+#undef _KERNEL
+
#include <assert.h>
#include <err.h>
#include <fcntl.h>
#include <grp.h>
#include <kvm.h>
-#include <nlist.h>
#include <limits.h>
+#include <nlist.h>
#include <paths.h>
#include <pwd.h>
#include <stddef.h>
@@ -43,17 +55,6 @@ __FBSDID("$FreeBSD$");
#include <string.h>
#include <unistd.h>
-#include <sys/types.h>
-#include <sys/param.h>
-#include <sys/time.h>
-#include <sys/proc.h>
-#include <sys/sysctl.h>
-#define _KERNEL
-#include <sys/ipc.h>
-#include <sys/sem.h>
-#include <sys/shm.h>
-#include <sys/msg.h>
-
/* SysCtlGatherStruct structure. */
struct scgs_vector {
const char *sysctl;
@@ -63,10 +64,10 @@ struct scgs_vector {
int use_sysctl = 1;
struct semid_kernel *sema;
-struct seminfo seminfo;
-struct msginfo msginfo;
+struct seminfo seminfo;
+struct msginfo msginfo;
struct msqid_kernel *msqids;
-struct shminfo shminfo;
+struct shminfo shminfo;
struct shmid_kernel *shmsegs;
char *fmt_perm(u_short);
@@ -75,6 +76,15 @@ void sysctlgatherstruct(void *addr, size_t size, struct scgs_vector *vec);
void kget(int idx, void *addr, size_t size);
void usage(void);
uid_t user2uid(char *username);
+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);
static struct nlist symbols[] = {
{"sema"},
@@ -92,32 +102,29 @@ static struct nlist symbols[] = {
{NULL}
};
-#define SHMINFO_XVEC \
-X(shmmax, sizeof(u_long)) \
-X(shmmin, sizeof(u_long)) \
-X(shmmni, sizeof(u_long)) \
-X(shmseg, sizeof(u_long)) \
-X(shmall, sizeof(u_long))
-
-#define SEMINFO_XVEC \
-X(semmap, sizeof(int)) \
-X(semmni, sizeof(int)) \
-X(semmns, sizeof(int)) \
-X(semmnu, sizeof(int)) \
-X(semmsl, sizeof(int)) \
-X(semopm, sizeof(int)) \
-X(semume, sizeof(int)) \
-X(semusz, sizeof(int)) \
-X(semvmx, sizeof(int)) \
-X(semaem, sizeof(int))
-
-#define MSGINFO_XVEC \
-X(msgmax, sizeof(int)) \
-X(msgmni, sizeof(int)) \
-X(msgmnb, sizeof(int)) \
-X(msgtql, sizeof(int)) \
-X(msgssz, sizeof(int)) \
-X(msgseg, sizeof(int))
+#define SHMINFO_XVEC X(shmmax, sizeof(u_long)) \
+ X(shmmin, sizeof(u_long)) \
+ X(shmmni, sizeof(u_long)) \
+ X(shmseg, sizeof(u_long)) \
+ X(shmall, sizeof(u_long))
+
+#define SEMINFO_XVEC X(semmap, sizeof(int)) \
+ X(semmni, sizeof(int)) \
+ X(semmns, sizeof(int)) \
+ X(semmnu, sizeof(int)) \
+ X(semmsl, sizeof(int)) \
+ X(semopm, sizeof(int)) \
+ X(semume, sizeof(int)) \
+ X(semusz, sizeof(int)) \
+ X(semvmx, sizeof(int)) \
+ X(semaem, sizeof(int))
+
+#define MSGINFO_XVEC X(msgmax, sizeof(int)) \
+ X(msgmni, sizeof(int)) \
+ X(msgmnb, sizeof(int)) \
+ X(msgtql, sizeof(int)) \
+ X(msgssz, sizeof(int)) \
+ X(msgseg, sizeof(int))
#define X(a, b) { "kern.ipc." #a, offsetof(TYPEC, a), (b) },
#define TYPEC struct shminfo
@@ -187,28 +194,10 @@ main(int argc, char *argv[])
char *core = NULL, *user = NULL, *namelist = NULL;
char kvmoferr[_POSIX2_LINE_MAX]; /* Error buf for kvm_openfiles. */
int i;
- uid_t uid;
+ uid_t uid = 0;
while ((i = getopt(argc, argv, "MmQqSsabC:cN:optTu:y")) != -1)
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;
@@ -224,6 +213,12 @@ main(int argc, char *argv[])
case 'c':
option |= CREATOR;
break;
+ case 'M':
+ display = SHMTOTAL;
+ break;
+ case 'm':
+ display = SHMINFO;
+ break;
case 'N':
namelist = optarg;
break;
@@ -233,16 +228,28 @@ main(int argc, char *argv[])
case 'p':
option |= PID;
break;
+ case 'Q':
+ display = MSGTOTAL;
+ break;
+ case 'q':
+ display = MSGINFO;
+ break;
+ case 'S':
+ display = SEMTOTAL;
+ break;
+ case 's':
+ display = SEMINFO;
+ break;
case 't':
option |= TIME;
break;
- case 'y':
- use_sysctl = 0;
- break;
case 'u':
user = optarg;
uid = user2uid(user);
break;
+ case 'y':
+ use_sysctl = 0;
+ break;
default:
usage();
}
@@ -265,195 +272,70 @@ main(int argc, char *argv[])
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);
-#endif
break;
}
}
kget(X_MSGINFO, &msginfo, sizeof(msginfo));
if ((display & (MSGINFO | MSGTOTAL))) {
- if (display & MSGTOTAL) {
- 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);
- }
+ if (display & MSGTOTAL)
+ print_kmsqtotal(msginfo);
+
if (display & MSGINFO) {
struct msqid_kernel *kxmsqids;
size_t kxmsqids_len;
-
- kxmsqids_len = sizeof(struct msqid_kernel) * msginfo.msgmni;
+ kxmsqids_len =
+ sizeof(struct msqid_kernel) * msginfo.msgmni;
kxmsqids = malloc(kxmsqids_len);
kget(X_MSQIDS, kxmsqids, kxmsqids_len);
- 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");
+ print_kmsqheader(option);
+
for (i = 0; i < msginfo.msgmni; i += 1) {
if (kxmsqids[i].u.msg_qbytes != 0) {
- char stime_buf[100], rtime_buf[100],
- ctime_buf[100];
- struct msqid_kernel *kmsqptr = &kxmsqids[i];
-
- if (user)
- if (uid != kmsqptr->u.msg_perm.uid)
- continue;
- cvt_time(kmsqptr->u.msg_stime, stime_buf);
- cvt_time(kmsqptr->u.msg_rtime, rtime_buf);
- cvt_time(kmsqptr->u.msg_ctime, ctime_buf);
-
- printf("q %12d %12d %s %8s %8s",
- 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)
- printf(" %8s %8s",
- 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");
+ if (user &&
+ uid != kxmsqids[i].u.msg_perm.uid)
+ continue;
+
+ print_kmsqptr(i, option, &kxmsqids[i]);
}
+
}
+
printf("\n");
}
} else
if (display & (MSGINFO | MSGTOTAL)) {
fprintf(stderr,
- "SVID messages facility not configured in the system\n");
+ "SVID messages facility "
+ "not configured in the system\n");
}
kget(X_SHMINFO, &shminfo, sizeof(shminfo));
if ((display & (SHMINFO | SHMTOTAL))) {
- if (display & SHMTOTAL) {
- printf("shminfo:\n");
- printf("\tshmmax: %12d\t(max shared memory segment size)\n",
- shminfo.shmmax);
- printf("\tshmmin: %12d\t(min shared memory segment size)\n",
- shminfo.shmmin);
- printf("\tshmmni: %12d\t(max number of shared memory identifiers)\n",
- shminfo.shmmni);
- printf("\tshmseg: %12d\t(max shared memory segments per process)\n",
- shminfo.shmseg);
- printf("\tshmall: %12d\t(max amount of shared memory in pages)\n\n",
- shminfo.shmall);
- }
+
+ if (display & SHMTOTAL)
+ print_kshmtotal(shminfo);
+
if (display & SHMINFO) {
struct shmid_kernel *kxshmids;
size_t kxshmids_len;
- kxshmids_len = sizeof(struct shmid_kernel) * shminfo.shmmni;
+ kxshmids_len =
+ sizeof(struct shmid_kernel) * shminfo.shmmni;
kxshmids = malloc(kxshmids_len);
kget(X_SHMSEGS, kxshmids, kxshmids_len);
- 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");
+ print_kshmheader(option);
+
for (i = 0; i < shminfo.shmmni; i += 1) {
if (kxshmids[i].u.shm_perm.mode & 0x0800) {
- char atime_buf[100], dtime_buf[100],
- ctime_buf[100];
- struct shmid_kernel *kshmptr = &kxshmids[i];
-
- if (user)
- if (uid != kshmptr->u.shm_perm.uid)
- continue;
- cvt_time(kshmptr->u.shm_atime, atime_buf);
- cvt_time(kshmptr->u.shm_dtime, dtime_buf);
- cvt_time(kshmptr->u.shm_ctime, ctime_buf);
-
- printf("m %12d %12d %s %8s %8s",
- 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)
- printf(" %8s %8s",
- 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)
- printf(" %12d",
- kshmptr->u.shm_segsz);
-
- 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");
+ if (user &&
+ uid != kxshmids[i].u.shm_perm.uid)
+ continue;
+
+ print_kshmptr(i, option, &kxshmids[i]);
}
}
printf("\n");
@@ -461,7 +343,8 @@ main(int argc, char *argv[])
} else
if (display & (SHMINFO | SHMTOTAL)) {
fprintf(stderr,
- "SVID shared memory facility not configured in the system\n");
+ "SVID shared memory facility "
+ "not configured in the system\n");
}
kget(X_SEMINFO, &seminfo, sizeof(seminfo));
@@ -469,77 +352,25 @@ main(int argc, char *argv[])
struct semid_kernel *kxsema;
size_t kxsema_len;
- if (display & SEMTOTAL) {
- printf("seminfo:\n");
- printf("\tsemmap: %12d\t(# of entries in semaphore map)\n",
- seminfo.semmap);
- 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);
- }
+ if (display & SEMTOTAL)
+ print_ksemtotal(seminfo);
+
if (display & SEMINFO) {
- kxsema_len = sizeof(struct semid_kernel) * seminfo.semmni;
+ kxsema_len =
+ sizeof(struct semid_kernel) * seminfo.semmni;
kxsema = malloc(kxsema_len);
kget(X_SEMA, kxsema, kxsema_len);
- 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");
+ print_ksemheader(option);
+
for (i = 0; i < seminfo.semmni; i += 1) {
if ((kxsema[i].u.sem_perm.mode & SEM_ALLOC) != 0) {
- char ctime_buf[100], otime_buf[100];
- struct semid_kernel *ksemaptr = &kxsema[i];
-
- if (user)
- if (uid != ksemaptr->u.sem_perm.uid)
- continue;
- cvt_time(ksemaptr->u.sem_otime, otime_buf);
- cvt_time(ksemaptr->u.sem_ctime, ctime_buf);
-
- printf("s %12d %12d %s %8s %8s",
- 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)
- printf(" %8s %8s",
- 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");
+ if (user &&
+ uid != kxsema[i].u.sem_perm.uid)
+ continue;
+
+ print_ksemptr(i, option, &kxsema[i]);
+
}
}
@@ -547,8 +378,11 @@ main(int argc, char *argv[])
}
} else
if (display & (SEMINFO | SEMTOTAL)) {
- fprintf(stderr, "SVID semaphores facility not configured in the system\n");
+ fprintf(stderr,
+ "SVID semaphores facility "
+ "not configured in the system\n");
}
+
if (!use_sysctl)
kvm_close(kd);
@@ -556,6 +390,240 @@ main(int argc, char *argv[])
}
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);
+}
+
+void print_kmsqheader(int option) {
+
+ 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);
+
+ printf("q %12d %12d %s %8s %8s",
+ 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)
+ printf(" %8s %8s",
+ 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");
+ printf("\tshmmax: %12d\t(max shared memory segment size)\n",
+ shminfo.shmmax);
+ printf("\tshmmin: %12d\t(min shared memory segment size)\n",
+ shminfo.shmmin);
+ printf("\tshmmni: %12d\t(max number of shared memory identifiers)\n",
+ shminfo.shmmni);
+ printf("\tshmseg: %12d\t(max shared memory segments per process)\n",
+ shminfo.shmseg);
+ printf("\tshmall: %12d\t(max amount of shared memory in pages)\n\n",
+ 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);
+
+ printf("m %12d %12d %s %8s %8s",
+ 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)
+ printf(" %8s %8s",
+ 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)
+ printf(" %12d",
+ kshmptr->u.shm_segsz);
+
+ 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("\tsemmap: %12d\t(# of entries in semaphore map)\n",
+ seminfo.semmap);
+ 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
+print_ksemheader(int option) {
+
+ 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);
+
+ printf("s %12d %12d %s %8s %8s",
+ 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)
+ printf(" %8s %8s",
+ 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");
+}
+
+void
sysctlgatherstruct(void *addr, size_t size, struct scgs_vector *vecarr)
{
struct scgs_vector *xp;
@@ -677,6 +745,7 @@ usage(void)
{
fprintf(stderr,
- "usage: ipcs [-abcmopqstyMQST] [-C corefile] [-N namelist] [-u user]\n");
+ "usage: "
+ "ipcs [-abcmopqstyMQST] [-C corefile] [-N namelist] [-u user]\n");
exit(1);
}
OpenPOWER on IntegriCloud