From 717ee1c88f23000fce84c589819e61e166c2a5f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Dejean?= Date: Wed, 23 Feb 2005 08:20:45 +0000 Subject: [PATCH] Add support for FreeBSD 6-CURRENT. Use the more portable getrlimit to * Makefile.am: * netlist.c: (glibtop_get_netlist_s): * procmap.c: (glibtop_get_proc_map_p): * procmem.c: (glibtop_get_proc_mem_p): * procopenfiles.c: (glibtop_init_proc_open_files_s), (glibtop_get_proc_open_files_s): * proctime.c: Add support for FreeBSD 6-CURRENT. Use the more portable getrlimit to obtain process memory limits. Correctly determine process time. Stub out the procopenfiles() function (this is not yet implemented, however). Fix a nasty infinite loop and memory leak due to a forgot pointer increment. Patch from marcus@freebsd.org (Joe Marcus Clarke). Closes #168232. --- sysdeps/freebsd/ChangeLog | 19 ++++++++++++ sysdeps/freebsd/Makefile.am | 2 +- sysdeps/freebsd/netlist.c | 1 + sysdeps/freebsd/procmap.c | 20 ++++++++----- sysdeps/freebsd/procmem.c | 11 +++---- sysdeps/freebsd/procopenfiles.c | 52 +++++++++++++++++++++++++++++++++ sysdeps/freebsd/proctime.c | 14 ++------- 7 files changed, 92 insertions(+), 27 deletions(-) create mode 100644 sysdeps/freebsd/procopenfiles.c diff --git a/sysdeps/freebsd/ChangeLog b/sysdeps/freebsd/ChangeLog index fb645932..c4830110 100644 --- a/sysdeps/freebsd/ChangeLog +++ b/sysdeps/freebsd/ChangeLog @@ -1,3 +1,22 @@ +2005-02-23 Benoît Dejean + + * Makefile.am: + * netlist.c: (glibtop_get_netlist_s): + * procmap.c: (glibtop_get_proc_map_p): + * procmem.c: (glibtop_get_proc_mem_p): + * procopenfiles.c: (glibtop_init_proc_open_files_s), + (glibtop_get_proc_open_files_s): + * proctime.c: + + Add support for FreeBSD 6-CURRENT. + Use the more portable getrlimit to obtain process memory limits. + Correctly determine process time. + Stub out the procopenfiles() function (this is not yet implemented, however). + Fix a nasty infinite loop and memory leak due to a forgot pointer increment. + + Patch from marcus@freebsd.org (Joe Marcus Clarke). + Closes #168232. + 2004-12-05 Benoît Dejean * Makefile.am: diff --git a/sysdeps/freebsd/Makefile.am b/sysdeps/freebsd/Makefile.am index 3a313b64..2adb51a5 100644 --- a/sysdeps/freebsd/Makefile.am +++ b/sysdeps/freebsd/Makefile.am @@ -12,7 +12,7 @@ libgtop_sysdeps_suid_2_0_la_SOURCES = open.c close.c cpu.c mem.c swap.c \ sem_limits.c proclist.c procstate.c procuid.c \ proctime.c procmem.c procsignal.c prockernel.c \ procsegment.c procargs.c procmap.c netlist.c \ - netload.c ppp.c + netload.c ppp.c procopenfiles.c libgtop_sysdeps_suid_2_0_la_LDFLAGS = $(LT_VERSION_INFO) diff --git a/sysdeps/freebsd/netlist.c b/sysdeps/freebsd/netlist.c index 62411732..8c595385 100644 --- a/sysdeps/freebsd/netlist.c +++ b/sysdeps/freebsd/netlist.c @@ -50,6 +50,7 @@ glibtop_get_netlist_s (glibtop *server, glibtop_netlist *buf) while(ifs && ifs->if_name) { g_ptr_array_add(devices, g_strdup(ifs->if_name)); buf->number++; + ifs++; } if_freenameindex(ifstart); diff --git a/sysdeps/freebsd/procmap.c b/sysdeps/freebsd/procmap.c index d8ac5b8b..d8919819 100644 --- a/sysdeps/freebsd/procmap.c +++ b/sysdeps/freebsd/procmap.c @@ -47,7 +47,13 @@ #endif #endif +#ifdef __FreeBSD__ +#define _KVM_VNODE +#endif #include +#ifdef __FreeBSD__ +#undef _KVM_VNODE +#endif #include #include #include @@ -104,7 +110,7 @@ glibtop_get_proc_map_p (glibtop *server, glibtop_proc_map *buf, glibtop_map_entry *maps; #if defined __FreeBSD__ struct vnode vnode; -#if __FreeBSD_version >= 500039 +#if __FreeBSD_version < 500039 struct inode inode; #endif #endif @@ -122,8 +128,10 @@ glibtop_get_proc_map_p (glibtop *server, glibtop_proc_map *buf, /* Get the process data */ pinfo = kvm_getprocs (server->machine.kd, KERN_PROC_PID, pid, &count); - if ((pinfo == NULL) || (count < 1)) + if ((pinfo == NULL) || (count < 1)) { glibtop_error_io_r (server, "kvm_getprocs (%d)", pid); + return NULL; + } /* Now we get the memory maps. */ @@ -264,8 +272,10 @@ glibtop_get_proc_map_p (glibtop *server, glibtop_proc_map *buf, #if defined(__FreeBSD__) && (__FreeBSD_version >= 500039) switch (vnode.v_type) { case VREG: +#if __FreeBSD_version < 600006 maps [i-1].inode = vnode.v_cachedid; maps [i-1].device = vnode.v_cachedfs; +#endif default: continue; } @@ -278,13 +288,9 @@ glibtop_get_proc_map_p (glibtop *server, glibtop_proc_map *buf, &inode, sizeof (inode)) != sizeof (inode)) glibtop_error_io_r (server, "kvm_read (inode)"); - if (kvm_read (server->machine.kd, - (unsigned long) vnode.v_mount, - &mount, sizeof (mount)) != sizeof (mount)) - glibtop_error_io_r (server, "kvm_read (mount)"); -#endif maps [i-1].inode = inode.i_number; maps [i-1].device = inode.i_dev; +#endif #endif } while (entry.next != first); diff --git a/sysdeps/freebsd/procmem.c b/sysdeps/freebsd/procmem.c index 78b376a2..0bba91a2 100644 --- a/sysdeps/freebsd/procmem.c +++ b/sysdeps/freebsd/procmem.c @@ -125,7 +125,7 @@ glibtop_get_proc_mem_p (glibtop *server, glibtop_proc_mem *buf, #else struct vm_object object; #endif - struct plimit plimit; + struct rlimit rlimit; int count; glibtop_init_p (server, (1L << GLIBTOP_SYSDEPS_PROC_MEM), 0); @@ -160,15 +160,12 @@ glibtop_get_proc_mem_p (glibtop *server, glibtop_proc_mem *buf, #define PROC_VMSPACE kp_proc.p_vmspace - if (kvm_read (server->machine.kd, - (unsigned long) pinfo [0].PROC_VMSPACE, - (char *) &plimit, sizeof (plimit)) != sizeof (plimit)) { - glibtop_warn_io_r (server, "kvm_read (plimit)"); + if (getrlimit (RLIMIT_RSS, &rlimit) < 0) { + glibtop_warn_io_r (server, "getrlimit"); return; } - buf->rss_rlim = (guint64) - (plimit.pl_rlimit [RLIMIT_RSS].rlim_cur); + buf->rss_rlim = (u_int64_t) (rlimit.rlim_cur); vms = &pinfo [0].kp_eproc.e_vm; diff --git a/sysdeps/freebsd/procopenfiles.c b/sysdeps/freebsd/procopenfiles.c new file mode 100644 index 00000000..c462e395 --- /dev/null +++ b/sysdeps/freebsd/procopenfiles.c @@ -0,0 +1,52 @@ +/* $Id$ */ + +/* Copyright (C) 1998-99 Martin Baulig + Copyright (C) 2004 Nicolás Lichtmaier + This file is part of LibGTop 1.0. + + Modified by Nicolás Lichtmaier to give a process open files. + + Contributed by Martin Baulig , April 1998. + + LibGTop is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, + or (at your option) any later version. + + LibGTop 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 General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with LibGTop; see the file COPYING. If not, write to the + Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ + +#include +#include +#include + +#include + +static const unsigned long _glibtop_sysdeps_proc_open_files = +(1L << GLIBTOP_PROC_OPEN_FILES_NUMBER)| +(1L << GLIBTOP_PROC_OPEN_FILES_TOTAL)| +(1L << GLIBTOP_PROC_OPEN_FILES_SIZE); + +/* Init function. */ + +void +glibtop_init_proc_open_files_s (glibtop *server) +{ + server->sysdeps.proc_open_files = _glibtop_sysdeps_proc_open_files; +} + + +/* XXX Unimplemented on FreeBSD */ +glibtop_open_files_entry * +glibtop_get_proc_open_files_s (glibtop *server, glibtop_proc_open_files *buf, pid_t pid) +{ + return NULL; +} diff --git a/sysdeps/freebsd/proctime.c b/sysdeps/freebsd/proctime.c index a1571d86..3d775365 100644 --- a/sysdeps/freebsd/proctime.c +++ b/sysdeps/freebsd/proctime.c @@ -59,6 +59,7 @@ glibtop_init_proc_time_p (glibtop *server) #ifndef __FreeBSD__ +#ifndef __FreeBSD__ static void calcru(p, up, sp, ip) struct proc *p; @@ -81,19 +82,10 @@ calcru(p, up, sp, ip) tot = 1; } -#if (defined __FreeBSD__) && (__FreeBSD_version >= 300003) - - /* This was changed from a `struct timeval' into a `guint64' - * on FreeBSD 3.0 and renamed p_rtime -> p_runtime. - */ - - totusec = (u_quad_t) p->p_runtime; -#else sec = p->p_rtime.tv_sec; usec = p->p_rtime.tv_usec; totusec = (quad_t)sec * 1000000 + usec; -#endif if (totusec < 0) { /* XXX no %qd in kernel. Truncate. */ @@ -116,6 +108,7 @@ calcru(p, up, sp, ip) ip->tv_usec = it % 1000000; } } +#endif #endif /* !__FreeBSD__ */ @@ -134,9 +127,6 @@ glibtop_get_proc_time_p (glibtop *server, glibtop_proc_time *buf, struct pstats pstats; int count; - char filename [BUFSIZ]; - struct stat statb; - glibtop_init_p (server, (1L << GLIBTOP_SYSDEPS_PROC_TIME), 0); memset (buf, 0, sizeof (glibtop_proc_time));