summaryrefslogtreecommitdiffstats
path: root/usr.bin/top
diff options
context:
space:
mode:
authordes <des@FreeBSD.org>2004-07-05 12:48:17 +0000
committerdes <des@FreeBSD.org>2004-07-05 12:48:17 +0000
commita9156607eb32ba4e7ea4afb912838d56a1aabf50 (patch)
tree91ac6ff2bf903215cfbdc179711c95ac54545861 /usr.bin/top
parent532e2f96defa47e2b0c54ee4431dfef20014753c (diff)
downloadFreeBSD-src-a9156607eb32ba4e7ea4afb912838d56a1aabf50.zip
FreeBSD-src-a9156607eb32ba4e7ea4afb912838d56a1aabf50.tar.gz
My previous commit fixed uid filtering, but broke io mode. Unravel the
process filtering logic to prevent this from happening again.
Diffstat (limited to 'usr.bin/top')
-rw-r--r--usr.bin/top/machine.c84
1 files changed, 49 insertions, 35 deletions
diff --git a/usr.bin/top/machine.c b/usr.bin/top/machine.c
index 6734452..bea1c57 100644
--- a/usr.bin/top/machine.c
+++ b/usr.bin/top/machine.c
@@ -546,43 +546,57 @@ get_process_info(si, sel, compare)
{
/*
* Place pointers to each valid proc structure in pref[].
- * Process slots that are actually in use have a non-zero
- * status field. Processes with P_SYSTEM set are system
- * processes---these get ignored unless show_sysprocs is set.
*/
-
- if (pp->ki_stat != 0 &&
- (show_self != pp->ki_pid) &&
- (show_system || ((pp->ki_flag & P_SYSTEM) == 0)))
+
+ if (pp->ki_stat == 0)
+ /* not in use */
+ continue;
+
+ if (!show_self && pp->ki_pid == sel->self)
+ /* skip self */
+ continue;
+
+ if (!show_system && (pp->ki_flag & P_SYSTEM))
+ /* skip system process */
+ continue;
+
+ p_io = get_io_stats(pp, &p_inblock, &p_oublock, &p_majflt);
+ total_inblock += p_inblock;
+ total_oublock += p_oublock;
+ total_majflt += p_majflt;
+ total_procs++;
+ process_states[(unsigned char) pp->ki_stat]++;
+
+ if (pp->ki_stat == SZOMB)
+ /* skip zombies */
+ continue;
+
+ if (displaymode == DISP_CPU && !show_idle &&
+ (pp->ki_pctcpu == 0 || pp->ki_stat != SRUN))
+ /* skip idle or non-running processes */
+ continue;
+
+ if (displaymode == DISP_IO && !show_idle && p_io == 0)
+ /* skip processes that aren't doing I/O */
+ continue;
+
+ if (show_uid && pp->ki_ruid != (uid_t)sel->uid)
+ /* skip processes which don't belong to the selected UID */
+ continue;
+
+ /*
+ * When not showing threads, take the first thread
+ * for output and add the fields that we can from
+ * the rest of the process's threads rather than
+ * using the system's mostly-broken KERN_PROC_PROC.
+ */
+ if (sel->thread || prev_pp == NULL || prev_pp->ki_pid != pp->ki_pid)
{
- p_io = get_io_stats(pp, &p_inblock, &p_oublock, &p_majflt);
- total_inblock += p_inblock;
- total_oublock += p_oublock;
- total_majflt += p_majflt;
- total_procs++;
- process_states[(unsigned char) pp->ki_stat]++;
- if ((pp->ki_stat != SZOMB) &&
- (displaymode == DISP_CPU &&
- (show_idle || (pp->ki_pctcpu != 0) || pp->ki_stat == SRUN)) &&
- (show_idle || (displaymode == DISP_IO && p_io != 0)) &&
- (!show_uid || pp->ki_ruid == (uid_t)sel->uid))
- {
- /*
- * When not showing threads, take the first thread
- * for output and add the fields that we can from
- * the rest of the process's threads rather than
- * using the system's mostly-broken KERN_PROC_PROC.
- */
- if (sel->thread || prev_pp == NULL ||
- prev_pp->ki_pid != pp->ki_pid)
- {
- *prefp++ = pp;
- active_procs++;
- prev_pp = pp;
- } else {
- prev_pp->ki_pctcpu += pp->ki_pctcpu;
- }
- }
+ *prefp++ = pp;
+ active_procs++;
+ prev_pp = pp;
+ } else {
+ prev_pp->ki_pctcpu += pp->ki_pctcpu;
}
}
OpenPOWER on IntegriCloud