diff options
author | Markus Friedl <markus@cvs.openbsd.org> | 2005-06-17 09:40:49 +0000 |
---|---|---|
committer | Markus Friedl <markus@cvs.openbsd.org> | 2005-06-17 09:40:49 +0000 |
commit | 22103caf422f5e370b6fb51a9f972ff091c454d4 (patch) | |
tree | c767e692b072c8dd676143bb940b4a3a096b83f4 /usr.bin/top | |
parent | cf2d68c4f65362d35a231e5edb5d1acd73ec3d10 (diff) |
add a 'C' command ) that toggles the display of the full cmdline;
with Jared Yanovich; ok deraadt
Diffstat (limited to 'usr.bin/top')
-rw-r--r-- | usr.bin/top/commands.c | 3 | ||||
-rw-r--r-- | usr.bin/top/machine.c | 42 | ||||
-rw-r--r-- | usr.bin/top/top.1 | 4 | ||||
-rw-r--r-- | usr.bin/top/top.c | 10 | ||||
-rw-r--r-- | usr.bin/top/top.h | 4 |
5 files changed, 54 insertions, 9 deletions
diff --git a/usr.bin/top/commands.c b/usr.bin/top/commands.c index a4a6f58b10b..8ab08859f52 100644 --- a/usr.bin/top/commands.c +++ b/usr.bin/top/commands.c @@ -1,4 +1,4 @@ -/* $OpenBSD: commands.c,v 1.16 2004/10/07 06:26:12 otto Exp $ */ +/* $OpenBSD: commands.c,v 1.17 2005/06/17 09:40:48 markus Exp $ */ /* * Top users/processes display for Unix @@ -100,6 +100,7 @@ show_help(void) "s - change number of seconds to delay between updates\n" "S - toggle the display of system processes\n" "u - display processes for only one user (+ selects all users)\n" + "C - toggle the display of the command line arguments\n" "\n\n", stdout); } } diff --git a/usr.bin/top/machine.c b/usr.bin/top/machine.c index 1950a27a706..bf35b584712 100644 --- a/usr.bin/top/machine.c +++ b/usr.bin/top/machine.c @@ -1,4 +1,4 @@ -/* $OpenBSD: machine.c,v 1.48 2005/06/08 22:36:43 millert Exp $ */ +/* $OpenBSD: machine.c,v 1.49 2005/06/17 09:40:48 markus Exp $ */ /*- * Copyright (c) 1994 Thorsten Lockert <tholo@sigmasoft.com> @@ -81,7 +81,7 @@ static char header[] = #define UNAME_START 6 #define Proc_format \ - "%5d %-8.8s %3d %4d %5s %5s %-8s %-6.6s %6s %5.2f%% %.11s" + "%5d %-8.8s %3d %4d %5s %5s %-8s %-6.6s %6s %5.2f%% %.51s" /* process state names for the "STATE" column of the display */ /* @@ -424,6 +424,42 @@ state_abbr(struct kinfo_proc2 *pp) } char * +format_comm(struct kinfo_proc2 *kp) +{ +#define ARG_SIZE 60 + static char **s, buf[ARG_SIZE]; + size_t siz = 100; + char **p; + int mib[4]; + extern int show_args; + + if (!show_args) + return (kp->p_comm); + + for (;; siz *= 2) { + if ((s = realloc(s, siz)) == NULL) + err(1, NULL); + mib[0] = CTL_KERN; + mib[1] = KERN_PROC_ARGS; + mib[2] = kp->p_pid; + mib[3] = KERN_PROC_ARGV; + if (sysctl(mib, 4, s, &siz, NULL, 0) == 0) + break; + if (errno != ENOMEM) + return (kp->p_comm); + } + buf[0] = '\0'; + for (p = s; *p != NULL; p++) { + if (p != s) + strlcat(buf, " ", sizeof(buf)); + strlcat(buf, *p, sizeof(buf)); + } + if (buf[0] == '\0') + return (kp->p_comm); + return (buf); +} + +char * format_next_process(caddr_t handle, char *(*get_userid)(uid_t)) { char *p_wait, waddr[sizeof(void *) * 2 + 3]; /* Hexify void pointer */ @@ -471,7 +507,7 @@ format_next_process(caddr_t handle, char *(*get_userid)(uid_t)) (pp->p_stat == SSLEEP && pp->p_slptime > maxslp) ? "idle" : state_abbr(pp), p_wait, format_time(cputime), 100.0 * pct, - printable(pp->p_comm)); + printable(format_comm(pp))); /* return the result */ return (fmt); diff --git a/usr.bin/top/top.1 b/usr.bin/top/top.1 index b192428fe3d..a8523da3f37 100644 --- a/usr.bin/top/top.1 +++ b/usr.bin/top/top.1 @@ -1,4 +1,4 @@ -.\" $OpenBSD: top.1,v 1.28 2005/05/25 02:19:43 jaredy Exp $ +.\" $OpenBSD: top.1,v 1.29 2005/06/17 09:40:48 markus Exp $ .\" .\" Copyright (c) 1997, Jason Downs. All rights reserved. .\" @@ -250,6 +250,8 @@ Quit .Pp The following commands may not be available with overstrike terminals: .Bl -tag -width XxXXXX +.It C +Toggle the display of process command line arguments. .It d Change the number of displays to show (prompt for new number). Remember that the next display counts as one, so typing diff --git a/usr.bin/top/top.c b/usr.bin/top/top.c index e0cb26faec9..411014a2617 100644 --- a/usr.bin/top/top.c +++ b/usr.bin/top/top.c @@ -1,4 +1,4 @@ -/* $OpenBSD: top.c,v 1.39 2005/06/08 22:36:43 millert Exp $ */ +/* $OpenBSD: top.c,v 1.40 2005/06/17 09:40:48 markus Exp $ */ /* * Top users/processes display for Unix @@ -97,6 +97,7 @@ char *order_name = NULL; int topn = Default_TOPN; int no_command = Yes; int old_system = No; +int show_args = No; #if Default_TOPN == Infinity char topn_specified = No; @@ -125,6 +126,7 @@ char topn_specified = No; #define CMD_system 15 #define CMD_order 16 #define CMD_pid 17 +#define CMD_command 18 static void usage(void) @@ -512,7 +514,7 @@ rundisplay(void) int change, i; struct pollfd pfd[1]; uid_t uid; - static char command_chars[] = "\f qh?en#sdkriIuSop"; + static char command_chars[] = "\f qh?en#sdkriIuSopC"; /* * assume valid command unless told @@ -848,6 +850,10 @@ rundisplay(void) clear_message(); break; + case CMD_command: + show_args = (show_args == No) ? Yes : No; + break; + default: new_message(MT_standout, " BAD CASE IN SWITCH!"); if (putchar('\r') == EOF) diff --git a/usr.bin/top/top.h b/usr.bin/top/top.h index b2165b35200..8559d27ff29 100644 --- a/usr.bin/top/top.h +++ b/usr.bin/top/top.h @@ -1,4 +1,4 @@ -/* $OpenBSD: top.h,v 1.6 2005/06/08 22:36:43 millert Exp $ */ +/* $OpenBSD: top.h,v 1.7 2005/06/17 09:40:48 markus Exp $ */ /* * Top users/processes display for Unix @@ -43,7 +43,7 @@ extern int Header_lines; /* Maximum number of columns allowed for display */ -#define MAX_COLS 128 +#define MAX_COLS 256 /* Log base 2 of 1024 is 10 (2^10 == 1024) */ #define LOG1024 10 |