diff options
author | Bryan Steele <brynet@cvs.openbsd.org> | 2012-06-05 18:52:54 +0000 |
---|---|---|
committer | Bryan Steele <brynet@cvs.openbsd.org> | 2012-06-05 18:52:54 +0000 |
commit | e587be9b554cd99ab0c870bebe4450d4c4d71a31 (patch) | |
tree | e59f9fd80a7c01f0650d341cee9748eddf21e385 /usr.bin/top | |
parent | 386ceb0ab6439e9a634adc3c9e8a9355f9ce4db9 (diff) |
Add support for hiding a user's processes in top.
feedback & ok lum@
Diffstat (limited to 'usr.bin/top')
-rw-r--r-- | usr.bin/top/display.c | 4 | ||||
-rw-r--r-- | usr.bin/top/machine.c | 5 | ||||
-rw-r--r-- | usr.bin/top/machine.h | 3 | ||||
-rw-r--r-- | usr.bin/top/top.1 | 19 | ||||
-rw-r--r-- | usr.bin/top/top.c | 36 |
5 files changed, 49 insertions, 18 deletions
diff --git a/usr.bin/top/display.c b/usr.bin/top/display.c index a45611d0e56..60a6f7d64ef 100644 --- a/usr.bin/top/display.c +++ b/usr.bin/top/display.c @@ -1,4 +1,4 @@ -/* $OpenBSD: display.c,v 1.42 2012/04/15 19:52:16 lum Exp $ */ +/* $OpenBSD: display.c,v 1.43 2012/06/05 18:52:53 brynet Exp $ */ /* * Top users/processes display for Unix @@ -782,7 +782,7 @@ 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" - "u user - display processes for `user' (u+ selects all users)\n" + "u [-]user - show processes for `user' (u+ shows all, u -user hides user)\n" "\n"); if (smart_terminal) { diff --git a/usr.bin/top/machine.c b/usr.bin/top/machine.c index 8bdaf9f4d4c..65cc6fe401c 100644 --- a/usr.bin/top/machine.c +++ b/usr.bin/top/machine.c @@ -1,4 +1,4 @@ -/* $OpenBSD: machine.c,v 1.72 2012/04/21 03:14:50 guenther Exp $ */ +/* $OpenBSD: machine.c,v 1.73 2012/06/05 18:52:53 brynet Exp $ */ /*- * Copyright (c) 1994 Thorsten Lockert <tholo@sigmasoft.com> @@ -330,6 +330,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 total_procs, active_procs; struct kinfo_proc **prefp, *pp; int what = KERN_PROC_KTHREAD; @@ -356,6 +357,7 @@ get_process_info(struct system_info *si, struct process_select *sel, show_system = sel->system; show_threads = sel->threads; show_uid = sel->uid != (uid_t)-1; + hide_uid = sel->huid != (uid_t)-1; show_pid = sel->pid != (pid_t)-1; show_cmd = sel->command != NULL; @@ -381,6 +383,7 @@ get_process_info(struct system_info *si, struct process_select *sel, if (pp->p_stat != SZOMB && (show_idle || pp->p_pctcpu != 0 || pp->p_stat == SRUN) && + (!hide_uid || pp->p_ruid != sel->huid) && (!show_uid || pp->p_ruid == sel->uid) && (!show_pid || pp->p_pid == sel->pid) && (!show_cmd || strstr(pp->p_comm, diff --git a/usr.bin/top/machine.h b/usr.bin/top/machine.h index 1ed4044267e..f4c3f3045d1 100644 --- a/usr.bin/top/machine.h +++ b/usr.bin/top/machine.h @@ -1,4 +1,4 @@ -/* $OpenBSD: machine.h,v 1.16 2011/04/10 03:20:59 guenther Exp $ */ +/* $OpenBSD: machine.h,v 1.17 2012/06/05 18:52:53 brynet Exp $ */ /* * Top users/processes display for Unix @@ -74,6 +74,7 @@ struct process_select { int system; /* show system processes */ int threads; /* show threads */ 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) */ char *command;/* only this command (unless == NULL) */ }; diff --git a/usr.bin/top/top.1 b/usr.bin/top/top.1 index 96cd7e704e4..3e09421c8e9 100644 --- a/usr.bin/top/top.1 +++ b/usr.bin/top/top.1 @@ -1,4 +1,4 @@ -.\" $OpenBSD: top.1,v 1.59 2011/12/16 14:50:24 jsing Exp $ +.\" $OpenBSD: top.1,v 1.60 2012/06/05 18:52:53 brynet 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: December 16 2011 $ +.Dd $Mdocdate: June 5 2012 $ .Dt TOP 1 .Os .Sh NAME @@ -38,7 +38,7 @@ .Op Fl o Ar field .Op Fl p Ar pid .Op Fl s Ar time -.Op Fl U Ar user +.Oo Fl U Op Ar - Oc Ns Ar user .Op Ar number .Ek .Sh DESCRIPTION @@ -173,9 +173,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 U Ar user +.It Fl U Oo Ar - Oc Ns Ar user Show only those processes owned by .Ar user . +Prefix +.Ar - +with +.Ar user +to hide processes owned by that user. This option currently only accepts usernames and will not understand UID numbers. .It Fl u @@ -354,11 +359,15 @@ Toggle the display of system processes. Set the delay between screen updates to .Ar time seconds. -.It u Ar user +.It u Oo Ar - Oc Ns Ar user Show only those processes owned by .Ar user . .Sq u+ shows processes belonging to all users. +The +.Ar - +prefix hides processes belonging to a single +.Ar user . .El .Sh THE DISPLAY .\" The actual display varies depending on the specific variant of Unix diff --git a/usr.bin/top/top.c b/usr.bin/top/top.c index 4f36aa961fc..7a79fe72f54 100644 --- a/usr.bin/top/top.c +++ b/usr.bin/top/top.c @@ -1,4 +1,4 @@ -/* $OpenBSD: top.c,v 1.77 2012/04/20 16:36:11 pirofti Exp $ */ +/* $OpenBSD: top.c,v 1.78 2012/06/05 18:52:53 brynet Exp $ */ /* * Top users/processes display for Unix @@ -126,7 +126,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[-U [-]user] [number]\n", __progname); } @@ -149,7 +149,11 @@ parseargs(int ac, char **av) break; case 'U': /* display only username's processes */ - if ((ps.uid = userid(optarg)) == (uid_t)-1) + if (optarg[0] == '-') { + if ((ps.huid = userid(optarg+1)) == (uid_t)-1) + new_message(MT_delayed, "%s: unknown user", + optarg); + } else if ((ps.uid = userid(optarg)) == (uid_t)-1) new_message(MT_delayed, "%s: unknown user", optarg); break; @@ -282,6 +286,7 @@ main(int argc, char *argv[]) ps.idle = Yes; ps.system = No; ps.uid = (uid_t)-1; + ps.huid = (uid_t)-1; ps.pid = (pid_t)-1; ps.command = NULL; @@ -540,7 +545,7 @@ rundisplay(void) char ch, *iptr; int change, i; struct pollfd pfd[1]; - uid_t uid; + uid_t uid, huid; static char command_chars[] = "\f qh?en#sdkriIuSopCHg+P1"; /* @@ -774,15 +779,27 @@ rundisplay(void) new_message(MT_standout, "Username to show: "); if (readline(tempbuf, sizeof(tempbuf)) > 0) { - if (tempbuf[0] == '+' && + if ((tempbuf[0] == '+' || tempbuf[0] == '-') && tempbuf[1] == '\0') { ps.uid = (uid_t)-1; + ps.huid = (uid_t)-1; + } else if (tempbuf[0] == '-') { + if ((huid = userid(tempbuf+1)) == (uid_t)-1) { + new_message(MT_standout, + " %s: unknown user", tempbuf+1); + no_command = Yes; + } else { + ps.huid = huid; + ps.uid = (uid_t)-1; + } } else if ((uid = userid(tempbuf)) == (uid_t)-1) { - new_message(MT_standout, - " %s: unknown user", tempbuf); - no_command = Yes; - } else + new_message(MT_standout, + " %s: unknown user", tempbuf); + no_command = Yes; + } else { ps.uid = uid; + ps.huid = (uid_t)-1; + } putr(); } else clear_message(); @@ -899,6 +916,7 @@ rundisplay(void) case CMD_add: ps.uid = (uid_t)-1; /* uid */ + ps.huid = (uid_t)-1; ps.pid = (pid_t)-1; /* pid */ ps.system = old_system; ps.command = NULL; /* grep */ |