summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Baulig <martin@src.gnome.org>1998-08-07 13:14:17 +0000
committerMartin Baulig <martin@src.gnome.org>1998-08-07 13:14:17 +0000
commit35e900692a5d1a8d74c5105bf51da329885eadb3 (patch)
tree040934b671bc638316b32d69c9931364085413cb
parent8e8cb05168a64accfc7a9988cc7ffb3d4c2de710 (diff)
downloadlibgtop-35e900692a5d1a8d74c5105bf51da329885eadb3.tar.gz
Merged some stuff from `stub_suid'.
-rw-r--r--sysdeps/freebsd/cpu.c88
-rw-r--r--sysdeps/freebsd/glibtop_suid.h42
-rw-r--r--sysdeps/freebsd/loadavg.c39
-rw-r--r--sysdeps/freebsd/mem.c84
-rw-r--r--sysdeps/freebsd/msg_limits.c49
-rw-r--r--sysdeps/freebsd/prockernel.c92
-rw-r--r--sysdeps/freebsd/proclist.c67
-rw-r--r--sysdeps/freebsd/procmem.c107
-rw-r--r--sysdeps/freebsd/procsegment.c65
-rw-r--r--sysdeps/freebsd/procsignal.c58
-rw-r--r--sysdeps/freebsd/procstate.c41
-rw-r--r--sysdeps/freebsd/proctime.c21
-rw-r--r--sysdeps/freebsd/procuid.c21
-rw-r--r--sysdeps/freebsd/sem_limits.c18
-rw-r--r--sysdeps/freebsd/shm_limits.c18
-rw-r--r--sysdeps/freebsd/swap.c19
-rw-r--r--sysdeps/freebsd/uptime.c19
17 files changed, 315 insertions, 533 deletions
diff --git a/sysdeps/freebsd/cpu.c b/sysdeps/freebsd/cpu.c
index 903ee03d..25bb8c14 100644
--- a/sysdeps/freebsd/cpu.c
+++ b/sysdeps/freebsd/cpu.c
@@ -2,7 +2,7 @@
/* Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc.
This file is part of the Gnome Top Library.
- Contributed by Joshua Sled <jsled@xcf.berkeley.edu>, July 1998.
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
The Gnome Top Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
@@ -19,84 +19,28 @@
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
-#include <config.h>
+#include <glibtop.h>
+#include <glibtop/error.h>
#include <glibtop/cpu.h>
-#include <nlist.h>
-#include <kvm.h>
-#include <sys/dkstat.h>
-#include <time.h>
-#include <sys/types.h>
-#include <sys/sysctl.h>
+#include <glibtop_suid.h>
-static const unsigned long _glibtop_sysdeps_cpu =
-(1 << GLIBTOP_CPU_TOTAL) + (1 << GLIBTOP_CPU_USER) +
-(1 << GLIBTOP_CPU_NICE) + (1 << GLIBTOP_CPU_SYS) +
-(1 << GLIBTOP_CPU_IDLE) + (1 << GLIBTOP_CPU_FREQUENCY);
+static const unsigned long _glibtop_sysdeps_cpu = 0;
-/* Provides information about cpu usage. */
+/* Init function. */
void
-glibtop_get_cpu_s (glibtop *server, glibtop_cpu *buf)
+glibtop_init_cpu_p (glibtop *server)
{
- /* kvm_* vars */
- kvm_t *kd;
- static const int nlst_length=2;
- long cpts[CPUSTATES];
- /* sysctl vars*/
- static const int mib_length=2;
- int mib[mib_length];
- struct clockinfo ci;
- size_t length;
-
- /* nlist structure for kernel access */
- struct nlist nlst[nlst_length] = {
- { "_cp_time" },
- { 0 }
- };
-
- /* MIB array for sysctl(3) use */
- mib[0] = CTL_KERN;
- mib[1] = KERN_CLOCKRATE;
-
- glibtop_init_r (& server);
-
- memset (buf, 0, sizeof (glibtop_cpu));
-
- /* Get the value out of the kernel */
- if (kvm_open(NULL, NULL, NULL, O_RDONLY, "kvm_open") == NULL) {
- /* If we can't get at the kernel, return the null values we just
- gave the array. */
- return;
- }
- kvm_nlist(kd, &nlst);
- kvm_read(kd, nlst[0].n_value, &cpts, sizeof(cpts));
- kvm_close(kd);
-
- /* Get the clockrate data */
- length = sizeof(clockinfo);
- sysctl(mib, mib_length, &ci, &len, NULL, 0);
-
- buf->flags = _glibtop_sysdeps_cpu;
-
- /* set user time */
- buf->user = cpts[CP_USER];
- /* set nice time */
- buf->nice = cpts[CP_NICE];
- /* set sys time */
- buf->sys = cpts[CP_SYS];
- /* set idle time */
- buf->idle = cpts[CP_IDLE];
- /* set frequency */
- /*
- FIXME -- is hz, tick, profhz or stathz wanted?
- buf->frequency = sysctl("kern.clockrate", ...);
+ server->sysdeps.cpu = _glibtop_sysdeps_cpu;
+}
- struct clockinfo
- */
- buf->frequency = ci.hz;
- /* set total */
- buf->total = cpts[CP_USER] + cpts[CP_NICE]
- + cpts[CP_SYS] + cpts[CP_IDLE];
+/* Provides information about cpu usage. */
+void
+glibtop_get_cpu_p (glibtop *server, glibtop_cpu *buf)
+{
+ glibtop_init_p (server, GLIBTOP_SYSDEPS_CPU, 0);
+
+ memset (buf, 0, sizeof (glibtop_cpu));
}
diff --git a/sysdeps/freebsd/glibtop_suid.h b/sysdeps/freebsd/glibtop_suid.h
new file mode 100644
index 00000000..349d8f2a
--- /dev/null
+++ b/sysdeps/freebsd/glibtop_suid.h
@@ -0,0 +1,42 @@
+/* $Id$ */
+
+/* Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc.
+ This file is part of the Gnome Top Library.
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ The Gnome Top Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The Gnome Top Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#ifndef __GLIBTOP_SUID_H__
+#define __GLIBTOP_SUID_H__
+
+__BEGIN_DECLS
+
+static inline void glibtop_suid_enter (glibtop *server) {
+ setreuid (server->machine.uid, server->machine.euid);
+};
+
+static inline void glibtop_suid_leave (glibtop *server) {
+ if (setreuid (server->machine.euid, server->machine.uid))
+ _exit (1);
+};
+
+extern void glibtop_init_p __P((glibtop *, const unsigned long, const unsigned));
+
+extern void glibtop_open_p __P((glibtop *, const char *, const unsigned long, const unsigned));
+
+__END_DECLS
+
+#endif
diff --git a/sysdeps/freebsd/loadavg.c b/sysdeps/freebsd/loadavg.c
index e54ffec1..733e263b 100644
--- a/sysdeps/freebsd/loadavg.c
+++ b/sysdeps/freebsd/loadavg.c
@@ -2,7 +2,7 @@
/* Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc.
This file is part of the Gnome Top Library.
- Contributed by Joshua Sled <jsled@xcf.berkeley.edu>, July 1998.
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
The Gnome Top Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
@@ -19,31 +19,28 @@
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
-#include <config.h>
+#include <glibtop.h>
+#include <glibtop/error.h>
#include <glibtop/loadavg.h>
-#include <stdlib.h>
+#include <glibtop_suid.h>
-/* Provides load averange. */
+static const unsigned long _glibtop_sysdeps_loadavg = 0;
+
+/* Init function. */
-static const unsigned long _glibtop_sysdeps_loadavg =
-(1 << GLIBTOP_LOADAVG_LOADAVG);
+void
+glibtop_init_loadavg_p (glibtop *server)
+{
+ server->sysdeps.loadavg = _glibtop_sysdeps_loadavg;
+}
+
+/* Provides load averange. */
void
-glibtop_get_loadavg_s (glibtop *server, glibtop_loadavg *buf)
+glibtop_get_loadavg_p (glibtop *server, glibtop_loadavg *buf)
{
- double ldavg[3];
-
- glibtop_init_r (&server);
-
- memset (buf, 0, sizeof (glibtop_loadavg));
-
- getloadavg(ldavg, 3);
-
- /* fill in the struct */
- buf->flags = _glibtop_sysdeps_loadavg;
- for (int i=0; i<3; i++) {
- buf->loadavg[i] = ldavg[i];
- } /* end for */
-
+ glibtop_init_p (server, GLIBTOP_SYSDEPS_LOADAVG, 0);
+
+ memset (buf, 0, sizeof (glibtop_loadavg));
}
diff --git a/sysdeps/freebsd/mem.c b/sysdeps/freebsd/mem.c
index 1dff4185..f379f451 100644
--- a/sysdeps/freebsd/mem.c
+++ b/sysdeps/freebsd/mem.c
@@ -2,7 +2,7 @@
/* Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc.
This file is part of the Gnome Top Library.
- Contributed by Joshua Sled <jsled@xcf.berkeley.edu>, July 1998.
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
The Gnome Top Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
@@ -19,80 +19,28 @@
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
-#include <config.h>
+#include <glibtop.h>
+#include <glibtop/error.h>
#include <glibtop/mem.h>
-#include <sys/types.h>
-#include <sys/sysctl.h>
-#include <sys/vmmeter.h>
+#include <glibtop_suid.h>
-static const unsigned long _glibtop_sysdeps_mem =
-(1 << GLIBTOP_MEM_TOTAL) + (1 << GLIBTOP_MEM_USED) +
-(1 << GLIBTOP_MEM_FREE) + (1 << GLIBTOP_MEM_SHARED) +
-(1 << GLIBTOP_MEM_BUFFER) + (1 << GLIBTOP_MEM_CACHED);
-/* + (1 << GLIBTOP_MEM_USER); */
+static const unsigned long _glibtop_sysdeps_mem = 0;
-/* Provides information about memory usage. */
+/* Init function. */
void
-glibtop_get_mem_s (glibtop *server, glibtop_mem *buf)
+glibtop_init_mem_p (glibtop *server)
{
- /* for kvm_*, which is needed to get cache and buffer data */
- kvm_t *kd;
- struct nlist nlst[3];
- static unsigned long cnt_offset;
- static unsigned long bufsize_offset;
- struct vmtotal vmt;
- static int bufspace = 0;
- /* for sysctl(3) */
- size_t length_vmt;
- int mib_vm[2];
- struct vmmeter vmm;
-
- /* Setup nlist array */
- nlst = {
- { "_cnt" },
- { "_bufspace" },
- { 0 }
- }
-
- /* Setup MIB array for sysctl */
- mib_vm[0] = CTL_VM;
- mib_vm[1] = VM_METER;
-
- glibtop_init_r (&server, 0, 0);
-
- memset (buf, 0, sizeof (glibtop_mem));
-
- /* Get the data from sysctl */
- length_vmt = sizeof(vmt);
- sysctl(mib, 2, &vmt, &length_vmt, NULL, 0);
+ server->sysdeps.mem = _glibtop_sysdeps_mem;
+}
- /* Get the data from kvm_* */
- kd = kvm_open(NULL, NULL, NULL, OD_RDONLY, "kvm_open");
- kvm_nlist(kd, &nlst);
- cnt_offset = nlst[0].n_value;
- bufspace_offset = nlst[1].n_value;
- kvm_read(kd, cnt_offset, &vmm, sizeof(vmm));
- kvm_read(kd, bufspace_offset, &bufspace, sizeof(bufspace));
- kvm_close(kd);
-
- /* Set the values to return */
- buf->flags = _glibtop_sysdeps_mem;
- /* total */
- buf->total = (unsigned long)vmt.t_vm;
- /* used */
- buf->used = (unsigned long)vmt.t_avm;
- /* free */
- buf->free = (unsigned long)vmt.t_free;
- /* shared */
- buf->shared = (unsigned long)vmt.t_vmshr;
- /* buffer */
- buf->buffer = (unsigned long)bufspace;
- /* cached */
- buf->cache = (unsigned long)(vmm.v_cache_count * vmm.v_page_size);
+/* Provides information about memory usage. */
- /* user */
- /* FIXME: Any way to get or calculate this? */
-
+void
+glibtop_get_mem_p (glibtop *server, glibtop_mem *buf)
+{
+ glibtop_init_p (server, GLIBTOP_SYSDEPS_MEM, 0);
+
+ memset (buf, 0, sizeof (glibtop_mem));
}
diff --git a/sysdeps/freebsd/msg_limits.c b/sysdeps/freebsd/msg_limits.c
index a1504cd5..ea1417f2 100644
--- a/sysdeps/freebsd/msg_limits.c
+++ b/sysdeps/freebsd/msg_limits.c
@@ -2,7 +2,7 @@
/* Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc.
This file is part of the Gnome Top Library.
- Contributed by Joshua Sled <jsled@xcf.berkeley.edu>, July 1998.
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
The Gnome Top Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
@@ -19,43 +19,28 @@
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
+#include <glibtop.h>
+#include <glibtop/error.h>
#include <glibtop/msg_limits.h>
-#include <sys/msg.h>
+#include <glibtop_suid.h>
-static const unsigned long _glibtop_sysdeps_msg_limits =
-(1 << GLIBTOP_IPC_MSGMAX) + (1 << GLIBTOP_IPC_MSGMNB) +
-(1 << GLIBTOP_IPC_MSGMNI) + (1 << GLIBTOP_IPC_MSGSSZ) +
-(1 << GLIBTOP_IPC_MSGTQL);
+static const unsigned long _glibtop_sysdeps_msg_limits = 0;
-/* Provides information about sysv ipc limits. */
+/* Init function. */
void
-glibtop_get_msg_limits_s (glibtop *server, glibtop_msg_limits *buf)
+glibtop_init_msg_limits_p (glibtop *server)
{
- glibtop_init_r(&server, 0, 0);
-
- memset (buf, 0, sizeof (glibtop_msg_limits));
-
- /* Set values */
-
- /* msgpool */
- /* Any way to get this?
- Seems to be MSGMAX-bytes long.*/
- /* buf->msgpool = MSGMAX; */
-
- /* msgmap: sys/msg.h ? */
- /* Different type in /usr/include/sys/msg.h */
-
- /* msgmax: sys/msg.h:MSGMAX*/
- buf->msgmax = MSGMAX;
- /* msgmnb: sys/msg.h:MSGMNB */
- buf->msgmnb = MSGMNB;
- /* msgmni: sys/msg.h:MSGMNI */
- buf->msgmni = MSGMNI;
- /* msgssz: sys/msg.h:MSGSSZ */
- buf->msgssz = MSGSSZ;
- /* msgtql: sys/msg.h:MSGTQL */
- buf->msgtql = MSGTQL;
+ server->sysdeps.msg_limits = _glibtop_sysdeps_msg_limits;
}
+/* Provides information about sysv ipc limits. */
+
+void
+glibtop_get_msg_limits_p (glibtop *server, glibtop_msg_limits *buf)
+{
+ glibtop_init_p (server, GLIBTOP_SYSDEPS_MSG_LIMITS, 0);
+
+ memset (buf, 0, sizeof (glibtop_msg_limits));
+}
diff --git a/sysdeps/freebsd/prockernel.c b/sysdeps/freebsd/prockernel.c
index 02f88956..4f183894 100644
--- a/sysdeps/freebsd/prockernel.c
+++ b/sysdeps/freebsd/prockernel.c
@@ -2,7 +2,7 @@
/* Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc.
This file is part of the Gnome Top Library.
- Contributed by Joshua Sled <jsled@xcf.berkeley.edu>, July 1998.
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
The Gnome Top Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
@@ -19,89 +19,29 @@
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
-#include <config.h>
+#include <glibtop.h>
+#include <glibtop/error.h>
#include <glibtop/prockernel.h>
-#include <kvm.h>
-#include <sys/param.h>
-#include <sys/sysctl.h>
-#include <sys/proc.h>
-#include <sys/user.h>
-#include <machine/pcb.h>
-#include <machine/tss.h>
+#include <glibtop_suid.h>
-#include <unistd.h>
-#include <fcntl.h>
+static const unsigned long _glibtop_sysdeps_proc_kernel = 0;
-static const unsigned long _glibtop_sysdeps_proc_kernel =
-(1 << GLIBTOP_PROC_KERNEL_K_FLAGS) +
-(1 << GLIBTOP_PROC_KERNEL_MIN_FLT) +
-(1 << GLIBTOP_PROC_KERNEL_MAJ_FLT) +
-(1 << GLIBTOP_PROC_KERNEL_CMIN_FLT) +
-(1 << GLIBTOP_PROC_KERNEL_CMAJ_FLT) +
-(1 << GLIBTOP_PROC_KERNEL_KSTK_ESP) +
-(1 << GLIBTOP_PROC_KERNEL_KSTK_EIP) +
-(1 << GLIBTOP_PROC_KERNEL_WCHAN);
+/* Init function. */
+
+void
+glibtop_init_proc_kernel_p (glibtop *server)
+{
+ server->sysdeps.proc_kernel = _glibtop_sysdeps_proc_kernel;
+}
/* Provides detailed information about a process. */
void
-glibtop_get_proc_kernel_s (glibtop *server,
- glibtop_proc_kernel *buf,
+glibtop_get_proc_kernel_p (glibtop *server, glibtop_proc_kernel *buf,
pid_t pid)
{
- struct kinfo_proc *pinfo;
- int count;
- struct i386tss *pcb_tss;
- int kmem;
- struct pstats ps;
- struct user usr;
-
- glibtop_init_r (&server, 0, 0);
-
- memset (buf, 0, sizeof (glibtop_proc_kernel));
-
- /* Get the information pertaining to the given PID */
- pinfo = kvm_getprocs(server->machine.kd, KERN_PROC_PID, pid, &count);
- if (count != 1) {
- return; /* the 0-filled struct, since we can't get any info */
- }
-
- kmem = open("/dev/kmem", O_RDONLY, NULL);
- if (f == NULL) {
- /* FIXME: error */
- }
- /* Read the p_stats struct from kernel memory */
- lseek(f, (long)pinfo[0].kp_proc.p_stats, SEEK_SET);
- read(f, &ps, sizeof(pstats));
- /* Read the struct at kp_proc.p_addr */
- lseek(f, (long)pinfo[0].kp_proc.p_addr, SEEK_SET);
- read(f, &usr, sizeof(user));
- close(f);
-
-
- /* kflags:
- kinfo_proc.e_flag?
- proc.p_flag
- proc.p_stat
- */
- buf->kflags = pinfo[0].kp_eproc.e_flag;
-
- /* min_flt: rusage.ru_minflt */
- buf->min_flt = ps.p_ru.ru_minflt;
- /* maj_flt: rusage.ru_majflt */
- buf->majflt = ps.p_ru.ru_majflt;
- /* cmin_flt: */
- buf->cmin_flt = ps.p_cru.ru_minflt;
- /* cmaj_flt: */
- buf->cmaj_flt = ps.p_cru.ru_majflt;
-
- /* kstk_esp: pcb_tss.tss_esp */
- buf->kstk_esp = (unsigned long)usr.u_pcb.pcb_ksp;
- /* kstk_eip: pcb_tss.tss_eip */
- buf->kstk_eip = (unsigned long)usr.u_pcb.pcb_pc;
-
- /* wchan : kinfo_proc.proc.p_wchan */
- buf->wchan = (unsigned long)pinfo[0].kp_proc.p_wchan;
-
+ glibtop_init_p (server, GLIBTOP_SYSDEPS_PROC_KERNEL, 0);
+
+ memset (buf, 0, sizeof (glibtop_proc_kernel));
}
diff --git a/sysdeps/freebsd/proclist.c b/sysdeps/freebsd/proclist.c
index b929a445..d94600ca 100644
--- a/sysdeps/freebsd/proclist.c
+++ b/sysdeps/freebsd/proclist.c
@@ -2,7 +2,7 @@
/* Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc.
This file is part of the Gnome Top Library.
- Contributed by Joshua Sled <jsled@xcf.berkeley.edu>, July 1998.
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
The Gnome Top Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
@@ -19,63 +19,28 @@
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
-#include <config.h>
+#include <glibtop.h>
+#include <glibtop/error.h>
#include <glibtop/proclist.h>
-#include <kvm.h>
-#include <sys/param.h>
-#include <sys/sysctl.h>
+#include <glibtop_suid.h>
-#define GLIBTOP_PROCLIST_FLAGS 3
+static const unsigned long _glibtop_sysdeps_proclist = 0;
-static const unsigned long _glibtop_sysdeps_proclist =
-(1 << GLIBTOP_PROCLIST_TOTAL) + (1 << GLIBTOP_PROCLIST_NUMBER) +
-(1 << GLIBTOP_PROCLIST_SIZE);
+/* Init function. */
-/* Fetch list of currently running processes.
- * The interface of this function is a little bit different from the others:
- * buf->flags is only set if the call succeeded, in this case pids_chain,
- * a list of the pids of all currently running processes is returned,
- * buf->number is the number of elements of this list and buf->size is
- * the size of one single element (sizeof (unsigned)). The total size is
- * stored in buf->total.
- *
- * The calling function has to free the memory to which a pointer is returned.
- *
- * IMPORTANT NOTE:
- * On error, this function MUST return NULL and set buf->flags to zero !
- * On success, it returnes a pointer to a list of buf->number elements
- * each buf->size big. The total size is stored in buf->total.
- * The calling function has to free the memory to which a pointer is returned.
- *
- * On error, NULL is returned and buf->flags is zero. */
+void
+glibtop_init_proclist_p (glibtop *server)
+{
+ server->sysdeps.proclist = _glibtop_sysdeps_proclist;
+}
unsigned *
-glibtop_get_proclist_s (glibtop *server, glibtop_proclist *buf)
+glibtop_get_proclist_p (glibtop *server, glibtop_proclist *buf)
{
- struct kinfo_proc *pinfo;
- unsigned *pids=NULL;
- int count;
- int i;
-
- glibtop_init_r (&server, 0, 0);
-
- memset (buf, 0, sizeof (glibtop_proclist));
+ glibtop_init_p (server, GLIBTOP_SYSDEPS_PROCLIST, 0);
+
+ memset (buf, 0, sizeof (glibtop_proclist));
- /* Get the process data */
- pinfo = kvm_getprocs(server->machine.kd, KERN_PROC_ALL, NULL, &count);
- /* Allocate count objects in the pids_chain array
- Same as malloc is pids is NULL, which it is. */
- pids = glibtop_realloc__r(server, pids, count * sizeof(unsigned));
- /* Copy the pids over to this chain */
- for (i=0; i < count; i++) {
- pids[i] = (unsigned)pinfo[i].kp_proc.p_pid;
- } /* end for */
- /* Set the fields in buf */
- buf->number = count;
- buf->size = sizeof(unsigned);
- buf->total = count * sizeof(unsigned);
- buf->flags = _glibtop_sysdeps_proclist;
- /* return the data */
- return pids;
+ return NULL;
}
diff --git a/sysdeps/freebsd/procmem.c b/sysdeps/freebsd/procmem.c
index 3b762a03..357d9456 100644
--- a/sysdeps/freebsd/procmem.c
+++ b/sysdeps/freebsd/procmem.c
@@ -2,7 +2,7 @@
/* Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc.
This file is part of the Gnome Top Library.
- Contributed by Joshua Sled <jsled@xcf.berkeley.edu>, July 1998.
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
The Gnome Top Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
@@ -19,102 +19,29 @@
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
-#include <config.h>
+#include <glibtop.h>
+#include <glibtop/error.h>
#include <glibtop/procmem.h>
-#include <kvm.h>
-#include <sys/param.h>
-#include <sys/sysctl.h>
-#include <sys/user.h>
-#include <sys/proc.h>
-#include <sys/resource.h>
-#include <vm/vm_map.h>
-#include <machine/pmap.h>
+#include <glibtop_suid.h>
-static const unsigned long _glibtop_sysdeps_proc_mem =
-(1 << GLIBTOP_PROC_MEM_SIZE) +
-(1 << GLIBTOP_PROC_MEM_VSIZE) +
-(1 << GLIBTOP_PROC_MEM_RESIDENT) +
-/* (1 << GLIBTOP_PROC_MEM_SHARE) + */
-(1 << GLIBTOP_PROC_MEM_RSS) +
-(1 << GLIBTOP_PROC_MEM_RSS_RLIM);
+static const unsigned long _glibtop_sysdeps_proc_mem = 0;
-/* Provides detailed information about a process. */
+/* Init function. */
void
-glibtop_get_proc_mem_s (glibtop *server, glibtop_proc_mem *buf,
- pid_t pid)
+glibtop_init_proc_mem_p (glibtop *server)
{
- struct kinfo_proc *pinfo;
- int count;
- struct vmspace vms;
- struct vm_map vmm;
- struct pstats ps;
- int f;
-
- glibtop_init_r(&server, 0, 0);
-
- memset (buf, 0, sizeof (glibtop_proc_mem));
-
- if (pid == 0) {
- /* Client is only interested in the flags. */
- buf->flags = _glibtop_sysdeps_proc_mem;
- return;
- }
-
- f = open("/dev/kmem", O_ORDONLY, NULL);
- if (f == NULL) {
- /* FIXME: error */
- }
- /* Read the vmspace from kernel memeory */
- lseek(f, (long)pinfo[0].kp_proc.p_vmspace, SEEK_SET);
- read(f, &vms, sizeof(vmspace));
- /* Read the vm_map from kernel memeory */
- lseek(f, (long)vms.vm_map, SEEK_SET);
- read(f, &vmm, sizeof(vm_map));
- /* Read the pstats [for the RSS rlimit] from kernel memory. */
- lseek(f, (long)pinfo[0].kp_proc.p_stats, SEEK_SET);
- read(f, &ps, sizeof(pstats));
- close(f);
-
- /* Get the process information */
- kvm_getprocs(server->machine.kd, KERN_PROC_PID, pid, &count);
- if (count != 1) {
- /* Return no information */
- return;
- }
-
- /* size: total # of pages in memory
- (segsz_t)pinfo[0].kp_proc.p_vmspace.(vm_tsize + vm_dsize + vm_ssize)
- */
- buf->size = (unsigned long)(vms.vm_tsize + vms.vm_dsize + vms.vm_ssize);
- /* vsize: number of pages of VM
- (vm_size_t)pinfo[0].kp_proc.p_vmspace.vm_map.size
- */
- buf->vsize = (unsigned long)vmm.size;
-
- /* resident: number of resident (non-swapped) pages [4k]
- (long)pmap_resident_count(pinfo[0]->kp_proc.p_vmspace.vm_map.pmap);
- */
- buf->resident = (unsigned long)pmap_resident_count(vmm.pmap);
-
- /* share: number of pages shared (mmap'd) memory
- ??? vm_object has this info, but how to get it?
- Even if we could, it's not reachable information.
- */
-
-
- /* rss: resident set size
- (segsz_t)kp_proc.p_vmspace.vm_rssize
- */
- buf->rss = (unsigned long)vms.vm_rssize;
- /* rss_rlim: current rss limit [bytes]
- (rlim_t)kp_proc.p_limit.pl_rlimit[RLIMIT_RSS].rlim_cur
- or
- (long)kp_proc.p_stats->p_ru.ru_maxrss */
- buf->rss_rlim = ps.p_ru.ru_maxrss;
+ server->sysdeps.proc_mem = _glibtop_sysdeps_proc_mem;
+}
- /* Set the flags */
- buf->flags = _glibtop_sysdeps_proc_mem;
+/* Provides detailed information about a process. */
+void
+glibtop_get_proc_mem_p (glibtop *server, glibtop_proc_mem *buf,
+ pid_t pid)
+{
+ glibtop_init_p (server, GLIBTOP_SYSDEPS_PROC_MEM, 0);
+
+ memset (buf, 0, sizeof (glibtop_proc_mem));
}
diff --git a/sysdeps/freebsd/procsegment.c b/sysdeps/freebsd/procsegment.c
index 9563b483..0f087b21 100644
--- a/sysdeps/freebsd/procsegment.c
+++ b/sysdeps/freebsd/procsegment.c
@@ -2,7 +2,7 @@
/* Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc.
This file is part of the Gnome Top Library.
- Contributed by Joshua Sled <jsled@xcf.berkeley.edu>, July 1998.
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
The Gnome Top Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
@@ -19,60 +19,29 @@
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
-#include <config.h>
+#include <glibtop.h>
+#include <glibtop/error.h>
#include <glibtop/procsegment.h>
-#include <kvm.h>
-#include <sys/param.h>
-#include <sys/sysctl.h>
+#include <glibtop_suid.h>
-static const unsigned long _glibtop_sysdeps_proc_segment =
-(1 << GLIBTOP_PROC_SEGMENT_TRS);
-/* (1 << GLIBTOP_PROC_SEGMENT_LRS) +
-(1 << GLIBTOP_PROC_SEGMENT_DRS) +
-(1 << GLIBTOP_PROC_SEGMENT_DT) +
-(1 << GLIBTOP_PROC_SEGMENT_START_CODE) +
-(1 << GLIBTOP_PROC_SEGMENT_END_CODE) +
-(1 << GLIBTOP_PROC_SEGMENT_START_STACK) */
+static const unsigned long _glibtop_sysdeps_proc_segment = 0;
-/* Provides detailed information about a process. */
+/* Init function. */
void
-glibtop_get_proc_segment_s (glibtop *server,
- glibtop_proc_segment *buf,
- pid_t pid)
+glibtop_init_proc_segment_p (glibtop *server)
{
- struct kinfo_proc *pinfo;
- int *count;
-
- glibtop_init_r(&server, 0, 0);
-
- memset (buf, 0, sizeof (glibtop_proc_segment));
-
- /* Get the process info from the kernel */
- kvm_getprocs(server->machine.kd, KERN_PROC_PID, pid, count);
- if (*count != 1) {
- return; /* the zeroed-out buffer indicating no data */
- }
+ server->sysdeps.proc_segment = _glibtop_sysdeps_proc_segment;
+}
- /* trs: text resident set size
- pinfo[0]->kp_eproc.e_xrssize;
- */
- buf->trs = pinfo[0]->kp_eproc.e_xrssize;
- /* lrs: shared-lib resident set size
- ? */
- /* drs: data resident set size
- pinfo[0]->kp_eproc.e_vm.vm_map.vm_dsize;
- */
- /* dt: dirty pages
- */
- /* start_code: address of beginning of code segment
-
- */
- /* end_code: address of end of code segment
- */
- /* start_stack: address of the bottom of stack segment
- */
+/* Provides detailed information about a process. */
+void
+glibtop_get_proc_segment_p (glibtop *server, glibtop_proc_segment *buf,
+ pid_t pid)
+{
+ glibtop_init_p (server, GLIBTOP_SYSDEPS_PROC_SEGMENT, 0);
+
+ memset (buf, 0, sizeof (glibtop_proc_segment));
}
-
diff --git a/sysdeps/freebsd/procsignal.c b/sysdeps/freebsd/procsignal.c
index 9d3aa408..63b9ccad 100644
--- a/sysdeps/freebsd/procsignal.c
+++ b/sysdeps/freebsd/procsignal.c
@@ -2,7 +2,7 @@
/* Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc.
This file is part of the Gnome Top Library.
- Contributed by Joshua Sled <jsled@xcf.berkeley.edu>, July 1998.
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
The Gnome Top Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
@@ -19,51 +19,29 @@
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
-#include <config.h>
+#include <glibtop.h>
+#include <glibtop/error.h>
#include <glibtop/procsignal.h>
-static const unsigned long _glibtop_sysdeps_proc_signal =
-(1 << GLIBTOP_PROC_SIGNAL_SIGNAL) +
-(1 << GLIBTOP_PROC_SIGNAL_BLOCKED) +
-(1 << GLIBTOP_PROC_SIGNAL_SIGIGNORE) +
-(1 << GLIBTOP_PROC_SIGNAL_SIGCATCH);
+#include <glibtop_suid.h>
-/* Provides detailed information about a process. */
+static const unsigned long _glibtop_sysdeps_proc_signal = 0;
+
+/* Init function. */
void
-glibtop_get_proc_signal_s (glibtop *server,
- glibtop_proc_signal *buf,
- pid_t pid)
+glibtop_init_proc_signal_p (glibtop *server)
{
- glibtop_init_r(&server, 0, 0);
-
- memset (buf, 0, sizeof (glibtop_proc_signal));
-
- if (pid == 0) {
- /* Client is only interested in the flags. */
- buf->flags = _glibtop_sysdeps_proc_signal;
- return;
- }
-
- /* signal: mask of pending signals.
- pinfo[0].kp_proc.p_siglist
- */
- buf->signal = pinfo[0].kp_proc.p_siglist;
-
- /* blocked: mask of blocked signals.
- pinfo[0].kp_proc.p_sigmask
- */
- buf->blocked = pinfo[0].kp_proc.p_sigmask;
-
- /* sigignore: mask of ignored signals.
- pinfo[0].kp_proc.p_sigignore
- */
- buf->sigignore = pinfo[0].kp_proc.p_sigignore;
-
- /* sigcatch: mask of caught signals.
- pinfo[0].kp_proc.p_sigcatch
- */
- buf->sigcatch = pinfo[0].kp_proc.p_sigcatch;
+ server->sysdeps.proc_signal = _glibtop_sysdeps_proc_signal;
+}
+/* Provides detailed information about a process. */
+void
+glibtop_get_proc_signal_p (glibtop *server, glibtop_proc_signal *buf,
+ pid_t pid)
+{
+ glibtop_init_p (server, GLIBTOP_SYSDEPS_PROC_SIGNAL, 0);
+
+ memset (buf, 0, sizeof (glibtop_proc_signal));
}
diff --git a/sysdeps/freebsd/procstate.c b/sysdeps/freebsd/procstate.c
index e63924bd..c33e3a9b 100644
--- a/sysdeps/freebsd/procstate.c
+++ b/sysdeps/freebsd/procstate.c
@@ -2,7 +2,7 @@
/* Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc.
This file is part of the Gnome Top Library.
- Contributed by Joshua Sled <jsled@xcf.berkeley.edu, July 1998.
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
The Gnome Top Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
@@ -19,34 +19,29 @@
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
-#include <config.h>
+#include <glibtop.h>
+#include <glibtop/error.h>
#include <glibtop/procstate.h>
-static const unsigned long _glibtop_sysdeps_proc_state =
-(1 << GLIBTOP_PROC_STATE_CMD) +
-(1 << GLIBTOP_PROC_STATE_STATE) +
-(1 << GLIBTOP_PROC_STATE_UID) +
-(1 << GLIBTOP_PROC_STATE_GID);
+#include <glibtop_suid.h>
-/* Provides detailed information about a process. */
+static const unsigned long _glibtop_sysdeps_proc_state = 0;
+
+/* Init function. */
void
-glibtop_get_proc_state_s (glibtop *server,
- glibtop_proc_state *buf,
- pid_t pid)
+glibtop_init_proc_state_p (glibtop *server)
{
- glibtop_init_r (&server, 0, 0);
-
- memset (buf, 0, sizeof (glibtop_proc_state));
-
- if (pid == INVALID_PID) {
- /* Client is only interested in the flags. */
- buf->flags = _glibtop_sysdeps_proc_state;
- return;
- }
-
+ server->sysdeps.proc_state = _glibtop_sysdeps_proc_state;
+}
+/* Provides detailed information about a process. */
- /* Set the flags for the data we're about to return*/
- buf->flags = _glibtop_sysdeps_proc_state;
+void
+glibtop_get_proc_state_p (glibtop *server, glibtop_proc_state *buf,
+ pid_t pid)
+{
+ glibtop_init_p (server, GLIBTOP_SYSDEPS_PROC_STATE, 0);
+
+ memset (buf, 0, sizeof (glibtop_proc_state));
}
diff --git a/sysdeps/freebsd/proctime.c b/sysdeps/freebsd/proctime.c
index ec81d2a0..0d51542c 100644
--- a/sysdeps/freebsd/proctime.c
+++ b/sysdeps/freebsd/proctime.c
@@ -19,14 +19,29 @@
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
-#include <config.h>
+#include <glibtop.h>
+#include <glibtop/error.h>
#include <glibtop/proctime.h>
+#include <glibtop_suid.h>
+
+static const unsigned long _glibtop_sysdeps_proc_time = 0;
+
+/* Init function. */
+
+void
+glibtop_init_proc_time_p (glibtop *server)
+{
+ server->sysdeps.proc_time = _glibtop_sysdeps_proc_time;
+}
+
/* Provides detailed information about a process. */
void
-glibtop_get_proc_time__r (glibtop *server, glibtop_proc_time *buf,
- pid_t pid)
+glibtop_get_proc_time_p (glibtop *server, glibtop_proc_time *buf,
+ pid_t pid)
{
+ glibtop_init_p (server, GLIBTOP_SYSDEPS_PROC_TIME, 0);
+
memset (buf, 0, sizeof (glibtop_proc_time));
}
diff --git a/sysdeps/freebsd/procuid.c b/sysdeps/freebsd/procuid.c
index 7fbb85fa..fd6404bf 100644
--- a/sysdeps/freebsd/procuid.c
+++ b/sysdeps/freebsd/procuid.c
@@ -19,14 +19,29 @@
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
-#include <config.h>
+#include <glibtop.h>
+#include <glibtop/error.h>
#include <glibtop/procuid.h>
+#include <glibtop_suid.h>
+
+static const unsigned long _glibtop_sysdeps_proc_uid = 0;
+
+/* Init function. */
+
+void
+glibtop_init_proc_uid_p (glibtop *server)
+{
+ server->sysdeps.proc_uid = _glibtop_sysdeps_proc_uid;
+}
+
/* Provides detailed information about a process. */
void
-glibtop_get_proc_uid__r (glibtop *server, glibtop_proc_uid *buf,
- pid_t pid)
+glibtop_get_proc_uid_p (glibtop *server, glibtop_proc_uid *buf,
+ pid_t pid)
{
+ glibtop_init_p (server, GLIBTOP_SYSDEPS_PROC_UID, 0);
+
memset (buf, 0, sizeof (glibtop_proc_uid));
}
diff --git a/sysdeps/freebsd/sem_limits.c b/sysdeps/freebsd/sem_limits.c
index 3768408b..188dc4d9 100644
--- a/sysdeps/freebsd/sem_limits.c
+++ b/sysdeps/freebsd/sem_limits.c
@@ -19,12 +19,28 @@
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
+#include <glibtop.h>
+#include <glibtop/error.h>
#include <glibtop/sem_limits.h>
+#include <glibtop_suid.h>
+
+static const unsigned long _glibtop_sysdeps_sem_limits = 0;
+
+/* Init function. */
+
+void
+glibtop_init_sem_limits_p (glibtop *server)
+{
+ server->sysdeps.sem_limits = _glibtop_sysdeps_sem_limits;
+}
+
/* Provides information about sysv sem limits. */
void
-glibtop_get_sem_limits__r (glibtop *server, glibtop_sem_limits *buf)
+glibtop_get_sem_limits_p (glibtop *server, glibtop_sem_limits *buf)
{
+ glibtop_init_p (server, GLIBTOP_SYSDEPS_SEM_LIMITS, 0);
+
memset (buf, 0, sizeof (glibtop_sem_limits));
}
diff --git a/sysdeps/freebsd/shm_limits.c b/sysdeps/freebsd/shm_limits.c
index 52e801ba..6f81c819 100644
--- a/sysdeps/freebsd/shm_limits.c
+++ b/sysdeps/freebsd/shm_limits.c
@@ -19,12 +19,28 @@
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
+#include <glibtop.h>
+#include <glibtop/error.h>
#include <glibtop/shm_limits.h>
+#include <glibtop_suid.h>
+
+static const unsigned long _glibtop_sysdeps_shm_limits = 0;
+
+/* Init function. */
+
+void
+glibtop_init_shm_limits_p (glibtop *server)
+{
+ server->sysdeps.shm_limits = _glibtop_sysdeps_shm_limits;
+}
+
/* Provides information about sysv ipc limits. */
void
-glibtop_get_shm_limits__r (glibtop *server, glibtop_shm_limits *buf)
+glibtop_get_shm_limits_p (glibtop *server, glibtop_shm_limits *buf)
{
+ glibtop_init_p (server, GLIBTOP_SYSDEPS_SHM_LIMITS, 0);
+
memset (buf, 0, sizeof (glibtop_shm_limits));
}
diff --git a/sysdeps/freebsd/swap.c b/sysdeps/freebsd/swap.c
index 8e0d046b..e0f72cae 100644
--- a/sysdeps/freebsd/swap.c
+++ b/sysdeps/freebsd/swap.c
@@ -19,13 +19,28 @@
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
-#include <config.h>
+#include <glibtop.h>
+#include <glibtop/error.h>
#include <glibtop/swap.h>
+#include <glibtop_suid.h>
+
+static const unsigned long _glibtop_sysdeps_swap = 0;
+
+/* Init function. */
+
+void
+glibtop_init_swap_p (glibtop *server)
+{
+ server->sysdeps.swap = _glibtop_sysdeps_swap;
+}
+
/* Provides information about swap usage. */
void
-glibtop_get_swap__r (glibtop *server, glibtop_swap *buf)
+glibtop_get_swap_p (glibtop *server, glibtop_swap *buf)
{
+ glibtop_init_p (server, GLIBTOP_SYSDEPS_SWAP, 0);
+
memset (buf, 0, sizeof (glibtop_swap));
}
diff --git a/sysdeps/freebsd/uptime.c b/sysdeps/freebsd/uptime.c
index 5b9ea63f..5aa76522 100644
--- a/sysdeps/freebsd/uptime.c
+++ b/sysdeps/freebsd/uptime.c
@@ -19,13 +19,28 @@
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
-#include <config.h>
+#include <glibtop.h>
+#include <glibtop/error.h>
#include <glibtop/uptime.h>
+#include <glibtop_suid.h>
+
+static const unsigned long _glibtop_sysdeps_uptime = 0;
+
+/* Init function. */
+
+void
+glibtop_init_uptime_p (glibtop *server)
+{
+ server->sysdeps.uptime = _glibtop_sysdeps_uptime;
+}
+
/* Provides uptime and idle time. */
void
-glibtop_get_uptime__r (glibtop *server, glibtop_uptime *buf)
+glibtop_get_uptime_p (glibtop *server, glibtop_uptime *buf)
{
+ glibtop_init_p (server, GLIBTOP_SYSDEPS_UPTIME, 0);
+
memset (buf, 0, sizeof (glibtop_uptime));
}