svn commit: r266286 - in stable/9: bin/ps rescue/rescue

Bryan Drewery bdrewery at FreeBSD.org
Sat May 17 03:21:51 UTC 2014


Author: bdrewery
Date: Sat May 17 03:21:50 2014
New Revision: 266286
URL: http://svnweb.freebsd.org/changeset/base/266286

Log:
  MFC r265229,r265239:
  
      Add -J to filter by matching jail IDs and names.

Modified:
  stable/9/bin/ps/Makefile
  stable/9/bin/ps/ps.1
  stable/9/bin/ps/ps.c
  stable/9/rescue/rescue/Makefile
Directory Properties:
  stable/9/bin/ps/   (props changed)
  stable/9/rescue/   (props changed)
  stable/9/rescue/rescue/   (props changed)

Modified: stable/9/bin/ps/Makefile
==============================================================================
--- stable/9/bin/ps/Makefile	Sat May 17 03:05:52 2014	(r266285)
+++ stable/9/bin/ps/Makefile	Sat May 17 03:21:50 2014	(r266286)
@@ -11,7 +11,7 @@ SRCS=	fmt.c keyword.c nlist.c print.c ps
 # on large systems.
 #
 CFLAGS+=-DLAZY_PS
-DPADD=	${LIBM} ${LIBKVM}
-LDADD=	-lm -lkvm
+DPADD=	${LIBM} ${LIBKVM} ${LIBJAIL}
+LDADD=	-lm -lkvm -ljail
 
 .include <bsd.prog.mk>

Modified: stable/9/bin/ps/ps.1
==============================================================================
--- stable/9/bin/ps/ps.1	Sat May 17 03:05:52 2014	(r266285)
+++ stable/9/bin/ps/ps.1	Sat May 17 03:21:50 2014	(r266286)
@@ -29,7 +29,7 @@
 .\"     @(#)ps.1	8.3 (Berkeley) 4/18/94
 .\" $FreeBSD$
 .\"
-.Dd February 7, 2013
+.Dd May 2, 2014
 .Dt PS 1
 .Os
 .Sh NAME
@@ -40,6 +40,7 @@
 .Op Fl aCcdefHhjlmrSTuvwXxZ
 .Op Fl O Ar fmt | Fl o Ar fmt
 .Op Fl G Ar gid Ns Op , Ns Ar gid Ns Ar ...
+.Op Fl J Ar jid Ns Op , Ns Ar jid Ns Ar ...
 .Op Fl M Ar core
 .Op Fl N Ar system
 .Op Fl p Ar pid Ns Op , Ns Ar pid Ns Ar ...
@@ -62,7 +63,7 @@ will also display processes that do not 
 .Pp
 A different set of processes can be selected for display by using any
 combination of the
-.Fl a , G , p , T , t ,
+.Fl a , G , J , p , T , t ,
 and
 .Fl U
 options.
@@ -152,6 +153,20 @@ Print information associated with the fo
 .Cm user , pid , ppid , pgid , sid , jobc , state , tt , time ,
 and
 .Cm command .
+.It Fl J
+Display information about processes which match the specified jail IDs.
+This may be either the
+.Cm jid
+or
+.Cm name
+of the jail.
+Use
+.Fl J
+.Sy 0
+to display only host processes.
+This flag implies
+.Fl x
+by default.
 .It Fl L
 List the set of keywords available for the
 .Fl O

Modified: stable/9/bin/ps/ps.c
==============================================================================
--- stable/9/bin/ps/ps.c	Sat May 17 03:05:52 2014	(r266285)
+++ stable/9/bin/ps/ps.c	Sat May 17 03:21:50 2014	(r266286)
@@ -50,6 +50,7 @@ static char sccsid[] = "@(#)ps.c	8.4 (Be
 __FBSDID("$FreeBSD$");
 
 #include <sys/param.h>
+#include <sys/jail.h>
 #include <sys/proc.h>
 #include <sys/user.h>
 #include <sys/stat.h>
@@ -62,6 +63,7 @@ __FBSDID("$FreeBSD$");
 #include <errno.h>
 #include <fcntl.h>
 #include <grp.h>
+#include <jail.h>
 #include <kvm.h>
 #include <limits.h>
 #include <locale.h>
@@ -123,6 +125,7 @@ struct listinfo {
 	const char	*lname;
 	union {
 		gid_t	*gids;
+		int	*jids;
 		pid_t	*pids;
 		dev_t	*ttys;
 		uid_t	*uids;
@@ -131,6 +134,7 @@ struct listinfo {
 };
 
 static int	 addelem_gid(struct listinfo *, const char *);
+static int	 addelem_jid(struct listinfo *, const char *);
 static int	 addelem_pid(struct listinfo *, const char *);
 static int	 addelem_tty(struct listinfo *, const char *);
 static int	 addelem_uid(struct listinfo *, const char *);
@@ -161,12 +165,12 @@ static char vfmt[] = "pid,state,time,sl,
 			"%cpu,%mem,command";
 static char Zfmt[] = "label";
 
-#define	PS_ARGS	"AaCcde" OPT_LAZY_f "G:gHhjLlM:mN:O:o:p:rSTt:U:uvwXxZ"
+#define	PS_ARGS	"AaCcde" OPT_LAZY_f "G:gHhjJ:LlM:mN:O:o:p:rSTt:U:uvwXxZ"
 
 int
 main(int argc, char *argv[])
 {
-	struct listinfo gidlist, pgrplist, pidlist;
+	struct listinfo gidlist, jidlist, pgrplist, pidlist;
 	struct listinfo ruidlist, sesslist, ttylist, uidlist;
 	struct kinfo_proc *kp;
 	KINFO *kinfo = NULL, *next_KINFO;
@@ -204,6 +208,7 @@ main(int argc, char *argv[])
 	prtheader = showthreads = wflag = xkeep_implied = 0;
 	xkeep = -1;			/* Neither -x nor -X. */
 	init_list(&gidlist, addelem_gid, sizeof(gid_t), "group");
+	init_list(&jidlist, addelem_jid, sizeof(int), "jail id");
 	init_list(&pgrplist, addelem_pid, sizeof(pid_t), "process group");
 	init_list(&pidlist, addelem_pid, sizeof(pid_t), "process id");
 	init_list(&ruidlist, addelem_uid, sizeof(uid_t), "ruser");
@@ -271,6 +276,11 @@ main(int argc, char *argv[])
 		case 'h':
 			prtheader = ws.ws_row > 5 ? ws.ws_row : 22;
 			break;
+		case 'J':
+			add_list(&jidlist, optarg);
+			xkeep_implied = 1;
+			nselectors++;
+			break;
 		case 'j':
 			parsefmt(jfmt, 0);
 			_fmt = 1;
@@ -534,6 +544,11 @@ main(int argc, char *argv[])
 					if (kp->ki_rgid == gidlist.l.gids[elem])
 						goto keepit;
 			}
+			if (jidlist.count > 0) {
+				for (elem = 0; elem < jidlist.count; elem++)
+					if (kp->ki_jid == jidlist.l.jids[elem])
+						goto keepit;
+			}
 			if (pgrplist.count > 0) {
 				for (elem = 0; elem < pgrplist.count; elem++)
 					if (kp->ki_pgid ==
@@ -662,6 +677,7 @@ main(int argc, char *argv[])
 		}
 	}
 	free_list(&gidlist);
+	free_list(&jidlist);
 	free_list(&pidlist);
 	free_list(&pgrplist);
 	free_list(&ruidlist);
@@ -724,6 +740,30 @@ addelem_gid(struct listinfo *inf, const 
 
 #define	BSD_PID_MAX	99999		/* Copy of PID_MAX from sys/proc.h. */
 static int
+addelem_jid(struct listinfo *inf, const char *elem)
+{
+	int tempid;
+
+	if (*elem == '\0') {
+		warnx("Invalid (zero-length) jail id");
+		optfatal = 1;
+		return (0);		/* Do not add this value. */
+	}
+
+	tempid = jail_getid(elem);
+	if (tempid < 0) {
+		warnx("Invalid %s: %s", inf->lname, elem);
+		optfatal = 1;
+		return (0);
+	}
+
+	if (inf->count >= inf->maxcount)
+		expand_list(inf);
+	inf->l.jids[(inf->count)++] = tempid;
+	return (1);
+}
+
+static int
 addelem_pid(struct listinfo *inf, const char *elem)
 {
 	char *endp;
@@ -1359,7 +1399,7 @@ usage(void)
 
 	(void)fprintf(stderr, "%s\n%s\n%s\n%s\n",
 	    "usage: ps " SINGLE_OPTS " [-O fmt | -o fmt] [-G gid[,gid...]]",
-	    "          [-M core] [-N system]",
+	    "          [-J jid[,jid...]] [-M core] [-N system]",
 	    "          [-p pid[,pid...]] [-t tty[,tty...]] [-U user[,user...]]",
 	    "       ps [-L]");
 	exit(1);

Modified: stable/9/rescue/rescue/Makefile
==============================================================================
--- stable/9/rescue/rescue/Makefile	Sat May 17 03:05:52 2014	(r266285)
+++ stable/9/rescue/rescue/Makefile	Sat May 17 03:21:50 2014	(r266286)
@@ -52,7 +52,7 @@ CRUNCH_SRCDIRS+= bin
 CRUNCH_PROGS_bin= cat chflags chio chmod cp date dd df echo 	\
 	 ed expr getfacl hostname kenv kill ln ls mkdir mv	\
 	 pkill ps pwd realpath rm rmdir setfacl sh stty sync test
-CRUNCH_LIBS+= -lcrypt -ledit -lkvm -ll -ltermcap -lutil
+CRUNCH_LIBS+= -lcrypt -ledit -ljail -lkvm -ll -ltermcap -lutil
 CRUNCH_BUILDTOOLS+= bin/sh
 
 # Additional options for specific programs
@@ -123,7 +123,7 @@ CRUNCH_LIBS+= -lalias -lcam -lcurses -ld
 CRUNCH_LIBS+= -lipx
 .endif
 .if ${MK_ZFS} != "no"
-CRUNCH_LIBS+= -lavl -ljail -lzfs_core -lzfs -lnvpair -lpthread -luutil -lumem
+CRUNCH_LIBS+= -lavl -lzfs_core -lzfs -lnvpair -lpthread -luutil -lumem
 .endif
 CRUNCH_LIBS+= -lgeom -lbsdxml -ljail -lkiconv -lmd -lreadline -lsbuf -lufs -lz
 


More information about the svn-src-all mailing list