svn commit: r266287 - in stable/9: contrib/top usr.bin/top
Bryan Drewery
bdrewery at FreeBSD.org
Sat May 17 03:23:47 UTC 2014
Author: bdrewery
Date: Sat May 17 03:23:45 2014
New Revision: 266287
URL: http://svnweb.freebsd.org/changeset/base/266287
Log:
MFC r265249,r265250,r265251:
- Add -J command/flag to filter by jail name/jid. This will automatically
display the JID as well (the -j command/flag).
- Add a hint for 'u' and 'J' command that '+' displays all.
- Add J command to help.
Modified:
stable/9/contrib/top/commands.c
stable/9/contrib/top/machine.h
stable/9/contrib/top/top.X
stable/9/contrib/top/top.c
stable/9/usr.bin/top/Makefile
stable/9/usr.bin/top/machine.c
Directory Properties:
stable/9/contrib/top/ (props changed)
stable/9/usr.bin/top/ (props changed)
Modified: stable/9/contrib/top/commands.c
==============================================================================
--- stable/9/contrib/top/commands.c Sat May 17 03:21:50 2014 (r266286)
+++ stable/9/contrib/top/commands.c Sat May 17 03:23:45 2014 (r266287)
@@ -74,6 +74,7 @@ e - list errors generated by last
H - toggle the displaying of threads\n\
i or I - toggle the displaying of idle processes\n\
j - toggle the displaying of jail ID\n\
+J - display processes for only one jail (+ selects all jails)\n\
k - kill processes; send a signal to a list of processes\n\
m - toggle the display between 'cpu' and 'io' modes\n\
n or # - change number of processes to display\n", stdout);
Modified: stable/9/contrib/top/machine.h
==============================================================================
--- stable/9/contrib/top/machine.h Sat May 17 03:21:50 2014 (r266286)
+++ stable/9/contrib/top/machine.h Sat May 17 03:23:45 2014 (r266287)
@@ -66,6 +66,7 @@ struct process_select
int thread; /* show threads */
int uid; /* only this uid (unless uid == -1) */
int wcpu; /* show weighted cpu */
+ int jid; /* only this jid (unless jid == -1) */
int jail; /* show jail ID */
int kidle; /* show per-CPU idle threads */
char *command; /* only this command (unless == NULL) */
Modified: stable/9/contrib/top/top.X
==============================================================================
--- stable/9/contrib/top/top.X Sat May 17 03:21:50 2014 (r266286)
+++ stable/9/contrib/top/top.X Sat May 17 03:23:45 2014 (r266287)
@@ -20,6 +20,8 @@ top \- display and update information ab
] [
.BI \-s time
] [
+.BI \-J jail
+] [
.BI \-U username
] [
.I number
@@ -171,6 +173,21 @@ values are \*(lqcpu\*(rq, \*(lqsize\*(rq
but may vary on different operating systems. Note that
not all operating systems support this option.
.TP
+.BI \-J jail
+Show only those processes owned by
+.IR jail .
+This may be either the
+.B jid
+or
+.B name
+of the jail.
+Use
+.B 0
+to limit to host processes.
+Using this option implies the
+.B \-j
+flag.
+.PP
.BI \-U username
Show only those processes owned by
.IR username .
@@ -315,6 +332,12 @@ Toggle the display of
.IR jail (8)
ID.
.TP
+.B J
+Display only processes owned by a specific jail (prompt for jail).
+If the jail specified is simply \*(lq+\*(rq, then processes belonging
+to all jails and the host will be displayed.
+This will also enable the display of JID.
+.TP
.B P
Toggle the display of per-CPU statistics.
.TP
Modified: stable/9/contrib/top/top.c
==============================================================================
--- stable/9/contrib/top/top.c Sat May 17 03:21:50 2014 (r266286)
+++ stable/9/contrib/top/top.c Sat May 17 03:23:45 2014 (r266287)
@@ -38,7 +38,9 @@ char *copyright =
#include <signal.h>
#include <setjmp.h>
#include <ctype.h>
+#include <sys/jail.h>
#include <sys/time.h>
+#include <jail.h>
/* includes specific to top */
#include "display.h" /* interface to display package */
@@ -198,9 +200,9 @@ char *argv[];
fd_set readfds;
#ifdef ORDER
- static char command_chars[] = "\f qh?en#sdkriIutHmSCajzPo";
+ static char command_chars[] = "\f qh?en#sdkriIutHmSCajzPJo";
#else
- static char command_chars[] = "\f qh?en#sdkriIutHmSCajzP";
+ static char command_chars[] = "\f qh?en#sdkriIutHmSCajzPJ";
#endif
/* these defines enumerate the "strchr"s of the commands in command_chars */
#define CMD_redraw 0
@@ -228,8 +230,9 @@ char *argv[];
#define CMD_jidtog 21
#define CMD_kidletog 22
#define CMD_pcputog 23
+#define CMD_jail 24
#ifdef ORDER
-#define CMD_order 24
+#define CMD_order 25
#endif
/* set the buffer for stdout */
@@ -261,6 +264,7 @@ char *argv[];
ps.uid = -1;
ps.thread = No;
ps.wcpu = 1;
+ ps.jid = -1;
ps.jail = No;
ps.kidle = Yes;
ps.command = NULL;
@@ -288,7 +292,7 @@ char *argv[];
optind = 1;
}
- while ((i = getopt(ac, av, "CSIHPabijnquvzs:d:U:m:o:t")) != EOF)
+ while ((i = getopt(ac, av, "CSIHPabijJ:nquvzs:d:U:m:o:t")) != EOF)
{
switch(i)
{
@@ -413,6 +417,15 @@ char *argv[];
ps.jail = !ps.jail;
break;
+ case 'J': /* display only jail's processes */
+ if ((ps.jid = jail_getid(optarg)) == -1)
+ {
+ fprintf(stderr, "%s: unknown jail\n", optarg);
+ exit(1);
+ }
+ ps.jail = 1;
+ break;
+
case 'P':
pcpu_stats = !pcpu_stats;
break;
@@ -425,7 +438,7 @@ char *argv[];
fprintf(stderr,
"Top version %s\n"
"Usage: %s [-abCHIijnPqStuvz] [-d count] [-m io | cpu] [-o field] [-s time]\n"
-" [-U username] [number]\n",
+" [-J jail] [-U username] [number]\n",
version_string(), myname);
exit(1);
}
@@ -994,7 +1007,7 @@ restart:
case CMD_user:
new_message(MT_standout,
- "Username to show: ");
+ "Username to show (+ for all): ");
if (readline(tempbuf2, sizeof(tempbuf2), No) > 0)
{
if (tempbuf2[0] == '+' &&
@@ -1085,6 +1098,44 @@ restart:
reset_display();
putchar('\r');
break;
+
+ case CMD_jail:
+ new_message(MT_standout,
+ "Jail to show (+ for all): ");
+ if (readline(tempbuf2, sizeof(tempbuf2), No) > 0)
+ {
+ if (tempbuf2[0] == '+' &&
+ tempbuf2[1] == '\0')
+ {
+ ps.jid = -1;
+ }
+ else if ((i = jail_getid(tempbuf2)) == -1)
+ {
+ new_message(MT_standout,
+ " %s: unknown jail", tempbuf2);
+ no_command = Yes;
+ }
+ else
+ {
+ ps.jid = i;
+ }
+ if (ps.jail == 0) {
+ ps.jail = 1;
+ new_message(MT_standout |
+ MT_delayed, " Displaying jail "
+ "ID.");
+ header_text =
+ format_header(uname_field);
+ reset_display();
+ }
+ putchar('\r');
+ }
+ else
+ {
+ clear_message();
+ }
+ break;
+
case CMD_kidletog:
ps.kidle = !ps.kidle;
new_message(MT_standout | MT_delayed,
Modified: stable/9/usr.bin/top/Makefile
==============================================================================
--- stable/9/usr.bin/top/Makefile Sat May 17 03:21:50 2014 (r266286)
+++ stable/9/usr.bin/top/Makefile Sat May 17 03:23:45 2014 (r266287)
@@ -21,8 +21,8 @@ WARNS?= 0
CFLAGS+= -D"Table_size=${TOP_TABLE_SIZE}"
.endif
-DPADD= ${LIBTERMCAP} ${LIBM} ${LIBKVM}
-LDADD= -ltermcap -lm -lkvm
+DPADD= ${LIBTERMCAP} ${LIBM} ${LIBKVM} ${LIBJAIL}
+LDADD= -ltermcap -lm -lkvm -ljail
CLEANFILES= sigdesc.h
SIGCONV_AWK= ${.CURDIR}/../../contrib/top/sigconv.awk
Modified: stable/9/usr.bin/top/machine.c
==============================================================================
--- stable/9/usr.bin/top/machine.c Sat May 17 03:21:50 2014 (r266286)
+++ stable/9/usr.bin/top/machine.c Sat May 17 03:23:45 2014 (r266287)
@@ -668,6 +668,7 @@ get_process_info(struct system_info *si,
/* these are copied out of sel for speed */
int show_idle;
+ int show_jid;
int show_self;
int show_system;
int show_uid;
@@ -710,6 +711,7 @@ get_process_info(struct system_info *si,
/* set up flags which define what we are going to select */
show_idle = sel->idle;
+ show_jid = sel->jid != -1;
show_self = sel->self == -1;
show_system = sel->system;
show_uid = sel->uid != -1;
@@ -764,6 +766,10 @@ get_process_info(struct system_info *si,
/* skip processes that aren't doing I/O */
continue;
+ if (show_jid && pp->ki_jid != sel->jid)
+ /* skip proc. that don't belong to the selected JID */
+ continue;
+
if (show_uid && pp->ki_ruid != (uid_t)sel->uid)
/* skip proc. that don't belong to the selected UID */
continue;
More information about the svn-src-stable-9
mailing list