From 93568304b034cf1f8bff34090595ff44c6a62986 Mon Sep 17 00:00:00 2001 From: Martin Baulig Date: Thu, 1 Oct 1998 17:04:48 +0000 Subject: [PATCH] Honor the `which' parameter to select which processes to fetch. 1998-10-01 Martin Baulig * proclist.c (glibtop_init_proclist_s): Honor the `which' parameter to select which processes to fetch. --- sysdeps/linux/ChangeLog | 5 +++++ sysdeps/linux/proclist.c | 43 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) diff --git a/sysdeps/linux/ChangeLog b/sysdeps/linux/ChangeLog index 0cdfd28c..3cdeabda 100644 --- a/sysdeps/linux/ChangeLog +++ b/sysdeps/linux/ChangeLog @@ -1,3 +1,8 @@ +1998-10-01 Martin Baulig + + * proclist.c (glibtop_init_proclist_s): Honor the `which' parameter + to select which processes to fetch. + 1998-09-12 Martin Baulig * sysinfo.c: New file. diff --git a/sysdeps/linux/proclist.c b/sysdeps/linux/proclist.c index 92cabaae..d31c7379 100644 --- a/sysdeps/linux/proclist.c +++ b/sysdeps/linux/proclist.c @@ -21,6 +21,7 @@ #include #include +#include #include #include @@ -66,6 +67,7 @@ glibtop_get_proclist_s (glibtop *server, glibtop_proclist *buf, unsigned count, total, pid; unsigned pids [BLOCK_COUNT], *pids_chain = NULL; unsigned pids_size = 0, pids_offset = 0, new_size; + glibtop_proc_uid procuid; struct stat statb; int len, i, ok; @@ -100,6 +102,47 @@ glibtop_get_proclist_s (glibtop *server, glibtop_proclist *buf, if (!S_ISDIR (statb.st_mode)) continue; + switch (which) { + case GLIBTOP_KERN_PROC_ALL: + break; + case GLIBTOP_KERN_PROC_PID: + if ((unsigned) arg != pid) + continue; + break; + case GLIBTOP_KERN_PROC_UID: + if ((uid_t) arg != statb.st_uid) + continue; + break; + case GLIBTOP_KERN_PROC_PGRP: + /* Do you really, really need this ? */ + glibtop_get_proc_uid_s (server, &procuid, pid); + if (procuid.flags & (1 << GLIBTOP_PROC_UID_PGRP)) + if ((int) arg != procuid.pgrp) + continue; + break; + case GLIBTOP_KERN_PROC_SESSION: + /* Do you really, really need this ? */ + glibtop_get_proc_uid_s (server, &procuid, pid); + if (procuid.flags & (1 << GLIBTOP_PROC_UID_SESSION)) + if ((int) arg != procuid.session) + continue; + break; + case GLIBTOP_KERN_PROC_TTY: + /* Do you really, really need this ? */ + glibtop_get_proc_uid_s (server, &procuid, pid); + if (procuid.flags & (1 << GLIBTOP_PROC_UID_TTY)) + if ((int) arg != procuid.tty) + continue; + break; + case GLIBTOP_KERN_PROC_RUID: + /* Do you really, really need this ? */ + glibtop_get_proc_uid_s (server, &procuid, pid); + if (procuid.flags & (1 << GLIBTOP_PROC_UID_EUID)) + if ((int) arg != procuid.euid) + continue; + break; + } + /* Fine. Now we first try to store it in pids. If this buffer is * full, we copy it to the pids_chain. */