summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Baulig <martin@src.gnome.org>1998-08-06 23:34:50 +0000
committerMartin Baulig <martin@src.gnome.org>1998-08-06 23:34:50 +0000
commit79f5a9c667cbdb6ddff84372115efb15020a49f7 (patch)
tree32addd94f4190d910c5e29585740c8585f37a7e1
parent864867aeeb8088f4e178472005a710bad629347c (diff)
downloadlibgtop-79f5a9c667cbdb6ddff84372115efb15020a49f7.tar.gz
Importing FreeBSD port of libgtop from Josh Sled.freebsd_0_1
-rw-r--r--sysdeps/freebsd/Makefile.am11
-rw-r--r--sysdeps/freebsd/close.c4
-rw-r--r--sysdeps/freebsd/cpu.c104
-rw-r--r--sysdeps/freebsd/glibtop_machine.h65
-rw-r--r--sysdeps/freebsd/loadavg.c24
-rw-r--r--sysdeps/freebsd/mem.c73
-rw-r--r--sysdeps/freebsd/msg_limits.c37
-rw-r--r--sysdeps/freebsd/open.c128
-rw-r--r--sysdeps/freebsd/prockernel.c81
-rw-r--r--sysdeps/freebsd/proclist.c52
-rw-r--r--sysdeps/freebsd/procmem.c94
-rw-r--r--sysdeps/freebsd/procsegment.c52
-rw-r--r--sysdeps/freebsd/procsignal.c43
-rw-r--r--sysdeps/freebsd/procstate.c26
-rw-r--r--sysdeps/freebsd/proctime.c4
-rw-r--r--sysdeps/freebsd/procuid.c4
-rw-r--r--sysdeps/freebsd/sem_limits.c2
-rw-r--r--sysdeps/freebsd/shm_limits.c2
-rw-r--r--sysdeps/freebsd/swap.c2
-rw-r--r--sysdeps/freebsd/uptime.c2
20 files changed, 560 insertions, 250 deletions
diff --git a/sysdeps/freebsd/Makefile.am b/sysdeps/freebsd/Makefile.am
index 046ec1bd..9c188950 100644
--- a/sysdeps/freebsd/Makefile.am
+++ b/sysdeps/freebsd/Makefile.am
@@ -1,15 +1,16 @@
LINK = $(LIBTOOL) --mode=link $(CC) $(CFLAGS) $(LDFLAGS) -o $@
-CFLAGS = -Wall -W @CFLAGS@
+INCLUDES = -I$(includedir) -I$(top_builddir) -I$(top_srcdir) @machine_incs@ \
+ -I$(top_srcdir)/include -I$(top_srcdir)/intl @GUILE_INCS@ \
+ -DGTOPLOCALEDIR=\"$(datadir)/locale\" -D_GNU_SOURCE
-lib_LTLIBRARIES = libgtop_sysdeps.la libgtop_sysdeps_suid.la
+CFLAGS = -Wall -W @CFLAGS@
-libgtop_sysdeps_la_SOURCES = nosuid.c siglist.c
+lib_LTLIBRARIES = libgtop_sysdeps.la
-libgtop_sysdeps_suid_la_SOURCES = open.c close.c siglist.c cpu.c mem.c swap.c \
+libgtop_sysdeps_la_SOURCES = init.c open.c close.c cpu.c mem.c swap.c \
uptime.c loadavg.c shm_limits.c msg_limits.c \
sem_limits.c proclist.c procstate.c procuid.c \
proctime.c procmem.c procsignal.c prockernel.c \
procsegment.c
-include_HEADERS = glibtop_server.h glibtop_machine.h
diff --git a/sysdeps/freebsd/close.c b/sysdeps/freebsd/close.c
index 9506f275..55229adf 100644
--- a/sysdeps/freebsd/close.c
+++ b/sysdeps/freebsd/close.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 Martin Baulig <martin@home-of-linux.org>, April 1998.
+ Contributed by Joshua Sled <jsled@xcf.berkeley.edu>, July 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
@@ -24,5 +24,5 @@
/* Closes pipe to gtop server. */
void
-glibtop_close_s (glibtop *server)
+glibtop_close_l (glibtop *server)
{ }
diff --git a/sysdeps/freebsd/cpu.c b/sysdeps/freebsd/cpu.c
index e6be9d7a..903ee03d 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 Martin Baulig <martin@home-of-linux.org>, April 1998.
+ Contributed by Joshua Sled <jsled@xcf.berkeley.edu>, July 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
@@ -22,6 +22,13 @@
#include <config.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>
+
static const unsigned long _glibtop_sysdeps_cpu =
(1 << GLIBTOP_CPU_TOTAL) + (1 << GLIBTOP_CPU_USER) +
(1 << GLIBTOP_CPU_NICE) + (1 << GLIBTOP_CPU_SYS) +
@@ -30,41 +37,66 @@ static const unsigned long _glibtop_sysdeps_cpu =
/* Provides information about cpu usage. */
void
-glibtop_get_cpu_p (glibtop *server, glibtop_cpu *buf)
+glibtop_get_cpu_s (glibtop *server, glibtop_cpu *buf)
{
- long cp_time [CPUSTATES];
- int i;
-
- glibtop_init_p (server, 0, 0);
-
- memset (buf, 0, sizeof (glibtop_cpu));
-
- /* !!! THE FOLLOWING CODE RUNS SGID KMEM - CHANGE WITH CAUTION !!! */
-
- setregid (server->machine.gid, server->machine.egid);
-
- /* get the cp_time array */
-
- (void) _glibtop_getkval (server, _glibtop_nlist [X_CP_TIME].n_value,
- (int *) cp_time, sizeof (cp_time),
- _glibtop_nlist [X_CP_TIME].n_name);
-
- if (setregid (server->machine.egid, server->machine.gid))
- _exit (1);
-
- /* !!! END OF SUID ROOT PART !!! */
-
- buf->user = cp_time [CP_USER];
- buf->nice = cp_time [CP_NICE];
- buf->sys = cp_time [CP_SYS];
- buf->idle = cp_time [CP_IDLE];
- buf->frequency = server->machine.hz;
-
- /* Calculate total time. */
-
- buf->total = buf->user + buf->nice + buf->sys + buf->idle;
-
- /* Now we can set the flags. */
+ /* 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", ...);
+
+ struct clockinfo
+ */
+ buf->frequency = ci.hz;
+ /* set total */
+ buf->total = cpts[CP_USER] + cpts[CP_NICE]
+ + cpts[CP_SYS] + cpts[CP_IDLE];
- buf->flags = _glibtop_sysdeps_cpu;
}
diff --git a/sysdeps/freebsd/glibtop_machine.h b/sysdeps/freebsd/glibtop_machine.h
index 5f404a5f..9fb3afdc 100644
--- a/sysdeps/freebsd/glibtop_machine.h
+++ b/sysdeps/freebsd/glibtop_machine.h
@@ -22,64 +22,17 @@
#ifndef __GLIBTOP_MACHINE_H__
#define __GLIBTOP_MACHINE_H__
-#include <sys/types.h>
-#include <sys/signal.h>
-#include <sys/param.h>
-
-#include <stdio.h>
-#include <nlist.h>
-#include <math.h>
-#include <kvm.h>
-#include <sys/errno.h>
-#include <sys/sysctl.h>
-#include <sys/dir.h>
-#include <sys/dkstat.h>
-#include <sys/file.h>
-#include <sys/time.h>
-
-#include <stdlib.h>
-#include <sys/rlist.h>
-#include <sys/conf.h>
-
-__BEGIN_DECLS
-
-#define X_CCPU 0
-#define X_CP_TIME 1
-#define X_HZ 2
-#define X_STATHZ 3
-#define X_AVENRUN 4
-#define VM_SWAPLIST 5 /* list of free swap areas */
-#define VM_SWDEVT 6 /* list of swap devices and sizes */
-#define VM_NSWAP 7 /* size of largest swap device */
-#define VM_NSWDEV 8 /* number of swap devices */
-#define VM_DMMAX 9 /* maximum size of a swap block */
-#define X_CNT 10 /* struct vmmeter cnt */
-#define X_LASTPID 11
-
-typedef struct _glibtop_machine glibtop_machine;
+typedef struct _glibtop_machine glibtop_machine;
struct _glibtop_machine
{
- uid_t uid, euid; /* Real and effective user id */
- gid_t gid, egid; /* Real and effective group id */
- int nlist_count; /* Number of symbols in the nlist */
- u_int64_t hz; /* Tick frequency */
- int ncpu; /* Number of CPUs we have */
- kvm_t *kd;
-};
-
-/* Those functions are used internally in libgtop */
+ uid_t uid, euid;
+ gid_t gid, egid;
-#ifdef _IN_LIBGTOP
-
-extern struct nlist _glibtop_nlist[];
-
-extern int _glibtop_check_nlist __P((void *, register struct nlist *));
-
-extern int _glibtop_getkval __P((void *, unsigned long, int *, int, char *));
-
-#endif
-
-__END_DECLS
+ /* The kernel descriptor, used by kvm_* calls. We keep and re-use
+ it rather than re-getting it for almost all function
+ invocations. */
+ kvm_t *kd;
+};
-#endif
+#endif __GLIBTOP_MACHINE_H__
diff --git a/sysdeps/freebsd/loadavg.c b/sysdeps/freebsd/loadavg.c
index 714485e9..e54ffec1 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 Martin Baulig <martin@home-of-linux.org>, April 1998.
+ Contributed by Joshua Sled <jsled@xcf.berkeley.edu>, July 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
@@ -22,10 +22,28 @@
#include <config.h>
#include <glibtop/loadavg.h>
+#include <stdlib.h>
+
/* Provides load averange. */
+static const unsigned long _glibtop_sysdeps_loadavg =
+(1 << GLIBTOP_LOADAVG_LOADAVG);
+
void
-glibtop_get_loadavg_p (glibtop *server, glibtop_loadavg *buf)
+glibtop_get_loadavg_s (glibtop *server, glibtop_loadavg *buf)
{
- memset (buf, 0, sizeof (glibtop_loadavg));
+ 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 */
+
}
diff --git a/sysdeps/freebsd/mem.c b/sysdeps/freebsd/mem.c
index 9618a575..1dff4185 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 Martin Baulig <martin@home-of-linux.org>, April 1998.
+ Contributed by Joshua Sled <jsled@xcf.berkeley.edu>, July 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
@@ -22,10 +22,77 @@
#include <config.h>
#include <glibtop/mem.h>
+#include <sys/types.h>
+#include <sys/sysctl.h>
+#include <sys/vmmeter.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); */
+
/* Provides information about memory usage. */
void
-glibtop_get_mem_p (glibtop *server, glibtop_mem *buf)
+glibtop_get_mem_s (glibtop *server, glibtop_mem *buf)
{
- memset (buf, 0, sizeof (glibtop_mem));
+ /* 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);
+
+ /* 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);
+
+ /* user */
+ /* FIXME: Any way to get or calculate this? */
+
}
diff --git a/sysdeps/freebsd/msg_limits.c b/sysdeps/freebsd/msg_limits.c
index fbe5b3a5..a1504cd5 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 Martin Baulig <martin@home-of-linux.org>, April 1998.
+ Contributed by Joshua Sled <jsled@xcf.berkeley.edu>, July 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
@@ -21,10 +21,41 @@
#include <glibtop/msg_limits.h>
+#include <sys/msg.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);
+
/* Provides information about sysv ipc limits. */
void
-glibtop_get_msg_limits_p (glibtop *server, glibtop_msg_limits *buf)
+glibtop_get_msg_limits_s (glibtop *server, glibtop_msg_limits *buf)
{
- memset (buf, 0, sizeof (glibtop_msg_limits));
+ 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;
}
+
diff --git a/sysdeps/freebsd/open.c b/sysdeps/freebsd/open.c
index 0a9e408b..e4c0b48b 100644
--- a/sysdeps/freebsd/open.c
+++ b/sysdeps/freebsd/open.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 Martin Baulig <martin@home-of-linux.org>, April 1998.
+ Contributed by Joshua Sled <jsled@xcf.berkeley.edu>, July 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,126 +19,26 @@
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
-#include <glibtop.h>
#include <glibtop/open.h>
-#include <glibtop/xmalloc.h>
-struct nlist _glibtop_nlist[] = {
- { "_ccpu" }, /* 0 */
- { "_cp_time" }, /* 1 */
- { "_hz" }, /* 2 */
- { "_stathz" }, /* 3 */
- { "_averunnable" }, /* 4 */
- { "_swaplist" }, /* 5 */
- { "_swdevt" }, /* 6 */
- { "_nswap" }, /* 7 */
- { "_nswdev" }, /* 8 */
- { "_dmmax" }, /* 9 */
- { "_cnt" }, /* 10 */
- { "_nextpid" }, /* 11 */
- { 0 }
-};
+#include <kvm.h>
+#include <osreldate.h>
/* Opens pipe to gtop server. Returns 0 on success and -1 on error. */
-/* !!! THIS FUNCTION RUNS SUID ROOT - CHANGE WITH CAUTION !!! */
-
void
-glibtop_init_p (glibtop *server, const unsigned long features,
- const unsigned flags)
-{
- if (server == NULL)
- glibtop_error_r (NULL, "glibtop_init_p (server == NULL)");
-
- glibtop_open_p (server, "glibtop", features, flags);
-}
-
-void
-glibtop_open_p (glibtop *server, const char *program_name,
- const unsigned long features, const unsigned flags)
-{
- fprintf (stderr, "DEBUG (%d): glibtop_open_p ()\n", getpid ());
-
- /* !!! WE ARE ROOT HERE - CHANGE WITH CAUTION !!! */
-
- server->name = program_name;
-
- server->machine.uid = getuid ();
- server->machine.euid = geteuid ();
- server->machine.gid = getgid ();
- server->machine.egid = getegid ();
-
- /* initialize the kernel interface */
-
- server->machine.kd = kvm_open (NULL, NULL, NULL, O_RDONLY, "libgtop");
-
- if (server->machine.kd == NULL)
- glibtop_error_io_r (server, "kvm_open");
-
- /* get the list of symbols we want to access in the kernel */
-
- server->machine.nlist_count = kvm_nlist
- (server->machine.kd, _glibtop_nlist);
-
- /* On FreeBSD, kvm_nlist () returns the number of invalid
- * entries in the nlist. */
-
- if (server->machine.nlist_count)
- glibtop_error_io_r (server, "nlist");
-
- /* Get tick frequency. */
-
- (void) _glibtop_getkval (server, _glibtop_nlist [X_STATHZ].n_value,
- (int *) &server->machine.hz,
- sizeof (server->machine.hz),
- _glibtop_nlist [X_STATHZ].n_name);
-
- if (!server->machine.hz)
- (void) _glibtop_getkval
- (server, _glibtop_nlist [X_HZ].n_value,
- (int *) &server->machine.hz,
- sizeof (server->machine.hz),
- _glibtop_nlist [X_STATHZ].n_name);
-
- /* Drop priviledges. */
-
- if (setreuid (server->machine.euid, server->machine.uid))
- _exit (1);
-
- if (setregid (server->machine.egid, server->machine.gid))
- _exit (1);
-
- /* !!! END OF SUID ROOT PART !!! */
-
- /* Our effective uid is now those of the user invoking the server,
- * so we do no longer have any priviledges. */
-
- /* NOTE: On SunOS, we do not need to be suid root, we just need to
- * be sgid kmem.
- *
- * The server will only use setegid() to get back it's priviledges,
- * so it will fail if it is suid root and not sgid kmem. */
-}
-
-/* Used internally. Fetches value from kernel. */
-
-int
-_glibtop_getkval (void *void_server, unsigned long offset, int *ptr,
- int size, char *refstr)
+glibtop_open (glibtop *server, const char *program_name,
+ const unsigned long features, const unsigned flags)
{
- glibtop *server = (glibtop *) void_server;
+ memset (server, 0, sizeof (glibtop));
+ server->name = program_name;
- fprintf (stderr, "DEBUG: kvm_read: %d - %lu - %p - %lu\n",
- server->machine.kd, offset, ptr, size);
+ server->os_version_code = __FreeBSD_version;
+
+ /* Setup machine-specific data */
+ server->machine.kd = kvm_open(NULL, NULL, NULL, O_RDONLY, "kvm_open");
+ if (server->machine.kd == NULL) {
+ /* FIXME: error */
+ }
- if (kvm_read (server->machine.kd, offset, ptr, size) != size)
- {
- if (*refstr == '!') return 0;
-
- glibtop_error_r (server, "kvm_read(%s): %s",
- refstr, strerror (errno));
- }
-
- return 1;
}
-
diff --git a/sysdeps/freebsd/prockernel.c b/sysdeps/freebsd/prockernel.c
index 9312f924..02f88956 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 Martin Baulig <martin@home-of-linux.org>, April 1998.
+ Contributed by Joshua Sled <jsled@xcf.berkeley.edu>, July 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
@@ -22,11 +22,86 @@
#include <config.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 <unistd.h>
+#include <fcntl.h>
+
+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);
+
/* Provides detailed information about a process. */
void
-glibtop_get_proc_kernel_p (glibtop *server, glibtop_proc_kernel *buf,
+glibtop_get_proc_kernel_s (glibtop *server,
+ glibtop_proc_kernel *buf,
pid_t pid)
{
- memset (buf, 0, sizeof (glibtop_proc_kernel));
+ 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;
+
}
diff --git a/sysdeps/freebsd/proclist.c b/sysdeps/freebsd/proclist.c
index 916d73ab..b929a445 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 Martin Baulig <martin@home-of-linux.org>, April 1998.
+ Contributed by Joshua Sled <jsled@xcf.berkeley.edu>, July 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
@@ -22,18 +22,60 @@
#include <config.h>
#include <glibtop/proclist.h>
+#include <kvm.h>
+#include <sys/param.h>
+#include <sys/sysctl.h>
+
#define GLIBTOP_PROCLIST_FLAGS 3
+static const unsigned long _glibtop_sysdeps_proclist =
+(1 << GLIBTOP_PROCLIST_TOTAL) + (1 << GLIBTOP_PROCLIST_NUMBER) +
+(1 << GLIBTOP_PROCLIST_SIZE);
+
/* 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. */
+ * 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. */
unsigned *
-glibtop_get_proclist_p (glibtop *server, glibtop_proclist *buf)
+glibtop_get_proclist_s (glibtop *server, glibtop_proclist *buf)
{
- memset (buf, 0, sizeof (glibtop_proclist));
- return NULL;
+ struct kinfo_proc *pinfo;
+ unsigned *pids=NULL;
+ int count;
+ int i;
+
+ glibtop_init_r (&server, 0, 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;
}
diff --git a/sysdeps/freebsd/procmem.c b/sysdeps/freebsd/procmem.c
index 70eadd88..3b762a03 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 Martin Baulig <martin@home-of-linux.org>, April 1998.
+ Contributed by Joshua Sled <jsled@xcf.berkeley.edu>, July 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
@@ -22,11 +22,99 @@
#include <config.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>
+
+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);
+
/* Provides detailed information about a process. */
void
-glibtop_get_proc_mem_p (glibtop *server, glibtop_proc_mem *buf,
+glibtop_get_proc_mem_s (glibtop *server, glibtop_proc_mem *buf,
pid_t pid)
{
- memset (buf, 0, sizeof (glibtop_proc_mem));
+ 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;
+
+ /* Set the flags */
+ buf->flags = _glibtop_sysdeps_proc_mem;
+
}
diff --git a/sysdeps/freebsd/procsegment.c b/sysdeps/freebsd/procsegment.c
index 6bc504d1..9563b483 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 Martin Baulig <martin@home-of-linux.org>, April 1998.
+ Contributed by Joshua Sled <jsled@xcf.berkeley.edu>, July 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
@@ -22,11 +22,57 @@
#include <config.h>
#include <glibtop/procsegment.h>
+#include <kvm.h>
+#include <sys/param.h>
+#include <sys/sysctl.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) */
+
/* Provides detailed information about a process. */
void
-glibtop_get_proc_segment_p (glibtop *server, glibtop_proc_segment *buf,
+glibtop_get_proc_segment_s (glibtop *server,
+ glibtop_proc_segment *buf,
pid_t pid)
{
- memset (buf, 0, sizeof (glibtop_proc_segment));
+ 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 */
+ }
+
+ /* 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
+ */
+
}
+
diff --git a/sysdeps/freebsd/procsignal.c b/sysdeps/freebsd/procsignal.c
index 09f4c7d0..9d3aa408 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 Martin Baulig <martin@home-of-linux.org>, April 1998.
+ Contributed by Joshua Sled <jsled@xcf.berkeley.edu>, July 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
@@ -22,11 +22,48 @@
#include <config.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);
+
/* Provides detailed information about a process. */
void
-glibtop_get_proc_signal_p (glibtop *server, glibtop_proc_signal *buf,
+glibtop_get_proc_signal_s (glibtop *server,
+ glibtop_proc_signal *buf,
pid_t pid)
{
- memset (buf, 0, sizeof (glibtop_proc_signal));
+ 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;
+
+
}
diff --git a/sysdeps/freebsd/procstate.c b/sysdeps/freebsd/procstate.c
index 4a3bd963..e63924bd 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 Martin Baulig <martin@home-of-linux.org>, April 1998.
+ Contributed by Joshua Sled <jsled@xcf.berkeley.edu, July 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
@@ -22,11 +22,31 @@
#include <config.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);
+
/* Provides detailed information about a process. */
void
-glibtop_get_proc_state_p (glibtop *server, glibtop_proc_state *buf,
+glibtop_get_proc_state_s (glibtop *server,
+ glibtop_proc_state *buf,
pid_t pid)
{
- memset (buf, 0, sizeof (glibtop_proc_state));
+ 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;
+ }
+
+
+
+ /* Set the flags for the data we're about to return*/
+ buf->flags = _glibtop_sysdeps_proc_state;
}
diff --git a/sysdeps/freebsd/proctime.c b/sysdeps/freebsd/proctime.c
index c0e6fddc..ec81d2a0 100644
--- a/sysdeps/freebsd/proctime.c
+++ b/sysdeps/freebsd/proctime.c
@@ -25,8 +25,8 @@
/* Provides detailed information about a process. */
void
-glibtop_get_proc_time_p (glibtop *server, glibtop_proc_time *buf,
- pid_t pid)
+glibtop_get_proc_time__r (glibtop *server, glibtop_proc_time *buf,
+ pid_t pid)
{
memset (buf, 0, sizeof (glibtop_proc_time));
}
diff --git a/sysdeps/freebsd/procuid.c b/sysdeps/freebsd/procuid.c
index 759652f6..7fbb85fa 100644
--- a/sysdeps/freebsd/procuid.c
+++ b/sysdeps/freebsd/procuid.c
@@ -25,8 +25,8 @@
/* Provides detailed information about a process. */
void
-glibtop_get_proc_uid_p (glibtop *server, glibtop_proc_uid *buf,
- pid_t pid)
+glibtop_get_proc_uid__r (glibtop *server, glibtop_proc_uid *buf,
+ pid_t pid)
{
memset (buf, 0, sizeof (glibtop_proc_uid));
}
diff --git a/sysdeps/freebsd/sem_limits.c b/sysdeps/freebsd/sem_limits.c
index 35790c04..3768408b 100644
--- a/sysdeps/freebsd/sem_limits.c
+++ b/sysdeps/freebsd/sem_limits.c
@@ -24,7 +24,7 @@
/* Provides information about sysv sem limits. */
void
-glibtop_get_sem_limits_p (glibtop *server, glibtop_sem_limits *buf)
+glibtop_get_sem_limits__r (glibtop *server, glibtop_sem_limits *buf)
{
memset (buf, 0, sizeof (glibtop_sem_limits));
}
diff --git a/sysdeps/freebsd/shm_limits.c b/sysdeps/freebsd/shm_limits.c
index b7695150..52e801ba 100644
--- a/sysdeps/freebsd/shm_limits.c
+++ b/sysdeps/freebsd/shm_limits.c
@@ -24,7 +24,7 @@
/* Provides information about sysv ipc limits. */
void
-glibtop_get_shm_limits_p (glibtop *server, glibtop_shm_limits *buf)
+glibtop_get_shm_limits__r (glibtop *server, glibtop_shm_limits *buf)
{
memset (buf, 0, sizeof (glibtop_shm_limits));
}
diff --git a/sysdeps/freebsd/swap.c b/sysdeps/freebsd/swap.c
index 1a5a7476..8e0d046b 100644
--- a/sysdeps/freebsd/swap.c
+++ b/sysdeps/freebsd/swap.c
@@ -25,7 +25,7 @@
/* Provides information about swap usage. */
void
-glibtop_get_swap_p (glibtop *server, glibtop_swap *buf)
+glibtop_get_swap__r (glibtop *server, glibtop_swap *buf)
{
memset (buf, 0, sizeof (glibtop_swap));
}
diff --git a/sysdeps/freebsd/uptime.c b/sysdeps/freebsd/uptime.c
index 0bda199a..5b9ea63f 100644
--- a/sysdeps/freebsd/uptime.c
+++ b/sysdeps/freebsd/uptime.c
@@ -25,7 +25,7 @@
/* Provides uptime and idle time. */
void
-glibtop_get_uptime_p (glibtop *server, glibtop_uptime *buf)
+glibtop_get_uptime__r (glibtop *server, glibtop_uptime *buf)
{
memset (buf, 0, sizeof (glibtop_uptime));
}