Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 28 Feb 2011 17:02:56 GMT
From:      Edward Tomasz Napierala <trasz@FreeBSD.org>
To:        Perforce Change Reviews <perforce@freebsd.org>
Subject:   PERFORCE change 189283 for review
Message-ID:  <201102281702.p1SH2uJL007705@skunkworks.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://p4web.freebsd.org/@@189283?ac=10

Change 189283 by trasz@trasz_victim on 2011/02/28 17:02:47

	Add pid argument to getloginclass(2) and add "-o class" argument
	to ps(1).

Affected files ...

.. //depot/projects/soc2009/trasz_limits/bin/ps/extern.h#4 edit
.. //depot/projects/soc2009/trasz_limits/bin/ps/keyword.c#6 edit
.. //depot/projects/soc2009/trasz_limits/bin/ps/print.c#6 edit
.. //depot/projects/soc2009/trasz_limits/bin/ps/ps.1#9 edit
.. //depot/projects/soc2009/trasz_limits/include/unistd.h#10 edit
.. //depot/projects/soc2009/trasz_limits/sys/compat/freebsd32/syscalls.master#15 edit
.. //depot/projects/soc2009/trasz_limits/sys/kern/kern_loginclass.c#32 edit
.. //depot/projects/soc2009/trasz_limits/sys/kern/syscalls.master#16 edit
.. //depot/projects/soc2009/trasz_limits/usr.bin/id/id.c#8 edit

Differences ...

==== //depot/projects/soc2009/trasz_limits/bin/ps/extern.h#4 (text+ko) ====

@@ -55,6 +55,7 @@
 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 *);
@@ -74,6 +75,7 @@
 void	 rvar(KINFO *, VARENT *);
 int	 s_comm(KINFO *);
 int	 s_label(KINFO *);
+int	 s_loginclass(KINFO *);
 int	 s_rgroupname(KINFO *);
 int	 s_runame(KINFO *);
 int	 s_uname(KINFO *);

==== //depot/projects/soc2009/trasz_limits/bin/ps/keyword.c#6 (text+ko) ====

@@ -79,6 +79,8 @@
 		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|DSIZ, loginclass, s_loginclass,
+	    SHRT_MAX, 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,

==== //depot/projects/soc2009/trasz_limits/bin/ps/print.c#6 (text+ko) ====

@@ -862,6 +862,25 @@
 	return;
 }
 
+void
+loginclass(KINFO *k, VARENT *ve)
+{
+	char buf[MAXLOGNAME + 1];
+	int error;
+	VAR *v;
+
+	v = ve->var;
+	if (k->ki_p->ki_flag & P_SYSTEM) {
+		(void)printf("%-*s", v->width, "  -");
+		return;
+	}
+	error = getloginclass(k->ki_p->ki_pid, buf, sizeof(buf));
+	if (error == 0)
+		(void)printf("%-*s", v->width, buf);
+	else
+		(void)printf("%-*s", v->width, "  -");
+}
+
 int
 s_comm(KINFO *k)
 {
@@ -895,3 +914,17 @@
 	mac_free(proclabel);
 	return (size);
 }
+
+int
+s_loginclass(KINFO *k)
+{
+	char buf[MAXLOGNAME + 1];
+	int error;
+
+	if (k->ki_p->ki_flag & P_SYSTEM)
+		return (3); /* strlen ("  -") */
+	error = getloginclass(k->ki_p->ki_pid, buf, sizeof(buf));
+	if (error != 0)
+		return (0);
+	return (strlen(buf));
+}

==== //depot/projects/soc2009/trasz_limits/bin/ps/ps.1#9 (text+ko) ====

@@ -280,6 +280,8 @@
 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 @@
 .Cm acflg )
 .It Cm args
 command and arguments
+.It Cm class
+login class
 .It Cm comm
 command
 .It Cm command

==== //depot/projects/soc2009/trasz_limits/include/unistd.h#10 (text+ko) ====

@@ -500,7 +500,7 @@
 char	*fflagstostr(u_long);
 int	 getdomainname(char *, int);
 int	 getgrouplist(const char *, gid_t, gid_t *, int *);
-int	 getloginclass(char *, size_t);
+int	 getloginclass(pid_t, char *, size_t);
 mode_t	 getmode(const void *, mode_t);
 int	 getosreldate(void);
 int	 getpeereid(int, uid_t *, gid_t *);

==== //depot/projects/soc2009/trasz_limits/sys/compat/freebsd32/syscalls.master#15 (text+ko) ====

@@ -962,8 +962,8 @@
 				    fd_set *ou, fd_set *ex, \
 				    const struct timespec32 *ts, \
 				    const sigset_t *sm); }
-523	AUE_NULL	NOPROTO	{ int getloginclass(char *namebuf, size_t \
-				    namelen); }
+523	AUE_NULL	NOPROTO	{ int getloginclass(pid_t pid, char *namebuf, \
+				    size_t namelen); }
 524	AUE_NULL	NOPROTO	{ int setloginclass(const char *namebuf); }
 525	AUE_NULL	NOPROTO	{ int rctl_get_usage(const void *inbufp, size_t inbuflen, void *outbufp, size_t outbuflen); }
 526	AUE_NULL	NOPROTO	{ int rctl_get_rules(const void *inbufp, size_t inbuflen, void *outbufp, size_t outbuflen); }

==== //depot/projects/soc2009/trasz_limits/sys/kern/kern_loginclass.c#32 (text+ko) ====

@@ -156,10 +156,22 @@
 {
 	int error = 0;
 	size_t lcnamelen;
-	struct proc *p = td->td_proc;
+	struct proc *p;
 	struct loginclass *lc;
 
-	PROC_LOCK(p);
+	if (uap->pid == 0) {
+		p = td->td_proc;
+		PROC_LOCK(p);
+	} else {
+		p = pfind(uap->pid);
+		if (p == NULL)
+			return (ESRCH);
+		error = p_cansee(td, p);
+		if (error != 0) {
+			PROC_UNLOCK(p);
+			return (error);
+		}
+	}
 	lc = p->p_ucred->cr_loginclass;
 	loginclass_acquire(lc);
 	PROC_UNLOCK(p);

==== //depot/projects/soc2009/trasz_limits/sys/kern/syscalls.master#16 (text+ko) ====

@@ -926,8 +926,8 @@
 				    fd_set *ou, fd_set *ex, \
 				    const struct timespec *ts, \
 				    const sigset_t *sm); }
-523	AUE_NULL	STD	{ int getloginclass(char *namebuf, size_t \
-				    namelen); }
+523	AUE_NULL	STD	{ int getloginclass(pid_t pid, char *namebuf, \
+				    size_t namelen); }
 524	AUE_NULL	STD	{ int setloginclass(const char *namebuf); }
 525	AUE_NULL	STD	{ int rctl_get_usage(const void *inbufp, size_t inbuflen, void *outbufp, size_t outbuflen); }
 526	AUE_NULL	STD	{ int rctl_get_rules(const void *inbufp, size_t inbuflen, void *outbufp, size_t outbuflen); }

==== //depot/projects/soc2009/trasz_limits/usr.bin/id/id.c#8 (text+ko) ====

@@ -164,7 +164,7 @@
 #endif
 
 	if (cflag) {
-		error = getloginclass(loginclass, sizeof(loginclass));
+		error = getloginclass(0, loginclass, sizeof(loginclass));
 		if (error != 0)
 			err(1, "loginclass");
 		(void)printf("%s\n", loginclass);



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