diff options
author | Martin Baulig <martin@src.gnome.org> | 1998-08-16 13:40:15 +0000 |
---|---|---|
committer | Martin Baulig <martin@src.gnome.org> | 1998-08-16 13:40:15 +0000 |
commit | 77f56522c52d147c4163647bf03d9fe19e0df1de (patch) | |
tree | a93f4280a4817c5dd3e7c4d79543369c7c244158 | |
parent | b40e08fb74efa3027103a7e606028e64db3afa66 (diff) | |
download | libgtop-77f56522c52d147c4163647bf03d9fe19e0df1de.tar.gz |
*** empty log message ***
-rw-r--r-- | kernel/table.h | 20 | ||||
-rw-r--r-- | kernel/table20/main.c | 29 | ||||
-rw-r--r-- | kernel/table21/module.c | 51 | ||||
-rw-r--r-- | kernel/version.h | 1 | ||||
-rw-r--r-- | sysdeps/kernel/proclist.c | 6 | ||||
-rw-r--r-- | sysdeps/kernel/procstate.c | 6 |
6 files changed, 106 insertions, 7 deletions
diff --git a/kernel/table.h b/kernel/table.h index 6dac48d4..d4959370 100644 --- a/kernel/table.h +++ b/kernel/table.h @@ -7,6 +7,20 @@ #define NR_TASKS 512 #endif +#define TABLE_KERN_PROC_ALL 0 /* all processes */ +#define TABLE_KERN_PROC_PID 1 +#define TABLE_KERN_PROC_PGRP 2 +#define TABLE_KERN_PROC_SESSION 3 +#define TABLE_KERN_PROC_TTY 4 +#define TABLE_KERN_PROC_UID 5 +#define TABLE_KERN_PROC_RUID 6 + +#define TABLE_KERN_PROC_MASK 15 + +#define TABLE_EXCLUDE_IDLE 0x1000 +#define TABLE_EXCLUDE_SYSTEM 0x2000 +#define TABLE_EXCLUDE_NOTTY 0x4000 + #define TABLE_VERSION 0 #define TABLE_CPU 1 #define TABLE_MEM 2 @@ -77,6 +91,11 @@ struct table_uptime /* Process list. */ +struct proclist_args +{ + int which, arg; +}; + struct table_proclist { int nr_running, nr_tasks, last_pid; @@ -90,6 +109,7 @@ struct table_proc_state long state; unsigned long flags; char comm[16]; + int uid, gid; }; struct table_proc_uid diff --git a/kernel/table20/main.c b/kernel/table20/main.c index b5397eba..97950afb 100644 --- a/kernel/table20/main.c +++ b/kernel/table20/main.c @@ -189,6 +189,9 @@ sys_table (int type, union table *buf, const void *param) union table tbl; struct sysinfo i; struct task_struct *tsk = NULL; + struct ip_chain *chain; + struct ip_fwkernel *rule; + char devname [9]; int index, err; pid_t pid; @@ -219,6 +222,14 @@ sys_table (int type, union table *buf, const void *param) if (tsk == NULL) return -ESRCH; break; + case TABLE_NETACCT: + err = verify_area (VERIFY_READ, param, 5); + if (err) + return err; + copy_from_user (devname, param, 5); + devname [5] = 0; + + break; } /* Main function dispatcher */ @@ -426,6 +437,24 @@ sys_table (int type, union table *buf, const void *param) tbl.proc_kernel.wchan = get_wchan (tsk); break; + case TABLE_NETACCT: + for (chain = ip_fw_chains; chain; chain = chain->next) { + for (rule = chain->chain; rule; rule = rule->next) { + const char *name = rule->ipfw.fw_vianame; + int k; + + if (name [0] && !strncmp (param, name, 5)) + continue; + + for (k = 0; k < NUM_SLOTS; k++) { + tbl.netacct.packets += + rule->counters[k].pcnt; + tbl.netacct.bytes += + rule->counters[k].bcnt; + } + } + } + break; default: return -EINVAL; } diff --git a/kernel/table21/module.c b/kernel/table21/module.c index 9b55eca6..739c23dc 100644 --- a/kernel/table21/module.c +++ b/kernel/table21/module.c @@ -304,8 +304,9 @@ table_fkt (int type, union table *buf, const void *param) union table tbl; struct sysinfo i; struct task_struct *tsk = NULL; + struct proclist_args plistargs; + int index, tindex, err, tty; sigset_t sigign, sigcatch; - int index, tindex, err; pid_t pid; if (type == TABLE_VERSION) @@ -339,6 +340,14 @@ table_fkt (int type, union table *buf, const void *param) if (tsk == NULL) return -ESRCH; break; + case TABLE_PROCLIST: + err = verify_area (VERIFY_READ, param, + sizeof (struct proclist_args)); + if (err) + return err; + copy_from_user (&plistargs, param, + sizeof (struct proclist_args)); + break; } /* Main function dispatcher */ @@ -347,10 +356,40 @@ table_fkt (int type, union table *buf, const void *param) case TABLE_PROCLIST: tsk = task [0]; read_lock (&tasklist_lock); - for (index = tindex = 0; index < nr_tasks; index++) { - if (tsk->pid) - tbl.proclist.pids [tindex++] = tsk->pid; - tsk = tsk->next_task; + for (index = tindex = 0; index < nr_tasks; + index++, tsk = tsk->next_task) { + if (tsk->pid == 0) continue; + switch (plistargs.which & TABLE_KERN_PROC_MASK) { + case TABLE_KERN_PROC_PID: + if (tsk->pid != plistargs.arg) continue; + break; + case TABLE_KERN_PROC_PGRP: + if (tsk->pgrp != plistargs.arg) continue; + break; + case TABLE_KERN_PROC_SESSION: + if (tsk->session != plistargs.arg) continue; + case TABLE_KERN_PROC_TTY: + tty = tsk->tty ? + kdev_t_to_nr (tsk->tty->device) : 0; + if (tty != plistargs.arg) continue; + break; + case TABLE_KERN_PROC_UID: + if (tsk->uid != plistargs.arg) continue; + break; + case TABLE_KERN_PROC_RUID: + if (tsk->euid != plistargs.arg) continue; + break; + } + + if ((plistargs.which & TABLE_EXCLUDE_IDLE) && + (tsk->state != 0)) + continue; + + if ((plistargs.which & TABLE_EXCLUDE_NOTTY) && + (tsk->tty == NULL)) + continue; + + tbl.proclist.pids [tindex++] = tsk->pid; } tbl.proclist.nr_running = nr_running; tbl.proclist.last_pid = last_pid; @@ -395,6 +434,8 @@ table_fkt (int type, union table *buf, const void *param) task[0]->times.tms_stime; break; case TABLE_PROC_STATE: + tbl.proc_state.uid = tsk->uid; + tbl.proc_state.gid = tsk->gid; tbl.proc_state.state = tsk->state; tbl.proc_state.flags = tsk->flags; memcpy (tbl.proc_state.comm, tsk->comm, diff --git a/kernel/version.h b/kernel/version.h new file mode 100644 index 00000000..d47411ee --- /dev/null +++ b/kernel/version.h @@ -0,0 +1 @@ +#define _TABLE_VERSION 1 diff --git a/sysdeps/kernel/proclist.c b/sysdeps/kernel/proclist.c index e9289444..5a4f9871 100644 --- a/sysdeps/kernel/proclist.c +++ b/sysdeps/kernel/proclist.c @@ -59,12 +59,16 @@ glibtop_get_proclist_s (glibtop *server, glibtop_proclist *buf, { union table tbl; unsigned *pids_chain; + struct proclist_args args; glibtop_init_s (&server, GLIBTOP_SYSDEPS_PROCLIST, 0); memset (buf, 0, sizeof (glibtop_proclist)); - if (table (TABLE_PROCLIST, &tbl, NULL)) + args.which = which; + args.arg = arg; + + if (table (TABLE_PROCLIST, &tbl, &args)) glibtop_error_io_r (server, "table(TABLE_PROCLIST)"); buf->size = sizeof (unsigned); diff --git a/sysdeps/kernel/procstate.c b/sysdeps/kernel/procstate.c index 6776af46..5dd06399 100644 --- a/sysdeps/kernel/procstate.c +++ b/sysdeps/kernel/procstate.c @@ -26,7 +26,8 @@ #include "kernel.h" static const unsigned long _glibtop_sysdeps_proc_state = -(1 << GLIBTOP_PROC_STATE_CMD) + (1 << GLIBTOP_PROC_STATE_STATE); +(1 << GLIBTOP_PROC_STATE_CMD) + (1 << GLIBTOP_PROC_STATE_STATE) + +(1 << GLIBTOP_PROC_STATE_UID) + (1 << GLIBTOP_PROC_STATE_GID); /* Init function. */ @@ -60,6 +61,9 @@ glibtop_get_proc_state_s (glibtop *server, glibtop_proc_state *buf, memcpy (buf->cmd, tbl.proc_state.comm, sizeof (tbl.proc_state.comm)); + buf->uid = tbl.proc_state.uid; + buf->gid = tbl.proc_state.state; + state = (unsigned) tbl.proc_state.state; if (state >= NR_STATES) |