Add p_svuid and p_svgid to kinfo_proc2. Populate them in the kernel
and in libkvm. Then teach ps how to show them to you. Also, teach ps how to show the names for all the uids, the rest of the group numbers, and the "group access list".
This commit is contained in:
parent
d0ee51001e
commit
40f3045957
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: extern.h,v 1.22 2003/01/18 10:52:16 thorpej Exp $ */
|
||||
/* $NetBSD: extern.h,v 1.23 2003/03/01 05:41:56 atatat Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1991, 1993, 1994
|
||||
@ -58,6 +58,9 @@ void fmt_puts __P((char *, int *));
|
||||
void fmt_putc __P((int, int *));
|
||||
double getpcpu __P((struct kinfo_proc2 *));
|
||||
double getpmem __P((struct kinfo_proc2 *));
|
||||
void gname __P((void *, VARENT *, int));
|
||||
void groups __P((void *, VARENT *, int));
|
||||
void groupnames __P((void *, VARENT *, int));
|
||||
void logname __P((void *, VARENT *, int));
|
||||
void longtname __P((void *, VARENT *, int));
|
||||
void lstarted __P((void *, VARENT *, int));
|
||||
@ -73,11 +76,14 @@ void pnice __P((void *, VARENT *, int));
|
||||
void pri __P((void *, VARENT *, int));
|
||||
void printheader __P((void));
|
||||
void pvar __P((void *, VARENT *, int));
|
||||
void rgname __P((void *, VARENT *, int));
|
||||
void rssize __P((void *, VARENT *, int));
|
||||
void runame __P((void *, VARENT *, int));
|
||||
void showkey __P((void));
|
||||
void started __P((void *, VARENT *, int));
|
||||
void state __P((void *, VARENT *, int));
|
||||
void svgname __P((void *, VARENT *, int));
|
||||
void svuname __P((void *, VARENT *, int));
|
||||
void tdev __P((void *, VARENT *, int));
|
||||
void tname __P((void *, VARENT *, int));
|
||||
void tsize __P((void *, VARENT *, int));
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: keyword.c,v 1.29 2003/01/18 10:52:16 thorpej Exp $ */
|
||||
/* $NetBSD: keyword.c,v 1.30 2003/03/01 05:41:56 atatat Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1990, 1993, 1994
|
||||
@ -38,7 +38,7 @@
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)keyword.c 8.5 (Berkeley) 4/2/94";
|
||||
#else
|
||||
__RCSID("$NetBSD: keyword.c,v 1.29 2003/01/18 10:52:16 thorpej Exp $");
|
||||
__RCSID("$NetBSD: keyword.c,v 1.30 2003/03/01 05:41:56 atatat Exp $");
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
||||
@ -95,8 +95,16 @@ VAR var[] = {
|
||||
{"command", "COMMAND", NULL, COMM|LJUST, command},
|
||||
{"cpu", "CPU", NULL, 0, pvar, 0, POFF(p_estcpu), UINT, "u"},
|
||||
{"cputime", "", "time"},
|
||||
GID("egid", "EGID", pvar, POFF(p_gid)),
|
||||
{"egroup", "EGROUP", NULL, LJUST, gname},
|
||||
UID("euid", "EUID", pvar, POFF(p_uid)),
|
||||
{"euser", "EUSER", NULL, LJUST, uname},
|
||||
{"f", "F", NULL, 0, pvar, 0, POFF(p_flag), INT, "x"},
|
||||
{"flags", "", "f"},
|
||||
GID("gid", "GID", pvar, POFF(p_gid)),
|
||||
{"group", "GROUP", NULL, LJUST, gname},
|
||||
{"groupnames", "GROUPNAMES", NULL, LJUST, groupnames},
|
||||
{"groups", "GROUPS", NULL, LJUST, groups},
|
||||
{"holdcnt", "HOLDCNT", NULL, LWP, pvar, 0, LOFF(l_holdcnt), INT, "d"},
|
||||
{"ignored", "", "sigignore"},
|
||||
{"inblk", "INBLK", NULL, 0, pvar, 0, POFF(p_uru_inblock), UINT64, "llu"},
|
||||
@ -141,6 +149,7 @@ VAR var[] = {
|
||||
{"pri", "PRI", NULL, LWP, pri},
|
||||
{"re", "RE", NULL, INF127|LWP, pvar, 0, LOFF(l_swtime), UINT, "u"},
|
||||
GID("rgid", "RGID", pvar, POFF(p_rgid)),
|
||||
{"rgroup", "RGROUP", NULL, LJUST, rgname},
|
||||
/* XXX */
|
||||
{"rlink", "RLINK", NULL, LWP, pvar, 0, LOFF(l_back), KPTR, "llx"},
|
||||
{"rlwp", "RLWP", NULL, 0, pvar, 0, POFF(p_nrlwps), UINT64, "lld"},
|
||||
@ -164,7 +173,9 @@ VAR var[] = {
|
||||
{"stat", "", "state"},
|
||||
{"state", "STAT", NULL, LJUST, state},
|
||||
GID("svgid", "SVGID", pvar, POFF(p_gid)),
|
||||
{"svgroup", "SVGROUP", NULL, LJUST, svgname},
|
||||
UID("svuid", "SVUID", pvar, POFF(p_uid)),
|
||||
{"svuser", "SVUSER", NULL, LJUST, svuname},
|
||||
{"tdev", "TDEV", NULL, 0, tdev},
|
||||
{"time", "TIME", NULL, 0, cputime},
|
||||
PID("tpgid", "TGPID", pvar, POFF(p_tpgid)),
|
||||
|
146
bin/ps/print.c
146
bin/ps/print.c
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: print.c,v 1.76 2003/01/18 10:52:17 thorpej Exp $ */
|
||||
/* $NetBSD: print.c,v 1.77 2003/03/01 05:41:56 atatat Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2000 The NetBSD Foundation, Inc.
|
||||
@ -74,7 +74,7 @@
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)print.c 8.6 (Berkeley) 4/16/94";
|
||||
#else
|
||||
__RCSID("$NetBSD: print.c,v 1.76 2003/01/18 10:52:17 thorpej Exp $");
|
||||
__RCSID("$NetBSD: print.c,v 1.77 2003/03/01 05:41:56 atatat Exp $");
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
||||
@ -88,6 +88,7 @@ __RCSID("$NetBSD: print.c,v 1.76 2003/01/18 10:52:17 thorpej Exp $");
|
||||
#include <sys/sysctl.h>
|
||||
|
||||
#include <err.h>
|
||||
#include <grp.h>
|
||||
#include <kvm.h>
|
||||
#include <math.h>
|
||||
#include <nlist.h>
|
||||
@ -345,6 +346,91 @@ command(arg, ve, mode)
|
||||
printf("%*s", left, "");
|
||||
}
|
||||
|
||||
void
|
||||
groups(arg, ve, mode)
|
||||
void *arg;
|
||||
VARENT *ve;
|
||||
int mode;
|
||||
{
|
||||
struct kinfo_proc2 *ki;
|
||||
VAR *v;
|
||||
int left, i;
|
||||
char buf[16], *p;
|
||||
|
||||
if (mode == WIDTHMODE)
|
||||
return;
|
||||
|
||||
ki = arg;
|
||||
v = ve->var;
|
||||
if (ve->next != NULL || termwidth != UNLIMITED) {
|
||||
if (ve->next == NULL) {
|
||||
left = termwidth - (totwidth - v->width);
|
||||
if (left < 1) /* already wrapped, just use std width */
|
||||
left = v->width;
|
||||
} else
|
||||
left = v->width;
|
||||
} else
|
||||
left = -1;
|
||||
|
||||
if (ki->p_ngroups == 0) {
|
||||
fmt_putc('-', &left);
|
||||
return;
|
||||
}
|
||||
|
||||
for (i = 0; i < ki->p_ngroups; i++) {
|
||||
(void)snprintf(buf, sizeof(buf), "%d", ki->p_groups[i]);
|
||||
if (i)
|
||||
fmt_putc(' ', &left);
|
||||
for (p = &buf[0]; *p; p++)
|
||||
fmt_putc(*p, &left);
|
||||
}
|
||||
|
||||
if (ve->next && left > 0)
|
||||
printf("%*s", left, "");
|
||||
}
|
||||
|
||||
void
|
||||
groupnames(arg, ve, mode)
|
||||
void *arg;
|
||||
VARENT *ve;
|
||||
int mode;
|
||||
{
|
||||
struct kinfo_proc2 *ki;
|
||||
VAR *v;
|
||||
int left, i;
|
||||
const char *p;
|
||||
|
||||
if (mode == WIDTHMODE)
|
||||
return;
|
||||
|
||||
ki = arg;
|
||||
v = ve->var;
|
||||
if (ve->next != NULL || termwidth != UNLIMITED) {
|
||||
if (ve->next == NULL) {
|
||||
left = termwidth - (totwidth - v->width);
|
||||
if (left < 1) /* already wrapped, just use std width */
|
||||
left = v->width;
|
||||
} else
|
||||
left = v->width;
|
||||
} else
|
||||
left = -1;
|
||||
|
||||
if (ki->p_ngroups == 0) {
|
||||
fmt_putc('-', &left);
|
||||
return;
|
||||
}
|
||||
|
||||
for (i = 0; i < ki->p_ngroups; i++) {
|
||||
if (i)
|
||||
fmt_putc(' ', &left);
|
||||
for (p = group_from_gid(ki->p_groups[i], 0); *p; p++)
|
||||
fmt_putc(*p, &left);
|
||||
}
|
||||
|
||||
if (ve->next && left > 0)
|
||||
printf("%*s", left, "");
|
||||
}
|
||||
|
||||
void
|
||||
ucomm(arg, ve, mode)
|
||||
void *arg;
|
||||
@ -574,6 +660,62 @@ runame(arg, ve, mode)
|
||||
strprintorsetwidth(v, user_from_uid(k->p_ruid, 0), mode);
|
||||
}
|
||||
|
||||
void
|
||||
svuname(arg, ve, mode)
|
||||
void *arg;
|
||||
VARENT *ve;
|
||||
int mode;
|
||||
{
|
||||
struct kinfo_proc2 *k;
|
||||
VAR *v;
|
||||
|
||||
k = arg;
|
||||
v = ve->var;
|
||||
strprintorsetwidth(v, user_from_uid(k->p_svuid, 0), mode);
|
||||
}
|
||||
|
||||
void
|
||||
gname(arg, ve, mode)
|
||||
void *arg;
|
||||
VARENT *ve;
|
||||
int mode;
|
||||
{
|
||||
struct kinfo_proc2 *k;
|
||||
VAR *v;
|
||||
|
||||
k = arg;
|
||||
v = ve->var;
|
||||
strprintorsetwidth(v, group_from_gid(k->p_gid, 0), mode);
|
||||
}
|
||||
|
||||
void
|
||||
rgname(arg, ve, mode)
|
||||
void *arg;
|
||||
VARENT *ve;
|
||||
int mode;
|
||||
{
|
||||
struct kinfo_proc2 *k;
|
||||
VAR *v;
|
||||
|
||||
k = arg;
|
||||
v = ve->var;
|
||||
strprintorsetwidth(v, group_from_gid(k->p_rgid, 0), mode);
|
||||
}
|
||||
|
||||
void
|
||||
svgname(arg, ve, mode)
|
||||
void *arg;
|
||||
VARENT *ve;
|
||||
int mode;
|
||||
{
|
||||
struct kinfo_proc2 *k;
|
||||
VAR *v;
|
||||
|
||||
k = arg;
|
||||
v = ve->var;
|
||||
strprintorsetwidth(v, group_from_gid(k->p_svgid, 0), mode);
|
||||
}
|
||||
|
||||
void
|
||||
tdev(arg, ve, mode)
|
||||
void *arg;
|
||||
|
24
bin/ps/ps.1
24
bin/ps/ps.1
@ -1,4 +1,4 @@
|
||||
.\" $NetBSD: ps.1,v 1.58 2003/02/25 10:34:40 wiz Exp $
|
||||
.\" $NetBSD: ps.1,v 1.59 2003/03/01 05:41:57 atatat Exp $
|
||||
.\"
|
||||
.\" Copyright (c) 1980, 1990, 1991, 1993, 1994
|
||||
.\" The Regents of the University of California. All rights reserved.
|
||||
@ -441,7 +441,7 @@ The following is a complete list of the available keywords and their
|
||||
meanings.
|
||||
Several of them have aliases (keywords which are synonyms).
|
||||
.Pp
|
||||
.Bl -tag -width sigignore -compact
|
||||
.Bl -tag -width groupnames -compact
|
||||
.It %cpu
|
||||
percentage cpu usage (alias pcpu)
|
||||
.It %mem
|
||||
@ -454,6 +454,22 @@ command and arguments
|
||||
short-term cpu usage factor (for scheduling)
|
||||
.It flags
|
||||
the process flags, in hexadecimal (alias f)
|
||||
.It egid
|
||||
effective group id
|
||||
.It egroup
|
||||
group name (from egid)
|
||||
.It euid
|
||||
effective user id
|
||||
.It euser
|
||||
user name (from euid)
|
||||
.It gid
|
||||
effective group id
|
||||
.It group
|
||||
group name (from gid)
|
||||
.It groups
|
||||
group access list
|
||||
.It groupnames
|
||||
group names (from group access list)
|
||||
.It inblk
|
||||
total blocks read (alias inblock)
|
||||
.It jobc
|
||||
@ -552,8 +568,12 @@ time started
|
||||
symbolic process state (alias stat)
|
||||
.It svgid
|
||||
saved gid from a setgid executable
|
||||
.It svgroup
|
||||
group name (from svgid)
|
||||
.It svuid
|
||||
saved uid from a setuid executable
|
||||
.It svuser
|
||||
user name (from svuid)
|
||||
.It tdev
|
||||
control terminal device number
|
||||
.It time
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: kvm_proc.c,v 1.49 2003/02/26 23:05:53 enami Exp $ */
|
||||
/* $NetBSD: kvm_proc.c,v 1.50 2003/03/01 05:41:56 atatat Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1998 The NetBSD Foundation, Inc.
|
||||
@ -78,7 +78,7 @@
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)kvm_proc.c 8.3 (Berkeley) 9/23/93";
|
||||
#else
|
||||
__RCSID("$NetBSD: kvm_proc.c,v 1.49 2003/02/26 23:05:53 enami Exp $");
|
||||
__RCSID("$NetBSD: kvm_proc.c,v 1.50 2003/03/01 05:41:56 atatat Exp $");
|
||||
#endif
|
||||
#endif /* LIBC_SCCS and not lint */
|
||||
|
||||
@ -559,8 +559,10 @@ kvm_getproc2(kd, op, arg, esize, cnt)
|
||||
|
||||
kp2p->p_uid = kp->kp_eproc.e_ucred.cr_uid;
|
||||
kp2p->p_ruid = kp->kp_eproc.e_pcred.p_ruid;
|
||||
kp2p->p_svuid = kp->kp_eproc.e_pcred.p_svuid;
|
||||
kp2p->p_gid = kp->kp_eproc.e_ucred.cr_gid;
|
||||
kp2p->p_rgid = kp->kp_eproc.e_pcred.p_rgid;
|
||||
kp2p->p_svgid = kp->kp_eproc.e_pcred.p_svgid;
|
||||
|
||||
/*CONSTCOND*/
|
||||
memcpy(kp2p->p_groups, kp->kp_eproc.e_ucred.cr_groups,
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: kern_sysctl.c,v 1.127 2003/02/27 01:39:56 thorpej Exp $ */
|
||||
/* $NetBSD: kern_sysctl.c,v 1.128 2003/03/01 05:41:56 atatat Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1982, 1986, 1989, 1993
|
||||
@ -43,7 +43,7 @@
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: kern_sysctl.c,v 1.127 2003/02/27 01:39:56 thorpej Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: kern_sysctl.c,v 1.128 2003/03/01 05:41:56 atatat Exp $");
|
||||
|
||||
#include "opt_ddb.h"
|
||||
#include "opt_insecure.h"
|
||||
@ -1823,6 +1823,8 @@ fill_kproc2(struct proc *p, struct kinfo_proc2 *ki)
|
||||
ki->p_ruid = p->p_cred->p_ruid;
|
||||
ki->p_gid = p->p_ucred->cr_gid;
|
||||
ki->p_rgid = p->p_cred->p_rgid;
|
||||
ki->p_svuid = p->p_cred->p_svuid;
|
||||
ki->p_svgid = p->p_cred->p_svgid;
|
||||
|
||||
memcpy(ki->p_groups, p->p_cred->pc_ucred->cr_groups,
|
||||
min(sizeof(ki->p_groups), sizeof(p->p_cred->pc_ucred->cr_groups)));
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: sysctl.h,v 1.91 2003/02/27 01:39:56 thorpej Exp $ */
|
||||
/* $NetBSD: sysctl.h,v 1.92 2003/03/01 05:41:55 atatat Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1989, 1993
|
||||
@ -456,6 +456,8 @@ struct kinfo_proc2 {
|
||||
u_int64_t p_nlwps; /* LONG: Number of LWPs */
|
||||
u_int64_t p_nrlwps; /* LONG: Number of running LWPs */
|
||||
u_int64_t p_realstat; /* LONG: non-LWP process status */
|
||||
u_int32_t p_svuid; /* UID_T: saved user id */
|
||||
u_int32_t p_svgid; /* GID_T: saved group id */
|
||||
};
|
||||
|
||||
/*
|
||||
|
Loading…
Reference in New Issue
Block a user