summaryrefslogtreecommitdiff
path: root/usr.bin/top
diff options
context:
space:
mode:
authorkn <kn@cvs.openbsd.org>2020-08-23 21:11:56 +0000
committerkn <kn@cvs.openbsd.org>2020-08-23 21:11:56 +0000
commit6446d40c4e87255ce69ace9d2d4d6505d7e71479 (patch)
tree9e6529dcceda19cd30db3a560c6cf97fff5d3fc8 /usr.bin/top
parentb5623ac92412547b6901f29d796bd8be7cb3a927 (diff)
Filter by routing table
"-T-0" for processes outside the default routing table, "-T3" for those in a specific one; same semantics as with other filters. Manual wording and command line flag taken from pgrep(1) being the only way to identify processes by routing table; After netstat(1)'s recent addition of "-R", filtering in top makes for handy tooling around rtable(4). "looks good to me" millert OK remi
Diffstat (limited to 'usr.bin/top')
-rw-r--r--usr.bin/top/display.c4
-rw-r--r--usr.bin/top/machine.c8
-rw-r--r--usr.bin/top/machine.h4
-rw-r--r--usr.bin/top/top.121
-rw-r--r--usr.bin/top/top.c64
5 files changed, 91 insertions, 10 deletions
diff --git a/usr.bin/top/display.c b/usr.bin/top/display.c
index ecc331fd99a..73dbe6bc84f 100644
--- a/usr.bin/top/display.c
+++ b/usr.bin/top/display.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: display.c,v 1.63 2020/07/26 21:59:16 kn Exp $ */
+/* $OpenBSD: display.c,v 1.64 2020/08/23 21:11:55 kn Exp $ */
/*
* Top users/processes display for Unix
@@ -824,6 +824,8 @@ show_help(void)
"r count pid - renice process `pid' to nice value `count'\n"
"S - toggle the display of system processes\n"
"s time - change delay between displays to `time' seconds\n"
+ "T [-]rtable - show processes associated with routing table `rtable'\n"
+ " (T+ shows all, T -rtable hides rtable)\n"
"u [-]user - show processes for `user' (u+ shows all, u -user hides user)\n"
"\n");
diff --git a/usr.bin/top/machine.c b/usr.bin/top/machine.c
index 5c63cd56912..42bffc21ad8 100644
--- a/usr.bin/top/machine.c
+++ b/usr.bin/top/machine.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: machine.c,v 1.107 2020/07/06 16:27:59 kn Exp $ */
+/* $OpenBSD: machine.c,v 1.108 2020/08/23 21:11:55 kn Exp $ */
/*-
* Copyright (c) 1994 Thorsten Lockert <tholo@sigmasoft.com>
@@ -414,7 +414,7 @@ get_process_info(struct system_info *si, struct process_select *sel,
int (*compare) (const void *, const void *))
{
int show_idle, show_system, show_threads, show_uid, show_pid, show_cmd;
- int hide_uid;
+ int show_rtable, hide_rtable, hide_uid;
int total_procs, active_procs;
struct kinfo_proc **prefp, *pp;
int what = KERN_PROC_ALL;
@@ -446,6 +446,8 @@ get_process_info(struct system_info *si, struct process_select *sel,
show_uid = sel->uid != (uid_t)-1;
hide_uid = sel->huid != (uid_t)-1;
show_pid = sel->pid != (pid_t)-1;
+ show_rtable = sel->rtableid != -1;
+ hide_rtable = sel->hrtableid != -1;
show_cmd = sel->command != NULL;
/* count up process states and get pointers to interesting procs */
@@ -474,6 +476,8 @@ get_process_info(struct system_info *si, struct process_select *sel,
(!hide_uid || pp->p_ruid != sel->huid) &&
(!show_uid || pp->p_ruid == sel->uid) &&
(!show_pid || pp->p_pid == sel->pid) &&
+ (!hide_rtable || pp->p_rtableid != sel->hrtableid) &&
+ (!show_rtable || pp->p_rtableid == sel->rtableid) &&
(!show_cmd || cmd_matches(pp, sel->command))) {
*prefp++ = pp;
active_procs++;
diff --git a/usr.bin/top/machine.h b/usr.bin/top/machine.h
index 731acc4fcdc..5807d5dd7ea 100644
--- a/usr.bin/top/machine.h
+++ b/usr.bin/top/machine.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: machine.h,v 1.29 2020/06/25 20:38:41 kn Exp $ */
+/* $OpenBSD: machine.h,v 1.30 2020/08/23 21:11:55 kn Exp $ */
/*
* Top users/processes display for Unix
@@ -77,6 +77,8 @@ struct process_select {
uid_t uid; /* only this uid (unless uid == -1) */
uid_t huid; /* hide this uid (unless huid == -1) */
pid_t pid; /* only this pid (unless pid == -1) */
+ int rtableid; /* only this rtable (unless rtableid == -1) */
+ int hrtableid; /* hide this rtable (unless hrtableid == -1) */
char *command;/* only this command (unless == NULL) */
};
diff --git a/usr.bin/top/top.1 b/usr.bin/top/top.1
index 089a345b5e8..6267981fd44 100644
--- a/usr.bin/top/top.1
+++ b/usr.bin/top/top.1
@@ -1,4 +1,4 @@
-.\" $OpenBSD: top.1,v 1.75 2020/07/26 21:59:16 kn Exp $
+.\" $OpenBSD: top.1,v 1.76 2020/08/23 21:11:55 kn Exp $
.\"
.\" Copyright (c) 1997, Jason Downs. All rights reserved.
.\"
@@ -23,7 +23,7 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.Dd $Mdocdate: July 26 2020 $
+.Dd $Mdocdate: August 23 2020 $
.Dt TOP 1
.Os
.Sh NAME
@@ -38,6 +38,7 @@
.Op Fl o Oo - Oc Ns Ar field
.Op Fl p Ar pid
.Op Fl s Ar time
+.Op Fl T Oo - Oc Ns Ar rtable
.Op Fl U Oo - Oc Ns Ar user
.Op Ar number
.Ek
@@ -179,6 +180,14 @@ Set the delay between screen updates to
seconds.
The value may be fractional, to permit delays of less than 1 second.
The default delay between updates is 5 seconds.
+.It Fl T Oo - Oc Ns Ar rtable
+Display only processes associated with the specified routing table
+.Ar rtable .
+.Sq T+
+shows processes associated with all routing tables.
+The
+.Sq -
+prefix hides proccesses associated with a single routing table.
.It Fl U Oo - Oc Ns Ar user
Show only those processes owned by username or UID
.Ar user .
@@ -371,6 +380,14 @@ Toggle the display of system processes.
Set the delay between screen updates to
.Ar time
seconds.
+.It T Oo - Oc Ns Ar rtable
+Display only processes associated with the specified routing table
+.Ar rtable .
+.Sq T+
+shows processes associated with all routing tables.
+The
+.Sq -
+prefix hides proccesses associated with a single routing table.
.It u Oo - Oc Ns Ar user
Show only those processes owned by username or UID
.Ar user .
diff --git a/usr.bin/top/top.c b/usr.bin/top/top.c
index 21c409b5e81..5964cfd65c2 100644
--- a/usr.bin/top/top.c
+++ b/usr.bin/top/top.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: top.c,v 1.104 2020/07/26 21:59:16 kn Exp $ */
+/* $OpenBSD: top.c,v 1.105 2020/08/23 21:11:55 kn Exp $ */
/*
* Top users/processes display for Unix
@@ -29,6 +29,7 @@
*/
#include <sys/types.h>
+#include <sys/socket.h>
#include <curses.h>
#include <err.h>
#include <errno.h>
@@ -132,6 +133,7 @@ struct statics statics;
#define CMD_pagedown 26
#define CMD_pageup 27
#define CMD_grep2 28
+#define CMD_rtable 29
static void
usage(void)
@@ -140,7 +142,7 @@ usage(void)
fprintf(stderr,
"usage: %s [-1bCHIinqSu] [-d count] [-g string] [-o [-]field] "
- "[-p pid] [-s time]\n\t[-U [-]user] [number]\n",
+ "[-p pid] [-s time]\n\t[-T [-]rtable] [-U [-]user] [number]\n",
__progname);
}
@@ -207,13 +209,39 @@ filterpid(char buf[], int hl)
return 0;
}
+static int
+filterrtable(char buf[])
+{
+ const char *errstr;
+ char *bufp = buf;
+ uint32_t *rtableidp;
+ uint32_t rtableid;
+
+ if (bufp[0] == '-') {
+ bufp++;
+ rtableidp = &ps.hrtableid;
+ ps.rtableid = -1;
+ } else {
+ rtableidp = &ps.rtableid;
+ ps.hrtableid = -1;
+ }
+
+ rtableid = strtonum(bufp, 0, RT_TABLEID_MAX, &errstr);
+ if (errstr == NULL) {
+ *rtableidp = rtableid;
+ return 0;
+ }
+
+ return -1;
+}
+
static void
parseargs(int ac, char **av)
{
char *endp;
int i;
- while ((i = getopt(ac, av, "1SHICbinqus:d:p:U:o:g:")) != -1) {
+ while ((i = getopt(ac, av, "1SHICbinqus:d:p:U:o:g:T:")) != -1) {
switch (i) {
case '1':
combine_cpus = 1;
@@ -305,6 +333,12 @@ parseargs(int ac, char **av)
err(1, NULL);
break;
+ case 'T':
+ if (filterrtable(optarg) == -1)
+ new_message(MT_delayed,
+ "%s: invalid routing table", optarg);
+ break;
+
default:
usage();
exit(1);
@@ -357,6 +391,8 @@ main(int argc, char *argv[])
ps.uid = (uid_t)-1;
ps.huid = (uid_t)-1;
ps.pid = (pid_t)-1;
+ ps.rtableid = -1;
+ ps.hrtableid = -1;
ps.command = NULL;
/* get preset options from the environment */
@@ -632,7 +668,7 @@ rundisplay(void)
char ch, *iptr;
int change, i;
struct pollfd pfd[1];
- static char command_chars[] = "\f qh?en#sdkriIuSopCHg+P109)(/";
+ static char command_chars[] = "\f qh?en#sdkriIuSopCHg+P109)(/T";
/*
* assume valid command unless told
@@ -973,6 +1009,8 @@ rundisplay(void)
ps.uid = (uid_t)-1; /* uid */
ps.huid = (uid_t)-1;
ps.pid = (pid_t)-1; /* pid */
+ ps.rtableid = -1; /* rtableid */
+ ps.hrtableid = -1;
ps.system = old_system;
ps.command = NULL; /* grep */
hlpid = (pid_t)-1;
@@ -997,6 +1035,24 @@ rundisplay(void)
if (skip < 0)
skip = 0;
break;
+ case CMD_rtable:
+ new_message(MT_standout,
+ "Routing table: ");
+ if (readline(tempbuf, sizeof(tempbuf)) > 0) {
+ if (tempbuf[0] == '+' && tempbuf[1] == '\0') {
+ ps.rtableid = -1;
+ ps.hrtableid = -1;
+ } else if (filterrtable(tempbuf) == -1) {
+ new_message(MT_standout,
+ " %s: invalid routing table",
+ tempbuf[0] == '-' ? tempbuf + 1 :
+ tempbuf);
+ no_command = true;
+ }
+ putr();
+ } else
+ clear_message();
+ break;
default:
new_message(MT_standout, " BAD CASE IN SWITCH!");
putr();