From owner-svn-src-all@FreeBSD.ORG Sat May 17 03:23:47 2014 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 9295A4F4; Sat, 17 May 2014 03:23:47 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 733E0269D; Sat, 17 May 2014 03:23:47 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.8/8.14.8) with ESMTP id s4H3NlNJ043763; Sat, 17 May 2014 03:23:47 GMT (envelope-from bdrewery@svn.freebsd.org) Received: (from bdrewery@localhost) by svn.freebsd.org (8.14.8/8.14.8/Submit) id s4H3Nk9t043757; Sat, 17 May 2014 03:23:46 GMT (envelope-from bdrewery@svn.freebsd.org) Message-Id: <201405170323.s4H3Nk9t043757@svn.freebsd.org> From: Bryan Drewery Date: Sat, 17 May 2014 03:23:46 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-9@freebsd.org Subject: svn commit: r266287 - in stable/9: contrib/top usr.bin/top X-SVN-Group: stable-9 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 17 May 2014 03:23:47 -0000 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 #include #include +#include #include +#include /* 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;