Export login class information via kinfo and make it possible to view

it using "ps -o class".
This commit is contained in:
Edward Tomasz Napierala 2011-03-05 14:41:49 +00:00
parent 976018d24f
commit 7123f4cd6f
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=219307
7 changed files with 37 additions and 3 deletions

View File

@ -55,6 +55,7 @@ const char *fmt_argv(char **, char *, size_t);
double getpcpu(const KINFO *);
void kvar(KINFO *, VARENT *);
void label(KINFO *, VARENT *);
void loginclass(KINFO *, VARENT *);
void logname(KINFO *, VARENT *);
void longtname(KINFO *, VARENT *);
void lstarted(KINFO *, VARENT *);

View File

@ -79,6 +79,8 @@ static VAR var[] = {
CHAR, NULL, 0},
{"blocked", "", "sigmask", 0, NULL, NULL, 0, 0, CHAR, NULL, 0},
{"caught", "", "sigcatch", 0, NULL, NULL, 0, 0, CHAR, NULL, 0},
{"class", "CLASS", NULL, LJUST, loginclass, NULL, MAXLOGNAME-1, 0,
CHAR, NULL, 0},
{"comm", "COMMAND", NULL, LJUST|DSIZ, ucomm, s_comm,
COMMLEN + OCOMMLEN + 1, 0, CHAR, NULL, 0},
{"command", "COMMAND", NULL, COMM|LJUST|USER, command, NULL, 16, 0,

View File

@ -862,6 +862,26 @@ label(KINFO *k, VARENT *ve)
return;
}
void
loginclass(KINFO *k, VARENT *ve)
{
VAR *v;
char *s;
v = ve->var;
/*
* Don't display login class for system processes;
* login classes are used for resource limits,
* and limits don't apply to system processes.
*/
if (k->ki_p->ki_flag & P_SYSTEM) {
(void)printf("%-*s", v->width, " -");
return;
}
s = k->ki_p->ki_loginclass;
(void)printf("%-*s", v->width, *s ? s : "-");
}
int
s_comm(KINFO *k)
{

View File

@ -29,7 +29,7 @@
.\" @(#)ps.1 8.3 (Berkeley) 4/18/94
.\" $FreeBSD$
.\"
.Dd July 24, 2010
.Dd March 5, 2011
.Dt PS 1
.Os
.Sh NAME
@ -280,6 +280,8 @@ be very young) it is possible for the sum of all
fields to exceed 100%.
.It Cm %mem
The percentage of real memory used by this process.
.It Cm class
Login class associated with the process.
.It Cm flags
The flags associated with the process as in
the include file
@ -475,6 +477,8 @@ accounting flag (alias
.Cm acflg )
.It Cm args
command and arguments
.It Cm class
login class
.It Cm comm
command
.It Cm command

View File

@ -316,7 +316,8 @@ struct kinfo_proc32 {
char ki_lockname[LOCKNAMELEN+1];
char ki_comm[COMMLEN+1];
char ki_emul[KI_EMULNAMELEN+1];
char ki_sparestrings[68];
char ki_loginclass[LOGINCLASSLEN+1];
char ki_sparestrings[50];
int ki_spareints[KI_NSPARE_INT];
u_int ki_cr_flags;
int ki_jid;

View File

@ -44,6 +44,7 @@ __FBSDID("$FreeBSD$");
#include <sys/kernel.h>
#include <sys/limits.h>
#include <sys/lock.h>
#include <sys/loginclass.h>
#include <sys/malloc.h>
#include <sys/mount.h>
#include <sys/mutex.h>
@ -745,6 +746,8 @@ fill_kinfo_proc_only(struct proc *p, struct kinfo_proc *kp)
if (cred->cr_prison != curthread->td_ucred->cr_prison)
kp->ki_jid = cred->cr_prison->pr_id;
}
strlcpy(kp->ki_loginclass, cred->cr_loginclass->lc_name,
sizeof(kp->ki_loginclass));
}
ps = p->p_sigacts;
if (ps) {
@ -1059,6 +1062,7 @@ freebsd32_kinfo_proc_out(const struct kinfo_proc *ki, struct kinfo_proc32 *ki32)
bcopy(ki->ki_lockname, ki32->ki_lockname, LOCKNAMELEN + 1);
bcopy(ki->ki_comm, ki32->ki_comm, COMMLEN + 1);
bcopy(ki->ki_emul, ki32->ki_emul, KI_EMULNAMELEN + 1);
bcopy(ki->ki_loginclass, ki32->ki_loginclass, LOGINCLASSLEN + 1);
CP(*ki, *ki32, ki_cr_flags);
CP(*ki, *ki32, ki_jid);
CP(*ki, *ki32, ki_numthreads);

View File

@ -100,6 +100,7 @@
#define KI_EMULNAMELEN 16 /* size of returned ki_emul */
#define KI_NGROUPS 16 /* number of groups in ki_groups */
#define LOGNAMELEN 17 /* size of returned ki_login */
#define LOGINCLASSLEN 17 /* size of returned ki_loginclass */
/* Flags for the process credential. */
#define KI_CRF_CAPABILITY_MODE 0x00000001
@ -172,12 +173,13 @@ struct kinfo_proc {
char ki_lockname[LOCKNAMELEN+1]; /* lock name */
char ki_comm[COMMLEN+1]; /* command name */
char ki_emul[KI_EMULNAMELEN+1]; /* emulation name */
char ki_loginclass[LOGINCLASSLEN+1]; /* login class */
/*
* When adding new variables, take space for char-strings from the
* front of ki_sparestrings, and ints from the end of ki_spareints.
* That way the spare room from both arrays will remain contiguous.
*/
char ki_sparestrings[68]; /* spare string space */
char ki_sparestrings[50]; /* spare string space */
int ki_spareints[KI_NSPARE_INT]; /* spare room for growth */
u_int ki_cr_flags; /* Credential flags */
int ki_jid; /* Process jail ID */