more ifdef cleaning

This commit is contained in:
jasper 2011-05-23 18:47:30 +00:00
parent 832c9594c4
commit 99cbaafb32
11 changed files with 1 additions and 472 deletions

View File

@ -28,23 +28,14 @@
#include <sys/sysctl.h>
#include <sys/vmmeter.h>
#if defined(__NetBSD__) && (__NetBSD_Version__ < 105020000)
#include <vm/vm_param.h>
#endif
#if defined(__NetBSD__) && (__NetBSD_Version__ >= 104000000) || defined(__OpenBSD__)
#include <uvm/uvm_extern.h>
#include <uvm/uvm_param.h>
#endif
static const unsigned long _glibtop_sysdeps_mem =
(1L << GLIBTOP_MEM_TOTAL) + (1L << GLIBTOP_MEM_USED) +
(1L << GLIBTOP_MEM_FREE) +
(1L << GLIBTOP_MEM_SHARED) +
(1L << GLIBTOP_MEM_BUFFER) +
#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
(1L << GLIBTOP_MEM_CACHED) +
#endif
(1L << GLIBTOP_MEM_USER) + (1L << GLIBTOP_MEM_LOCKED);
#ifndef LOG1024
@ -59,32 +50,13 @@ static int pageshift; /* log base 2 of the pagesize */
/* nlist structure for kernel access */
static struct nlist nlst [] = {
#if defined(__NetBSD__) && (__NetBSD_Version__ >= 104000000) || defined(__OpenBSD__)
{ "_bufpages" },
{ 0 }
#else
#if defined(__bsdi__)
{ "_bufcachemem" },
#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
{ "_bufspace" },
#else
{ "_bufpages" },
#endif
{ "_cnt" },
{ 0 }
#endif
};
/* MIB array for sysctl */
#ifdef __bsdi__
static int mib [] = { CTL_VM, VM_TOTAL };
#else
static int mib [] = { CTL_VM, VM_METER };
#endif
#if defined(__NetBSD__) && (__NetBSD_Version__ >= 104000000) || defined(__OpenBSD__)
static int mib_uvmexp [] = { CTL_VM, VM_UVMEXP };
#endif
/* Init function. */
@ -118,12 +90,8 @@ glibtop_get_mem_p (glibtop *server, glibtop_mem *buf)
{
struct vmtotal vmt;
size_t length_vmt;
#if defined(__NetBSD__) && (__NetBSD_Version__ >= 104000000) || defined(__OpenBSD__)
struct uvmexp uvmexp;
size_t length_uvmexp;
#else
struct vmmeter vmm;
#endif
u_int v_used_count;
u_int v_total_count;
u_int v_free_count;
@ -147,20 +115,11 @@ glibtop_get_mem_p (glibtop *server, glibtop_mem *buf)
return;
}
#if defined(__NetBSD__) && (__NetBSD_Version__ >= 104000000) || defined(__OpenBSD__)
length_uvmexp = sizeof (uvmexp);
if (sysctl (mib_uvmexp, 2, &uvmexp, &length_uvmexp, NULL, 0)) {
glibtop_warn_io_r (server, "sysctl (uvmexp)");
return;
}
#else
/* Get the data from kvm_* */
if (kvm_read (server->machine.kd, nlst[1].n_value,
&vmm, sizeof (vmm)) != sizeof (vmm)) {
glibtop_warn_io_r (server, "kvm_read (cnt)");
return;
}
#endif
if (kvm_read (server->machine.kd, nlst[0].n_value,
&bufspace, sizeof (bufspace)) != sizeof (bufspace)) {
@ -170,50 +129,20 @@ glibtop_get_mem_p (glibtop *server, glibtop_mem *buf)
/* convert memory stats to Kbytes */
#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
v_total_count = vmm.v_page_count;
#else
#if defined(__NetBSD__) && (__NetBSD_Version__ >= 104000000) || defined(__OpenBSD__)
v_total_count = uvmexp.reserve_kernel +
uvmexp.reserve_pagedaemon +
uvmexp.free + uvmexp.wired + uvmexp.active +
uvmexp.inactive;
#else
v_total_count = vmm.v_kernel_pages +
vmm.v_free_count + vmm.v_wire_count +
vmm.v_active_count + vmm.v_inactive_count;
#endif
#endif
#if defined(__NetBSD__) && (__NetBSD_Version__ >= 104000000) || defined(__OpenBSD__)
v_used_count = uvmexp.active + uvmexp.inactive;
v_free_count = uvmexp.free;
#else
v_used_count = vmm.v_active_count + vmm.v_inactive_count;
v_free_count = vmm.v_free_count;
#endif
buf->total = (guint64) pagetok (v_total_count) << LOG1024;
buf->used = (guint64) pagetok (v_used_count) << LOG1024;
buf->free = (guint64) pagetok (v_free_count) << LOG1024;
#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
buf->cached = (guint64) pagetok (vmm.v_cache_count) << LOG1024;
#endif
#if defined(__NetBSD__) && (__NetBSD_Version__ >= 104000000) || defined(__OpenBSD__)
buf->locked = (guint64) pagetok (uvmexp.wired) << LOG1024;
#else
buf->locked = (guint64) pagetok (vmm.v_wire_count) << LOG1024;
#endif
buf->shared = (guint64) pagetok (vmt.t_rmshr) << LOG1024;
#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
buf->buffer = (guint64) bufspace;
#else
buf->buffer = (guint64) pagetok (bufspace) << LOG1024;
#endif
/* user */
buf->user = buf->total - buf->free - buf->shared - buf->buffer;

View File

@ -26,23 +26,6 @@
#include <glibtop_suid.h>
#if (defined __bsdi__) && (_BSDI_VERSION < 199700)
/* Older versions of BSDI don't seem to have this. */
void
_glibtop_init_msg_limits_p (glibtop *server)
{ }
void
glibtop_get_msg_limits_p (glibtop *server, glibtop_msg_limits *buf)
{
glibtop_init_p (server, (1L << GLIBTOP_SYSDEPS_MSG_LIMITS), 0);
memset (buf, 0, sizeof (glibtop_msg_limits));
}
#else
/* Define the appropriate macro (if any) to get declaration of `struct
* msginfo'. Needed on, at least, FreeBSD. */
#if defined (STRUCT_MSGINFO_NEEDS_KERNEL)
@ -109,6 +92,3 @@ glibtop_get_msg_limits_p (glibtop *server, glibtop_msg_limits *buf)
buf->flags = _glibtop_sysdeps_msg_limits;
}
#endif /* either a newer BSDI or no BSDI at all. */

View File

@ -54,9 +54,7 @@ static const unsigned long _glibtop_sysdeps_netload =
static const unsigned _glibtop_sysdeps_netload_data =
(1L << GLIBTOP_NETLOAD_ADDRESS) +
#if !defined(__bsdi__)
(1L << GLIBTOP_NETLOAD_SUBNET) +
#endif
(1L << GLIBTOP_NETLOAD_MTU);
/* nlist structure for kernel access */
@ -85,9 +83,6 @@ glibtop_get_netload_p (glibtop *server, glibtop_netload *buf,
struct ifnet ifnet;
u_long ifnetaddr, ifnetfound;
struct sockaddr *sa = NULL;
#if (defined(__FreeBSD__) && (__FreeBSD_version < 501113)) || defined(__bsdi__)
char tname [16];
#endif
char name [32];
union {
@ -115,33 +110,13 @@ glibtop_get_netload_p (glibtop *server, glibtop_netload *buf,
sizeof (ifnet)) != sizeof (ifnet))
glibtop_error_io_r (server, "kvm_read (ifnetaddr)");
#if (defined(__FreeBSD__) && (__FreeBSD_version < 501113)) || defined(__bsdi__)
if (kvm_read (server->machine.kd, (u_long) ifnet.if_name,
tname, 16) != 16)
glibtop_error_io_r (server, "kvm_read (if_name)");
tname[15] = '\0';
snprintf (name, 32, "%s%d", tname, ifnet.if_unit);
#else
g_strlcpy (name, ifnet.if_xname, sizeof(name));
#endif
#if defined(__FreeBSD__) && (__FreeBSD_version >= 300000)
ifnetaddr = (u_long) ifnet.if_link.tqe_next;
#elif defined(__FreeBSD__) || defined(__bsdi__)
ifnetaddr = (u_long) ifnet.if_next;
#else
ifnetaddr = (u_long) ifnet.if_list.tqe_next;
#endif
if (strcmp (name, interface) != 0)
continue;
#if defined(__FreeBSD__) && (__FreeBSD_version >= 300000)
ifaddraddr = (u_long) ifnet.if_addrhead.tqh_first;
#elif defined(__FreeBSD__) || defined(__bsdi__)
ifaddraddr = (u_long) ifnet.if_addrlist;
#else
ifaddraddr = (u_long) ifnet.if_addrlist.tqh_first;
#endif
}
if (ifnet.if_flags & IFF_UP)
buf->if_flags |= (1L << GLIBTOP_IF_FLAGS_UP);
@ -179,10 +154,6 @@ glibtop_get_netload_p (glibtop *server, glibtop_netload *buf,
buf->if_flags |= (1L << GLIBTOP_IF_FLAGS_LINK1);
if (ifnet.if_flags & IFF_LINK2)
buf->if_flags |= (1L << GLIBTOP_IF_FLAGS_LINK2);
#ifdef __FreeBSD__
if (ifnet.if_flags & IFF_ALTPHYS)
buf->if_flags |= (1L << GLIBTOP_IF_FLAGS_ALTPHYS);
#endif
if (ifnet.if_flags & IFF_MULTICAST)
buf->if_flags |= (1L << GLIBTOP_IF_FLAGS_MULTICAST);
@ -218,16 +189,7 @@ glibtop_get_netload_p (glibtop *server, glibtop_netload *buf,
buf->flags |= GLIBTOP_NETLOAD_HWADDRESS;
} else if (sa->sa_family == AF_INET) {
sin = (struct sockaddr_in *)sa;
#if !defined(__bsdi__)
/* Commenting out to "fix" #13345. */
#if defined(__NetBSD__)
buf->subnet = ifaddr.in.ia_net;
#elif defined(__OpenBSD__)
buf->subnet = ifaddr.in.ia_netmask;
#else
buf->subnet = htonl (ifaddr.in.ia_subnet);
#endif
#endif
buf->address = sin->sin_addr.s_addr;
buf->mtu = ifnet.if_mtu;
@ -239,11 +201,7 @@ glibtop_get_netload_p (glibtop *server, glibtop_netload *buf,
buf->flags |= GLIBTOP_NETLOAD_ADDRESS6;
}
/* FIXME prefix6, scope6 */
#if defined (__OpenBSD__)
ifaddraddr = (u_long) ifaddr.ifa.ifa_list.tqe_next;
#else
ifaddraddr = (u_long) ifaddr.ifa.ifa_link.tqe_next;
#endif
}
return;
}

View File

@ -64,10 +64,6 @@ glibtop_open_p (glibtop *server, const char *program_name,
server->machine.gid = getgid ();
server->machine.egid = getegid ();
#ifdef __FreeBSD__
server->os_version_code = __FreeBSD_version;
#endif
/* Setup machine-specific data */
server->machine.kd = kvm_open (NULL, NULL, NULL, O_RDONLY, "kvm_open");

View File

@ -38,11 +38,7 @@
#include <net/netisr.h>
#include <net/route.h>
#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__)
#include <net/if_sppp.h>
#else
#include <i4b/sppp/if_sppp.h>
#endif
/* Read `misc/i4b_acct.txt' for details ... */
#ifdef HAVE_I4B_ACCT

View File

@ -47,20 +47,11 @@ char *
glibtop_get_proc_args_p (glibtop *server, glibtop_proc_args *buf,
pid_t pid, unsigned max_len)
{
#if defined(__OpenBSD__)
struct kinfo_proc2 *pinfo;
#else
struct kinfo_proc *pinfo;
#endif
char *retval, **args, **ptr;
size_t size = 0, pos = 0;
int count;
#if !defined(__bsdi__) && !defined(__OpenBSD__)
char filename [BUFSIZ];
struct stat statb;
#endif
glibtop_init_p (server, (1L << GLIBTOP_SYSDEPS_PROC_ARGS), 0);
memset (buf, 0, sizeof (glibtop_proc_args));
@ -68,31 +59,18 @@ glibtop_get_proc_args_p (glibtop *server, glibtop_proc_args *buf,
/* swapper, init, pagedaemon, vmdaemon, update - this doen't work. */
if (pid < 5) return NULL;
#if !defined(__bsdi__) && !defined(__OpenBSD__)
sprintf (filename, "/proc/%d/mem", pid);
if (stat (filename, &statb)) return NULL;
#endif
glibtop_suid_enter (server);
/* Get the process data */
#if defined(__OpenBSD__)
pinfo = kvm_getproc2 (server->machine.kd, KERN_PROC_PID, pid,
sizeof (*pinfo), &count);
#else
pinfo = kvm_getprocs (server->machine.kd, KERN_PROC_PID, pid, &count);
#endif
if ((pinfo == NULL) || (count < 1)) {
glibtop_suid_leave (server);
glibtop_warn_io_r (server, "kvm_getprocs (%d)", pid);
return NULL;
}
#if defined(__OpenBSD__)
args = kvm_getargv2 (server->machine.kd, pinfo, max_len);
#else
args = kvm_getargv (server->machine.kd, pinfo, max_len);
#endif
if (args == NULL) {
glibtop_suid_leave (server);
glibtop_warn_io_r (server, "kvm_getargv (%d)", pid);

View File

@ -60,11 +60,7 @@ pid_t *
glibtop_get_proclist_p (glibtop *server, glibtop_proclist *buf,
gint64 real_which, gint64 arg)
{
#if defined(__OpenBSD__)
struct kinfo_proc2 *pinfo;
#else
struct kinfo_proc *pinfo;
#endif
unsigned *pids = NULL;
int which, count;
int i,j;
@ -76,12 +72,8 @@ glibtop_get_proclist_p (glibtop *server, glibtop_proclist *buf,
which = (int)(real_which & GLIBTOP_KERN_PROC_MASK);
/* Get the process data */
#if defined(__OpenBSD__)
pinfo = kvm_getproc2 (server->machine.kd, which, arg,
sizeof (*pinfo), &count);
#else
pinfo = kvm_getprocs (server->machine.kd, which, arg, &count);
#endif
if ((pinfo == NULL) || (count < 1)) {
glibtop_warn_io_r (server, "kvm_getprocs (proclist)");
return NULL;
@ -93,24 +85,10 @@ glibtop_get_proclist_p (glibtop *server, glibtop_proclist *buf,
pids = g_realloc (pids, count * sizeof (unsigned));
/* Copy the pids over to this chain */
for (i=j=0; i < count; i++) {
#if (defined(__FreeBSD__) && (__FreeBSD_version >= 500013)) || defined(__FreeBSD_kernel__)
#define PROC_STAT ki_stat
#define PROC_RUID ki_ruid
#define PROC_PID ki_pid
#elif defined(__OpenBSD__)
#define PROC_STAT p_stat
#define PROC_RUID p_ruid
#define PROC_PID p_pid
#else
#define PROC_STAT kp_proc.p_stat
#define PROC_RUID kp_eproc.e_pcred.p_ruid
#define PROC_PID kp_proc.p_pid
#endif
if ((real_which & GLIBTOP_EXCLUDE_IDLE) &&
(pinfo[i].PROC_STAT != SRUN))
continue;

View File

@ -28,10 +28,6 @@
#include <sys/param.h>
#ifdef __FreeBSD__
#include <osreldate.h>
#endif
static const unsigned long _glibtop_sysdeps_proc_signal =
(1L << GLIBTOP_PROC_SIGNAL_SIGNAL) +
(1L << GLIBTOP_PROC_SIGNAL_BLOCKED) +
@ -51,11 +47,7 @@ glibtop_get_proc_signal_p (glibtop *server,
glibtop_proc_signal *buf,
pid_t pid)
{
#if defined(__OpenBSD__)
struct kinfo_proc2 *pinfo;
#else
struct kinfo_proc *pinfo;
#endif
int count = 0;
glibtop_init_p (server, (1L << GLIBTOP_SYSDEPS_PROC_SIGNAL), 0);
@ -66,100 +58,32 @@ glibtop_get_proc_signal_p (glibtop *server,
if (pid == 0) return;
/* Get the process information */
#if defined(__OpenBSD__)
pinfo = kvm_getproc2 (server->machine.kd, KERN_PROC_PID, pid,
sizeof (*pinfo), &count);
#else
pinfo = kvm_getprocs (server->machine.kd, KERN_PROC_PID, pid, &count);
#endif
if ((pinfo == NULL) || (count != 1)) {
glibtop_warn_io_r (server, "kvm_getprocs (%d)", pid);
return;
}
#if (defined(__FreeBSD__) && (__FreeBSD_version >= 500013)) || defined(__FreeBSD_kernel__)
#define PROC_SIGLIST ki_siglist
#define PROC_SIGMASK ki_sigmask
#define PROC_SIGIGNORE ki_sigignore
#define PROC_SIGCATCH ki_sigcatch
#elif defined(__OpenBSD__)
/* nothing to see here, move along */
#else
#define PROC_SIGLIST kp_proc.p_siglist
#define PROC_SIGMASK kp_proc.p_sigmask
#define PROC_SIGIGNORE kp_proc.p_sigignore
#define PROC_SIGCATCH kp_proc.p_sigcatch
#endif
/* signal: mask of pending signals.
* pinfo [0].kp_proc.p_siglist
*/
#if defined(__OpenBSD__)
buf->signal [0] = pinfo [0].p_siglist;
#else
#if defined(__NetBSD__) && (__NetBSD_Version__ >= 105150000)
buf->signal [0] = pinfo [0].kp_proc.p_sigctx.ps_siglist.__bits[0];
#elif (defined(__NetBSD__) && (NSIG > 32)) || \
(defined(__FreeBSD__) && (__FreeBSD_version >= 400011) || defined(__FreeBSD_kernel__))
buf->signal [0] = pinfo [0].PROC_SIGLIST.__bits[0];
#else
buf->signal [0] = pinfo [0].kp_proc.p_siglist;
#endif
#endif /* __OpenBSD__ */
/* blocked: mask of blocked signals.
* pinfo [0].kp_proc.p_sigmask
*/
#if defined(__OpenBSD__)
buf->blocked [0] = pinfo [0].p_sigmask;
#else
#if defined(__NetBSD__) && (__NetBSD_Version__ >= 105150000)
buf->blocked [0] = pinfo [0].kp_proc.p_sigctx.ps_sigmask.__bits[0];
#elif (defined(__NetBSD__) && (NSIG > 32)) || \
(defined(__FreeBSD__) && (__FreeBSD_version >= 400011) || defined(__FreeBSD_kernel__))
buf->blocked [0] = pinfo [0].PROC_SIGMASK.__bits[0];
#else
buf->blocked [0] = pinfo [0].kp_proc.p_sigmask;
#endif
#endif /* __OpenBSD__ */
/* sigignore: mask of ignored signals.
* pinfo [0].kp_proc.p_sigignore
*/
#if defined(__OpenBSD__)
buf->sigignore [0] = pinfo [0].p_sigignore;
#else
#if defined(__NetBSD__) && (__NetBSD_Version__ >= 105150000)
buf->sigignore [0] = pinfo [0].kp_proc.p_sigctx.ps_sigignore.__bits[0];
#elif (defined(__NetBSD__) && (NSIG > 32)) || \
(defined(__FreeBSD__) && (__FreeBSD_version >= 400011) || defined(__FreeBSD_kernel__))
buf->sigignore [0] = pinfo [0].PROC_SIGIGNORE.__bits[0];
#else
buf->sigignore [0] = pinfo [0].kp_proc.p_sigignore;
#endif
#endif /* __OpenBSD__ */
/* sigcatch: mask of caught signals.
* pinfo [0].kp_proc.p_sigcatch
*/
#if defined(__OpenBSD__)
buf->sigcatch [0] = pinfo [0].p_sigcatch;
#else
#if defined(__NetBSD__) && (__NetBSD_Version__ >= 105150000)
buf->sigcatch [0] = pinfo [0].kp_proc.p_sigctx.ps_sigcatch.__bits[0];
#elif (defined(__NetBSD__) && (NSIG > 32)) || \
(defined(__FreeBSD__) && (__FreeBSD_version >= 400011) || defined(__FreeBSD_kernel__))
buf->sigcatch [0] = pinfo [0].PROC_SIGCATCH.__bits[0];
#else
buf->sigcatch [0] = pinfo [0].kp_proc.p_sigcatch;
#endif
#endif /* __OpenBSD__ */
buf->flags = _glibtop_sysdeps_proc_signal;
}

View File

@ -26,11 +26,6 @@
#include <glibtop_suid.h>
#if !defined(__OpenBSD__)
/* && (!defined __bsdi__) */
#include <sys/user.h>
#endif
static const unsigned long _glibtop_sysdeps_proc_state =
(1L << GLIBTOP_PROC_STATE_CMD) + (1L << GLIBTOP_PROC_STATE_UID) +
(1L << GLIBTOP_PROC_STATE_GID);
@ -54,11 +49,7 @@ glibtop_get_proc_state_p (glibtop *server,
glibtop_proc_state *buf,
pid_t pid)
{
#if defined(__OpenBSD__)
struct kinfo_proc2 *pinfo;
#else
struct kinfo_proc *pinfo;
#endif
int count = 0;
glibtop_init_p (server, (1L << GLIBTOP_SYSDEPS_PROC_STATE), 0);
@ -69,42 +60,18 @@ glibtop_get_proc_state_p (glibtop *server,
if (pid == 0) return;
/* Get the process information */
#if defined(__OpenBSD__)
pinfo = kvm_getproc2 (server->machine.kd, KERN_PROC_PID, pid,
sizeof (*pinfo), &count);
#else
pinfo = kvm_getprocs (server->machine.kd, KERN_PROC_PID, pid, &count);
#endif
if ((pinfo == NULL) || (count != 1)) {
glibtop_warn_io_r (server, "kvm_getprocs (%d)", pid);
return;
}
#if (defined(__FreeBSD__) && (__FreeBSD_version >= 500013)) || defined(__FreeBSD_kernel__)
#define PROC_COMM ki_comm
#define PROC_SVUID ki_svuid
#define PROC_SVGID ki_svgid
#define PROC_RUID ki_ruid
#define PROC_RGID ki_rgid
#define PROC_STAT ki_stat
#elif defined(__OpenBSD__)
#define PROC_COMM p_comm
#define PROC_SVUID p_svuid
#define PROC_SVGID p_svgid
#define PROC_STAT p_stat
#else
#define PROC_COMM kp_proc.p_comm
#define PROC_SVUID kp_eproc.e_pcred.p_svuid
#define PROC_SVGID kp_eproc.e_pcred.p_svgid
#define PROC_RUID kp_eproc.e_pcred.p_ruid
#define PROC_RGID kp_eproc.e_pcred.p_rgid
#define PROC_STAT kp_proc.p_stat
#endif
g_strlcpy (buf->cmd, pinfo [0].PROC_COMM, sizeof buf->cmd);
buf->uid = pinfo [0].PROC_SVUID;

View File

@ -26,10 +26,6 @@
#include <glibtop_suid.h>
#ifdef __FreeBSD__
#include <osreldate.h>
#endif
static const unsigned long _glibtop_sysdeps_proc_time =
(1L << GLIBTOP_PROC_TIME_RTIME) + (1L << GLIBTOP_PROC_TIME_FREQUENCY);
@ -40,17 +36,14 @@ static const unsigned long _glibtop_sysdeps_proc_time_user =
#define tv2sec(tv) (((guint64) tv.tv_sec * 1000000) + (guint64) tv.tv_usec)
#if defined(__NetBSD__) || defined(__OpenBSD__)
static unsigned int clockrate;
static const int mib [] = { CTL_KERN, KERN_CLOCKRATE };
#endif
/* Init function. */
void
_glibtop_init_proc_time_p (glibtop *server)
{
#if defined(__NetBSD__) || defined(__OpenBSD__)
struct clockinfo ci;
size_t length;
length = sizeof (ci);
@ -58,7 +51,7 @@ _glibtop_init_proc_time_p (glibtop *server)
clockrate = ci.hz;
if (!clockrate)
clockrate = 1; /* XXX avoid div by 0 later */
#endif
server->sysdeps.proc_time = _glibtop_sysdeps_proc_time |
_glibtop_sysdeps_proc_time_user;
}
@ -70,8 +63,6 @@ _glibtop_init_proc_time_p (glibtop *server)
* system, and interrupt time usage.
*/
#if !(defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__NetBSD__) || defined(__OpenBSD__))
static void
calcru(p, up, sp, ip)
struct proc *p;
@ -120,7 +111,6 @@ calcru(p, up, sp, ip)
ip->tv_usec = it % 1000000;
}
}
#endif /* !__FreeBSD__ */
/* Provides detailed information about a process. */
@ -128,13 +118,7 @@ void
glibtop_get_proc_time_p (glibtop *server, glibtop_proc_time *buf,
pid_t pid)
{
#if defined (__NetBSD__) || defined(__OpenBSD__)
struct kinfo_proc2 *pinfo;
#else
struct kinfo_proc *pinfo;
struct user *u_addr = (struct user *)USRSTACK;
struct pstats pstats;
#endif
int count;
glibtop_init_p (server, (1L << GLIBTOP_SYSDEPS_PROC_TIME), 0);
@ -144,40 +128,21 @@ glibtop_get_proc_time_p (glibtop *server, glibtop_proc_time *buf,
/* It does not work for the swapper task. */
if (pid == 0) return;
#if (defined(__NetBSD__) && (__NetBSD_Version__ >= 104000000))
if (server->sysdeps.proc_time == 0)
return;
#endif
/* Get the process information */
#if defined (__NetBSD__) || defined(__OpenBSD__)
pinfo = kvm_getproc2 (server->machine.kd, KERN_PROC_PID, pid,
sizeof (*pinfo), &count);
#else
pinfo = kvm_getprocs (server->machine.kd, KERN_PROC_PID, pid, &count);
#endif
if ((pinfo == NULL) || (count != 1)) {
glibtop_warn_io_r (server, "kvm_getprocs (%d)", pid);
return;
}
#if (defined(__FreeBSD__) && (__FreeBSD_version >= 500013)) || defined(__FreeBSD_kernel__)
buf->rtime = pinfo [0].ki_runtime;
#elif (defined __FreeBSD__) && (__FreeBSD_version <= 500013)
buf->rtime = pinfo [0].kp_proc.p_runtime;
#elif defined (__NetBSD__) || defined(__OpenBSD__)
buf->rtime = pinfo[0].p_rtime_sec * clockrate
+ pinfo[0].p_rtime_usec * clockrate / 1000000;
buf->frequency = clockrate;
#else
buf->rtime = tv2sec (pinfo [0].kp_proc.p_rtime);
buf->frequency = 1000000;
#endif
buf->flags = _glibtop_sysdeps_proc_time;
#if (defined(__NetBSD__) && (__NetBSD_Version__ >= 104000000)) || defined(__OpenBSD__)
buf->utime = pinfo[0].p_uutime_sec * 1000000
+ pinfo[0].p_uutime_usec;
buf->stime = pinfo[0].p_ustime_sec * 1000000
@ -188,76 +153,5 @@ glibtop_get_proc_time_p (glibtop *server, glibtop_proc_time *buf,
buf->start_time = pinfo[0].p_ustart_sec;
buf->flags |= _glibtop_sysdeps_proc_time_user;
#else
#if (defined(__FreeBSD__) && (__FreeBSD_version >= 500013)) || defined(__FreeBSD_kernel__)
#if (__FreeBSD_version >= 500016) || defined(__FreeBSD_kernel__)
if ((pinfo [0].ki_flag & PS_INMEM)) {
#else
if ((pinfo [0].ki_flag & P_INMEM)) {
#endif
buf->utime = pinfo [0].ki_runtime;
buf->stime = tv2sec (pinfo [0].ki_rusage.ru_stime);
buf->cutime = tv2sec (pinfo [0].ki_childtime);
#if (__FreeBSD_version >= 600000) || (__FreeBSD_kernel_version >= 600000)
buf->cstime = tv2sec (pinfo [0].ki_rusage_ch.ru_stime);
#else
buf->cstime = 0;
#endif
buf->start_time = tv2sec (pinfo [0].ki_start);
buf->flags = _glibtop_sysdeps_proc_time_user;
}
glibtop_suid_enter (server);
#elif (__FreeBSD_version <= 500013)
if ((pinfo [0].kp_proc.p_flag & P_INMEM) &&
kvm_uread (server->machine.kd, &(pinfo [0]).kp_proc,
(unsigned long) &u_addr->u_stats,
(char *) &pstats, sizeof (pstats)) == sizeof (pstats))
{
buf->utime = tv2sec (pinfo[0].kp_eproc.e_stats.p_ru.ru_utime);
buf->stime = tv2sec (pinfo[0].kp_eproc.e_stats.p_ru.ru_stime);
buf->cutime = tv2sec (pinfo[0].kp_eproc.e_stats.p_cru.ru_utime);
buf->cstime = tv2sec (pinfo[0].kp_eproc.e_stats.p_cru.ru_stime);
buf->start_time = tv2sec (pinfo[0].kp_eproc.e_stats.p_start);
buf->flags = _glibtop_sysdeps_proc_time_user;
glibtop_suid_leave (server);
}
#else
if ((pinfo [0].kp_proc.p_flag & P_INMEM) &&
kvm_uread (server->machine.kd, &(pinfo [0]).kp_proc,
(unsigned long) &u_addr->u_stats,
(char *) &pstats, sizeof (pstats)) == sizeof (pstats))
{
/* This is taken form the kernel source code of
* FreeBSD 2.2.6. */
/* Well, we just do the same getrusage () does ... */
register struct rusage *rup;
glibtop_suid_leave (server);
rup = &pstats.p_ru;
calcru(&(pinfo [0]).kp_proc,
&rup->ru_utime, &rup->ru_stime, NULL);
buf->utime = tv2sec (pstats.p_ru.ru_utime);
buf->stime = tv2sec (pstats.p_ru.ru_stime);
buf->cutime = tv2sec (pstats.p_cru.ru_utime);
buf->cstime = tv2sec (pstats.p_cru.ru_stime);
buf->start_time = tv2sec (pstats.p_start);
buf->flags = _glibtop_sysdeps_proc_time_user;
}
#endif
glibtop_suid_leave (server);
#endif
}

View File

@ -52,20 +52,9 @@ void
glibtop_get_proc_uid_p (glibtop *server, glibtop_proc_uid *buf,
pid_t pid)
{
#if defined (__OpenBSD__)
struct kinfo_proc2 *pinfo;
#else
struct kinfo_proc *pinfo;
#endif
int count = 0;
#if LIBGTOP_VERSION_CODE >= 1001000
#if defined(__NetBSD__) && (__NetBSD_Version__ >= 104000000)
struct ucred ucred;
void *ucred_ptr;
#endif
#endif
glibtop_init_p (server, (1L << GLIBTOP_SYSDEPS_PROC_UID), 0);
memset (buf, 0, sizeof (glibtop_proc_uid));
@ -74,31 +63,13 @@ glibtop_get_proc_uid_p (glibtop *server, glibtop_proc_uid *buf,
if (pid == 0) return;
/* Get the process information */
#if defined (__OpenBSD__)
pinfo = kvm_getproc2 (server->machine.kd, KERN_PROC_PID, pid,
sizeof (*pinfo), &count);
#else
pinfo = kvm_getprocs (server->machine.kd, KERN_PROC_PID, pid, &count);
#endif
if ((pinfo == NULL) || (count != 1)) {
glibtop_warn_io_r (server, "kvm_getprocs (%d)", pid);
return;
}
#if (defined(__FreeBSD__) && (__FreeBSD_version >= 500013)) || defined(__FreeBSD_kernel__)
#define PROC_RUID ki_ruid
#define PROC_SVUID ki_svuid
#define PROC_RGID ki_rgid
#define PROC_SVGID ki_svgid
#define PROC_PPID ki_ppid
#define PROC_PGID ki_pgid
#define PROC_TPGID ki_tpgid
#define PROC_NICE ki_nice
#define PROC_PRIORITY ki_pri.pri_user
#elif defined (__OpenBSD__)
#define PROC_RUID p_ruid
#define PROC_SVUID p_svuid
#define PROC_RGID p_rgid
@ -110,20 +81,6 @@ glibtop_get_proc_uid_p (glibtop *server, glibtop_proc_uid *buf,
#define PROC_NICE p_nice
#define PROC_PRIORITY p_priority
#else
#define PROC_RUID kp_eproc.e_pcred.p_ruid
#define PROC_SVUID kp_eproc.e_pcred.p_svuid
#define PROC_RGID kp_eproc.e_pcred.p_rgid
#define PROC_SVGID kp_eproc.e_pcred.p_svgid
#define PROC_PPID kp_eproc.e_ppid
#define PROC_PGID kp_eproc.e_pgid
#define PROC_TPGID kp_eproc.e_tpgid
#define PROC_NICE kp_proc.p_nice
#define PROC_PRIORITY kp_proc.p_priority
#endif
buf->uid = pinfo [0].PROC_RUID;
buf->euid = pinfo [0].PROC_SVUID;
buf->gid = pinfo [0].PROC_RGID;
@ -135,39 +92,11 @@ glibtop_get_proc_uid_p (glibtop *server, glibtop_proc_uid *buf,
buf->tpgid = pinfo [0].PROC_TPGID;
buf->nice = pinfo [0].PROC_NICE;
#if defined(__NetBSD__) && defined(SACTIVE)
buf->priority = 0;
#else
buf->priority = pinfo [0].PROC_PRIORITY;
#endif
/* Set the flags for the data we're about to return*/
buf->flags = _glibtop_sysdeps_proc_uid;
/* Use LibGTop conditionals here so we can more easily merge this
* code into the LIBGTOP_STABLE_1_0 branch. */
#if 0
/* This probably also works with other versions, but not yet
* tested. Please remove the conditional if this is true. */
#if defined(__NetBSD__) && (__NetBSD_Version__ >= 104000000)
ucred_ptr = (void *) pinfo [0].kp_eproc.e_pcred.pc_ucred;
if (ucred_ptr) {
if (kvm_read (server->machine.kd, (unsigned long) ucred_ptr,
&ucred, sizeof (ucred)) != sizeof (ucred)) {
glibtop_warn_io_r (server, "kvm_read (ucred)");
} else {
int count = (ucred.cr_ngroups < GLIBTOP_MAX_GROUPS) ?
ucred.cr_ngroups : GLIBTOP_MAX_GROUPS;
int i;
for (i = 0; i < count; i++)
buf->groups [i] = ucred.cr_groups [i];
buf->ngroups = count;
buf->flags |= _glibtop_sysdeps_proc_uid_groups;
}
}
#endif
#endif
}