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.
This commit is contained in:
@@ -1,3 +1,22 @@
|
|||||||
|
2005-02-23 Benoît Dejean <TazForEver@dlfp.org>
|
||||||
|
|
||||||
|
* 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 <tazforever@dlfp.org>
|
2004-12-05 Benoît Dejean <tazforever@dlfp.org>
|
||||||
|
|
||||||
* Makefile.am:
|
* 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 \
|
sem_limits.c proclist.c procstate.c procuid.c \
|
||||||
proctime.c procmem.c procsignal.c prockernel.c \
|
proctime.c procmem.c procsignal.c prockernel.c \
|
||||||
procsegment.c procargs.c procmap.c netlist.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)
|
libgtop_sysdeps_suid_2_0_la_LDFLAGS = $(LT_VERSION_INFO)
|
||||||
|
|
||||||
|
@@ -50,6 +50,7 @@ glibtop_get_netlist_s (glibtop *server, glibtop_netlist *buf)
|
|||||||
while(ifs && ifs->if_name) {
|
while(ifs && ifs->if_name) {
|
||||||
g_ptr_array_add(devices, g_strdup(ifs->if_name));
|
g_ptr_array_add(devices, g_strdup(ifs->if_name));
|
||||||
buf->number++;
|
buf->number++;
|
||||||
|
ifs++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if_freenameindex(ifstart);
|
if_freenameindex(ifstart);
|
||||||
|
@@ -47,7 +47,13 @@
|
|||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef __FreeBSD__
|
||||||
|
#define _KVM_VNODE
|
||||||
|
#endif
|
||||||
#include <sys/vnode.h>
|
#include <sys/vnode.h>
|
||||||
|
#ifdef __FreeBSD__
|
||||||
|
#undef _KVM_VNODE
|
||||||
|
#endif
|
||||||
#include <sys/mount.h>
|
#include <sys/mount.h>
|
||||||
#include <ufs/ufs/quota.h>
|
#include <ufs/ufs/quota.h>
|
||||||
#include <ufs/ufs/inode.h>
|
#include <ufs/ufs/inode.h>
|
||||||
@@ -104,7 +110,7 @@ glibtop_get_proc_map_p (glibtop *server, glibtop_proc_map *buf,
|
|||||||
glibtop_map_entry *maps;
|
glibtop_map_entry *maps;
|
||||||
#if defined __FreeBSD__
|
#if defined __FreeBSD__
|
||||||
struct vnode vnode;
|
struct vnode vnode;
|
||||||
#if __FreeBSD_version >= 500039
|
#if __FreeBSD_version < 500039
|
||||||
struct inode inode;
|
struct inode inode;
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
@@ -122,8 +128,10 @@ glibtop_get_proc_map_p (glibtop *server, glibtop_proc_map *buf,
|
|||||||
|
|
||||||
/* Get the process data */
|
/* Get the process data */
|
||||||
pinfo = kvm_getprocs (server->machine.kd, KERN_PROC_PID, pid, &count);
|
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);
|
glibtop_error_io_r (server, "kvm_getprocs (%d)", pid);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
/* Now we get the memory maps. */
|
/* 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)
|
#if defined(__FreeBSD__) && (__FreeBSD_version >= 500039)
|
||||||
switch (vnode.v_type) {
|
switch (vnode.v_type) {
|
||||||
case VREG:
|
case VREG:
|
||||||
|
#if __FreeBSD_version < 600006
|
||||||
maps [i-1].inode = vnode.v_cachedid;
|
maps [i-1].inode = vnode.v_cachedid;
|
||||||
maps [i-1].device = vnode.v_cachedfs;
|
maps [i-1].device = vnode.v_cachedfs;
|
||||||
|
#endif
|
||||||
default:
|
default:
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -278,13 +288,9 @@ glibtop_get_proc_map_p (glibtop *server, glibtop_proc_map *buf,
|
|||||||
&inode, sizeof (inode)) != sizeof (inode))
|
&inode, sizeof (inode)) != sizeof (inode))
|
||||||
glibtop_error_io_r (server, "kvm_read (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].inode = inode.i_number;
|
||||||
maps [i-1].device = inode.i_dev;
|
maps [i-1].device = inode.i_dev;
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
} while (entry.next != first);
|
} while (entry.next != first);
|
||||||
|
|
||||||
|
@@ -125,7 +125,7 @@ glibtop_get_proc_mem_p (glibtop *server, glibtop_proc_mem *buf,
|
|||||||
#else
|
#else
|
||||||
struct vm_object object;
|
struct vm_object object;
|
||||||
#endif
|
#endif
|
||||||
struct plimit plimit;
|
struct rlimit rlimit;
|
||||||
int count;
|
int count;
|
||||||
|
|
||||||
glibtop_init_p (server, (1L << GLIBTOP_SYSDEPS_PROC_MEM), 0);
|
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
|
#define PROC_VMSPACE kp_proc.p_vmspace
|
||||||
|
|
||||||
if (kvm_read (server->machine.kd,
|
if (getrlimit (RLIMIT_RSS, &rlimit) < 0) {
|
||||||
(unsigned long) pinfo [0].PROC_VMSPACE,
|
glibtop_warn_io_r (server, "getrlimit");
|
||||||
(char *) &plimit, sizeof (plimit)) != sizeof (plimit)) {
|
|
||||||
glibtop_warn_io_r (server, "kvm_read (plimit)");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
buf->rss_rlim = (guint64)
|
buf->rss_rlim = (u_int64_t) (rlimit.rlim_cur);
|
||||||
(plimit.pl_rlimit [RLIMIT_RSS].rlim_cur);
|
|
||||||
|
|
||||||
vms = &pinfo [0].kp_eproc.e_vm;
|
vms = &pinfo [0].kp_eproc.e_vm;
|
||||||
|
|
||||||
|
52
sysdeps/freebsd/procopenfiles.c
Normal file
52
sysdeps/freebsd/procopenfiles.c
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
/* $Id$ */
|
||||||
|
|
||||||
|
/* Copyright (C) 1998-99 Martin Baulig
|
||||||
|
Copyright (C) 2004 Nicol<6F>s Lichtmaier
|
||||||
|
This file is part of LibGTop 1.0.
|
||||||
|
|
||||||
|
Modified by Nicol<6F>s Lichtmaier to give a process open files.
|
||||||
|
|
||||||
|
Contributed by Martin Baulig <martin@home-of-linux.org>, 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 <glibtop.h>
|
||||||
|
#include <glibtop/error.h>
|
||||||
|
#include <glibtop/procopenfiles.h>
|
||||||
|
|
||||||
|
#include <glibtop_suid.h>
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
@@ -59,6 +59,7 @@ glibtop_init_proc_time_p (glibtop *server)
|
|||||||
|
|
||||||
#ifndef __FreeBSD__
|
#ifndef __FreeBSD__
|
||||||
|
|
||||||
|
#ifndef __FreeBSD__
|
||||||
static void
|
static void
|
||||||
calcru(p, up, sp, ip)
|
calcru(p, up, sp, ip)
|
||||||
struct proc *p;
|
struct proc *p;
|
||||||
@@ -81,19 +82,10 @@ calcru(p, up, sp, ip)
|
|||||||
tot = 1;
|
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;
|
sec = p->p_rtime.tv_sec;
|
||||||
usec = p->p_rtime.tv_usec;
|
usec = p->p_rtime.tv_usec;
|
||||||
|
|
||||||
totusec = (quad_t)sec * 1000000 + usec;
|
totusec = (quad_t)sec * 1000000 + usec;
|
||||||
#endif
|
|
||||||
|
|
||||||
if (totusec < 0) {
|
if (totusec < 0) {
|
||||||
/* XXX no %qd in kernel. Truncate. */
|
/* XXX no %qd in kernel. Truncate. */
|
||||||
@@ -116,6 +108,7 @@ calcru(p, up, sp, ip)
|
|||||||
ip->tv_usec = it % 1000000;
|
ip->tv_usec = it % 1000000;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif /* !__FreeBSD__ */
|
#endif /* !__FreeBSD__ */
|
||||||
|
|
||||||
@@ -134,9 +127,6 @@ glibtop_get_proc_time_p (glibtop *server, glibtop_proc_time *buf,
|
|||||||
struct pstats pstats;
|
struct pstats pstats;
|
||||||
int count;
|
int count;
|
||||||
|
|
||||||
char filename [BUFSIZ];
|
|
||||||
struct stat statb;
|
|
||||||
|
|
||||||
glibtop_init_p (server, (1L << GLIBTOP_SYSDEPS_PROC_TIME), 0);
|
glibtop_init_p (server, (1L << GLIBTOP_SYSDEPS_PROC_TIME), 0);
|
||||||
|
|
||||||
memset (buf, 0, sizeof (glibtop_proc_time));
|
memset (buf, 0, sizeof (glibtop_proc_time));
|
||||||
|
Reference in New Issue
Block a user