Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 5 Mar 2011 14:41:49 +0000 (UTC)
From:      Edward Tomasz Napierala <trasz@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r219307 - in head: bin/ps sys/compat/freebsd32 sys/kern sys/sys
Message-ID:  <201103051441.p25Efn29066148@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: trasz
Date: Sat Mar  5 14:41:49 2011
New Revision: 219307
URL: http://svn.freebsd.org/changeset/base/219307

Log:
  Export login class information via kinfo and make it possible to view
  it using "ps -o class".

Modified:
  head/bin/ps/extern.h
  head/bin/ps/keyword.c
  head/bin/ps/print.c
  head/bin/ps/ps.1
  head/sys/compat/freebsd32/freebsd32.h
  head/sys/kern/kern_proc.c
  head/sys/sys/user.h

Modified: head/bin/ps/extern.h
==============================================================================
--- head/bin/ps/extern.h	Sat Mar  5 13:27:13 2011	(r219306)
+++ head/bin/ps/extern.h	Sat Mar  5 14:41:49 2011	(r219307)
@@ -55,6 +55,7 @@ const	 char *fmt_argv(char **, char *, s
 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 *);

Modified: head/bin/ps/keyword.c
==============================================================================
--- head/bin/ps/keyword.c	Sat Mar  5 13:27:13 2011	(r219306)
+++ head/bin/ps/keyword.c	Sat Mar  5 14:41:49 2011	(r219307)
@@ -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,

Modified: head/bin/ps/print.c
==============================================================================
--- head/bin/ps/print.c	Sat Mar  5 13:27:13 2011	(r219306)
+++ head/bin/ps/print.c	Sat Mar  5 14:41:49 2011	(r219307)
@@ -862,6 +862,26 @@ out:
 	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)
 {

Modified: head/bin/ps/ps.1
==============================================================================
--- head/bin/ps/ps.1	Sat Mar  5 13:27:13 2011	(r219306)
+++ head/bin/ps/ps.1	Sat Mar  5 14:41:49 2011	(r219307)
@@ -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 su
 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

Modified: head/sys/compat/freebsd32/freebsd32.h
==============================================================================
--- head/sys/compat/freebsd32/freebsd32.h	Sat Mar  5 13:27:13 2011	(r219306)
+++ head/sys/compat/freebsd32/freebsd32.h	Sat Mar  5 14:41:49 2011	(r219307)
@@ -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;

Modified: head/sys/kern/kern_proc.c
==============================================================================
--- head/sys/kern/kern_proc.c	Sat Mar  5 13:27:13 2011	(r219306)
+++ head/sys/kern/kern_proc.c	Sat Mar  5 14:41:49 2011	(r219307)
@@ -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, str
 			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 ki
 	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);

Modified: head/sys/sys/user.h
==============================================================================
--- head/sys/sys/user.h	Sat Mar  5 13:27:13 2011	(r219306)
+++ head/sys/sys/user.h	Sat Mar  5 14:41:49 2011	(r219307)
@@ -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 */



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201103051441.p25Efn29066148>