Make it work with NetBSD 1.3.2.

1998-12-05  Martin Baulig  <martin@home-of-linux.org>

	* Make it work with NetBSD 1.3.2.

Well, it compiles without problems but not all features are currently
working; need to look a little bit closer at it.

Ok for now, think I'll install OpenBSD and test it there ...

Martin
This commit is contained in:
Martin Baulig
1998-12-05 18:52:09 +00:00
committed by Martin Baulig
parent d414a22ee3
commit 67a344b9d4
12 changed files with 108 additions and 14 deletions

View File

@@ -1,3 +1,7 @@
1998-12-05 Martin Baulig <martin@home-of-linux.org>
* Make it work with NetBSD 1.3.2.
1998-11-17 Martin Baulig <martin@home-of-linux.org>
* Make it work with FreeBSD 3.0.

View File

@@ -31,7 +31,10 @@
#include <sys/sysctl.h>
#include <fcntl.h>
#ifdef __FreeBSD__
#include <osreldate.h>
#endif
__BEGIN_DECLS

View File

@@ -32,7 +32,10 @@
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_BUFFER) +
#ifdef __FreeBSD__
(1 << GLIBTOP_MEM_CACHED) +
#endif
(1 << GLIBTOP_MEM_USER);
#ifndef LOG1024
@@ -124,11 +127,24 @@ glibtop_get_mem_p (glibtop *server, glibtop_mem *buf)
/* convert memory stats to Kbytes */
#ifdef __FreeBSD__
buf->total = (u_int64_t) pagetok (vmm.v_page_count) << LOG1024;
#else
{
u_int total_count = vmm.v_kernel_pages +
vmm.v_free_count + vmm.v_wire_count +
vmm.v_active_count + vmm.v_inactive_count;
buf->total = (u_int64_t) pagetok (total_count) << LOG1024;
}
#endif
buf->used = (u_int64_t) pagetok (vmm.v_active_count) << LOG1024;
buf->free = (u_int64_t) pagetok (vmm.v_free_count) << LOG1024;
#ifdef __FreeBSD__
buf->cached = (u_int64_t) pagetok (vmm.v_cache_count) << LOG1024;
#endif
buf->shared = (u_int64_t) pagetok (vmt.t_vmshr) << LOG1024;
buf->buffer = (u_int64_t) bufspace;

View File

@@ -27,7 +27,11 @@
/* #define KERNEL to get declaration of `struct msginfo'. */
#define KERNEL
#ifdef __FreeBSD__
#define KERNEL 1
#else
#define _KERNEL 1
#endif
#include <sys/ipc.h>
#include <sys/msg.h>

View File

@@ -101,16 +101,25 @@ glibtop_get_netload_p (glibtop *server, glibtop_netload *buf,
if (ifaddraddr == 0) {
ifnetfound = ifnetaddr;
if ((kvm_read (server->machine.kd, ifnetaddr, &ifnet,
sizeof (ifnet)) != sizeof (ifnet)) ||
(kvm_read (server->machine.kd, (u_long) ifnet.if_name,
tname, 16) != 16))
glibtop_error_io_r (server, "kvm_read (ifnetaddr)");
if (kvm_read (server->machine.kd, ifnetaddr, &ifnet,
sizeof (ifnet)) != sizeof (ifnet))
glibtop_error_io_r (server, "kvm_read (ifnetaddr)");
#ifdef __FreeBSD__
if (kvm_read (server->machine.kd, (u_long) ifnet.if_name,
tname, 16) != 16)
glibtop_error_io_r (server, "kvm_read (if_name)");
#else
strncpy (tname, ifnet.if_xname, 16);
tname [15] = 0;
#endif
#if (defined __FreeBSD__) && (__FreeBSD_version >= 300000)
ifaddraddr = (u_long) ifnet.if_addrhead.tqh_first;
#else
#elsif (defined __FreeBSD__)
ifaddraddr = (u_long) ifnet.if_addrlist;
#else
ifaddraddr = (u_long) ifnet.if_addrlist.tqh_first;
#endif
}
@@ -154,8 +163,10 @@ glibtop_get_netload_p (glibtop *server, glibtop_netload *buf,
buf->if_flags |= GLIBTOP_IF_FLAGS_LINK1;
if (ifnet.if_flags & IFF_LINK2)
buf->if_flags |= GLIBTOP_IF_FLAGS_LINK2;
#ifdef __FreeBSD__
if (ifnet.if_flags & IFF_ALTPHYS)
buf->if_flags |= GLIBTOP_IF_FLAGS_ALTPHYS;
#endif
if (ifnet.if_flags & IFF_MULTICAST)
buf->if_flags |= GLIBTOP_IF_FLAGS_MULTICAST;
@@ -183,15 +194,19 @@ glibtop_get_netload_p (glibtop *server, glibtop_netload *buf,
#if (defined __FreeBSD__) && (__FreeBSD_version >= 300000)
ifaddraddr = (u_long)ifaddr.ifa.ifa_link.tqe_next;
#else
#elsif (defined __FreeBSD__)
ifaddraddr = (u_long)ifaddr.ifa.ifa_next;
#else
ifaddraddr = (u_long)ifaddr.ifa.ifa_list.tqe_next;
#endif
}
#if (defined __FreeBSD__) && (__FreeBSD_version >= 300000)
ifnetaddr = (u_long) ifnet.if_link.tqe_next;
#else
#elsif (defined __FreeBSD__)
ifnetaddr = (u_long) ifnet.if_next;
#else
ifnetaddr = (u_long) ifnet.if_list.tqe_next;
#endif
}
}

View File

@@ -62,7 +62,9 @@ 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

@@ -31,7 +31,9 @@
#include <sys/proc.h>
#include <sys/user.h>
#include <machine/pcb.h>
#ifdef __FreeBSD__
#include <machine/tss.h>
#endif
#include <unistd.h>
#include <fcntl.h>
@@ -148,10 +150,15 @@ glibtop_get_proc_kernel_p (glibtop *server,
* FreeBSD 3.0 at the moment.
*/
#else
#elsif (defined __FreeBSD__)
buf->kstk_esp = (u_int64_t) pcb.pcb_ksp;
buf->kstk_eip = (u_int64_t) pcb.pcb_pc;
buf->flags |= _glibtop_sysdeps_proc_kernel_pcb;
#else
buf->kstk_esp = (u_int64_t) pcb.pcb_tss.tss_esp0;
buf->kstk_eip = (u_int64_t) pcb.pcb_tss.__tss_eip;
buf->flags |= _glibtop_sysdeps_proc_kernel_pcb;
#endif
}

View File

@@ -135,8 +135,13 @@ glibtop_get_proc_map_p (glibtop *server, glibtop_proc_map *buf,
update = 1;
}
#ifdef __FreeBSD__
if (entry.eflags & (MAP_ENTRY_IS_A_MAP|MAP_ENTRY_IS_SUB_MAP))
continue;
#else
if (entry.is_a_map || entry.is_sub_map)
continue;
#endif
maps [i].flags = _glibtop_sysdeps_map_entry;
@@ -165,6 +170,7 @@ glibtop_get_proc_map_p (glibtop *server, glibtop_proc_map *buf,
&object, sizeof (object)) != sizeof (object))
glibtop_error_io_r (server, "kvm_read (object)");
#ifdef __FreeBSD__
/* If the object is of type vnode, add its size */
if (object.type != OBJT_VNODE)
@@ -193,7 +199,7 @@ glibtop_get_proc_map_p (glibtop *server, glibtop_proc_map *buf,
maps [i-1].inode = inode.i_number;
maps [i-1].device = inode.i_dev;
#endif
} while (entry.next != first);
return maps;

View File

@@ -161,8 +161,13 @@ glibtop_get_proc_mem_p (glibtop *server, glibtop_proc_mem *buf,
return;
}
#ifdef __FreeBSD__
if (entry.eflags & (MAP_ENTRY_IS_A_MAP|MAP_ENTRY_IS_SUB_MAP))
continue;
#else
if (entry.is_a_map || entry.is_sub_map)
continue;
#endif
if (!entry.object.vm_object)
continue;
@@ -178,10 +183,14 @@ glibtop_get_proc_mem_p (glibtop *server, glibtop_proc_mem *buf,
/* If the object is of type vnode, add its size */
#ifdef __FreeBSD__
if (object.type != OBJT_VNODE)
continue;
buf->share += object.un_pager.vnp.vnp_size;
#else
buf->share += object.size;
#endif
}
buf->flags = _glibtop_sysdeps_proc_mem;

View File

@@ -27,7 +27,11 @@
/* #define KERNEL to get declaration of `struct seminfo'. */
#define KERNEL
#ifdef __FreeBSD__
#define KERNEL 1
#else
#define _KERNEL 1
#endif
#include <sys/ipc.h>
#include <sys/sem.h>

View File

@@ -27,7 +27,11 @@
/* #define KERNEL to get declaration of `struct shminfo'. */
#define KERNEL
#ifdef __FreeBSD__
#define KERNEL 1
#else
#define _KERNEL 1
#endif
#include <sys/ipc.h>
#include <sys/shm.h>

View File

@@ -28,7 +28,9 @@
#include <glibtop_suid.h>
#include <sys/conf.h>
#ifdef __FreeBSD__
#include <sys/rlist.h>
#endif
#include <sys/vmmeter.h>
static const unsigned long _glibtop_sysdeps_swap =
@@ -79,9 +81,11 @@ glibtop_get_swap_p (glibtop *server, glibtop_swap *buf)
int i, div, avail, nfree, npfree, used;
struct swdevt *sw;
long blocksize, *perdev;
#ifdef __FreeBSD__
struct rlist head;
struct rlisthdr swaplist;
struct rlist *swapptr;
#endif
size_t sw_size;
u_long ptr;
@@ -109,12 +113,22 @@ glibtop_get_swap_p (glibtop *server, glibtop_swap *buf)
buf->pagein = 0;
buf->pageout = 0;
} else {
#ifdef __FreeBSD__
buf->pagein = vmm.v_swappgsin - swappgsin;
buf->pageout = vmm.v_swappgsout - swappgsout;
#else
buf->pagein = vmm.v_pswpin - swappgsin;
buf->pageout = vmm.v_pswpout - swappgsout;
#endif
}
#ifdef __FreeBSD__
swappgsin = vmm.v_swappgsin;
swappgsout = vmm.v_swappgsout;
#else
swappgsin = vmm.v_pswpin;
swappgsout = vmm.v_pswpout;
#endif
/* Size of largest swap device. */
@@ -140,6 +154,8 @@ glibtop_get_swap_p (glibtop *server, glibtop_swap *buf)
return;
}
#ifdef __FreeBSD__
/* List of free swap areas. */
if (kvm_read (server->machine.kd, nlst[VM_SWAPLIST].n_value,
@@ -148,6 +164,8 @@ glibtop_get_swap_p (glibtop *server, glibtop_swap *buf)
return;
}
#endif
/* Kernel offset of list of swap devices and sizes. */
if (kvm_read (server->machine.kd, nlst[VM_SWDEVT].n_value,
@@ -173,6 +191,7 @@ glibtop_get_swap_p (glibtop *server, glibtop_swap *buf)
nfree = 0;
memset (perdev, 0, nswdev * sizeof(*perdev));
#ifdef __FreeBSD__
swapptr = swaplist.rlh_list;
while (swapptr) {
@@ -212,6 +231,7 @@ glibtop_get_swap_p (glibtop *server, glibtop_swap *buf)
swapptr = head.rl_next;
}
#endif
header = getbsize (&hlen, &blocksize);