summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkn <kn@cvs.openbsd.org>2020-08-26 16:21:29 +0000
committerkn <kn@cvs.openbsd.org>2020-08-26 16:21:29 +0000
commit93a466a6bf1bec811a6d2be401129e5431a566ac (patch)
treee3c592f660a16faa53edf94db4d7ac368b5ab9e8
parenta66b30cbd457a955c7350f7594e69cd1808ee720 (diff)
Add "t" to toggle the display of routing tables
Swap the WAIT column with RTABLE (and vice versa); WAIT is wide enough to fit RTABLE, somewhat adds additional value to STATE and seems therefore most appropiate to hide in favour of RTABLE. Filtering rtables with "T" does not toggle the column, just like filtering users with "u" does not toggle between user and thread id. Feedback jmc OK remi
-rw-r--r--usr.bin/top/display.c3
-rw-r--r--usr.bin/top/machine.c32
-rw-r--r--usr.bin/top/machine.h7
-rw-r--r--usr.bin/top/top.110
-rw-r--r--usr.bin/top/top.c35
5 files changed, 58 insertions, 29 deletions
diff --git a/usr.bin/top/display.c b/usr.bin/top/display.c
index 73dbe6bc84f..abb8a4ba57e 100644
--- a/usr.bin/top/display.c
+++ b/usr.bin/top/display.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: display.c,v 1.64 2020/08/23 21:11:55 kn Exp $ */
+/* $OpenBSD: display.c,v 1.65 2020/08/26 16:21:28 kn Exp $ */
/*
* Top users/processes display for Unix
@@ -826,6 +826,7 @@ show_help(void)
"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"
+ "t - toggle the display of routing tables\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 d8c75b03730..93105d6577c 100644
--- a/usr.bin/top/machine.c
+++ b/usr.bin/top/machine.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: machine.c,v 1.109 2020/08/25 07:27:34 kn Exp $ */
+/* $OpenBSD: machine.c,v 1.110 2020/08/26 16:21:28 kn Exp $ */
/*-
* Copyright (c) 1994 Thorsten Lockert <tholo@sigmasoft.com>
@@ -75,8 +75,9 @@ struct handle {
static char header[] =
" PID X PRI NICE SIZE RES STATE WAIT TIME CPU COMMAND";
-/* 0123456 -- field to fill in starts at header+6 */
+/* offsets in the header line to start alternative columns */
#define UNAME_START 6
+#define RTABLE_START 46
#define Proc_format \
"%5d %-8.8s %3d %4d %5s %5s %-9s %-7.7s %6s %5.2f%% %s"
@@ -226,16 +227,16 @@ machine_init(struct statics *statics)
}
char *
-format_header(char *second_field)
+format_header(char *second_field, char *eighth_field)
{
- char *field_name, *thread_field = " TID";
- char *ptr;
-
- field_name = second_field ? second_field : thread_field;
+ char *second_fieldp = second_field, *eighth_fieldp = eighth_field, *ptr;
ptr = header + UNAME_START;
- while (*field_name != '\0')
- *ptr++ = *field_name++;
+ while (*second_fieldp != '\0')
+ *ptr++ = *second_fieldp++;
+ ptr = header + RTABLE_START;
+ while (*eighth_fieldp != '\0')
+ *ptr++ = *eighth_fieldp++;
return (header);
}
@@ -544,13 +545,12 @@ skip_processes(struct handle *hndl, int n)
char *
format_next_process(struct handle *hndl, const char *(*get_userid)(uid_t, int),
- pid_t *pid)
+ int rtable, pid_t *pid)
{
- char *p_wait;
struct kinfo_proc *pp;
int cputime;
double pct;
- char second_buf[16];
+ char second_buf[16], eighth_buf[8];
/* find and remember the next proc structure */
pp = *(hndl->next_proc++);
@@ -566,7 +566,11 @@ format_next_process(struct handle *hndl, const char *(*get_userid)(uid_t, int),
strlcpy(second_buf, (*get_userid)(pp->p_ruid, 0),
sizeof(second_buf));
- p_wait = pp->p_wmesg[0] ? pp->p_wmesg : "-";
+ if (rtable)
+ snprintf(eighth_buf, sizeof(eighth_buf), "%7d", pp->p_rtableid);
+ else
+ strlcpy(eighth_buf, pp->p_wmesg[0] ? pp->p_wmesg : "-",
+ sizeof(eighth_buf));
/* format this entry */
snprintf(fmt, sizeof(fmt), Proc_format, pp->p_pid, second_buf,
@@ -575,7 +579,7 @@ format_next_process(struct handle *hndl, const char *(*get_userid)(uid_t, int),
format_k(pagetok(pp->p_vm_rssize)),
(pp->p_stat == SSLEEP && pp->p_slptime > maxslp) ?
"idle" : state_abbr(pp),
- p_wait, format_time(cputime), 100.0 * pct,
+ eighth_buf, format_time(cputime), 100.0 * pct,
printable(format_comm(pp)));
*pid = pp->p_pid;
diff --git a/usr.bin/top/machine.h b/usr.bin/top/machine.h
index 5807d5dd7ea..f051d99bad0 100644
--- a/usr.bin/top/machine.h
+++ b/usr.bin/top/machine.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: machine.h,v 1.30 2020/08/23 21:11:55 kn Exp $ */
+/* $OpenBSD: machine.h,v 1.31 2020/08/26 16:21:28 kn Exp $ */
/*
* Top users/processes display for Unix
@@ -77,6 +77,7 @@ 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 rtable; /* show routing tables */
int rtableid; /* only this rtable (unless rtableid == -1) */
int hrtableid; /* hide this rtable (unless hrtableid == -1) */
char *command;/* only this command (unless == NULL) */
@@ -87,14 +88,14 @@ extern int display_init(struct statics *);
/* machine.c */
extern int machine_init(struct statics *);
-extern char *format_header(char *);
+extern char *format_header(char *, char *);
extern void get_system_info(struct system_info *);
extern struct handle
*get_process_info(struct system_info *, struct process_select *,
int (*) (const void *, const void *));
extern void skip_processes(struct handle *, int);
extern char *format_next_process(struct handle *,
- const char *(*)(uid_t, int), pid_t *);
+ const char *(*)(uid_t, int), int, pid_t *);
extern uid_t proc_owner(pid_t);
extern struct kinfo_proc *getprocs(int, int, int *);
diff --git a/usr.bin/top/top.1 b/usr.bin/top/top.1
index 6267981fd44..06e3224ecff 100644
--- a/usr.bin/top/top.1
+++ b/usr.bin/top/top.1
@@ -1,4 +1,4 @@
-.\" $OpenBSD: top.1,v 1.76 2020/08/23 21:11:55 kn Exp $
+.\" $OpenBSD: top.1,v 1.77 2020/08/26 16:21:28 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: August 23 2020 $
+.Dd $Mdocdate: August 26 2020 $
.Dt TOP 1
.Os
.Sh NAME
@@ -388,6 +388,8 @@ shows processes associated with all routing tables.
The
.Sq -
prefix hides proccesses associated with a single routing table.
+.It t
+Toggle the display of routing tables.
.It u Oo - Oc Ns Ar user
Show only those processes owned by username or UID
.Ar user .
@@ -463,6 +465,10 @@ number on which the process is bound.
.It WAIT
A description of the wait channel the process is sleeping on if it's
asleep.
+.It RTABLE
+The routing table, used instead of WAIT if
+.Fl t
+is specified.
.It TIME
The number of system and user CPU seconds that the process has used.
.It CPU
diff --git a/usr.bin/top/top.c b/usr.bin/top/top.c
index 5964cfd65c2..59c46bde594 100644
--- a/usr.bin/top/top.c
+++ b/usr.bin/top/top.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: top.c,v 1.105 2020/08/23 21:11:55 kn Exp $ */
+/* $OpenBSD: top.c,v 1.106 2020/08/26 16:21:28 kn Exp $ */
/*
* Top users/processes display for Unix
@@ -133,7 +133,8 @@ struct statics statics;
#define CMD_pagedown 26
#define CMD_pageup 27
#define CMD_grep2 28
-#define CMD_rtable 29
+#define CMD_rtableid 29
+#define CMD_rtable 30
static void
usage(void)
@@ -141,7 +142,7 @@ usage(void)
extern char *__progname;
fprintf(stderr,
- "usage: %s [-1bCHIinqSu] [-d count] [-g string] [-o [-]field] "
+ "usage: %s [-1bCHIinqStu] [-d count] [-g string] [-o [-]field] "
"[-p pid] [-s time]\n\t[-T [-]rtable] [-U [-]user] [number]\n",
__progname);
}
@@ -241,7 +242,7 @@ parseargs(int ac, char **av)
char *endp;
int i;
- while ((i = getopt(ac, av, "1SHICbinqus:d:p:U:o:g:T:")) != -1) {
+ while ((i = getopt(ac, av, "1SHICbinqus:d:p:U:o:g:T:t")) != -1) {
switch (i) {
case '1':
combine_cpus = 1;
@@ -339,6 +340,10 @@ parseargs(int ac, char **av)
"%s: invalid routing table", optarg);
break;
+ case 't':
+ ps.rtable = true;
+ break;
+
default:
usage();
exit(1);
@@ -370,7 +375,9 @@ parseargs(int ac, char **av)
int
main(int argc, char *argv[])
{
- char *uname_field = "USERNAME", *header_text, *env_top;
+ char *header_text, *env_top;
+ char *uname_field = "USERNAME", *thread_field = " TID";
+ char *wait_field = "WAIT ", *rtable_field = " RTABLE";
const char *(*get_userid)(uid_t, int) = user_from_uid;
char **preset_argv = NULL, **av = argv;
int preset_argc = 0, ac = argc, active_procs, i, ncpuonline_now;
@@ -391,6 +398,7 @@ main(int argc, char *argv[])
ps.uid = (uid_t)-1;
ps.huid = (uid_t)-1;
ps.pid = (pid_t)-1;
+ ps.rtable = false;
ps.rtableid = -1;
ps.hrtableid = -1;
ps.command = NULL;
@@ -573,7 +581,9 @@ restart:
i_message();
/* get the string to use for the process area header */
- header_text = format_header(ps.threads ? NULL : uname_field);
+ header_text = format_header(
+ ps.threads ? thread_field : uname_field,
+ ps.rtable ? rtable_field : wait_field);
/* update the header area */
i_header(header_text);
@@ -613,7 +623,8 @@ restart:
char * s;
s = format_next_process(processes,
- ps.threads ? NULL : get_userid, &pid);
+ ps.threads ? NULL : get_userid, ps.rtable,
+ &pid);
i_process(i, s, pid == hlpid);
}
}
@@ -668,7 +679,7 @@ rundisplay(void)
char ch, *iptr;
int change, i;
struct pollfd pfd[1];
- static char command_chars[] = "\f qh?en#sdkriIuSopCHg+P109)(/T";
+ static char command_chars[] = "\f qh?en#sdkriIuSopCHg+P109)(/Tt";
/*
* assume valid command unless told
@@ -1035,7 +1046,7 @@ rundisplay(void)
if (skip < 0)
skip = 0;
break;
- case CMD_rtable:
+ case CMD_rtableid:
new_message(MT_standout,
"Routing table: ");
if (readline(tempbuf, sizeof(tempbuf)) > 0) {
@@ -1053,6 +1064,12 @@ rundisplay(void)
} else
clear_message();
break;
+ case CMD_rtable:
+ ps.rtable = !ps.rtable;
+ new_message(MT_standout | MT_delayed,
+ " %sisplaying routing tables.",
+ ps.rtable ? "D" : "Not d");
+ break;
default:
new_message(MT_standout, " BAD CASE IN SWITCH!");
putr();