Moved all sysdeps code to the new libgtop-backends module.
2001-04-20 Martin Baulig <baulig@suse.de> Moved all sysdeps code to the new libgtop-backends module. * sysdeps/freesd/*: Removed. * sysdeps/kernel/*: Removed. * sysdeps/linux/*: Removed. * sysdeps/osf1/*: Removed. * sysdeps/solaris/*: Removed. * sysdeps/stub/*: Removed. * sysdeps/stub_suid/*: Removed. * sysdeps/sun4/*: Removed.
This commit is contained in:
committed by
Martin Baulig
parent
5bfb085021
commit
7a7c6baf55
13
ChangeLog
13
ChangeLog
@@ -1,3 +1,16 @@
|
||||
2001-04-20 Martin Baulig <baulig@suse.de>
|
||||
|
||||
Moved all sysdeps code to the new libgtop-backends module.
|
||||
|
||||
* sysdeps/freesd/*: Removed.
|
||||
* sysdeps/kernel/*: Removed.
|
||||
* sysdeps/linux/*: Removed.
|
||||
* sysdeps/osf1/*: Removed.
|
||||
* sysdeps/solaris/*: Removed.
|
||||
* sysdeps/stub/*: Removed.
|
||||
* sysdeps/stub_suid/*: Removed.
|
||||
* sysdeps/sun4/*: Removed.
|
||||
|
||||
2001-04-20 Martin Baulig <baulig@suse.de>
|
||||
|
||||
* lib/Makefile.am (libgtop_la_SOURCES): Added xmalloc.c and
|
||||
|
@@ -1,6 +0,0 @@
|
||||
.deps
|
||||
.libs
|
||||
Makefile
|
||||
Makefile.in
|
||||
*.lo
|
||||
*.la
|
@@ -1,2 +0,0 @@
|
||||
Martin Baulig (martin@home-of-linux.org)
|
||||
Josh Sled (jsled@scam.XCF.Berkeley.EDU)
|
@@ -1,192 +0,0 @@
|
||||
2000-02-13 Martin Baulig <martin@home-of-linux.org>
|
||||
|
||||
* netinfo.c: Reflect latest interface changes.
|
||||
|
||||
2000-02-13 Martin Baulig <martin@home-of-linux.org>
|
||||
|
||||
* *.c: kvm_nlist () returns -1 on error, but a positive return value
|
||||
does not necessarily mean failure. Fixes #3302 which was reported by
|
||||
Matthias Scheler some time ago.
|
||||
|
||||
2000-02-06 Martin Baulig <martin@home-of-linux.org>
|
||||
|
||||
* Makefile.am: Removed the non-suid `libgtop-sysdeps.la'.
|
||||
* nosuid.c: Removed.
|
||||
|
||||
1999-12-12 Martin Baulig <martin@home-of-linux.org>
|
||||
|
||||
* netinfo.c: New file.
|
||||
|
||||
* interfaces.c: Reflect latest interface changes.
|
||||
* netload.c: Likewise.
|
||||
|
||||
1999-10-24 Martin Baulig <martin@home-of-linux.org>
|
||||
|
||||
* glibtop_machine.h: Make inclusion of <osreldate.h> conditional
|
||||
to `HAVE_OSRELDATE_H', not to `__FreeBSD__'.
|
||||
* procsignal.c, proctime.c, proctime.c: Likewise.
|
||||
|
||||
1999-10-16 Martin Baulig <martin@home-of-linux.org>
|
||||
|
||||
Applied all patches from the FreeBSD 3.3 ports collection.
|
||||
|
||||
* swap.c: Only #include <rlist.h> for __FreeBSD_version < 400005.
|
||||
|
||||
* prockernel.c: Make it compile on FreeBSD / alpha.
|
||||
|
||||
* procsignal.c: Some fixes for FreeBSD-current.
|
||||
|
||||
1999-10-16 Martin Baulig <martin@home-of-linux.org>
|
||||
|
||||
* procstate.c (glibtop_get_proc_state_p): Don't use the
|
||||
`GLIBTOP_PROCESS_*' constants for process states for
|
||||
LibGTop 1.0.x.
|
||||
|
||||
1999-07-29 Martin Baulig <martin@home-of-linux.org>
|
||||
|
||||
* proctime.c (glibtop_get_proc_time_p): Fix bug reported by
|
||||
Takis Psarogiannakopoulos: `start_time' are seconds since the
|
||||
epoch as it is stated in the manual.
|
||||
|
||||
Tue Jun 15 16:04:10 1999 Timur Bakeyev <mc@bat.ru>
|
||||
|
||||
* procuid.c: A fix to a ommitted case, when nor NetBSD, nor
|
||||
LibGTop >= 1.1.0. This should be investigated closely to cover
|
||||
more cases....
|
||||
|
||||
1999-05-26 Martin Baulig <martin@home-of-linux.org>
|
||||
|
||||
More NetBSD 1.4 fixes.
|
||||
|
||||
* mem.c, procmap.c, procmem.c: Make this work with the new UVM code.
|
||||
|
||||
[FIXME: This following most likely works on all BSD systems, but
|
||||
this needs to be tested; I made it conditional to NetBSD 1.4 at
|
||||
the moment. Please extend the conditionals to any other systems
|
||||
where this works ...]
|
||||
|
||||
* procstate.c: Added `ruid' and `rgid' for LibGTop >= 1.1.0.
|
||||
* procuid.c: Added `ngroups' and `groups' for LibGTop >= 1.1.0.
|
||||
|
||||
1999-05-25 Martin Baulig <martin@home-of-linux.org>
|
||||
|
||||
* ppp.c: Make this work on NetBSD.
|
||||
|
||||
Thu Apr 8 23:47:29 1999 Timur Bakeyev <timur@gnu.org>
|
||||
|
||||
* cpu.c, mem.c, netload.c, procargs.c, procstate.c, proctime.c,
|
||||
sem_limits.c, shm_limits.c, swap.c: Added initial port for BSD/OS
|
||||
(aka BSDI) 2.x and 3.x. 4.x should also(?) work.
|
||||
|
||||
Still, this port require more close look and extended check.
|
||||
|
||||
1999-03-19 Martin Baulig <martin@home-of-linux.org>
|
||||
|
||||
Added basic support for BSDI. It compiles without problems on
|
||||
BSDI 2.1 and 3.1, but it is *untested* - I'm neither root on
|
||||
the machine nor have I access to /dev/kmem, so I don't know
|
||||
whether it will work.
|
||||
|
||||
You need to give configure the `--enable-hacker-mode' parameter
|
||||
to use the code.
|
||||
|
||||
If someone can verify whether it actually works, please let me
|
||||
know.
|
||||
|
||||
1999-03-18 Martin Baulig <martin@home-of-linux.org>
|
||||
|
||||
* ppp.c: Don't use `sppp.pp_phase' if we don't HAVE_I4B_ACCT.
|
||||
This is an ugly hack until someone tells me which versions have
|
||||
this field and which not.
|
||||
|
||||
1999-02-25 Martin Baulig <martin@home-of-linux.org>
|
||||
|
||||
* prockernel.c, proctime.c: Applied patch Stanislav Grozev for
|
||||
OpenBSD: only include <osreldate.h> for FreeBSD.
|
||||
|
||||
1999-02-24 Martin Baulig <martin@home-of-linux.org>
|
||||
|
||||
* swap.c: Applied another patch from Jeremy Lea to
|
||||
make it work with FreeBSD-current.
|
||||
|
||||
1999-02-21 Martin Baulig <martin@home-of-linux.org>
|
||||
|
||||
* procmap.c, procmem.c: Applied patch from Jeremy Lea.
|
||||
|
||||
* prockernel.c, proctime.c: Applied patch from the FreeBSD 2.2.8
|
||||
ports collection.
|
||||
|
||||
* procsignal.c: Applied patch from the NetBSD-current ports
|
||||
collection.
|
||||
|
||||
1998-12-06 Martin Baulig <martin@home-of-linux.org>
|
||||
|
||||
* Make it work with OpenBSD 2.4.
|
||||
|
||||
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.
|
||||
|
||||
1998-11-11 Martin Baulig <martin@home-of-linux.org>
|
||||
|
||||
* *.c: It does not work to get information about the swapper task
|
||||
on FreeBSD 2.2.6, so we simple return if pid == 0.
|
||||
|
||||
1998-10-31 Martin Baulig <martin@home-of-linux.org>
|
||||
|
||||
* *.c: Use glibtop_warn_io_r () instead of glibtop_error_io_r ().
|
||||
|
||||
* proctime.c, prockernel.c, procargs.c: Don't call kvm_uread () if
|
||||
the /proc filesystem is not mounted.
|
||||
|
||||
1998-10-26 Martin Baulig <martin@home-of-linux.org>
|
||||
|
||||
* netload.c: New file to get network load.
|
||||
|
||||
1998-10-26 Martin Baulig <martin@home-of-linux.org>
|
||||
|
||||
* procargs.c: New file to get command line arguments.
|
||||
|
||||
1998-10-25 Martin Baulig <martin@home-of-linux.org>
|
||||
|
||||
* ppp.c: New file to get PPP/ISDN statistics. Currently this only
|
||||
get ISDN statistics if you have the I4B package.
|
||||
|
||||
To get the number of bytes transferred in/out you need to read the
|
||||
file `misc/i4b_acct.txt' in the LibGTop source directory to see
|
||||
how to enable this.
|
||||
|
||||
1998-10-03 Martin Baulig <martin@home-of-linux.org>
|
||||
|
||||
* procstate.c (glibtop_get_procstate_s): Use correct values for
|
||||
the `state' field.
|
||||
|
||||
* proclist.c (glibtop_get_proclist_p): Honor the GLIBTOP_EXCLUDE_IDLE
|
||||
and GLIBTOP_EXCLUDE_SYSTEM flags of the `which' parameter.
|
||||
|
||||
1998-08-24 Martin Baulig <martin@home-of-linux.org>
|
||||
|
||||
* *.c (glibtop_init_p): Using correct `(1 << GLIBTOP_SYSDPES_*)'.
|
||||
* cpu.c, mem.c: Removed `const' from sysctl () constants to keep
|
||||
compiler happy.
|
||||
|
||||
* procmem.c: Added missing call to `glibtop_init_p'.
|
||||
|
||||
* prockernel.c: Casting `nwchan' to `unsigned long' since this
|
||||
normally has the same size than a pointer. Well, is there a
|
||||
FreeBSD for 64bit architectures ?
|
||||
|
||||
1998-08-08 Martin Baulig <martin@home-of-linux.org>
|
||||
|
||||
* swap.c: Added swap usage based upton the source code
|
||||
of `pinfo'.
|
||||
|
||||
1998-08-07 Martin Baulig <martin@home-of-linux.org>
|
||||
|
||||
* *: Imported FreeBSD port of libgtop from Josh Sled.
|
||||
|
||||
* ChangeLog: New file.
|
@@ -1,18 +0,0 @@
|
||||
LINK = $(LIBTOOL) --mode=link $(CC) $(CFLAGS) $(LDFLAGS) -o $@
|
||||
|
||||
INCLUDES = @INCLUDES@
|
||||
|
||||
lib_LTLIBRARIES = libgtop_sysdeps_suid.la
|
||||
|
||||
libgtop_sysdeps_suid_la_SOURCES = 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 procargs.c procmap.c netload.c \
|
||||
netinfo.c interfaces.c ppp.c
|
||||
|
||||
libgtop_sysdeps_suid_la_LDFLAGS = $(LT_VERSION_INFO)
|
||||
|
||||
include_HEADERS = glibtop_server.h glibtop_machine.h \
|
||||
glibtop_suid.h
|
||||
|
@@ -1,10 +0,0 @@
|
||||
sysctl (3)
|
||||
/usr/include/sys/vmmeter.h : VM stats
|
||||
kvm (3)
|
||||
|
||||
CPU stats: /usr/include/sys/dkstat.h
|
||||
cp_time_offset = kvm_nlist(...)["_cp_time"].n_value;
|
||||
|
||||
"systemwide main memory usage structure"
|
||||
sysctl(...)
|
||||
|
@@ -1,33 +0,0 @@
|
||||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright (C) 1998 Joshua Sled
|
||||
This file is part of LibGTop 1.0.
|
||||
|
||||
Contributed by Joshua Sled <jsled@xcf.berkeley.edu>, July 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/close.h>
|
||||
|
||||
/* Closes pipe to gtop server. */
|
||||
|
||||
void
|
||||
glibtop_close_p (glibtop *server)
|
||||
{ }
|
@@ -1,123 +0,0 @@
|
||||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright (C) 1998 Joshua Sled
|
||||
This file is part of LibGTop 1.0.
|
||||
|
||||
Contributed by Joshua Sled <jsled@xcf.berkeley.edu>, July 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/cpu.h>
|
||||
|
||||
#include <glibtop_suid.h>
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_cpu =
|
||||
(1L << GLIBTOP_CPU_TOTAL) + (1L << GLIBTOP_CPU_USER) +
|
||||
(1L << GLIBTOP_CPU_NICE) + (1L << GLIBTOP_CPU_SYS) +
|
||||
(1L << GLIBTOP_CPU_IDLE) + (1L << GLIBTOP_CPU_FREQUENCY);
|
||||
|
||||
/* nlist structure for kernel access */
|
||||
static struct nlist nlst [] = {
|
||||
#ifdef __bsdi__
|
||||
{ "_cpustats" },
|
||||
#else
|
||||
{ "_cp_time" },
|
||||
#endif
|
||||
{ 0 }
|
||||
};
|
||||
|
||||
/* MIB array for sysctl */
|
||||
static int mib_length=2;
|
||||
static int mib [] = { CTL_KERN, KERN_CLOCKRATE };
|
||||
|
||||
/* Init function. */
|
||||
|
||||
int
|
||||
glibtop_init_cpu_p (glibtop *server)
|
||||
{
|
||||
if (kvm_nlist (server->_priv->machine.kd, nlst) < 0) {
|
||||
glibtop_warn_io_r (server, "kvm_nlist (cpu)");
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Set this only if kvm_nlist () succeeded. */
|
||||
server->sysdeps.cpu = _glibtop_sysdeps_cpu;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Provides information about cpu usage. */
|
||||
|
||||
int
|
||||
glibtop_get_cpu_p (glibtop *server, glibtop_cpu *buf)
|
||||
{
|
||||
long cpts [CPUSTATES];
|
||||
/* sysctl vars*/
|
||||
struct clockinfo ci;
|
||||
size_t length;
|
||||
|
||||
glibtop_init_p (server, (1L << GLIBTOP_SYSDEPS_CPU), 0);
|
||||
|
||||
memset (buf, 0, sizeof (glibtop_cpu));
|
||||
|
||||
/* If this fails, the nlist may not be valid. */
|
||||
if (server->sysdeps.cpu == 0)
|
||||
return -1;
|
||||
|
||||
if (kvm_read (server->_priv->machine.kd, nlst [0].n_value,
|
||||
&cpts, sizeof (cpts)) != sizeof (cpts)) {
|
||||
glibtop_warn_io_r (server, "kvm_read (cp_time)");
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Get the clockrate data */
|
||||
length = sizeof (struct clockinfo);
|
||||
if (sysctl (mib, mib_length, &ci, &length, NULL, 0)) {
|
||||
glibtop_warn_io_r (server, "sysctl");
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* 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];
|
||||
|
||||
/* Set the flags last. */
|
||||
buf->flags = _glibtop_sysdeps_cpu;
|
||||
|
||||
return 0;
|
||||
}
|
@@ -1,61 +0,0 @@
|
||||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright (C) 1998-99 Martin Baulig
|
||||
This file is part of LibGTop 1.0.
|
||||
|
||||
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.
|
||||
*/
|
||||
|
||||
#ifndef __GLIBTOP_MACHINE_H__
|
||||
#define __GLIBTOP_MACHINE_H__
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <nlist.h>
|
||||
#include <kvm.h>
|
||||
#include <sys/dkstat.h>
|
||||
#include <time.h>
|
||||
#include <sys/user.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/sysctl.h>
|
||||
|
||||
#include <fcntl.h>
|
||||
|
||||
#ifdef HAVE_OSRELDATE_H
|
||||
#include <osreldate.h>
|
||||
#endif
|
||||
|
||||
BEGIN_LIBGTOP_DECLS
|
||||
|
||||
typedef struct _glibtop_machine glibtop_machine;
|
||||
|
||||
struct _glibtop_machine
|
||||
{
|
||||
uid_t uid, euid;
|
||||
gid_t gid, egid;
|
||||
|
||||
/* 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;
|
||||
};
|
||||
|
||||
END_LIBGTOP_DECLS
|
||||
|
||||
#endif __GLIBTOP_MACHINE_H__
|
@@ -1,56 +0,0 @@
|
||||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright (C) 1998-99 Martin Baulig
|
||||
This file is part of LibGTop 1.0.
|
||||
|
||||
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.
|
||||
*/
|
||||
|
||||
#ifndef __GLIBTOP_SERVER_H__
|
||||
#define __GLIBTOP_SERVER_H__
|
||||
|
||||
BEGIN_LIBGTOP_DECLS
|
||||
|
||||
#define GLIBTOP_SUID_CPU (1 << GLIBTOP_SYSDEPS_CPU)
|
||||
#define GLIBTOP_SUID_MEM (1 << GLIBTOP_SYSDEPS_MEM)
|
||||
#define GLIBTOP_SUID_SWAP (1 << GLIBTOP_SYSDEPS_SWAP)
|
||||
#define GLIBTOP_SUID_UPTIME (1 << GLIBTOP_SYSDEPS_UPTIME)
|
||||
#define GLIBTOP_SUID_LOADAVG (1 << GLIBTOP_SYSDEPS_LOADAVG)
|
||||
#define GLIBTOP_SUID_SHM_LIMITS (1 << GLIBTOP_SYSDEPS_SHM_LIMITS)
|
||||
#define GLIBTOP_SUID_MSG_LIMITS (1 << GLIBTOP_SYSDEPS_MSG_LIMITS)
|
||||
#define GLIBTOP_SUID_SEM_LIMITS (1 << GLIBTOP_SYSDEPS_SEM_LIMITS)
|
||||
#define GLIBTOP_SUID_PROCLIST (1 << GLIBTOP_SYSDEPS_PROCLIST)
|
||||
#define GLIBTOP_SUID_PROC_STATE (1 << GLIBTOP_SYSDEPS_PROC_STATE)
|
||||
#define GLIBTOP_SUID_PROC_UID (1 << GLIBTOP_SYSDEPS_PROC_UID)
|
||||
#define GLIBTOP_SUID_PROC_MEM (1 << GLIBTOP_SYSDEPS_PROC_MEM)
|
||||
#define GLIBTOP_SUID_PROC_TIME (1 << GLIBTOP_SYSDEPS_PROC_TIME)
|
||||
#define GLIBTOP_SUID_PROC_SIGNAL (1 << GLIBTOP_SYSDEPS_PROC_SIGNAL)
|
||||
#define GLIBTOP_SUID_PROC_KERNEL (1 << GLIBTOP_SYSDEPS_PROC_KERNEL)
|
||||
#define GLIBTOP_SUID_PROC_SEGMENT (1 << GLIBTOP_SYSDEPS_PROC_SEGMENT)
|
||||
#define GLIBTOP_SUID_PROC_ARGS (1 << GLIBTOP_SYSDEPS_PROC_ARGS)
|
||||
#define GLIBTOP_SUID_PROC_MAP (1 << GLIBTOP_SYSDEPS_PROC_MAP)
|
||||
#define GLIBTOP_SUID_NETLOAD (1 << GLIBTOP_SYSDEPS_NETLOAD)
|
||||
#define GLIBTOP_SUID_NETINFO (1 << GLIBTOP_SYSDEPS_NETINFO)
|
||||
#define GLIBTOP_SUID_INTERFACE_NAMES (1 << GLIBTOP_SYSDEPS_INTERFACE_NAMES)
|
||||
#define GLIBTOP_SUID_PPP (1 << GLIBTOP_SYSDEPS_PPP)
|
||||
|
||||
END_LIBGTOP_DECLS
|
||||
|
||||
#endif
|
@@ -1,62 +0,0 @@
|
||||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright (C) 1998-99 Martin Baulig
|
||||
This file is part of LibGTop 1.0.
|
||||
|
||||
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.
|
||||
*/
|
||||
|
||||
#ifndef __GLIBTOP_SUID_H__
|
||||
#define __GLIBTOP_SUID_H__
|
||||
|
||||
BEGIN_LIBGTOP_DECLS
|
||||
|
||||
#if _IN_LIBGTOP
|
||||
#include <sys/param.h>
|
||||
#endif
|
||||
|
||||
#define KI_PROC(ki) (&(ki))->kp_proc)
|
||||
#define KI_EPROC(ki) (&(ki))->kp_eproc)
|
||||
|
||||
#define FORCEUREAD 1
|
||||
#define UREADOK(ki) (FORCEUREAD || (KI_PROC(ki)->p_flag & P_INMEM))
|
||||
|
||||
static inline void glibtop_suid_enter (glibtop *server) {
|
||||
setregid (server->_priv->machine.gid,
|
||||
server->_priv->machine.egid);
|
||||
};
|
||||
|
||||
static inline void glibtop_suid_leave (glibtop *server) {
|
||||
if (setregid (server->_priv->machine.egid,
|
||||
server->_priv->machine.gid))
|
||||
_exit (1);
|
||||
};
|
||||
|
||||
void
|
||||
glibtop_init_p (glibtop *server, const unsigned long features,
|
||||
const unsigned flags);
|
||||
void
|
||||
glibtop_open_p (glibtop *server, const char *program_name,
|
||||
const unsigned long features,
|
||||
const unsigned flags);
|
||||
|
||||
END_LIBGTOP_DECLS
|
||||
|
||||
#endif
|
@@ -1,47 +0,0 @@
|
||||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright (C) 1998 Joshua Sled
|
||||
This file is part of LibGTop 1.0.
|
||||
|
||||
Contributed by Joshua Sled <jsled@xcf.berkeley.edu>, July 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/open.h>
|
||||
|
||||
static glibtop _glibtop_global_server;
|
||||
glibtop *glibtop_global_server = NULL;
|
||||
|
||||
glibtop *
|
||||
glibtop_init_r (glibtop **server,
|
||||
const unsigned long features,
|
||||
const unsigned flags)
|
||||
{
|
||||
if (*server != NULL)
|
||||
return *server;
|
||||
|
||||
if (glibtop_global_server == NULL) {
|
||||
glibtop_global_server = &_glibtop_global_server;
|
||||
glibtop_open (glibtop_global_server, "glibtop",
|
||||
features, flags);
|
||||
}
|
||||
|
||||
return *server = glibtop_global_server;
|
||||
}
|
@@ -1,56 +0,0 @@
|
||||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright (C) 1998-99 Martin Baulig
|
||||
This file is part of LibGTop 1.0.
|
||||
|
||||
Contributed by Martin Baulig <martin@home-of-linux.org>, October 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/interfaces.h>
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_interface_names =
|
||||
(1L << GLIBTOP_ARRAY_NUMBER) + (1L << GLIBTOP_ARRAY_SIZE) +
|
||||
(1L << GLIBTOP_ARRAY_TOTAL);
|
||||
|
||||
/* Init function. */
|
||||
|
||||
int
|
||||
glibtop_init_interface_names_p (glibtop *server)
|
||||
{
|
||||
server->sysdeps.interface_names = _glibtop_sysdeps_interface_names;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Provides network statistics. */
|
||||
|
||||
glibtop_interface *
|
||||
glibtop_get_interface_names_p (glibtop *server, glibtop_array *array,
|
||||
u_int64_t interface, u_int64_t number,
|
||||
u_int64_t instance, u_int64_t strategy)
|
||||
{
|
||||
glibtop_init_p (server, (1L << GLIBTOP_SYSDEPS_INTERFACE_NAMES), 0);
|
||||
|
||||
memset (array, 0, sizeof (glibtop_array));
|
||||
|
||||
return NULL;
|
||||
}
|
@@ -1,66 +0,0 @@
|
||||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright (C) 1998 Joshua Sled
|
||||
This file is part of LibGTop 1.0.
|
||||
|
||||
Contributed by Joshua Sled <jsled@xcf.berkeley.edu>, July 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/loadavg.h>
|
||||
|
||||
#include <glibtop_suid.h>
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_loadavg =
|
||||
(1L << GLIBTOP_LOADAVG_LOADAVG);
|
||||
|
||||
/* Init function. */
|
||||
|
||||
int
|
||||
glibtop_init_loadavg_p (glibtop *server)
|
||||
{
|
||||
server->sysdeps.loadavg = _glibtop_sysdeps_loadavg;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Provides load averange. */
|
||||
|
||||
int
|
||||
glibtop_get_loadavg_p (glibtop *server, glibtop_loadavg *buf)
|
||||
{
|
||||
double ldavg[3];
|
||||
int i;
|
||||
|
||||
glibtop_init_p (server, (1L << GLIBTOP_SYSDEPS_LOADAVG), 0);
|
||||
|
||||
memset (buf, 0, sizeof (glibtop_loadavg));
|
||||
|
||||
getloadavg (ldavg, 3);
|
||||
|
||||
/* fill in the struct */
|
||||
buf->flags = _glibtop_sysdeps_loadavg;
|
||||
for (i = 0; i < 3; i++) {
|
||||
buf->loadavg [i] = ldavg [i];
|
||||
} /* end for */
|
||||
|
||||
return 0;
|
||||
}
|
@@ -1,228 +0,0 @@
|
||||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright (C) 1998 Joshua Sled
|
||||
This file is part of LibGTop 1.0.
|
||||
|
||||
Contributed by Joshua Sled <jsled@xcf.berkeley.edu>, July 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/mem.h>
|
||||
|
||||
#include <glibtop_suid.h>
|
||||
|
||||
#include <sys/sysctl.h>
|
||||
#include <sys/vmmeter.h>
|
||||
#include <vm/vm_param.h>
|
||||
|
||||
#if defined(__NetBSD__) && (__NetBSD_Version__ >= 104000000)
|
||||
#include <uvm/uvm_extern.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) +
|
||||
#ifdef __FreeBSD__
|
||||
(1L << GLIBTOP_MEM_CACHED) +
|
||||
#endif
|
||||
(1L << GLIBTOP_MEM_USER) + (1L << GLIBTOP_MEM_LOCKED);
|
||||
|
||||
#ifndef LOG1024
|
||||
#define LOG1024 10
|
||||
#endif
|
||||
|
||||
/* these are for getting the memory statistics */
|
||||
static int pageshift; /* log base 2 of the pagesize */
|
||||
|
||||
/* define pagetok in terms of pageshift */
|
||||
#define pagetok(size) ((size) << pageshift)
|
||||
|
||||
/* nlist structure for kernel access */
|
||||
static struct nlist nlst [] = {
|
||||
#if defined(__NetBSD__) && (__NetBSD_Version__ >= 104000000)
|
||||
{ "_bufpages" },
|
||||
{ 0 }
|
||||
#else
|
||||
#if defined(__bsdi__)
|
||||
{ "_bufcachemem" },
|
||||
#elif defined(__FreeBSD__)
|
||||
{ "_bufspace" },
|
||||
#else
|
||||
{ "_bufpages" },
|
||||
#endif
|
||||
{ "_cnt" },
|
||||
{ 0 }
|
||||
#endif
|
||||
};
|
||||
|
||||
/* MIB array for sysctl */
|
||||
static int mib_length=2;
|
||||
#ifdef __bsdi__
|
||||
static int mib [] = { CTL_VM, VM_TOTAL };
|
||||
#else
|
||||
static int mib [] = { CTL_VM, VM_METER };
|
||||
#endif
|
||||
|
||||
#if defined(__NetBSD__) && (__NetBSD_Version__ >= 104000000)
|
||||
static int mib_uvmexp [] = { CTL_VM, VM_UVMEXP };
|
||||
#endif
|
||||
|
||||
/* Init function. */
|
||||
|
||||
int
|
||||
glibtop_init_mem_p (glibtop *server)
|
||||
{
|
||||
register int pagesize;
|
||||
|
||||
if (kvm_nlist (server->_priv->machine.kd, nlst) < 0) {
|
||||
glibtop_warn_io_r (server, "kvm_nlist (mem)");
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* get the page size with "getpagesize" and calculate pageshift
|
||||
* from it */
|
||||
pagesize = getpagesize ();
|
||||
pageshift = 0;
|
||||
while (pagesize > 1) {
|
||||
pageshift++;
|
||||
pagesize >>= 1;
|
||||
}
|
||||
|
||||
/* we only need the amount of log(2)1024 for our conversion */
|
||||
pageshift -= LOG1024;
|
||||
|
||||
server->sysdeps.mem = _glibtop_sysdeps_mem;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
glibtop_get_mem_p (glibtop *server, glibtop_mem *buf)
|
||||
{
|
||||
struct vmtotal vmt;
|
||||
size_t length_vmt;
|
||||
#if defined(__NetBSD__) && (__NetBSD_Version__ >= 104000000)
|
||||
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;
|
||||
int bufspace;
|
||||
|
||||
glibtop_init_p (server, (1L << GLIBTOP_SYSDEPS_MEM), 0);
|
||||
|
||||
memset (buf, 0, sizeof (glibtop_mem));
|
||||
|
||||
if (server->sysdeps.mem == 0)
|
||||
return -1;
|
||||
|
||||
/* [FIXME: On FreeBSD 2.2.6, sysctl () returns an incorrect
|
||||
* value for `vmt.vm'. We use some code from Unix top
|
||||
* here.] */
|
||||
|
||||
/* Get the data from sysctl */
|
||||
length_vmt = sizeof (vmt);
|
||||
if (sysctl (mib, 2, &vmt, &length_vmt, NULL, 0)) {
|
||||
glibtop_warn_io_r (server, "sysctl (vmt)");
|
||||
return -1;
|
||||
}
|
||||
|
||||
#if defined(__NetBSD__) && (__NetBSD_Version__ >= 104000000)
|
||||
length_uvmexp = sizeof (uvmexp);
|
||||
if (sysctl (mib_uvmexp, 2, &uvmexp, &length_uvmexp, NULL, 0)) {
|
||||
glibtop_warn_io_r (server, "sysctl (uvmexp)");
|
||||
return -1;
|
||||
}
|
||||
#else
|
||||
/* Get the data from kvm_* */
|
||||
if (kvm_read (server->_priv->machine.kd, nlst[1].n_value,
|
||||
&vmm, sizeof (vmm)) != sizeof (vmm)) {
|
||||
glibtop_warn_io_r (server, "kvm_read (cnt)");
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (kvm_read (server->_priv->machine.kd, nlst[0].n_value,
|
||||
&bufspace, sizeof (bufspace)) != sizeof (bufspace)) {
|
||||
glibtop_warn_io_r (server, "kvm_read (bufspace)");
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* convert memory stats to Kbytes */
|
||||
|
||||
#if defined(__FreeBSD__)
|
||||
v_total_count = vmm.v_page_count;
|
||||
#else
|
||||
#if defined(__NetBSD__) && (__NetBSD_Version__ >= 104000000)
|
||||
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)
|
||||
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 = (u_int64_t) pagetok (v_total_count) << LOG1024;
|
||||
buf->used = (u_int64_t) pagetok (v_used_count) << LOG1024;
|
||||
buf->free = (u_int64_t) pagetok (v_free_count) << LOG1024;
|
||||
|
||||
#ifdef __FreeBSD__
|
||||
buf->cached = (u_int64_t) pagetok (vmm.v_cache_count) << LOG1024;
|
||||
#endif
|
||||
|
||||
#if defined(__NetBSD__) && (__NetBSD_Version__ >= 104000000)
|
||||
buf->locked = (u_int64_t) pagetok (uvmexp.wired) << LOG1024;
|
||||
#else
|
||||
buf->locked = (u_int64_t) pagetok (vmm.v_wire_count) << LOG1024;
|
||||
#endif
|
||||
|
||||
buf->shared = (u_int64_t) pagetok (vmt.t_rmshr) << LOG1024;
|
||||
|
||||
#if __FreeBSD__
|
||||
buf->buffer = (u_int64_t) bufspace;
|
||||
#else
|
||||
buf->buffer = (u_int64_t) pagetok (bufspace) << LOG1024;
|
||||
#endif
|
||||
|
||||
/* user */
|
||||
buf->user = buf->total - buf->free - buf->shared - buf->buffer;
|
||||
|
||||
/* Set the values to return */
|
||||
buf->flags = _glibtop_sysdeps_mem;
|
||||
|
||||
return 0;
|
||||
}
|
@@ -1,125 +0,0 @@
|
||||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright (C) 1998-99 Martin Baulig
|
||||
This file is part of LibGTop 1.0.
|
||||
|
||||
Contributed by Martin Baulig <martin@home-of-linux.org>, August 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/msg_limits.h>
|
||||
|
||||
#include <glibtop_suid.h>
|
||||
|
||||
#if (defined __bsdi__) && (_BSDI_VERSION < 199700)
|
||||
/* Older versions of BSDI don't seem to have this. */
|
||||
|
||||
int
|
||||
glibtop_init_msg_limits_p (glibtop *server)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
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));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
/* #define KERNEL to get declaration of `struct msginfo'. */
|
||||
|
||||
#if (defined __FreeBSD__) || (defined __bsdi__)
|
||||
#define KERNEL 1
|
||||
#else
|
||||
#define _KERNEL 1
|
||||
#endif
|
||||
|
||||
#include <sys/ipc.h>
|
||||
#include <sys/msg.h>
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_msg_limits =
|
||||
(1L << GLIBTOP_MSG_LIMITS_MSGMAX) + (1L << GLIBTOP_MSG_LIMITS_MSGMNI) +
|
||||
(1L << GLIBTOP_MSG_LIMITS_MSGMNB) + (1L << GLIBTOP_MSG_LIMITS_MSGTQL) +
|
||||
(1L << GLIBTOP_MSG_LIMITS_MSGSSZ);
|
||||
|
||||
/* The values in this structure never change at runtime, so we only
|
||||
* read it once during initialization. We have to use the name `_msginfo'
|
||||
* since `msginfo' is already declared external in <sys/msg.h>. */
|
||||
static struct msginfo _msginfo;
|
||||
|
||||
/* nlist structure for kernel access */
|
||||
static struct nlist nlst [] = {
|
||||
{ "_msginfo" },
|
||||
{ 0 }
|
||||
};
|
||||
|
||||
/* Init function. */
|
||||
|
||||
int
|
||||
glibtop_init_msg_limits_p (glibtop *server)
|
||||
{
|
||||
if (kvm_nlist (server->_priv->machine.kd, nlst) < 0) {
|
||||
glibtop_warn_io_r (server, "kvm_nlist (msg_limits)");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (kvm_read (server->_priv->machine.kd, nlst [0].n_value,
|
||||
&_msginfo, sizeof (_msginfo)) != sizeof (_msginfo)) {
|
||||
glibtop_warn_io_r (server, "kvm_read (msginfo)");
|
||||
return -1;
|
||||
}
|
||||
|
||||
server->sysdeps.msg_limits = _glibtop_sysdeps_msg_limits;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Provides information about sysv ipc limits. */
|
||||
|
||||
int
|
||||
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));
|
||||
|
||||
if (server->sysdeps.msg_limits == 0)
|
||||
return -1;
|
||||
|
||||
buf->msgmax = _msginfo.msgmax;
|
||||
buf->msgmni = _msginfo.msgmni;
|
||||
buf->msgmnb = _msginfo.msgmnb;
|
||||
buf->msgtql = _msginfo.msgtql;
|
||||
buf->msgssz = _msginfo.msgtql;
|
||||
|
||||
buf->flags = _glibtop_sysdeps_msg_limits;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif /* either a newer BSDI or no BSDI at all. */
|
||||
|
@@ -1,238 +0,0 @@
|
||||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright (C) 1998-99 Martin Baulig
|
||||
This file is part of LibGTop 1.0.
|
||||
|
||||
Contributed by Martin Baulig <martin@home-of-linux.org>, October 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/xmalloc.h>
|
||||
#include <glibtop/netinfo.h>
|
||||
|
||||
#include <glibtop_suid.h>
|
||||
|
||||
#include <net/if.h>
|
||||
#include <net/if_dl.h>
|
||||
#include <net/if_types.h>
|
||||
|
||||
#ifdef HAVE_NET_IF_VAR_H
|
||||
#include <net/if_var.h>
|
||||
#endif
|
||||
|
||||
#include <netinet/in.h>
|
||||
#include <netinet/in_var.h>
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_netinfo =
|
||||
(1L << GLIBTOP_NETINFO_IF_FLAGS) +
|
||||
(1L << GLIBTOP_NETINFO_MTU);
|
||||
|
||||
/* nlist structure for kernel access */
|
||||
static struct nlist nlst [] = {
|
||||
{ "_ifnet" },
|
||||
{ 0 }
|
||||
};
|
||||
|
||||
/* Init function. */
|
||||
|
||||
int
|
||||
glibtop_init_netinfo_p (glibtop *server)
|
||||
{
|
||||
server->sysdeps.netinfo = _glibtop_sysdeps_netinfo;
|
||||
|
||||
if (kvm_nlist (server->_priv->machine.kd, nlst) < 0)
|
||||
glibtop_error_io_r (server, "kvm_nlist");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
_netinfo_ipv4 (glibtop *server, glibtop_netinfo *buf,
|
||||
const char *interface, glibtop_ifaddr *address)
|
||||
{
|
||||
struct ifnet ifnet;
|
||||
u_long ifnetaddr, ifnetfound, ifaddraddr;
|
||||
char tname [16];
|
||||
|
||||
union {
|
||||
struct ifaddr ifa;
|
||||
struct in_ifaddr in;
|
||||
} ifaddr;
|
||||
|
||||
if (kvm_read (server->_priv->machine.kd, nlst [0].n_value,
|
||||
&ifnetaddr, sizeof (ifnetaddr)) != sizeof (ifnetaddr)) {
|
||||
glibtop_warn_io_r (server, "kvm_read (ifnet)");
|
||||
return -1;
|
||||
}
|
||||
|
||||
ifaddraddr = 0;
|
||||
while (ifnetaddr || ifaddraddr) {
|
||||
struct sockaddr_in *sin;
|
||||
register char *cp;
|
||||
|
||||
if (ifaddraddr == 0) {
|
||||
ifnetfound = ifnetaddr;
|
||||
|
||||
if (kvm_read (server->_priv->machine.kd, ifnetaddr, &ifnet,
|
||||
sizeof (ifnet)) != sizeof (ifnet)) {
|
||||
glibtop_warn_io_r (server, "kvm_read (ifnetaddr)");
|
||||
return -1;
|
||||
}
|
||||
|
||||
#if defined(__FreeBSD__) || defined(__bsdi__)
|
||||
if (kvm_read (server->_priv->machine.kd, (u_long) ifnet.if_name,
|
||||
tname, 16) != 16) {
|
||||
glibtop_warn_io_r (server, "kvm_read (if_name)");
|
||||
return -1;
|
||||
}
|
||||
#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;
|
||||
#elif defined(__FreeBSD__) || defined(__bsdi__)
|
||||
ifaddraddr = (u_long) ifnet.if_addrlist;
|
||||
#else
|
||||
ifaddraddr = (u_long) ifnet.if_addrlist.tqh_first;
|
||||
#endif
|
||||
}
|
||||
|
||||
if (ifaddraddr) {
|
||||
struct sockaddr *sa;
|
||||
|
||||
if ((kvm_read (server->_priv->machine.kd, ifaddraddr, &ifaddr,
|
||||
sizeof (ifaddr)) != sizeof (ifaddr))) {
|
||||
glibtop_warn_io_r (server, "kvm_read (ifaddraddr)");
|
||||
return -1;
|
||||
}
|
||||
|
||||
#define CP(x) ((char *)(x))
|
||||
|
||||
cp = (CP(ifaddr.ifa.ifa_addr) - CP(ifaddraddr)) + CP(&ifaddr);
|
||||
sa = (struct sockaddr *)cp;
|
||||
|
||||
if (!strcmp (interface, tname) && (sa->sa_family == AF_INET)) {
|
||||
sin = (struct sockaddr_in *)sa;
|
||||
|
||||
if (ifnet.if_flags & IFF_UP)
|
||||
buf->if_flags |= GLIBTOP_IF_FLAGS_UP;
|
||||
if (ifnet.if_flags & IFF_BROADCAST)
|
||||
buf->if_flags |= GLIBTOP_IF_FLAGS_BROADCAST;
|
||||
if (ifnet.if_flags & IFF_DEBUG)
|
||||
buf->if_flags |= GLIBTOP_IF_FLAGS_DEBUG;
|
||||
if (ifnet.if_flags & IFF_LOOPBACK)
|
||||
buf->if_flags |= GLIBTOP_IF_FLAGS_LOOPBACK;
|
||||
if (ifnet.if_flags & IFF_POINTOPOINT)
|
||||
buf->if_flags |= GLIBTOP_IF_FLAGS_POINTOPOINT;
|
||||
if (ifnet.if_flags & IFF_RUNNING)
|
||||
buf->if_flags |= GLIBTOP_IF_FLAGS_RUNNING;
|
||||
if (ifnet.if_flags & IFF_NOARP)
|
||||
buf->if_flags |= GLIBTOP_IF_FLAGS_NOARP;
|
||||
if (ifnet.if_flags & IFF_PROMISC)
|
||||
buf->if_flags |= GLIBTOP_IF_FLAGS_PROMISC;
|
||||
if (ifnet.if_flags & IFF_ALLMULTI)
|
||||
buf->if_flags |= GLIBTOP_IF_FLAGS_ALLMULTI;
|
||||
if (ifnet.if_flags & IFF_OACTIVE)
|
||||
buf->if_flags |= GLIBTOP_IF_FLAGS_OACTIVE;
|
||||
if (ifnet.if_flags & IFF_SIMPLEX)
|
||||
buf->if_flags |= GLIBTOP_IF_FLAGS_SIMPLEX;
|
||||
if (ifnet.if_flags & IFF_LINK0)
|
||||
buf->if_flags |= GLIBTOP_IF_FLAGS_LINK0;
|
||||
if (ifnet.if_flags & IFF_LINK1)
|
||||
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;
|
||||
|
||||
buf->mtu = ifnet.if_mtu;
|
||||
buf->flags = _glibtop_sysdeps_netinfo;
|
||||
|
||||
address->subnet = htonl (ifaddr.in.ia_subnet);
|
||||
address->flags |= (1L << GLIBTOP_IFADDR_SUBNET);
|
||||
|
||||
address->addr_len = 4;
|
||||
memcpy (&address->address, &sin->sin_addr.s_addr, 4);
|
||||
|
||||
address->flags |= (1L << GLIBTOP_IFADDR_ADDRESS);
|
||||
address->flags |= (1L << GLIBTOP_IFADDR_ADDR_LEN);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if defined(__FreeBSD__) && (__FreeBSD_version >= 300000)
|
||||
ifaddraddr = (u_long)ifaddr.ifa.ifa_link.tqe_next;
|
||||
#elif defined(__FreeBSD__) || defined(__bsdi__)
|
||||
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;
|
||||
#elif defined(__FreeBSD__) || defined(__bsdi__)
|
||||
ifnetaddr = (u_long) ifnet.if_next;
|
||||
#else
|
||||
ifnetaddr = (u_long) ifnet.if_list.tqe_next;
|
||||
#endif
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Provides Network statistics. */
|
||||
|
||||
glibtop_ifaddr *
|
||||
glibtop_get_netinfo_p (glibtop *server, glibtop_array *array,
|
||||
glibtop_netinfo *buf, const char *interface,
|
||||
u_int64_t transport)
|
||||
{
|
||||
glibtop_ifaddr address, *retval = NULL;
|
||||
|
||||
glibtop_init_p (server, (1L << GLIBTOP_SYSDEPS_NETINFO), 0);
|
||||
|
||||
memset (buf, 0, sizeof (glibtop_netinfo));
|
||||
memset (&address, 0, sizeof (glibtop_ifaddr));
|
||||
|
||||
if (transport & GLIBTOP_TRANSPORT_IPV4) {
|
||||
/* IPv4 */
|
||||
|
||||
if (!_netinfo_ipv4 (server, buf, interface, &address)) {
|
||||
retval = glibtop_calloc_r (server, 1, sizeof (glibtop_ifaddr));
|
||||
*retval = address;
|
||||
|
||||
array->number = 1;
|
||||
array->size = sizeof (glibtop_ifaddr);
|
||||
array->total = array->number * array->size;
|
||||
|
||||
return retval;
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
@@ -1,177 +0,0 @@
|
||||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright (C) 1998-99 Martin Baulig
|
||||
This file is part of LibGTop 1.0.
|
||||
|
||||
Contributed by Martin Baulig <martin@home-of-linux.org>, October 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/netload.h>
|
||||
|
||||
#include <glibtop_suid.h>
|
||||
|
||||
#include <net/if.h>
|
||||
#include <net/if_dl.h>
|
||||
#include <net/if_types.h>
|
||||
|
||||
#ifdef HAVE_NET_IF_VAR_H
|
||||
#include <net/if_var.h>
|
||||
#endif
|
||||
|
||||
#include <netinet/in.h>
|
||||
#include <netinet/in_var.h>
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_netload =
|
||||
(1L << GLIBTOP_NETLOAD_PACKETS_IN) +
|
||||
(1L << GLIBTOP_NETLOAD_PACKETS_OUT) +
|
||||
(1L << GLIBTOP_NETLOAD_PACKETS_TOTAL) +
|
||||
(1L << GLIBTOP_NETLOAD_BYTES_IN) +
|
||||
(1L << GLIBTOP_NETLOAD_BYTES_OUT) +
|
||||
(1L << GLIBTOP_NETLOAD_BYTES_TOTAL) +
|
||||
(1L << GLIBTOP_NETLOAD_ERRORS_IN) +
|
||||
(1L << GLIBTOP_NETLOAD_ERRORS_OUT) +
|
||||
(1L << GLIBTOP_NETLOAD_ERRORS_TOTAL) +
|
||||
(1L << GLIBTOP_NETLOAD_COLLISIONS);
|
||||
|
||||
/* nlist structure for kernel access */
|
||||
static struct nlist nlst [] = {
|
||||
{ "_ifnet" },
|
||||
{ 0 }
|
||||
};
|
||||
|
||||
/* Init function. */
|
||||
|
||||
int
|
||||
glibtop_init_netload_p (glibtop *server)
|
||||
{
|
||||
server->sysdeps.netload = _glibtop_sysdeps_netload;
|
||||
|
||||
if (kvm_nlist (server->_priv->machine.kd, nlst) < 0)
|
||||
glibtop_error_io_r (server, "kvm_nlist");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Provides Network statistics. */
|
||||
|
||||
int
|
||||
glibtop_get_netload_p (glibtop *server, glibtop_netload *buf,
|
||||
const char *interface, unsigned transport,
|
||||
unsigned protocol)
|
||||
{
|
||||
struct ifnet ifnet;
|
||||
u_long ifnetaddr, ifnetfound, ifaddraddr;
|
||||
struct sockaddr *sa;
|
||||
char tname [16];
|
||||
|
||||
union {
|
||||
struct ifaddr ifa;
|
||||
struct in_ifaddr in;
|
||||
} ifaddr;
|
||||
|
||||
glibtop_init_p (server, (1L << GLIBTOP_SYSDEPS_NETLOAD), 0);
|
||||
|
||||
memset (buf, 0, sizeof (glibtop_netload));
|
||||
|
||||
if (kvm_read (server->_priv->machine.kd, nlst [0].n_value,
|
||||
&ifnetaddr, sizeof (ifnetaddr)) != sizeof (ifnetaddr))
|
||||
glibtop_error_io_r (server, "kvm_read (ifnet)");
|
||||
|
||||
ifaddraddr = 0;
|
||||
while (ifnetaddr || ifaddraddr) {
|
||||
struct sockaddr_in *sin;
|
||||
register char *cp;
|
||||
|
||||
if (ifaddraddr == 0) {
|
||||
ifnetfound = ifnetaddr;
|
||||
|
||||
if (kvm_read (server->_priv->machine.kd, ifnetaddr, &ifnet,
|
||||
sizeof (ifnet)) != sizeof (ifnet))
|
||||
glibtop_error_io_r (server, "kvm_read (ifnetaddr)");
|
||||
|
||||
#if defined(__FreeBSD__) || defined(__bsdi__)
|
||||
if (kvm_read (server->_priv->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;
|
||||
#elif defined(__FreeBSD__) || defined(__bsdi__)
|
||||
ifaddraddr = (u_long) ifnet.if_addrlist;
|
||||
#else
|
||||
ifaddraddr = (u_long) ifnet.if_addrlist.tqh_first;
|
||||
#endif
|
||||
}
|
||||
|
||||
if (ifaddraddr) {
|
||||
if ((kvm_read (server->_priv->machine.kd, ifaddraddr, &ifaddr,
|
||||
sizeof (ifaddr)) != sizeof (ifaddr)))
|
||||
glibtop_error_io_r (server, "kvm_read (ifaddraddr)");
|
||||
|
||||
#define CP(x) ((char *)(x))
|
||||
cp = (CP(ifaddr.ifa.ifa_addr) - CP(ifaddraddr)) +
|
||||
CP(&ifaddr); sa = (struct sockaddr *)cp;
|
||||
|
||||
if (!strcmp (interface, tname) && (sa->sa_family == AF_INET)) {
|
||||
sin = (struct sockaddr_in *)sa;
|
||||
|
||||
buf->packets_in = ifnet.if_ipackets;
|
||||
buf->packets_out = ifnet.if_opackets;
|
||||
buf->packets_total = buf->packets_in + buf->packets_out;
|
||||
|
||||
buf->bytes_in = ifnet.if_ibytes;
|
||||
buf->bytes_out = ifnet.if_obytes;
|
||||
buf->bytes_total = buf->bytes_in + buf->bytes_out;
|
||||
|
||||
buf->errors_in = ifnet.if_ierrors;
|
||||
buf->errors_out = ifnet.if_oerrors;
|
||||
buf->errors_total = buf->errors_in + buf->errors_out;
|
||||
|
||||
buf->collisions = ifnet.if_collisions;
|
||||
buf->flags = _glibtop_sysdeps_netload;
|
||||
return -1;
|
||||
}
|
||||
|
||||
#if defined(__FreeBSD__) && (__FreeBSD_version >= 300000)
|
||||
ifaddraddr = (u_long)ifaddr.ifa.ifa_link.tqe_next;
|
||||
#elif defined(__FreeBSD__) || defined(__bsdi__)
|
||||
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;
|
||||
#elif defined(__FreeBSD__) || defined(__bsdi__)
|
||||
ifnetaddr = (u_long) ifnet.if_next;
|
||||
#else
|
||||
ifnetaddr = (u_long) ifnet.if_list.tqe_next;
|
||||
#endif
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
@@ -1,100 +0,0 @@
|
||||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright (C) 1998 Joshua Sled
|
||||
This file is part of LibGTop 1.0.
|
||||
|
||||
Contributed by Joshua Sled <jsled@xcf.berkeley.edu>, July 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/open.h>
|
||||
#include <glibtop/xmalloc.h>
|
||||
|
||||
/* !!! THIS FUNCTION RUNS SUID ROOT - CHANGE WITH CAUTION !!! */
|
||||
|
||||
void
|
||||
glibtop_init_p (glibtop *server, const unsigned long features,
|
||||
const unsigned flags)
|
||||
{
|
||||
glibtop_init_func_t *init_fkt;
|
||||
|
||||
if (server == NULL)
|
||||
glibtop_error_r (NULL, "glibtop_init_p (server == NULL)");
|
||||
|
||||
/* Do the initialization, but only if not already initialized. */
|
||||
|
||||
if ((server->flags & _GLIBTOP_INIT_STATE_SYSDEPS) == 0) {
|
||||
glibtop_open_p (server, "glibtop", features, flags);
|
||||
|
||||
for (init_fkt = _glibtop_init_hook_p; *init_fkt; init_fkt++)
|
||||
(*init_fkt) (server);
|
||||
|
||||
server->flags |= _GLIBTOP_INIT_STATE_SYSDEPS;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
glibtop_open_p (glibtop *server, const char *program_name,
|
||||
const unsigned long features,
|
||||
const unsigned flags)
|
||||
{
|
||||
#ifdef DEBUG
|
||||
fprintf (stderr, "DEBUG (%d): glibtop_open_p ()\n", getpid ());
|
||||
#endif
|
||||
|
||||
/* !!! WE ARE ROOT HERE - CHANGE WITH CAUTION !!! */
|
||||
|
||||
server->_priv->machine.uid = getuid ();
|
||||
server->_priv->machine.euid = geteuid ();
|
||||
server->_priv->machine.gid = getgid ();
|
||||
server->_priv->machine.egid = getegid ();
|
||||
|
||||
#ifdef __FreeBSD__
|
||||
server->os_version_code = __FreeBSD_version;
|
||||
#endif
|
||||
|
||||
/* Setup machine-specific data */
|
||||
server->_priv->machine.kd = kvm_open
|
||||
(NULL, NULL, NULL, O_RDONLY, "kvm_open");
|
||||
|
||||
if (server->_priv->machine.kd == NULL)
|
||||
glibtop_error_io_r (server, "kvm_open");
|
||||
|
||||
/* Drop priviledges. */
|
||||
|
||||
if (setreuid (server->_priv->machine.euid,
|
||||
server->_priv->machine.uid))
|
||||
_exit (1);
|
||||
|
||||
if (setregid (server->_priv->machine.egid,
|
||||
server->_priv->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 FreeBSD, 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. */
|
||||
}
|
@@ -1,151 +0,0 @@
|
||||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright (C) 1998-99 Martin Baulig
|
||||
This file is part of LibGTop 1.0.
|
||||
|
||||
Contributed by Martin Baulig <martin@home-of-linux.org>, October 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/ppp.h>
|
||||
|
||||
#include <glibtop_suid.h>
|
||||
|
||||
#ifdef HAVE_I4B
|
||||
|
||||
#include <net/if.h>
|
||||
#include <net/if_types.h>
|
||||
|
||||
#ifdef HAVE_NET_IF_VAR_H
|
||||
#include <net/if_var.h>
|
||||
#endif
|
||||
|
||||
#include <net/netisr.h>
|
||||
#include <net/route.h>
|
||||
|
||||
#if defined(__FreeBSD__) || defined(__NetBSD__)
|
||||
#include <net/if_sppp.h>
|
||||
#else
|
||||
#include <i4b/sppp/if_sppp.h>
|
||||
#endif
|
||||
|
||||
/* Read `misc/i4b_acct.txt' for details ... */
|
||||
#ifdef HAVE_I4B_ACCT
|
||||
#include <machine/i4b_acct.h>
|
||||
#endif
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_ppp =
|
||||
(1L << GLIBTOP_PPP_STATE);
|
||||
|
||||
#ifdef HAVE_I4B_ACCT
|
||||
static const unsigned long _glibtop_sysdeps_ppp_acct =
|
||||
(1L << GLIBTOP_PPP_BYTES_IN) + (1L << GLIBTOP_PPP_BYTES_OUT);
|
||||
#endif
|
||||
|
||||
#endif /* HAVE_I4B */
|
||||
|
||||
/* nlist structure for kernel access */
|
||||
static struct nlist nlst [] = {
|
||||
#ifdef HAVE_I4B
|
||||
{ "_i4bisppp_softc" },
|
||||
#endif
|
||||
{ 0 }
|
||||
};
|
||||
|
||||
/* Init function. */
|
||||
|
||||
int
|
||||
glibtop_init_ppp_p (glibtop *server)
|
||||
{
|
||||
#ifdef HAVE_I4B
|
||||
#ifdef HAVE_I4B_ACCT
|
||||
server->sysdeps.ppp = _glibtop_sysdeps_ppp |
|
||||
_glibtop_sysdeps_ppp_acct;
|
||||
#else
|
||||
server->sysdeps.ppp = _glibtop_sysdeps_ppp;
|
||||
#endif
|
||||
#endif /* HAVE_I4B */
|
||||
|
||||
if (kvm_nlist (server->_priv->machine.kd, nlst) < 0)
|
||||
glibtop_error_io_r (server, "kvm_nlist");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Provides information about ppp usage. */
|
||||
|
||||
int
|
||||
glibtop_get_ppp_p (glibtop *server, glibtop_ppp *buf, unsigned short device,
|
||||
unsigned short isdn)
|
||||
{
|
||||
#ifdef HAVE_I4B
|
||||
#ifdef HAVE_I4B_ACCT
|
||||
struct i4bisppp_softc data;
|
||||
#else
|
||||
struct sppp data;
|
||||
#endif
|
||||
int phase;
|
||||
|
||||
glibtop_init_p (server, (1L << GLIBTOP_SYSDEPS_PPP), 0);
|
||||
|
||||
memset (buf, 0, sizeof (glibtop_ppp));
|
||||
|
||||
if (kvm_read (server->_priv->machine.kd, nlst [0].n_value,
|
||||
&data, sizeof (data)) != sizeof (data))
|
||||
glibtop_error_io_r (server, "kvm_read (i4bisppp_softc)");
|
||||
|
||||
#ifdef HAVE_I4B_ACCT
|
||||
phase = data.sc_if_un.scu_sp.pp_phase;
|
||||
#else
|
||||
/* FIXME: Which FreeBSD version have this field and
|
||||
* which not. */
|
||||
#if 0
|
||||
phase = data.pp_phase;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
switch (phase) {
|
||||
#ifdef HAVE_I4B_ACCT
|
||||
case PHASE_DEAD:
|
||||
case PHASE_TERMINATE:
|
||||
buf->state = GLIBTOP_PPP_STATE_HANGUP;
|
||||
break;
|
||||
case PHASE_ESTABLISH:
|
||||
case PHASE_NETWORK:
|
||||
buf->state = GLIBTOP_PPP_STATE_ONLINE;
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
buf->state = GLIBTOP_PPP_STATE_UNKNOWN;
|
||||
break;
|
||||
}
|
||||
|
||||
buf->flags = _glibtop_sysdeps_ppp;
|
||||
|
||||
#ifdef HAVE_I4B_ACCT
|
||||
buf->bytes_in = data.sc_inb;
|
||||
buf->bytes_out = data.sc_outb;
|
||||
buf->flags |= _glibtop_sysdeps_ppp_acct;
|
||||
#endif
|
||||
#endif /* HAVE_I4B */
|
||||
|
||||
return 0;
|
||||
}
|
@@ -1,114 +0,0 @@
|
||||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright (C) 1998 Joshua Sled
|
||||
This file is part of LibGTop 1.0.
|
||||
|
||||
Contributed by Joshua Sled <jsled@xcf.berkeley.edu>, July 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/xmalloc.h>
|
||||
#include <glibtop/procargs.h>
|
||||
|
||||
#include <glibtop_suid.h>
|
||||
|
||||
#include <kvm.h>
|
||||
#include <sys/param.h>
|
||||
#include <sys/proc.h>
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_proc_args =
|
||||
(1L << GLIBTOP_ARRAY_NUMBER) + (1L << GLIBTOP_ARRAY_SIZE);
|
||||
|
||||
/* Init function. */
|
||||
|
||||
int
|
||||
glibtop_init_proc_args_p (glibtop *server)
|
||||
{
|
||||
server->sysdeps.proc_args = _glibtop_sysdeps_proc_args;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Provides detailed information about a process. */
|
||||
|
||||
char **
|
||||
glibtop_get_proc_args_p (glibtop *server, glibtop_array *array, pid_t pid)
|
||||
{
|
||||
struct kinfo_proc *pinfo;
|
||||
char **args, **ptr, **ptrlist;
|
||||
size_t count;
|
||||
int i;
|
||||
|
||||
#ifndef __bsdi__
|
||||
char filename [BUFSIZ];
|
||||
struct stat statb;
|
||||
#endif
|
||||
|
||||
glibtop_init_p (server, (1L << GLIBTOP_SYSDEPS_PROC_ARGS), 0);
|
||||
|
||||
memset (array, 0, sizeof (glibtop_array));
|
||||
|
||||
/* swapper, init, pagedaemon, vmdaemon, update - this doen't work. */
|
||||
if (pid < 5) return NULL;
|
||||
|
||||
#ifndef __bsdi__
|
||||
sprintf (filename, "/proc/%d/mem", pid);
|
||||
if (stat (filename, &statb)) return NULL;
|
||||
#endif
|
||||
|
||||
glibtop_suid_enter (server);
|
||||
|
||||
/* Get the process data */
|
||||
pinfo = kvm_getprocs (server->_priv->machine.kd,
|
||||
KERN_PROC_PID, pid, &count);
|
||||
if ((pinfo == NULL) || (count < 1)) {
|
||||
glibtop_suid_leave (server);
|
||||
glibtop_warn_io_r (server, "kvm_getprocs (%d)", pid);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
args = kvm_getargv (server->_priv->machine.kd, pinfo, BUFSIZ);
|
||||
if (args == NULL) {
|
||||
glibtop_suid_leave (server);
|
||||
glibtop_warn_io_r (server, "kvm_getargv (%d)", pid);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
glibtop_suid_leave (server);
|
||||
|
||||
count = 0;
|
||||
for (ptr = args; *ptr; ptr++)
|
||||
count++;
|
||||
|
||||
ptrlist = glibtop_calloc_r (server, count+1, sizeof (char *));
|
||||
|
||||
for (i = 0, ptr = args; *ptr; ptr++, i++) {
|
||||
ptrlist [i] = glibtop_strdup_r (server, *ptr);
|
||||
}
|
||||
|
||||
ptrlist [count] = NULL;
|
||||
|
||||
array->number = count;
|
||||
array->size = sizeof (char *);
|
||||
array->flags = _glibtop_sysdeps_proc_args;
|
||||
|
||||
return ptrlist;
|
||||
}
|
@@ -1,182 +0,0 @@
|
||||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright (C) 1998 Joshua Sled
|
||||
This file is part of LibGTop 1.0.
|
||||
|
||||
Contributed by Joshua Sled <jsled@xcf.berkeley.edu>, July 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 <config.h>
|
||||
#include <glibtop/procdata.h>
|
||||
|
||||
#include <sys/stat.h>
|
||||
|
||||
#define LINUX_VERSION(x,y,z) (0x10000*(x) + 0x100*(y) + z)
|
||||
|
||||
#define BIT_SHIFT(x) (1L << (x % 64))
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_procdata_0 =
|
||||
BIT_SHIFT(GLIBTOP_PROCDATA_CMD) +
|
||||
BIT_SHIFT(GLIBTOP_PROCDATA_STATE) +
|
||||
BIT_SHIFT(GLIBTOP_PROCDATA_UID) +
|
||||
BIT_SHIFT(GLIBTOP_PROCDATA_PID) +
|
||||
BIT_SHIFT(GLIBTOP_PROCDATA_PPID) +
|
||||
BIT_SHIFT(GLIBTOP_PROCDATA_PGRP) +
|
||||
BIT_SHIFT(GLIBTOP_PROCDATA_SESSION) +
|
||||
BIT_SHIFT(GLIBTOP_PROCDATA_TTY) +
|
||||
BIT_SHIFT(GLIBTOP_PROCDATA_TPGID) +
|
||||
BIT_SHIFT(GLIBTOP_PROCDATA_PRIORITY) +
|
||||
BIT_SHIFT(GLIBTOP_PROCDATA_NICE) +
|
||||
BIT_SHIFT(GLIBTOP_PROCDATA_SIGNAL) +
|
||||
BIT_SHIFT(GLIBTOP_PROCDATA_BLOCKED) +
|
||||
BIT_SHIFT(GLIBTOP_PROCDATA_SIGIGNORE) +
|
||||
BIT_SHIFT(GLIBTOP_PROCDATA_SIGCATCH) +
|
||||
BIT_SHIFT(GLIBTOP_PROCDATA_START_TIME) +
|
||||
BIT_SHIFT(GLIBTOP_PROCDATA_UTIME) +
|
||||
BIT_SHIFT(GLIBTOP_PROCDATA_STIME) +
|
||||
BIT_SHIFT(GLIBTOP_PROCDATA_CUTIME) +
|
||||
BIT_SHIFT(GLIBTOP_PROCDATA_CSTIME) +
|
||||
BIT_SHIFT(GLIBTOP_PROCDATA_SIZE) +
|
||||
BIT_SHIFT(GLIBTOP_PROCDATA_RESIDENT) +
|
||||
BIT_SHIFT(GLIBTOP_PROCDATA_SHARE) +
|
||||
BIT_SHIFT(GLIBTOP_PROCDATA_TRS) +
|
||||
BIT_SHIFT(GLIBTOP_PROCDATA_LRS) +
|
||||
BIT_SHIFT(GLIBTOP_PROCDATA_DRS) +
|
||||
BIT_SHIFT(GLIBTOP_PROCDATA_DT) +
|
||||
BIT_SHIFT(GLIBTOP_PROCDATA_VSIZE) +
|
||||
BIT_SHIFT(GLIBTOP_PROCDATA_RSS) +
|
||||
BIT_SHIFT(GLIBTOP_PROCDATA_RSS_RLIM) +
|
||||
BIT_SHIFT(GLIBTOP_PROCDATA_TIMEOUT) +
|
||||
BIT_SHIFT(GLIBTOP_PROCDATA_IT_REAL_VALUE);
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_procdata_1 =
|
||||
BIT_SHIFT(GLIBTOP_PROCDATA_K_FLAGS) +
|
||||
BIT_SHIFT(GLIBTOP_PROCDATA_MIN_FLT) +
|
||||
BIT_SHIFT(GLIBTOP_PROCDATA_MAJ_FLT) +
|
||||
BIT_SHIFT(GLIBTOP_PROCDATA_CMIN_FLT) +
|
||||
BIT_SHIFT(GLIBTOP_PROCDATA_CMAJ_FLT) +
|
||||
BIT_SHIFT(GLIBTOP_PROCDATA_START_CODE) +
|
||||
BIT_SHIFT(GLIBTOP_PROCDATA_END_CODE) +
|
||||
BIT_SHIFT(GLIBTOP_PROCDATA_START_STACK) +
|
||||
BIT_SHIFT(GLIBTOP_PROCDATA_KSTK_ESP) +
|
||||
BIT_SHIFT(GLIBTOP_PROCDATA_KSTK_EIP) +
|
||||
BIT_SHIFT(GLIBTOP_PROCDATA_WCHAN);
|
||||
|
||||
/* Provides detailed information about a process. */
|
||||
|
||||
void
|
||||
glibtop_get_procdata_s (glibtop *server, glibtop_procdata *buf, pid_t pid)
|
||||
{
|
||||
char input [BUFSIZ], *tmp;
|
||||
struct stat statb;
|
||||
int nread;
|
||||
FILE *f;
|
||||
|
||||
glibtop_init_r (&server, 0, 0);
|
||||
|
||||
memset (buf, 0, sizeof (glibtop_procdata));
|
||||
|
||||
if (pid == 0) {
|
||||
/* Client is only interested in the flags. */
|
||||
buf->flags [0] = _glibtop_sysdeps_procdata_0;
|
||||
buf->flags [1] = _glibtop_sysdeps_procdata_1;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
sprintf (input, "/proc/%d/stat", pid);
|
||||
|
||||
if (stat (input, &statb)) return;
|
||||
|
||||
buf->uid = statb.st_uid;
|
||||
|
||||
f = fopen (input, "r");
|
||||
if (!f) return;
|
||||
|
||||
nread = fread (input, 1, BUFSIZ, f);
|
||||
|
||||
if (nread < 0) {
|
||||
fclose (f);
|
||||
return;
|
||||
}
|
||||
|
||||
input [nread] = 0;
|
||||
|
||||
/* This is from guile-utils/gtop/proc/readproc.c */
|
||||
|
||||
/* split into "PID (cmd" and "<rest>" */
|
||||
tmp = strrchr (input, ')');
|
||||
*tmp = '\0'; /* replace trailing ')' with NUL */
|
||||
/* parse these two strings separately, skipping the leading "(". */
|
||||
memset (buf->cmd, 0, sizeof (buf->cmd));
|
||||
sscanf (input, "%d (%39c", &buf->pid, buf->cmd);
|
||||
sscanf(tmp + 2, /* skip space after ')' too */
|
||||
"%c %d %d %d %d %d %lu %lu %lu %lu %lu "
|
||||
"%ld %ld %ld %ld %d %d %lu %lu %ld %lu "
|
||||
"%lu %lu %lu %lu %lu %lu %lu %d %d %d %d %lu",
|
||||
&buf->state, &buf->ppid, &buf->pgrp, &buf->session,
|
||||
&buf->tty, &buf->tpgid, &buf->k_flags, &buf->min_flt,
|
||||
&buf->cmin_flt, &buf->maj_flt, &buf->cmaj_flt,
|
||||
&buf->utime, &buf->stime, &buf->cutime, &buf->cstime,
|
||||
&buf->priority, &buf->nice, &buf->timeout,
|
||||
&buf->it_real_value, &buf->start_time, &buf->vsize,
|
||||
&buf->rss, &buf->rss_rlim, &buf->start_code,
|
||||
&buf->end_code, &buf->start_stack, &buf->kstk_esp,
|
||||
&buf->kstk_eip, &buf->signal, &buf->blocked,
|
||||
&buf->sigignore, &buf->sigcatch, &buf->wchan);
|
||||
|
||||
if (buf->tty == 0)
|
||||
/* the old notty val, update elsewhere bef. moving to 0 */
|
||||
buf->tty = -1;
|
||||
|
||||
if (server->os_version_code < LINUX_VERSION(1,3,39)) {
|
||||
/* map old meanings to new */
|
||||
buf->priority = 2*15 - buf->priority;
|
||||
buf->nice = 15 - buf->nice;
|
||||
}
|
||||
if (server->os_version_code < LINUX_VERSION(1,1,30) && buf->tty != -1)
|
||||
/* when tty wasn't full devno */
|
||||
buf->tty = 4*0x100 + buf->tty;
|
||||
|
||||
fclose (f);
|
||||
|
||||
sprintf (input, "/proc/%d/statm", pid);
|
||||
|
||||
f = fopen (input, "r");
|
||||
if (!f) return;
|
||||
|
||||
nread = fread (input, 1, BUFSIZ, f);
|
||||
|
||||
if (nread < 0) {
|
||||
fclose (f);
|
||||
return;
|
||||
}
|
||||
|
||||
input [nread] = 0;
|
||||
|
||||
sscanf (input, "%ld %ld %ld %ld %ld %ld %ld",
|
||||
&buf->size, &buf->resident, &buf->share,
|
||||
&buf->trs, &buf->lrs, &buf->drs, &buf->dt);
|
||||
|
||||
fclose (f);
|
||||
|
||||
buf->flags [0] = _glibtop_sysdeps_procdata_0;
|
||||
buf->flags [1] = _glibtop_sysdeps_procdata_1;
|
||||
}
|
@@ -1,191 +0,0 @@
|
||||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright (C) 1998 Joshua Sled
|
||||
This file is part of LibGTop 1.0.
|
||||
|
||||
Contributed by Joshua Sled <jsled@xcf.berkeley.edu>, July 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/prockernel.h>
|
||||
|
||||
#include <glibtop_suid.h>
|
||||
|
||||
#include <kvm.h>
|
||||
#include <sys/param.h>
|
||||
#include <sys/sysctl.h>
|
||||
#include <sys/proc.h>
|
||||
#if (!defined __OpenBSD__) && (!defined __bsdi__)
|
||||
#include <sys/user.h>
|
||||
#endif
|
||||
#if !defined(__bsdi__) && !(defined(__FreeBSD__) && defined(__alpha__))
|
||||
#include <machine/pcb.h>
|
||||
#endif
|
||||
#if defined(__FreeBSD__) && !defined(__alpha__)
|
||||
#include <machine/tss.h>
|
||||
#endif
|
||||
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
#ifdef HAVE_OSRELDATE_H
|
||||
#include <osreldate.h>
|
||||
#endif
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_proc_kernel_pstats =
|
||||
(1L << GLIBTOP_PROC_KERNEL_MIN_FLT) +
|
||||
(1L << GLIBTOP_PROC_KERNEL_MAJ_FLT) +
|
||||
(1L << GLIBTOP_PROC_KERNEL_CMIN_FLT) +
|
||||
(1L << GLIBTOP_PROC_KERNEL_CMAJ_FLT);
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_proc_kernel_pcb =
|
||||
(1L << GLIBTOP_PROC_KERNEL_KSTK_EIP) +
|
||||
(1L << GLIBTOP_PROC_KERNEL_KSTK_ESP);
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_proc_kernel_wchan =
|
||||
(1L << GLIBTOP_PROC_KERNEL_NWCHAN) +
|
||||
(1L << GLIBTOP_PROC_KERNEL_WCHAN);
|
||||
|
||||
/* Init function. */
|
||||
|
||||
int
|
||||
glibtop_init_proc_kernel_p (glibtop *server)
|
||||
{
|
||||
server->sysdeps.proc_kernel = _glibtop_sysdeps_proc_kernel_pstats |
|
||||
_glibtop_sysdeps_proc_kernel_pcb |
|
||||
_glibtop_sysdeps_proc_kernel_wchan;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
glibtop_get_proc_kernel_p (glibtop *server,
|
||||
glibtop_proc_kernel *buf,
|
||||
pid_t pid)
|
||||
{
|
||||
struct kinfo_proc *pinfo;
|
||||
struct user *u_addr = (struct user *)USRSTACK;
|
||||
struct pstats pstats;
|
||||
struct pcb pcb;
|
||||
int count;
|
||||
|
||||
char filename [BUFSIZ];
|
||||
struct stat statb;
|
||||
|
||||
glibtop_init_p (server, (1L << GLIBTOP_SYSDEPS_PROC_KERNEL), 0);
|
||||
|
||||
memset (buf, 0, sizeof (glibtop_proc_kernel));
|
||||
|
||||
if (server->sysdeps.proc_time == 0)
|
||||
return -1;
|
||||
|
||||
/* It does not work for the swapper task. */
|
||||
if (pid == 0) return -1;
|
||||
|
||||
/* Get the process information */
|
||||
pinfo = kvm_getprocs (server->_priv->machine.kd,
|
||||
KERN_PROC_PID, pid, &count);
|
||||
if ((pinfo == NULL) || (count != 1))
|
||||
glibtop_error_io_r (server, "kvm_getprocs (%d)", pid);
|
||||
|
||||
buf->nwchan = (unsigned long) pinfo [0].kp_proc.p_wchan &~ KERNBASE;
|
||||
buf->flags |= (1L << GLIBTOP_PROC_KERNEL_NWCHAN);
|
||||
|
||||
if (pinfo [0].kp_proc.p_wchan && pinfo [0].kp_proc.p_wmesg) {
|
||||
strncpy (buf->wchan, pinfo [0].kp_eproc.e_wmesg,
|
||||
sizeof (buf->wchan) - 1);
|
||||
buf->wchan [sizeof (buf->wchan) - 1] = 0;
|
||||
buf->flags |= (1L << GLIBTOP_PROC_KERNEL_WCHAN);
|
||||
} else {
|
||||
buf->wchan [0] = 0;
|
||||
}
|
||||
|
||||
/* Taken from `saveuser ()' in `/usr/src/bin/ps/ps.c'. */
|
||||
|
||||
/* [FIXME]: /usr/include/sys/user.h tells me that the user area
|
||||
* may or may not be at the same kernel address in all
|
||||
* processes, but I don't see any way to get that address.
|
||||
* Since `ps' simply uses its own address, I think it's
|
||||
* safe to do this here, too. */
|
||||
|
||||
/* NOTE: You need to mount the /proc filesystem to make
|
||||
* `kvm_uread' work. */
|
||||
|
||||
sprintf (filename, "/proc/%d/mem", (int) pid);
|
||||
if (stat (filename, &statb)) return -1;
|
||||
|
||||
glibtop_suid_enter (server);
|
||||
|
||||
if ((pinfo [0].kp_proc.p_flag & P_INMEM) &&
|
||||
kvm_uread (server->_priv->machine.kd, &(pinfo [0]).kp_proc,
|
||||
(unsigned long) &u_addr->u_stats,
|
||||
(char *) &pstats, sizeof (pstats)) == sizeof (pstats))
|
||||
{
|
||||
/*
|
||||
* The u-area might be swapped out, and we can't get
|
||||
* at it because we have a crashdump and no swap.
|
||||
* If it's here fill in these fields, otherwise, just
|
||||
* leave them 0.
|
||||
*/
|
||||
|
||||
buf->min_flt = (u_int64_t) pstats.p_ru.ru_minflt;
|
||||
buf->maj_flt = (u_int64_t) pstats.p_ru.ru_majflt;
|
||||
buf->cmin_flt = (u_int64_t) pstats.p_cru.ru_minflt;
|
||||
buf->cmaj_flt = (u_int64_t) pstats.p_cru.ru_majflt;
|
||||
|
||||
buf->flags |= _glibtop_sysdeps_proc_kernel_pstats;
|
||||
}
|
||||
|
||||
if ((pinfo [0].kp_proc.p_flag & P_INMEM) &&
|
||||
kvm_uread (server->_priv->machine.kd, &(pinfo [0]).kp_proc,
|
||||
(unsigned long) &u_addr->u_pcb,
|
||||
(char *) &pcb, sizeof (pcb)) == sizeof (pcb))
|
||||
{
|
||||
#ifdef __FreeBSD__
|
||||
#ifndef __alpha__
|
||||
#if (__FreeBSD_version >= 300003)
|
||||
buf->kstk_esp = (u_int64_t) pcb.pcb_esp;
|
||||
buf->kstk_eip = (u_int64_t) pcb.pcb_eip;
|
||||
#else
|
||||
buf->kstk_esp = (u_int64_t) pcb.pcb_ksp;
|
||||
buf->kstk_eip = (u_int64_t) pcb.pcb_pc;
|
||||
#endif
|
||||
#else
|
||||
/*xxx FreeBSD/Alpha? */
|
||||
#endif
|
||||
#else
|
||||
buf->kstk_esp = (u_int64_t) pcb.pcb_tss.tss_esp0;
|
||||
#ifdef __bsdi__
|
||||
buf->kstk_eip = (u_int64_t) pcb.pcb_tss.tss_eip;
|
||||
#else
|
||||
buf->kstk_eip = (u_int64_t) pcb.pcb_tss.__tss_eip;
|
||||
#endif
|
||||
|
||||
buf->flags |= _glibtop_sysdeps_proc_kernel_pcb;
|
||||
#endif
|
||||
}
|
||||
|
||||
/* Taken from `wchan ()' in `/usr/src/bin/ps/print.c'. */
|
||||
|
||||
glibtop_suid_leave (server);
|
||||
|
||||
return 0;
|
||||
}
|
@@ -1,107 +0,0 @@
|
||||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright (C) 1998 Joshua Sled
|
||||
This file is part of LibGTop 1.0.
|
||||
|
||||
Contributed by Joshua Sled <jsled@xcf.berkeley.edu>, July 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/xmalloc.h>
|
||||
#include <glibtop/proclist.h>
|
||||
|
||||
#include <glibtop_suid.h>
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_proclist =
|
||||
(1L << GLIBTOP_PROCLIST_TOTAL) + (1L << GLIBTOP_PROCLIST_NUMBER) +
|
||||
(1L << 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.
|
||||
* The calling function has to free the memory to which a pointer is returned.
|
||||
*
|
||||
* On error, NULL is returned and buf->flags is zero. */
|
||||
|
||||
/* Init function. */
|
||||
|
||||
int
|
||||
glibtop_init_proclist_p (glibtop *server)
|
||||
{
|
||||
server->sysdeps.proclist = _glibtop_sysdeps_proclist;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
unsigned *
|
||||
glibtop_get_proclist_p (glibtop *server, glibtop_proclist *buf,
|
||||
int64_t real_which, int64_t arg)
|
||||
{
|
||||
struct kinfo_proc *pinfo;
|
||||
unsigned *pids = NULL;
|
||||
int which, count;
|
||||
int i,j;
|
||||
|
||||
glibtop_init_p (server, (1L << GLIBTOP_SYSDEPS_PROCLIST), 0);
|
||||
|
||||
memset (buf, 0, sizeof (glibtop_proclist));
|
||||
|
||||
which = (int)(real_which & GLIBTOP_KERN_PROC_MASK);
|
||||
|
||||
/* Get the process data */
|
||||
pinfo = kvm_getprocs (server->_priv->machine.kd, which, arg, &count);
|
||||
if ((pinfo == NULL) || (count < 1)) {
|
||||
glibtop_warn_io_r (server, "kvm_getprocs (proclist)");
|
||||
return 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=j=0; i < count; i++) {
|
||||
if ((real_which & GLIBTOP_EXCLUDE_IDLE) &&
|
||||
(pinfo[i].kp_proc.p_stat != SRUN))
|
||||
continue;
|
||||
else if ((real_which & GLIBTOP_EXCLUDE_SYSTEM) &&
|
||||
(pinfo[i].kp_eproc.e_pcred.p_ruid == 0))
|
||||
continue;
|
||||
pids [j++] = (unsigned) pinfo[i].kp_proc.p_pid;
|
||||
} /* end for */
|
||||
/* Set the fields in buf */
|
||||
buf->number = j;
|
||||
buf->size = sizeof (unsigned);
|
||||
buf->total = j * sizeof (unsigned);
|
||||
buf->flags = _glibtop_sysdeps_proclist;
|
||||
return pids;
|
||||
}
|
@@ -1,271 +0,0 @@
|
||||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright (C) 1998 Joshua Sled
|
||||
This file is part of LibGTop 1.0.
|
||||
|
||||
Contributed by Joshua Sled <jsled@xcf.berkeley.edu>, July 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/xmalloc.h>
|
||||
#include <glibtop/procmap.h>
|
||||
|
||||
#include <glibtop_suid.h>
|
||||
|
||||
#include <kvm.h>
|
||||
#include <sys/param.h>
|
||||
#include <sys/proc.h>
|
||||
#include <sys/resource.h>
|
||||
#include <vm/vm_object.h>
|
||||
#include <vm/vm_prot.h>
|
||||
#include <vm/vm_map.h>
|
||||
|
||||
#include <sys/vnode.h>
|
||||
#include <sys/mount.h>
|
||||
#include <ufs/ufs/quota.h>
|
||||
#include <ufs/ufs/inode.h>
|
||||
|
||||
#include <sys/ucred.h>
|
||||
#if (!defined __OpenBSD__) && (!defined __bsdi__)
|
||||
#include <sys/user.h>
|
||||
#endif
|
||||
#include <sys/sysctl.h>
|
||||
#include <vm/vm.h>
|
||||
|
||||
#if defined(__NetBSD__) && (__NetBSD_Version__ >= 104000000)
|
||||
/* Fixme ... */
|
||||
#undef _KERNEL
|
||||
#define _UVM_UVM_AMAP_I_H_ 1
|
||||
#define _UVM_UVM_MAP_I_H_ 1
|
||||
#include <uvm/uvm.h>
|
||||
#endif
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_proc_map =
|
||||
(1L << GLIBTOP_PROC_MAP_TOTAL) + (1L << GLIBTOP_PROC_MAP_NUMBER) +
|
||||
(1L << GLIBTOP_PROC_MAP_SIZE);
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_map_entry =
|
||||
(1L << GLIBTOP_MAP_ENTRY_START) + (1L << GLIBTOP_MAP_ENTRY_END) +
|
||||
(1L << GLIBTOP_MAP_ENTRY_OFFSET) + (1L << GLIBTOP_MAP_ENTRY_PERM) +
|
||||
(1L << GLIBTOP_MAP_ENTRY_INODE) + (1L << GLIBTOP_MAP_ENTRY_DEVICE);
|
||||
|
||||
/* Init function. */
|
||||
|
||||
int
|
||||
glibtop_init_proc_map_p (glibtop *server)
|
||||
{
|
||||
server->sysdeps.proc_map = _glibtop_sysdeps_proc_map;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Provides detailed information about a process. */
|
||||
|
||||
glibtop_map_entry *
|
||||
glibtop_get_proc_map_p (glibtop *server, glibtop_proc_map *buf,
|
||||
pid_t pid)
|
||||
{
|
||||
struct kinfo_proc *pinfo;
|
||||
struct vm_map_entry entry, *first;
|
||||
struct vmspace vmspace;
|
||||
#if defined(__NetBSD__) && (__NetBSD_Version__ >= 104000000)
|
||||
struct vnode vnode;
|
||||
struct inode inode;
|
||||
#else
|
||||
struct vm_object object;
|
||||
#endif
|
||||
glibtop_map_entry *maps;
|
||||
#if defined __FreeBSD__
|
||||
struct vnode vnode;
|
||||
struct inode inode;
|
||||
struct mount mount;
|
||||
#endif
|
||||
int count, i = 0;
|
||||
int update = 0;
|
||||
|
||||
glibtop_init_p (server, (1L << GLIBTOP_SYSDEPS_PROC_MAP), 0);
|
||||
|
||||
memset (buf, 0, sizeof (glibtop_proc_map));
|
||||
|
||||
/* It does not work for the swapper task. */
|
||||
if (pid == 0) return NULL;
|
||||
|
||||
glibtop_suid_enter (server);
|
||||
|
||||
/* Get the process data */
|
||||
pinfo = kvm_getprocs (server->_priv->machine.kd,
|
||||
KERN_PROC_PID, pid, &count);
|
||||
if ((pinfo == NULL) || (count < 1))
|
||||
glibtop_error_io_r (server, "kvm_getprocs (%d)", pid);
|
||||
|
||||
/* Now we get the memory maps. */
|
||||
|
||||
if (kvm_read (server->_priv->machine.kd,
|
||||
(unsigned long) pinfo [0].kp_proc.p_vmspace,
|
||||
(char *) &vmspace, sizeof (vmspace)) != sizeof (vmspace))
|
||||
glibtop_error_io_r (server, "kvm_read (vmspace)");
|
||||
|
||||
first = vmspace.vm_map.header.next;
|
||||
|
||||
if (kvm_read (server->_priv->machine.kd,
|
||||
(unsigned long) vmspace.vm_map.header.next,
|
||||
(char *) &entry, sizeof (entry)) != sizeof (entry))
|
||||
glibtop_error_io_r (server, "kvm_read (entry)");
|
||||
|
||||
/* Allocate space. */
|
||||
|
||||
buf->number = vmspace.vm_map.nentries;
|
||||
buf->size = sizeof (glibtop_map_entry);
|
||||
|
||||
buf->total = buf->number * buf->size;
|
||||
|
||||
maps = glibtop_malloc_r (server, buf->total);
|
||||
|
||||
memset (maps, 0, buf->total);
|
||||
|
||||
buf->flags = _glibtop_sysdeps_proc_map;
|
||||
|
||||
/* Walk through the `vm_map_entry' list ... */
|
||||
|
||||
/* I tested this a few times with `mmap'; as soon as you write
|
||||
* to the mmap'ed area, the object type changes from OBJT_VNODE
|
||||
* to OBJT_DEFAULT so if seems this really works. */
|
||||
|
||||
do {
|
||||
if (update) {
|
||||
if (kvm_read (server->_priv->machine.kd,
|
||||
(unsigned long) entry.next,
|
||||
&entry, sizeof (entry)) != sizeof (entry))
|
||||
glibtop_error_io_r (server, "kvm_read (entry)");
|
||||
} else {
|
||||
update = 1;
|
||||
}
|
||||
|
||||
#ifdef __FreeBSD__
|
||||
#if __FreeBSD__ >= 4
|
||||
if (entry.eflags & (MAP_ENTRY_IS_SUB_MAP))
|
||||
continue;
|
||||
#else
|
||||
if (entry.eflags & (MAP_ENTRY_IS_A_MAP|MAP_ENTRY_IS_SUB_MAP))
|
||||
continue;
|
||||
#endif
|
||||
#else
|
||||
#if defined(__NetBSD__) && (__NetBSD_Version__ >= 104000000)
|
||||
if (UVM_ET_ISSUBMAP (&entry))
|
||||
continue;
|
||||
#else
|
||||
if (entry.is_a_map || entry.is_sub_map)
|
||||
continue;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
maps [i].flags = _glibtop_sysdeps_map_entry;
|
||||
|
||||
maps [i].start = entry.start;
|
||||
maps [i].end = entry.end;
|
||||
maps [i].offset = entry.offset;
|
||||
|
||||
maps [i].perm = 0;
|
||||
|
||||
if (entry.protection & VM_PROT_READ)
|
||||
maps [i].perm |= GLIBTOP_MAP_PERM_READ;
|
||||
if (entry.protection & VM_PROT_WRITE)
|
||||
maps [i].perm |= GLIBTOP_MAP_PERM_WRITE;
|
||||
if (entry.protection & VM_PROT_EXECUTE)
|
||||
maps [i].perm |= GLIBTOP_MAP_PERM_EXECUTE;
|
||||
|
||||
i++;
|
||||
|
||||
#if defined(__NetBSD__) && (__NetBSD_Version__ >= 104000000)
|
||||
if (!entry.object.uvm_obj)
|
||||
continue;
|
||||
|
||||
/* We're only interested in vnodes */
|
||||
|
||||
if (kvm_read (server->_priv->machine.kd,
|
||||
(unsigned long) entry.object.uvm_obj,
|
||||
&vnode, sizeof (vnode)) != sizeof (vnode)) {
|
||||
glibtop_warn_io_r (server, "kvm_read (vnode)");
|
||||
return NULL;
|
||||
}
|
||||
#else
|
||||
if (!entry.object.vm_object)
|
||||
continue;
|
||||
|
||||
/* We're only interested in `vm_object's */
|
||||
|
||||
if (kvm_read (server->_priv->machine.kd,
|
||||
(unsigned long) entry.object.vm_object,
|
||||
&object, sizeof (object)) != sizeof (object))
|
||||
glibtop_error_io_r (server, "kvm_read (object)");
|
||||
#endif
|
||||
|
||||
#if defined(__NetBSD__) && (__NetBSD_Version__ >= 104000000)
|
||||
if (!vnode.v_uvm.u_flags & UVM_VNODE_VALID)
|
||||
continue;
|
||||
|
||||
if ((vnode.v_type != VREG) || (vnode.v_tag != VT_UFS) ||
|
||||
!vnode.v_data) continue;
|
||||
|
||||
if (kvm_read (server->_priv->machine.kd,
|
||||
(unsigned long) vnode.v_data,
|
||||
&inode, sizeof (inode)) != sizeof (inode))
|
||||
glibtop_error_io_r (server, "kvm_read (inode)");
|
||||
|
||||
maps [i-1].inode = inode.i_number;
|
||||
maps [i-1].device = inode.i_dev;
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef __FreeBSD__
|
||||
/* If the object is of type vnode, add its size */
|
||||
|
||||
if (object.type != OBJT_VNODE)
|
||||
continue;
|
||||
|
||||
if (!object.handle)
|
||||
continue;
|
||||
|
||||
if (kvm_read (server->_priv->machine.kd,
|
||||
(unsigned long) object.handle,
|
||||
&vnode, sizeof (vnode)) != sizeof (vnode))
|
||||
glibtop_error_io_r (server, "kvm_read (vnode)");
|
||||
|
||||
if ((vnode.v_type != VREG) || (vnode.v_tag != VT_UFS) ||
|
||||
!vnode.v_data) continue;
|
||||
|
||||
if (kvm_read (server->_priv->machine.kd,
|
||||
(unsigned long) vnode.v_data,
|
||||
&inode, sizeof (inode)) != sizeof (inode))
|
||||
glibtop_error_io_r (server, "kvm_read (inode)");
|
||||
|
||||
if (kvm_read (server->_priv->machine.kd,
|
||||
(unsigned long) vnode.v_mount,
|
||||
&mount, sizeof (mount)) != sizeof (mount))
|
||||
glibtop_error_io_r (server, "kvm_read (mount)");
|
||||
|
||||
maps [i-1].inode = inode.i_number;
|
||||
maps [i-1].device = inode.i_dev;
|
||||
#endif
|
||||
} while (entry.next != first);
|
||||
|
||||
return maps;
|
||||
}
|
@@ -1,266 +0,0 @@
|
||||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright (C) 1998 Joshua Sled
|
||||
This file is part of LibGTop 1.0.
|
||||
|
||||
Contributed by Joshua Sled <jsled@xcf.berkeley.edu>, July 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/procmem.h>
|
||||
|
||||
#include <glibtop_suid.h>
|
||||
|
||||
#include <kvm.h>
|
||||
#include <sys/param.h>
|
||||
#include <sys/proc.h>
|
||||
#include <sys/resource.h>
|
||||
#include <vm/vm_object.h>
|
||||
#include <vm/vm_map.h>
|
||||
|
||||
#include <sys/vnode.h>
|
||||
#include <ufs/ufs/quota.h>
|
||||
#include <ufs/ufs/inode.h>
|
||||
|
||||
#include <sys/ucred.h>
|
||||
#if (!defined __OpenBSD__) && (!defined __bsdi__)
|
||||
#include <sys/user.h>
|
||||
#endif
|
||||
#include <sys/sysctl.h>
|
||||
#include <vm/vm.h>
|
||||
|
||||
#if defined(__NetBSD__) && (__NetBSD_Version__ >= 104000000)
|
||||
/* Fixme ... */
|
||||
#undef _KERNEL
|
||||
#define _UVM_UVM_AMAP_I_H_ 1
|
||||
#define _UVM_UVM_MAP_I_H_ 1
|
||||
#include <uvm/uvm.h>
|
||||
#endif
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_proc_mem =
|
||||
(1L << GLIBTOP_PROC_MEM_SIZE) +
|
||||
(1L << GLIBTOP_PROC_MEM_VSIZE) +
|
||||
(1L << GLIBTOP_PROC_MEM_RESIDENT) +
|
||||
(1L << GLIBTOP_PROC_MEM_RSS) +
|
||||
(1L << GLIBTOP_PROC_MEM_RSS_RLIM);
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_proc_mem_share =
|
||||
#if defined(__NetBSD__) && (__NetBSD_Version__ >= 104000000)
|
||||
(1L << GLIBTOP_PROC_MEM_SHARE);
|
||||
#elif defined(__FreeBSD__)
|
||||
(1L << GLIBTOP_PROC_MEM_SHARE);
|
||||
#else
|
||||
0;
|
||||
#endif
|
||||
|
||||
#ifndef LOG1024
|
||||
#define LOG1024 10
|
||||
#endif
|
||||
|
||||
/* these are for getting the memory statistics */
|
||||
static int pageshift; /* log base 2 of the pagesize */
|
||||
|
||||
/* define pagetok in terms of pageshift */
|
||||
#define pagetok(size) ((size) << pageshift)
|
||||
|
||||
/* Init function. */
|
||||
|
||||
int
|
||||
glibtop_init_proc_mem_p (glibtop *server)
|
||||
{
|
||||
register int pagesize;
|
||||
|
||||
/* get the page size with "getpagesize" and calculate pageshift
|
||||
* from it */
|
||||
pagesize = getpagesize ();
|
||||
pageshift = 0;
|
||||
while (pagesize > 1) {
|
||||
pageshift++;
|
||||
pagesize >>= 1;
|
||||
}
|
||||
|
||||
/* we only need the amount of log(2)1024 for our conversion */
|
||||
pageshift -= LOG1024;
|
||||
|
||||
server->sysdeps.proc_mem = _glibtop_sysdeps_proc_mem |
|
||||
_glibtop_sysdeps_proc_mem_share;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Provides detailed information about a process. */
|
||||
|
||||
int
|
||||
glibtop_get_proc_mem_p (glibtop *server, glibtop_proc_mem *buf,
|
||||
pid_t pid)
|
||||
{
|
||||
struct kinfo_proc *pinfo;
|
||||
struct vm_map_entry entry, *first;
|
||||
struct vmspace *vms, vmspace;
|
||||
#if defined(__NetBSD__) && (__NetBSD_Version__ >= 104000000)
|
||||
struct vnode vnode;
|
||||
struct inode inode;
|
||||
#else
|
||||
struct vm_object object;
|
||||
#endif
|
||||
struct plimit plimit;
|
||||
int count;
|
||||
|
||||
glibtop_init_p (server, (1L << GLIBTOP_SYSDEPS_PROC_MEM), 0);
|
||||
|
||||
memset (buf, 0, sizeof (glibtop_proc_mem));
|
||||
|
||||
if (server->sysdeps.proc_mem == 0)
|
||||
return -1;
|
||||
|
||||
/* It does not work for the swapper task. */
|
||||
if (pid == 0) return -1;
|
||||
|
||||
/* Get the process data */
|
||||
pinfo = kvm_getprocs (server->_priv->machine.kd,
|
||||
KERN_PROC_PID, pid, &count);
|
||||
if ((pinfo == NULL) || (count < 1)) {
|
||||
glibtop_warn_io_r (server, "kvm_getprocs (%d)", pid);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (kvm_read (server->_priv->machine.kd,
|
||||
(unsigned long) pinfo [0].kp_proc.p_limit,
|
||||
(char *) &plimit, sizeof (plimit)) != sizeof (plimit)) {
|
||||
glibtop_warn_io_r (server, "kvm_read (plimit)");
|
||||
return -1;
|
||||
}
|
||||
|
||||
buf->rss_rlim = (u_int64_t)
|
||||
(plimit.pl_rlimit [RLIMIT_RSS].rlim_cur);
|
||||
|
||||
vms = &pinfo [0].kp_eproc.e_vm;
|
||||
|
||||
buf->vsize = buf->size = (u_int64_t) pagetok
|
||||
(vms->vm_tsize + vms->vm_dsize + vms->vm_ssize) << LOG1024;
|
||||
|
||||
buf->resident = buf->rss = (u_int64_t) pagetok
|
||||
(vms->vm_rssize) << LOG1024;
|
||||
|
||||
/* Now we get the shared memory. */
|
||||
|
||||
if (kvm_read (server->_priv->machine.kd,
|
||||
(unsigned long) pinfo [0].kp_proc.p_vmspace,
|
||||
(char *) &vmspace, sizeof (vmspace)) != sizeof (vmspace)) {
|
||||
glibtop_warn_io_r (server, "kvm_read (vmspace)");
|
||||
return -1;
|
||||
}
|
||||
|
||||
first = vmspace.vm_map.header.next;
|
||||
|
||||
if (kvm_read (server->_priv->machine.kd,
|
||||
(unsigned long) vmspace.vm_map.header.next,
|
||||
(char *) &entry, sizeof (entry)) != sizeof (entry)) {
|
||||
glibtop_warn_io_r (server, "kvm_read (entry)");
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Walk through the `vm_map_entry' list ... */
|
||||
|
||||
/* I tested this a few times with `mmap'; as soon as you write
|
||||
* to the mmap'ed area, the object type changes from OBJT_VNODE
|
||||
* to OBJT_DEFAULT so if seems this really works. */
|
||||
|
||||
while (entry.next != first) {
|
||||
if (kvm_read (server->_priv->machine.kd,
|
||||
(unsigned long) entry.next,
|
||||
&entry, sizeof (entry)) != sizeof (entry)) {
|
||||
glibtop_warn_io_r (server, "kvm_read (entry)");
|
||||
return -1;
|
||||
}
|
||||
|
||||
#ifdef __FreeBSD__
|
||||
#if __FreeBSD__ >= 4
|
||||
if (entry.eflags & (MAP_ENTRY_IS_SUB_MAP))
|
||||
continue;
|
||||
#else
|
||||
if (entry.eflags & (MAP_ENTRY_IS_A_MAP|MAP_ENTRY_IS_SUB_MAP))
|
||||
continue;
|
||||
#endif
|
||||
#else
|
||||
#if defined(__NetBSD__) && (__NetBSD_Version__ >= 104000000)
|
||||
if (UVM_ET_ISSUBMAP (&entry))
|
||||
continue;
|
||||
#else
|
||||
if (entry.is_a_map || entry.is_sub_map)
|
||||
continue;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(__NetBSD__) && (__NetBSD_Version__ >= 104000000)
|
||||
if (!entry.object.uvm_obj)
|
||||
continue;
|
||||
|
||||
/* We're only interested in vnodes */
|
||||
|
||||
if (kvm_read (server->_priv->machine.kd,
|
||||
(unsigned long) entry.object.uvm_obj,
|
||||
&vnode, sizeof (vnode)) != sizeof (vnode)) {
|
||||
glibtop_warn_io_r (server, "kvm_read (vnode)");
|
||||
return -1;
|
||||
}
|
||||
#else
|
||||
if (!entry.object.vm_object)
|
||||
continue;
|
||||
|
||||
/* We're only interested in `vm_object's */
|
||||
|
||||
if (kvm_read (server->_priv->machine.kd,
|
||||
(unsigned long) entry.object.vm_object,
|
||||
&object, sizeof (object)) != sizeof (object)) {
|
||||
glibtop_warn_io_r (server, "kvm_read (object)");
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
/* If the object is of type vnode, add its size */
|
||||
|
||||
#if defined(__NetBSD__) && (__NetBSD_Version__ >= 104000000)
|
||||
if (!vnode.v_uvm.u_flags & UVM_VNODE_VALID)
|
||||
continue;
|
||||
|
||||
if ((vnode.v_type != VREG) || (vnode.v_tag != VT_UFS) ||
|
||||
!vnode.v_data) continue;
|
||||
|
||||
/* Reference count must be at least two. */
|
||||
if (vnode.v_uvm.u_obj.uo_refs <= 1)
|
||||
continue;
|
||||
|
||||
buf->share += pagetok (vnode.v_uvm.u_obj.uo_npages) << LOG1024;
|
||||
#endif
|
||||
|
||||
#ifdef __FreeBSD__
|
||||
if (object.type != OBJT_VNODE)
|
||||
continue;
|
||||
|
||||
buf->share += object.un_pager.vnp.vnp_size;
|
||||
#endif
|
||||
}
|
||||
|
||||
buf->flags = _glibtop_sysdeps_proc_mem |
|
||||
_glibtop_sysdeps_proc_mem_share;
|
||||
|
||||
return 0;
|
||||
}
|
@@ -1,88 +0,0 @@
|
||||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright (C) 1998 Joshua Sled
|
||||
This file is part of LibGTop 1.0.
|
||||
|
||||
Contributed by Joshua Sled <jsled@xcf.berkeley.edu>, July 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/procsegment.h>
|
||||
|
||||
#include <glibtop_suid.h>
|
||||
|
||||
#include <kvm.h>
|
||||
#include <sys/param.h>
|
||||
#include <sys/sysctl.h>
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_proc_segment = 0;
|
||||
|
||||
/* Init function. */
|
||||
|
||||
int
|
||||
glibtop_init_proc_segment_p (glibtop *server)
|
||||
{
|
||||
server->sysdeps.proc_segment = _glibtop_sysdeps_proc_segment;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Provides detailed information about a process. */
|
||||
|
||||
int
|
||||
glibtop_get_proc_segment_p (glibtop *server,
|
||||
glibtop_proc_segment *buf,
|
||||
pid_t pid)
|
||||
{
|
||||
glibtop_init_p (server, (1L << GLIBTOP_SYSDEPS_PROC_SEGMENT), 0);
|
||||
|
||||
memset (buf, 0, sizeof (glibtop_proc_segment));
|
||||
|
||||
#if 0
|
||||
/* Get the process info from the kernel */
|
||||
kvm_getprocs (server->_priv->machine.kd, KERN_PROC_PID, pid, count);
|
||||
if (*count != 1) {
|
||||
return -1; /* 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
|
||||
*/
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@@ -1,114 +0,0 @@
|
||||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright (C) 1998 Joshua Sled
|
||||
This file is part of LibGTop 1.0.
|
||||
|
||||
Contributed by Joshua Sled <jsled@xcf.berkeley.edu>, July 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/procsignal.h>
|
||||
|
||||
#include <glibtop_suid.h>
|
||||
|
||||
#ifdef HAVE_OSRELDATE_H
|
||||
#include <osreldate.h>
|
||||
#endif
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_proc_signal =
|
||||
(1L << GLIBTOP_PROC_SIGNAL_SIGNAL) +
|
||||
(1L << GLIBTOP_PROC_SIGNAL_BLOCKED) +
|
||||
(1L << GLIBTOP_PROC_SIGNAL_SIGIGNORE) +
|
||||
(1L << GLIBTOP_PROC_SIGNAL_SIGCATCH);
|
||||
|
||||
/* Init function. */
|
||||
|
||||
int
|
||||
glibtop_init_proc_signal_p (glibtop *server)
|
||||
{
|
||||
server->sysdeps.proc_signal = _glibtop_sysdeps_proc_signal;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
glibtop_get_proc_signal_p (glibtop *server,
|
||||
glibtop_proc_signal *buf,
|
||||
pid_t pid)
|
||||
{
|
||||
struct kinfo_proc *pinfo;
|
||||
int count = 0;
|
||||
|
||||
glibtop_init_p (server, (1L << GLIBTOP_SYSDEPS_PROC_SIGNAL), 0);
|
||||
|
||||
memset (buf, 0, sizeof (glibtop_proc_signal));
|
||||
|
||||
/* It does not work for the swapper task. */
|
||||
if (pid == 0) return -1;
|
||||
|
||||
/* Get the process information */
|
||||
pinfo = kvm_getprocs (server->_priv->machine.kd,
|
||||
KERN_PROC_PID, pid, &count);
|
||||
if ((pinfo == NULL) || (count != 1)) {
|
||||
glibtop_warn_io_r (server, "kvm_getprocs (%d)", pid);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* signal: mask of pending signals.
|
||||
* pinfo [0].kp_proc.p_siglist
|
||||
*/
|
||||
#if (defined(__NetBSD__) && (NSIG > 32)) || (__FreeBSD_version >= 400011)
|
||||
buf->signal [0] = pinfo [0].kp_proc.p_siglist.__bits[0];
|
||||
#else
|
||||
buf->signal [0] = pinfo [0].kp_proc.p_siglist;
|
||||
#endif
|
||||
|
||||
/* blocked: mask of blocked signals.
|
||||
* pinfo [0].kp_proc.p_sigmask
|
||||
*/
|
||||
#if (defined(__NetBSD__) && (NSIG > 32)) || (__FreeBSD_version >= 400011)
|
||||
buf->blocked [0] = pinfo [0].kp_proc.p_sigmask.__bits[0];
|
||||
#else
|
||||
buf->blocked [0] = pinfo [0].kp_proc.p_sigmask;
|
||||
#endif
|
||||
|
||||
/* sigignore: mask of ignored signals.
|
||||
* pinfo [0].kp_proc.p_sigignore
|
||||
*/
|
||||
#if (defined(__NetBSD__) && (NSIG > 32)) || (__FreeBSD_version >= 400011)
|
||||
buf->sigignore [0] = pinfo [0].kp_proc.p_sigignore.__bits[0];
|
||||
#else
|
||||
buf->sigignore [0] = pinfo [0].kp_proc.p_sigignore;
|
||||
#endif
|
||||
|
||||
/* sigcatch: mask of caught signals.
|
||||
* pinfo [0].kp_proc.p_sigcatch
|
||||
*/
|
||||
#if (defined(__NetBSD__) && (NSIG > 32)) || (__FreeBSD_version >= 400011)
|
||||
buf->sigcatch [0] = pinfo [0].kp_proc.p_sigcatch.__bits[0];
|
||||
#else
|
||||
buf->sigcatch [0] = pinfo [0].kp_proc.p_sigcatch;
|
||||
#endif
|
||||
|
||||
buf->flags = _glibtop_sysdeps_proc_signal;
|
||||
|
||||
return 0;
|
||||
}
|
@@ -1,144 +0,0 @@
|
||||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright (C) 1998 Joshua Sled
|
||||
This file is part of LibGTop 1.0.
|
||||
|
||||
Contributed by Joshua Sled <jsled@xcf.berkeley.edu>, July 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/procstate.h>
|
||||
|
||||
#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);
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_proc_state_new =
|
||||
#if LIBGTOP_VERSION_CODE >= 1001000
|
||||
(1L << GLIBTOP_PROC_STATE_RUID) + (1L << GLIBTOP_PROC_STATE_RGID);
|
||||
#else
|
||||
0;
|
||||
#endif
|
||||
|
||||
/* Init function. */
|
||||
|
||||
int
|
||||
glibtop_init_proc_state_p (glibtop *server)
|
||||
{
|
||||
server->sysdeps.proc_state = _glibtop_sysdeps_proc_state |
|
||||
_glibtop_sysdeps_proc_state_new;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Provides detailed information about a process. */
|
||||
|
||||
int
|
||||
glibtop_get_proc_state_p (glibtop *server,
|
||||
glibtop_proc_state *buf,
|
||||
pid_t pid)
|
||||
{
|
||||
struct kinfo_proc *pinfo;
|
||||
int count = 0;
|
||||
|
||||
glibtop_init_p (server, (1L << GLIBTOP_SYSDEPS_PROC_STATE), 0);
|
||||
|
||||
memset (buf, 0, sizeof (glibtop_proc_state));
|
||||
|
||||
/* It does not work for the swapper task. */
|
||||
if (pid == 0) return -1;
|
||||
|
||||
/* Get the process information */
|
||||
pinfo = kvm_getprocs (server->_priv->machine.kd,
|
||||
KERN_PROC_PID, pid, &count);
|
||||
if ((pinfo == NULL) || (count != 1)) {
|
||||
glibtop_warn_io_r (server, "kvm_getprocs (%d)", pid);
|
||||
return -1;
|
||||
}
|
||||
|
||||
strncpy (buf->cmd, pinfo [0].kp_proc.p_comm, sizeof (buf->cmd)-1);
|
||||
buf->cmd [sizeof (buf->cmd)-1] = 0;
|
||||
|
||||
buf->uid = pinfo [0].kp_eproc.e_pcred.p_svuid;
|
||||
buf->gid = pinfo [0].kp_eproc.e_pcred.p_svgid;
|
||||
|
||||
#if LIBGTOP_VERSION_CODE >= 1001000
|
||||
buf->ruid = pinfo [0].kp_eproc.e_pcred.p_ruid;
|
||||
buf->rgid = pinfo [0].kp_eproc.e_pcred.p_rgid;
|
||||
#endif
|
||||
|
||||
/* Set the flags for the data we're about to return*/
|
||||
buf->flags = _glibtop_sysdeps_proc_state |
|
||||
_glibtop_sysdeps_proc_state_new;
|
||||
|
||||
#if LIBGTOP_VERSION_CODE >= 1001000
|
||||
switch (pinfo [0].kp_proc.p_stat) {
|
||||
case SIDL:
|
||||
buf->state = 0;
|
||||
break;
|
||||
case SRUN:
|
||||
buf->state = GLIBTOP_PROCESS_RUNNING;
|
||||
break;
|
||||
case SSLEEP:
|
||||
buf->state = GLIBTOP_PROCESS_INTERRUPTIBLE;
|
||||
break;
|
||||
case SSTOP:
|
||||
buf->state = GLIBTOP_PROCESS_STOPPED;
|
||||
break;
|
||||
case SZOMB:
|
||||
buf->state = GLIBTOP_PROCESS_ZOMBIE;
|
||||
break;
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
#else
|
||||
switch (pinfo [0].kp_proc.p_stat) {
|
||||
case SIDL:
|
||||
buf->state = 'S';
|
||||
break;
|
||||
case SRUN:
|
||||
buf->state = 'R';
|
||||
break;
|
||||
case SSLEEP:
|
||||
buf->state = 'S';
|
||||
break;
|
||||
case SSTOP:
|
||||
buf->state = 'T';
|
||||
break;
|
||||
case SZOMB:
|
||||
buf->state = 'Z';
|
||||
break;
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
|
||||
buf->flags |= (1L << GLIBTOP_PROC_STATE_STATE);
|
||||
|
||||
return 0;
|
||||
}
|
@@ -1,236 +0,0 @@
|
||||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright (C) 1998-99 Martin Baulig
|
||||
This file is part of LibGTop 1.0.
|
||||
|
||||
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/proctime.h>
|
||||
|
||||
#include <glibtop_suid.h>
|
||||
|
||||
#ifdef HAVE_OSRELDATE_H
|
||||
#include <osreldate.h>
|
||||
#endif
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_proc_time =
|
||||
(1L << GLIBTOP_PROC_TIME_RTIME) + (1L << GLIBTOP_PROC_TIME_FREQUENCY);
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_proc_time_user =
|
||||
(1L << GLIBTOP_PROC_TIME_UTIME) + (1L << GLIBTOP_PROC_TIME_STIME) +
|
||||
(1L << GLIBTOP_PROC_TIME_CUTIME) + (1L << GLIBTOP_PROC_TIME_CSTIME) +
|
||||
(1L << GLIBTOP_PROC_TIME_START_TIME);
|
||||
|
||||
#define tv2sec(tv) (((u_int64_t) tv.tv_sec * 1000000) + (u_int64_t) tv.tv_usec)
|
||||
|
||||
/* Init function. */
|
||||
|
||||
int
|
||||
glibtop_init_proc_time_p (glibtop *server)
|
||||
{
|
||||
server->sysdeps.proc_time = _glibtop_sysdeps_proc_time |
|
||||
_glibtop_sysdeps_proc_time_user;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Taken from /usr/src/sys/kern/kern_resource.c */
|
||||
|
||||
/*
|
||||
* Transform the running time and tick information in proc p into user,
|
||||
* system, and interrupt time usage.
|
||||
*/
|
||||
|
||||
static void
|
||||
calcru(p, up, sp, ip)
|
||||
struct proc *p;
|
||||
struct timeval *up;
|
||||
struct timeval *sp;
|
||||
struct timeval *ip;
|
||||
{
|
||||
quad_t totusec;
|
||||
u_quad_t u, st, ut, it, tot;
|
||||
#if (__FreeBSD_version < 300003)
|
||||
long sec, usec;
|
||||
#endif
|
||||
struct timeval tv;
|
||||
|
||||
st = p->p_sticks;
|
||||
ut = p->p_uticks;
|
||||
it = p->p_iticks;
|
||||
|
||||
tot = st + ut + it;
|
||||
if (tot == 0) {
|
||||
st = 1;
|
||||
tot = 1;
|
||||
}
|
||||
|
||||
#if (defined __FreeBSD__) && (__FreeBSD_version >= 300003)
|
||||
|
||||
/* This was changed from a `struct timeval' into a `u_int64_t'
|
||||
* 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. */
|
||||
fprintf (stderr, "calcru: negative time: %ld usec\n",
|
||||
(long)totusec);
|
||||
totusec = 0;
|
||||
}
|
||||
|
||||
|
||||
u = totusec;
|
||||
st = (u * st) / tot;
|
||||
sp->tv_sec = st / 1000000;
|
||||
sp->tv_usec = st % 1000000;
|
||||
ut = (u * ut) / tot;
|
||||
up->tv_sec = ut / 1000000;
|
||||
up->tv_usec = ut % 1000000;
|
||||
if (ip != NULL) {
|
||||
it = (u * it) / tot;
|
||||
ip->tv_sec = it / 1000000;
|
||||
ip->tv_usec = it % 1000000;
|
||||
}
|
||||
}
|
||||
|
||||
/* Provides detailed information about a process. */
|
||||
|
||||
int
|
||||
glibtop_get_proc_time_p (glibtop *server, glibtop_proc_time *buf,
|
||||
pid_t pid)
|
||||
{
|
||||
struct kinfo_proc *pinfo;
|
||||
#if defined(__NetBSD__) && (__NetBSD_Version__ >= 104000000)
|
||||
register struct rusage *rup;
|
||||
#else
|
||||
struct user *u_addr = (struct user *)USRSTACK;
|
||||
#endif
|
||||
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));
|
||||
|
||||
/* It does not work for the swapper task. */
|
||||
if (pid == 0) return -1;
|
||||
|
||||
#if !(defined(__NetBSD__) && (__NetBSD_Version__ >= 104000000))
|
||||
if (server->sysdeps.proc_time == 0)
|
||||
return -1;
|
||||
|
||||
#ifndef __bsdi__
|
||||
sprintf (filename, "/proc/%d/mem", (int) pid);
|
||||
if (stat (filename, &statb)) return -1;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* Get the process information */
|
||||
pinfo = kvm_getprocs (server->_priv->machine.kd,
|
||||
KERN_PROC_PID, pid, &count);
|
||||
if ((pinfo == NULL) || (count != 1))
|
||||
glibtop_error_io_r (server, "kvm_getprocs (%d)", pid);
|
||||
|
||||
#if (defined __FreeBSD__) && (__FreeBSD_version >= 300003)
|
||||
buf->rtime = pinfo [0].kp_proc.p_runtime;
|
||||
#else
|
||||
buf->rtime = tv2sec (pinfo [0].kp_proc.p_rtime);
|
||||
#endif
|
||||
|
||||
buf->frequency = 1000000;
|
||||
buf->flags = _glibtop_sysdeps_proc_time;
|
||||
|
||||
#if defined(__NetBSD__) && (__NetBSD_Version__ >= 104000000)
|
||||
glibtop_suid_enter (server);
|
||||
|
||||
if (kvm_read (server->_priv->machine.kd,
|
||||
(unsigned long) pinfo [0].kp_proc.p_stats,
|
||||
&pstats, sizeof (pstats)) != sizeof (pstats)) {
|
||||
glibtop_warn_io_r (server, "kvm_read (pstats)");
|
||||
return -1;
|
||||
}
|
||||
|
||||
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 = (u_int64_t) pstats.p_start.tv_sec;
|
||||
|
||||
buf->flags |= _glibtop_sysdeps_proc_time_user;
|
||||
#else
|
||||
glibtop_suid_enter (server);
|
||||
|
||||
if ((pinfo [0].kp_proc.p_flag & P_INMEM) &&
|
||||
kvm_uread (server->_priv->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;
|
||||
}
|
||||
|
||||
glibtop_suid_leave (server);
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@@ -1,136 +0,0 @@
|
||||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright (C) 1998-99 Martin Baulig
|
||||
This file is part of LibGTop 1.0.
|
||||
|
||||
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/procuid.h>
|
||||
|
||||
#include <glibtop_suid.h>
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_proc_uid =
|
||||
(1L << GLIBTOP_PROC_UID_UID) + (1L << GLIBTOP_PROC_UID_EUID) +
|
||||
(1L << GLIBTOP_PROC_UID_EGID) + (1L << GLIBTOP_PROC_UID_PID) +
|
||||
(1L << GLIBTOP_PROC_UID_PPID) + (1L << GLIBTOP_PROC_UID_PGRP) +
|
||||
(1L << GLIBTOP_PROC_UID_TPGID) + (1L << GLIBTOP_PROC_UID_PRIORITY) +
|
||||
(1L << GLIBTOP_PROC_UID_NICE);
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_proc_uid_groups =
|
||||
#if LIBGTOP_VERSION_CODE >= 1001000
|
||||
#if defined(__NetBSD__) && (__NetBSD_Version__ >= 104000000)
|
||||
(1L << GLIBTOP_PROC_UID_NGROUPS) + (1L << GLIBTOP_PROC_UID_GROUPS);
|
||||
#else
|
||||
0L;
|
||||
#endif
|
||||
#else /* LIBGTOP_VERSION_CODE < 1001000 */
|
||||
0L;
|
||||
#endif
|
||||
|
||||
/* Init function. */
|
||||
|
||||
int
|
||||
glibtop_init_proc_uid_p (glibtop *server)
|
||||
{
|
||||
server->sysdeps.proc_uid = _glibtop_sysdeps_proc_uid |
|
||||
_glibtop_sysdeps_proc_uid_groups;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Provides detailed information about a process. */
|
||||
|
||||
int
|
||||
glibtop_get_proc_uid_p (glibtop *server, glibtop_proc_uid *buf,
|
||||
pid_t pid)
|
||||
{
|
||||
struct kinfo_proc *pinfo;
|
||||
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));
|
||||
|
||||
/* It does not work for the swapper task. */
|
||||
if (pid == 0) return -1;
|
||||
|
||||
/* Get the process information */
|
||||
pinfo = kvm_getprocs (server->_priv->machine.kd,
|
||||
KERN_PROC_PID, pid, &count);
|
||||
if ((pinfo == NULL) || (count != 1)) {
|
||||
glibtop_warn_io_r (server, "kvm_getprocs (%d)", pid);
|
||||
return -1;
|
||||
}
|
||||
|
||||
buf->uid = pinfo [0].kp_eproc.e_pcred.p_ruid;
|
||||
buf->euid = pinfo [0].kp_eproc.e_pcred.p_svuid;
|
||||
buf->gid = pinfo [0].kp_eproc.e_pcred.p_rgid;
|
||||
buf->egid = pinfo [0].kp_eproc.e_pcred.p_svgid;
|
||||
|
||||
buf->ppid = pinfo [0].kp_eproc.e_ppid;
|
||||
buf->pgrp = pinfo [0].kp_eproc.e_pgid;
|
||||
buf->tpgid = pinfo [0].kp_eproc.e_tpgid;
|
||||
|
||||
buf->nice = pinfo [0].kp_proc.p_nice;
|
||||
buf->priority = pinfo [0].kp_proc.p_priority;
|
||||
|
||||
/* 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 LIBGTOP_VERSION_CODE >= 1001000
|
||||
/* 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->_priv->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
|
||||
|
||||
return 0;
|
||||
}
|
@@ -1,131 +0,0 @@
|
||||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright (C) 1998-99 Martin Baulig
|
||||
This file is part of LibGTop 1.0.
|
||||
|
||||
Contributed by Martin Baulig <martin@home-of-linux.org>, August 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/sem_limits.h>
|
||||
|
||||
#include <glibtop_suid.h>
|
||||
|
||||
#if defined(__bsdi__) && (_BSDI_VERSION < 199700)
|
||||
/* Older versions of BSDI don't seem to have this. */
|
||||
|
||||
int
|
||||
glibtop_init_sem_limits_p (glibtop *server)
|
||||
{
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
glibtop_get_sem_limits_p (glibtop *server, glibtop_sem_limits *buf)
|
||||
{
|
||||
glibtop_init_p (server, (1L << GLIBTOP_SYSDEPS_SEM_LIMITS), 0);
|
||||
|
||||
memset (buf, 0, sizeof (glibtop_sem_limits));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
/* #define KERNEL to get declaration of `struct seminfo'. */
|
||||
|
||||
#if defined(__FreeBSD__) || defined(__bsdi__)
|
||||
#define KERNEL 1
|
||||
#else
|
||||
#define _KERNEL 1
|
||||
#endif
|
||||
|
||||
#include <sys/ipc.h>
|
||||
#include <sys/sem.h>
|
||||
|
||||
static unsigned long _glibtop_sysdeps_sem_limits =
|
||||
(1L << GLIBTOP_SEM_LIMITS_SEMMAP) + (1L << GLIBTOP_SEM_LIMITS_SEMMNI) +
|
||||
(1L << GLIBTOP_SEM_LIMITS_SEMMNS) + (1L << GLIBTOP_SEM_LIMITS_SEMMNU) +
|
||||
(1L << GLIBTOP_SEM_LIMITS_SEMMSL) + (1L << GLIBTOP_SEM_LIMITS_SEMOPM) +
|
||||
(1L << GLIBTOP_SEM_LIMITS_SEMUME) + (1L << GLIBTOP_SEM_LIMITS_SEMUSZ) +
|
||||
(1L << GLIBTOP_SEM_LIMITS_SEMVMX) + (1L << GLIBTOP_SEM_LIMITS_SEMAEM);
|
||||
|
||||
/* The values in this structure never change at runtime, so we only
|
||||
* read it once during initialization. We have to use the name `_seminfo'
|
||||
* since `seminfo' is already declared external in <sys/sem.h>. */
|
||||
static struct seminfo _seminfo;
|
||||
|
||||
/* nlist structure for kernel access */
|
||||
static struct nlist nlst [] = {
|
||||
{ "_seminfo" },
|
||||
{ 0 }
|
||||
};
|
||||
|
||||
/* Init function. */
|
||||
|
||||
int
|
||||
glibtop_init_sem_limits_p (glibtop *server)
|
||||
{
|
||||
if (kvm_nlist (server->_priv->machine.kd, nlst) < 0) {
|
||||
glibtop_warn_io_r (server, "kvm_nlist (sem_limits)");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (kvm_read (server->_priv->machine.kd, nlst [0].n_value,
|
||||
&_seminfo, sizeof (_seminfo)) != sizeof (_seminfo)) {
|
||||
glibtop_warn_io_r (server, "kvm_read (seminfo)");
|
||||
return -1;
|
||||
}
|
||||
|
||||
server->sysdeps.sem_limits = _glibtop_sysdeps_sem_limits;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Provides information about sysv sem limits. */
|
||||
|
||||
int
|
||||
glibtop_get_sem_limits_p (glibtop *server, glibtop_sem_limits *buf)
|
||||
{
|
||||
glibtop_init_p (server, (1L << GLIBTOP_SYSDEPS_SEM_LIMITS), 0);
|
||||
|
||||
memset (buf, 0, sizeof (glibtop_sem_limits));
|
||||
|
||||
if (server->sysdeps.sem_limits == 0)
|
||||
return -1;
|
||||
|
||||
buf->semmap = _seminfo.semmap;
|
||||
buf->semmni = _seminfo.semmni;
|
||||
buf->semmns = _seminfo.semmns;
|
||||
buf->semmnu = _seminfo.semmnu;
|
||||
buf->semmsl = _seminfo.semmsl;
|
||||
buf->semopm = _seminfo.semopm;
|
||||
buf->semvmx = _seminfo.semvmx;
|
||||
buf->semaem = _seminfo.semaem;
|
||||
|
||||
buf->flags = _glibtop_sysdeps_sem_limits;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif /* either a newer BSDI or no BSDI at all. */
|
||||
|
@@ -1,126 +0,0 @@
|
||||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright (C) 1998-99 Martin Baulig
|
||||
This file is part of LibGTop 1.0.
|
||||
|
||||
Contributed by Martin Baulig <martin@home-of-linux.org>, August 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/shm_limits.h>
|
||||
|
||||
#include <glibtop_suid.h>
|
||||
|
||||
#if defined(__bsdi__) && (_BSDI_VERSION < 199700)
|
||||
/* Older versions of BSDI don't seem to have this. */
|
||||
|
||||
int
|
||||
glibtop_init_shm_limits_p (glibtop *server)
|
||||
{
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
glibtop_get_shm_limits_p (glibtop *server, glibtop_shm_limits *buf)
|
||||
{
|
||||
glibtop_init_p (server, (1L << GLIBTOP_SYSDEPS_SHM_LIMITS), 0);
|
||||
|
||||
memset (buf, 0, sizeof (glibtop_shm_limits));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
/* #define KERNEL to get declaration of `struct shminfo'. */
|
||||
|
||||
#if defined(__FreeBSD__) || defined(__bsdi__)
|
||||
#define KERNEL 1
|
||||
#else
|
||||
#define _KERNEL 1
|
||||
#endif
|
||||
|
||||
#include <sys/ipc.h>
|
||||
#include <sys/shm.h>
|
||||
|
||||
static unsigned long _glibtop_sysdeps_shm_limits =
|
||||
(1L << GLIBTOP_SHM_LIMITS_SHMMAX) + (1L << GLIBTOP_SHM_LIMITS_SHMMIN) +
|
||||
(1L << GLIBTOP_SHM_LIMITS_SHMMNI) + (1L << GLIBTOP_SHM_LIMITS_SHMSEG) +
|
||||
(1L << GLIBTOP_SHM_LIMITS_SHMALL);
|
||||
|
||||
/* The values in this structure never change at runtime, so we only
|
||||
* read it once during initialization. We have to use the name `_shminfo'
|
||||
* since `shminfo' is already declared external in <sys/shm.h>. */
|
||||
static struct shminfo _shminfo;
|
||||
|
||||
/* nlist structure for kernel access */
|
||||
static struct nlist nlst [] = {
|
||||
{ "_shminfo" },
|
||||
{ 0 }
|
||||
};
|
||||
|
||||
/* Init function. */
|
||||
|
||||
int
|
||||
glibtop_init_shm_limits_p (glibtop *server)
|
||||
{
|
||||
if (kvm_nlist (server->_priv->machine.kd, nlst) < 0) {
|
||||
glibtop_warn_io_r (server, "kvm_nlist (shm_limits)");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (kvm_read (server->_priv->machine.kd, nlst [0].n_value,
|
||||
&_shminfo, sizeof (_shminfo)) != sizeof (_shminfo)) {
|
||||
glibtop_warn_io_r (server, "kvm_read (shminfo)");
|
||||
return -1;
|
||||
}
|
||||
|
||||
server->sysdeps.shm_limits = _glibtop_sysdeps_shm_limits;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Provides information about sysv ipc limits. */
|
||||
|
||||
int
|
||||
glibtop_get_shm_limits_p (glibtop *server, glibtop_shm_limits *buf)
|
||||
{
|
||||
glibtop_init_p (server, (1L << GLIBTOP_SYSDEPS_SHM_LIMITS), 0);
|
||||
|
||||
memset (buf, 0, sizeof (glibtop_shm_limits));
|
||||
|
||||
if (server->sysdeps.shm_limits == 0)
|
||||
return -1;
|
||||
|
||||
buf->shmmax = _shminfo.shmmax;
|
||||
buf->shmmin = _shminfo.shmmin;
|
||||
buf->shmmni = _shminfo.shmmni;
|
||||
buf->shmseg = _shminfo.shmseg;
|
||||
buf->shmall = _shminfo.shmall;
|
||||
|
||||
buf->flags = _glibtop_sysdeps_shm_limits;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif /* either a newer BSDI or no BSDI at all. */
|
||||
|
@@ -1,432 +0,0 @@
|
||||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright (C) 1998-99 Martin Baulig
|
||||
This file is part of LibGTop 1.0.
|
||||
|
||||
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/swap.h>
|
||||
|
||||
#include <glibtop/xmalloc.h>
|
||||
|
||||
#include <glibtop_suid.h>
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_swap =
|
||||
(1L << GLIBTOP_SWAP_TOTAL) + (1L << GLIBTOP_SWAP_USED) +
|
||||
(1L << GLIBTOP_SWAP_FREE) + (1L << GLIBTOP_SWAP_PAGEIN) +
|
||||
(1L << GLIBTOP_SWAP_PAGEOUT);
|
||||
|
||||
#if defined(__FreeBSD__) || defined(__bsdi__)
|
||||
|
||||
#include <sys/conf.h>
|
||||
#ifdef __bsdi__
|
||||
#include <vm/swap_pager.h>
|
||||
#else
|
||||
#if __FreeBSD_version < 400005
|
||||
#include <sys/rlist.h>
|
||||
#endif
|
||||
#endif
|
||||
#include <sys/vmmeter.h>
|
||||
|
||||
/* nlist structure for kernel access */
|
||||
|
||||
#if defined(__bsdi__)
|
||||
static struct nlist nlst [] = {
|
||||
{ "_swapstats" }, /* general swap info */
|
||||
{ 0 }
|
||||
};
|
||||
#elif __FreeBSD__ < 4
|
||||
static struct nlist nlst [] = {
|
||||
#define VM_SWAPLIST 0
|
||||
{ "_swaplist" },/* list of free swap areas */
|
||||
#define VM_SWDEVT 1
|
||||
{ "_swdevt" }, /* list of swap devices and sizes */
|
||||
#define VM_NSWAP 2
|
||||
{ "_nswap" }, /* size of largest swap device */
|
||||
#define VM_NSWDEV 3
|
||||
{ "_nswdev" }, /* number of swap devices */
|
||||
#define VM_DMMAX 4
|
||||
{ "_dmmax" }, /* maximum size of a swap block */
|
||||
{ 0 }
|
||||
};
|
||||
#endif
|
||||
|
||||
#elif defined(__NetBSD__)
|
||||
|
||||
#if (__NetBSD_Version__ >= 104000000)
|
||||
#include <uvm/uvm_extern.h>
|
||||
#include <sys/swap.h>
|
||||
#else
|
||||
#include <vm/vm_swap.h>
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#if defined(__NetBSD__) && (__NetBSD_Version__ >= 104000000)
|
||||
static int mib_uvmexp [] = { CTL_VM, VM_UVMEXP };
|
||||
#else
|
||||
/* nlist structure for kernel access */
|
||||
static struct nlist nlst2 [] = {
|
||||
{ "_cnt" },
|
||||
{ 0 }
|
||||
};
|
||||
#endif
|
||||
|
||||
/* Init function. */
|
||||
|
||||
int
|
||||
glibtop_init_swap_p (glibtop *server)
|
||||
{
|
||||
#if defined(__FreeBSD__) || defined(__bsdi__)
|
||||
#if __FreeBSD__ < 4 || defined(__bsdi__)
|
||||
if (kvm_nlist (server->_priv->machine.kd, nlst) < 0) {
|
||||
glibtop_warn_io_r (server, "kvm_nlist (swap)");
|
||||
return -1;
|
||||
}
|
||||
#else
|
||||
struct kvm_swap dummy;
|
||||
|
||||
if (kvm_getswapinfo (server->_priv->machine.kd, &dummy, 1, 0) != 0) {
|
||||
glibtop_warn_io_r (server, "kvm_swap (swap)");
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if !(defined(__NetBSD__) && (__NetBSD_Version__ >= 104000000))
|
||||
if (kvm_nlist (server->_priv->machine.kd, nlst2) < 0) {
|
||||
glibtop_warn_io_r (server, "kvm_nlist (cnt)");
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
|
||||
server->sysdeps.swap = _glibtop_sysdeps_swap;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Provides information about swap usage. */
|
||||
|
||||
/*
|
||||
* This function is based on a program called swapinfo written
|
||||
* by Kevin Lahey <kml@rokkaku.atl.ga.us>.
|
||||
*/
|
||||
|
||||
int
|
||||
glibtop_get_swap_p (glibtop *server, glibtop_swap *buf)
|
||||
{
|
||||
#if defined(__FreeBSD__)
|
||||
|
||||
# if __FreeBSD__ < 4
|
||||
char *header;
|
||||
int hlen, nswdev, dmmax;
|
||||
int div, nfree, npfree;
|
||||
struct swdevt *sw;
|
||||
long blocksize, *perdev;
|
||||
struct rlist head;
|
||||
struct rlisthdr swaplist;
|
||||
struct rlist *swapptr;
|
||||
size_t sw_size;
|
||||
u_long ptr;
|
||||
# else
|
||||
int nswdev;
|
||||
struct kvm_swap kvmsw[16];
|
||||
# endif
|
||||
|
||||
#elif defined(__bsdi__)
|
||||
struct swapstats swap;
|
||||
#elif defined(__NetBSD__)
|
||||
struct swapent *swaplist;
|
||||
#endif
|
||||
|
||||
int nswap, i;
|
||||
int avail = 0, inuse = 0;
|
||||
|
||||
#if defined(__NetBSD__) && (__NetBSD_Version__ >= 104000000)
|
||||
struct uvmexp uvmexp;
|
||||
size_t length_uvmexp;
|
||||
#else
|
||||
/* To get `pagein' and `pageout'. */
|
||||
struct vmmeter vmm;
|
||||
#endif
|
||||
static int swappgsin = -1;
|
||||
static int swappgsout = -1;
|
||||
|
||||
glibtop_init_p (server, (1L << GLIBTOP_SYSDEPS_SWAP), 0);
|
||||
|
||||
memset (buf, 0, sizeof (glibtop_swap));
|
||||
|
||||
if (server->sysdeps.swap == 0)
|
||||
return -1;
|
||||
|
||||
#if defined(__NetBSD__) && (__NetBSD_Version__ >= 104000000)
|
||||
length_uvmexp = sizeof (uvmexp);
|
||||
if (sysctl (mib_uvmexp, 2, &uvmexp, &length_uvmexp, NULL, 0)) {
|
||||
glibtop_warn_io_r (server, "sysctl (uvmexp)");
|
||||
return -1;
|
||||
}
|
||||
#else
|
||||
/* This is used to get the `pagein' and `pageout' members. */
|
||||
|
||||
if (kvm_read (server->_priv->machine.kd, nlst2[0].n_value,
|
||||
&vmm, sizeof (vmm)) != sizeof (vmm)) {
|
||||
glibtop_warn_io_r (server, "kvm_read (cnt)");
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (swappgsin < 0) {
|
||||
buf->pagein = 0;
|
||||
buf->pageout = 0;
|
||||
} else {
|
||||
#ifdef __FreeBSD__
|
||||
buf->pagein = vmm.v_swappgsin - swappgsin;
|
||||
buf->pageout = vmm.v_swappgsout - swappgsout;
|
||||
#else
|
||||
#if defined(__NetBSD__) && (__NetBSD_Version__ >= 104000000)
|
||||
buf->pagein = uvmexp.swapins - swappgsin;
|
||||
buf->pageout = uvmexp.swapouts - swappgsout;
|
||||
#else
|
||||
buf->pagein = vmm.v_swpin - swappgsin;
|
||||
buf->pageout = vmm.v_swpout - swappgsout;
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef __FreeBSD__
|
||||
swappgsin = vmm.v_swappgsin;
|
||||
swappgsout = vmm.v_swappgsout;
|
||||
#else
|
||||
#if defined(__NetBSD__) && (__NetBSD_Version__ >= 104000000)
|
||||
swappgsin = uvmexp.swapins;
|
||||
swappgsout = uvmexp.swapouts;
|
||||
#else
|
||||
swappgsin = vmm.v_swpin;
|
||||
swappgsout = vmm.v_swpout;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(__FreeBSD__)
|
||||
|
||||
#if __FreeBSD__ < 4
|
||||
|
||||
/* Size of largest swap device. */
|
||||
|
||||
if (kvm_read (server->_priv->machine.kd, nlst[VM_NSWAP].n_value,
|
||||
&nswap, sizeof (nswap)) != sizeof (nswap)) {
|
||||
glibtop_warn_io_r (server, "kvm_read (nswap)");
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Number of swap devices. */
|
||||
|
||||
if (kvm_read (server->_priv->machine.kd, nlst[VM_NSWDEV].n_value,
|
||||
&nswdev, sizeof (nswdev)) != sizeof (nswdev)) {
|
||||
glibtop_warn_io_r (server, "kvm_read (nswdev)");
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Maximum size of a swap block. */
|
||||
|
||||
if (kvm_read (server->_priv->machine.kd, nlst[VM_DMMAX].n_value,
|
||||
&dmmax, sizeof (dmmax)) != sizeof (dmmax)) {
|
||||
glibtop_warn_io_r (server, "kvm_read (dmmax)");
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* List of free swap areas. */
|
||||
|
||||
if (kvm_read (server->_priv->machine.kd, nlst[VM_SWAPLIST].n_value,
|
||||
&swaplist, sizeof (swaplist)) != sizeof (swaplist)) {
|
||||
glibtop_warn_io_r (server, "kvm_read (swaplist)");
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Kernel offset of list of swap devices and sizes. */
|
||||
|
||||
if (kvm_read (server->_priv->machine.kd, nlst[VM_SWDEVT].n_value,
|
||||
&ptr, sizeof (ptr)) != sizeof (ptr)) {
|
||||
glibtop_warn_io_r (server, "kvm_read (swdevt)");
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* List of swap devices and sizes. */
|
||||
|
||||
sw_size = nswdev * sizeof (*sw);
|
||||
sw = glibtop_malloc_r (server, sw_size);
|
||||
|
||||
if (kvm_read (server->_priv->machine.kd, ptr, sw, sw_size) != (ssize_t)sw_size) {
|
||||
glibtop_warn_io_r (server, "kvm_read (*swdevt)");
|
||||
return -1;
|
||||
}
|
||||
|
||||
perdev = glibtop_malloc (nswdev * sizeof (*perdev));
|
||||
|
||||
/* Count up swap space. */
|
||||
|
||||
nfree = 0;
|
||||
memset (perdev, 0, nswdev * sizeof(*perdev));
|
||||
|
||||
swapptr = swaplist.rlh_list;
|
||||
|
||||
while (swapptr) {
|
||||
int top, bottom, next_block;
|
||||
|
||||
if (kvm_read (server->_priv->machine.kd, (int) swapptr, &head,
|
||||
sizeof (struct rlist)) != sizeof (struct rlist)) {
|
||||
glibtop_warn_io_r (server, "kvm_read (swapptr)");
|
||||
return -1;
|
||||
}
|
||||
|
||||
top = head.rl_end;
|
||||
bottom = head.rl_start;
|
||||
|
||||
nfree += top - bottom + 1;
|
||||
|
||||
/*
|
||||
* Swap space is split up among the configured disks.
|
||||
*
|
||||
* For interleaved swap devices, the first dmmax blocks
|
||||
* of swap space some from the first disk, the next dmmax
|
||||
* blocks from the next, and so on up to nswap blocks.
|
||||
*
|
||||
* The list of free space joins adjacent free blocks,
|
||||
* ignoring device boundries. If we want to keep track
|
||||
* of this information per device, we'll just have to
|
||||
* extract it ourselves.
|
||||
*/
|
||||
while (top / dmmax != bottom / dmmax) {
|
||||
next_block = ((bottom + dmmax) / dmmax);
|
||||
perdev[(bottom / dmmax) % nswdev] +=
|
||||
next_block * dmmax - bottom;
|
||||
bottom = next_block * dmmax;
|
||||
}
|
||||
perdev[(bottom / dmmax) % nswdev] +=
|
||||
top - bottom + 1;
|
||||
|
||||
swapptr = head.rl_next;
|
||||
}
|
||||
|
||||
header = getbsize (&hlen, &blocksize);
|
||||
|
||||
div = blocksize / 512;
|
||||
avail = npfree = 0;
|
||||
for (i = 0; i < nswdev; i++) {
|
||||
int xsize, xfree;
|
||||
|
||||
/*
|
||||
* Don't report statistics for partitions which have not
|
||||
* yet been activated via swapon(8).
|
||||
*/
|
||||
if (!(sw[i].sw_flags & SW_FREED))
|
||||
continue;
|
||||
|
||||
/* The first dmmax is never allocated to avoid trashing of
|
||||
* disklabels
|
||||
*/
|
||||
xsize = sw[i].sw_nblks - dmmax;
|
||||
xfree = perdev[i];
|
||||
inuse = xsize - xfree;
|
||||
npfree++;
|
||||
avail += xsize;
|
||||
}
|
||||
|
||||
/*
|
||||
* If only one partition has been set up via swapon(8), we don't
|
||||
* need to bother with totals.
|
||||
*/
|
||||
inuse = avail - nfree;
|
||||
|
||||
glibtop_free_r (server, sw);
|
||||
glibtop_free_r (server, perdev);
|
||||
|
||||
buf->flags = _glibtop_sysdeps_swap;
|
||||
|
||||
buf->used = inuse;
|
||||
buf->free = avail;
|
||||
|
||||
buf->total = inuse + avail;
|
||||
|
||||
#else
|
||||
|
||||
nswdev = kvm_getswapinfo(server->_priv->machine.kd, kvmsw, 16, 0);
|
||||
|
||||
buf->flags = _glibtop_sysdeps_swap;
|
||||
|
||||
buf->used = kvmsw[nswdev].ksw_used;
|
||||
buf->total = kvmsw[nswdev].ksw_total;
|
||||
|
||||
buf->free = buf->total - buf->used;
|
||||
|
||||
#endif
|
||||
|
||||
#elif defined(__bsdi__)
|
||||
|
||||
/* General info about swap devices. */
|
||||
|
||||
if (kvm_read (server->_priv->machine.kd, nlst[0].n_value,
|
||||
&swap, sizeof (swap)) != sizeof (swap)) {
|
||||
glibtop_warn_io_r (server, "kvm_read (swap)");
|
||||
return -1;
|
||||
}
|
||||
|
||||
buf->flags = _glibtop_sysdeps_swap;
|
||||
|
||||
buf->used = swap.swap_total - swap.swap_free;
|
||||
buf->free = swap.swap_free;
|
||||
|
||||
buf->total = swap.swap_total;
|
||||
|
||||
#elif defined(__NetBSD__)
|
||||
|
||||
nswap = swapctl (SWAP_NSWAP, NULL, 0);
|
||||
if (nswap < 0) {
|
||||
glibtop_warn_io_r (server, "swapctl (SWAP_NSWAP)");
|
||||
return -1;
|
||||
}
|
||||
|
||||
swaplist = glibtop_calloc_r (server, nswap, sizeof (struct swapent));
|
||||
|
||||
if (swapctl (SWAP_STATS, swaplist, nswap) != nswap) {
|
||||
glibtop_warn_io_r (server, "swapctl (SWAP_STATS)");
|
||||
glibtop_free_r (server, swaplist);
|
||||
return -1;
|
||||
}
|
||||
|
||||
for (i = 0; i < nswap; i++) {
|
||||
avail += swaplist[i].se_nblks;
|
||||
inuse += swaplist[i].se_inuse;
|
||||
}
|
||||
|
||||
glibtop_free_r (server, swaplist);
|
||||
|
||||
buf->flags = _glibtop_sysdeps_swap;
|
||||
|
||||
buf->used = inuse;
|
||||
buf->free = avail;
|
||||
|
||||
buf->total = inuse + avail;
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
@@ -1,79 +0,0 @@
|
||||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright (C) 1998-99 Martin Baulig
|
||||
This file is part of LibGTop 1.0.
|
||||
|
||||
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/uptime.h>
|
||||
|
||||
#include <glibtop/cpu.h>
|
||||
|
||||
#include <glibtop_suid.h>
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_uptime =
|
||||
(1L << GLIBTOP_UPTIME_UPTIME) + (1L << GLIBTOP_UPTIME_IDLETIME);
|
||||
|
||||
static const unsigned long _required_cpu_flags =
|
||||
(1L << GLIBTOP_CPU_TOTAL) + (1L << GLIBTOP_CPU_IDLE) +
|
||||
(1L << GLIBTOP_CPU_FREQUENCY);
|
||||
|
||||
/* Init function. */
|
||||
|
||||
int
|
||||
glibtop_init_uptime_p (glibtop *server)
|
||||
{
|
||||
server->sysdeps.uptime = _glibtop_sysdeps_uptime;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Provides uptime and idle time. */
|
||||
|
||||
int
|
||||
glibtop_get_uptime_p (glibtop *server, glibtop_uptime *buf)
|
||||
{
|
||||
glibtop_cpu cpu;
|
||||
|
||||
glibtop_init_p (server, (1L << GLIBTOP_SYSDEPS_UPTIME), 0);
|
||||
|
||||
memset (buf, 0, sizeof (glibtop_uptime));
|
||||
|
||||
/* We simply calculate it from the CPU usage. */
|
||||
|
||||
glibtop_get_cpu_p (server, &cpu);
|
||||
|
||||
/* Make sure all required fields are present. */
|
||||
|
||||
if ((cpu.flags & _required_cpu_flags) != _required_cpu_flags)
|
||||
return -1;
|
||||
|
||||
/* Calculate values. */
|
||||
|
||||
buf->uptime = (double) cpu.total / (double) cpu.frequency;
|
||||
buf->idletime = (double) cpu.idle / (double) cpu.frequency;
|
||||
|
||||
buf->flags = _glibtop_sysdeps_uptime;
|
||||
|
||||
return 0;
|
||||
}
|
@@ -1,8 +0,0 @@
|
||||
.deps
|
||||
.libs
|
||||
Makefile
|
||||
Makefile.in
|
||||
*.lo
|
||||
*.la
|
||||
marshal.c
|
||||
backend-kernel.h
|
@@ -1 +0,0 @@
|
||||
Martin Baulig (martin@home-of-linux.org)
|
@@ -1,54 +0,0 @@
|
||||
2000-01-24 Martin Baulig <martin@home-of-linux.org>
|
||||
|
||||
* interfaces.c, netinfo.c: Removed.
|
||||
|
||||
2000-01-23 Martin Baulig <martin@home-of-linux.org>
|
||||
|
||||
This is now a LibGTop backend which can be loaded additionally
|
||||
to the normal Linux sysdeps code.
|
||||
|
||||
* open.c, close.c: Removed.
|
||||
* shm_limits.c, msg_limits.c, sem_limits.c, ppp.c: Removed.
|
||||
* siglist.c, sysinfo.c: Removed.
|
||||
|
||||
* backend-kernel.c: New file.
|
||||
* glibtop-backend-private.h: New file.
|
||||
* libgtop-kernel.backend: New file.
|
||||
|
||||
* backend-kernel.pl: New file. Automatically creates
|
||||
`backend-kernel.h'.
|
||||
|
||||
* marshal.pl: New file. Automatically creates `marshal.c'.
|
||||
|
||||
* glibtop_server.h: Replaced all `GLIBTOP_SUID_<feature>' constants
|
||||
with `GLIBTOP_IMPL_<feature>' ones; they're used in marshal.c to
|
||||
find out which features this backend implements.
|
||||
|
||||
* *.c: Renamed all `glibtop_get_<feature>_s' functions to
|
||||
`glibtop_get_<feature>_k' and all `glibtop_init_<feature>_s' ones
|
||||
to `glibtop_init_<feature>_k'.
|
||||
|
||||
1999-12-22 Martin Baulig <martin@home-of-linux.org>
|
||||
|
||||
* procdata.c: Distinguish between GLIBTOP_ERROR_NO_KERNEL_SUPPORT
|
||||
and GLIBTOP_ERROR_NO_SUCH_PROCESS.
|
||||
|
||||
* procdata.c (glibtop_get_proc_data_proc_state_s): Return
|
||||
-GLIBTOP_ERROR_NO_SUCH_PROCESS if the process doesn't exist.
|
||||
(glibtop_get_proc_data_proc_mem_s): Likewise.
|
||||
(glibtop_get_proc_data_proc_signal_s): Likewise.
|
||||
(glibtop_get_proc_data_proc_kernel_s): Likewise.
|
||||
(glibtop_get_proc_data_proc_args_s): Likewise.
|
||||
(glibtop_get_proc_data_proc_maps_s): Likewise.
|
||||
|
||||
1999-04-09 Martin Baulig <martin@home-of-linux.org>
|
||||
|
||||
* sysinfo.c: Copied from the Linux sysdeps directory.
|
||||
|
||||
1999-03-21 Martin Baulig <martin@home-of-linux.org>
|
||||
|
||||
Imported new sysctl () based interface to the Linux Kernel.
|
||||
|
||||
* procdata.c: This file handles all interaction with the kernel.
|
||||
|
||||
|
@@ -1,47 +0,0 @@
|
||||
LINK = \
|
||||
$(LIBTOOL) --mode=link $(CC) $(CFLAGS) $(LDFLAGS) -o $@
|
||||
|
||||
INCLUDES = \
|
||||
@INCLUDES@
|
||||
|
||||
backenddir = \
|
||||
@LIBGTOP_BACKEND_DIR@
|
||||
|
||||
backend_LTLIBRARIES = \
|
||||
libgtop_backend_kernel.la
|
||||
|
||||
backend_DATA = \
|
||||
libgtop-kernel.backend
|
||||
|
||||
libgtop_backend_kernel_la_SOURCES = \
|
||||
cpu.c mem.c swap.c uptime.c loadavg.c \
|
||||
proclist.c procstate.c procuid.c \
|
||||
proctime.c procmem.c procsignal.c prockernel.c \
|
||||
procsegment.c procargs.c procmap.c netload.c \
|
||||
procdata.c backend-kernel.c marshal.c
|
||||
|
||||
libgtop_backend_kernel_la_LDFLAGS = \
|
||||
$(LT_VERSION_INFO)
|
||||
|
||||
noinst_HEADERS = \
|
||||
glibtop_server.h glibtop_private.h
|
||||
|
||||
BUILT_SOURCES = \
|
||||
marshal.c \
|
||||
backend-kernel.h
|
||||
|
||||
EXTRA_DIST = \
|
||||
marshal.pl \
|
||||
backend-kernel.pl \
|
||||
libgtop-kernel.backend
|
||||
|
||||
CLEANFILES = $(BUILT_SOURCES)
|
||||
|
||||
marshal.c: marshal.pl $(top_builddir)/config.h $(top_srcdir)/features.def $(top_srcdir)/scripts/c_types.pl
|
||||
$(PERL) -I $(top_srcdir)/scripts $(srcdir)/marshal.pl < $(top_srcdir)/features.def > tmp-t
|
||||
mv tmp-t marshal.c
|
||||
|
||||
backend-kernel.h: backend-kernel.pl $(top_builddir)/config.h $(top_srcdir)/features.def $(top_srcdir)/scripts/c_types.pl
|
||||
$(PERL) -I $(top_srcdir)/scripts $(srcdir)/backend-kernel.pl < $(top_srcdir)/features.def > tmp-t
|
||||
mv tmp-t backend-kernel.h
|
||||
|
@@ -1,88 +0,0 @@
|
||||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright (C) 1998-99 Martin Baulig
|
||||
This file is part of LibGTop 1.0.
|
||||
|
||||
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/global.h>
|
||||
#include <glibtop/xmalloc.h>
|
||||
|
||||
#include <glibtop/open.h>
|
||||
#include <glibtop/backend.h>
|
||||
#include <glibtop-backend-private.h>
|
||||
|
||||
#include <glibtop_private.h>
|
||||
|
||||
static int
|
||||
_open_kernel (glibtop *, glibtop_backend *, u_int64_t, const char **);
|
||||
|
||||
static int
|
||||
_close_kernel (glibtop *, glibtop_backend *);
|
||||
|
||||
extern glibtop_call_vector glibtop_backend_kernel_call_vector;
|
||||
extern glibtop_init_func_t _glibtop_init_hook_k [];
|
||||
|
||||
glibtop_backend_info LibGTopBackendInfo = {
|
||||
"glibtop-backend-kernel", _open_kernel, _close_kernel,
|
||||
&glibtop_backend_kernel_call_vector
|
||||
};
|
||||
|
||||
static int
|
||||
_open_kernel (glibtop *server, glibtop_backend *backend,
|
||||
u_int64_t features, const char **backend_args)
|
||||
{
|
||||
glibtop_init_func_t *init_fkt;
|
||||
int version, name [2] = { CTL_LIBGTOP, LIBGTOP_VERSION };
|
||||
size_t size = sizeof (int);
|
||||
|
||||
if (sysctl (name, 2, &version, &size, NULL, 0)) {
|
||||
if (errno == ENOTDIR)
|
||||
return -GLIBTOP_ERROR_NO_KERNEL_SUPPORT;
|
||||
else
|
||||
glibtop_warn_io_r (server, "sysctl (libgtop/stat)");
|
||||
return -1;
|
||||
}
|
||||
|
||||
backend->_priv = glibtop_calloc_r
|
||||
(server, 1, sizeof (glibtop_backend_private));
|
||||
|
||||
/* Do the initialization, but only if not already initialized. */
|
||||
|
||||
if ((server->flags & _GLIBTOP_INIT_STATE_SYSDEPS) == 0) {
|
||||
for (init_fkt = _glibtop_init_hook_k; *init_fkt; init_fkt++)
|
||||
(*init_fkt) (server);
|
||||
|
||||
server->sysdeps.pointer_size = sizeof (void*)*8;
|
||||
|
||||
server->flags |= _GLIBTOP_INIT_STATE_SYSDEPS;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
_close_kernel (glibtop *server, glibtop_backend *backend)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
@@ -1,152 +0,0 @@
|
||||
#!/usr/bin/perl
|
||||
|
||||
require 'c_types.pl';
|
||||
|
||||
$[ = 1; # set array base to 1
|
||||
$, = ' '; # set output field separator
|
||||
$\ = "\n"; # set output record separator
|
||||
|
||||
$always_use_temp_storage = 1;
|
||||
|
||||
sub toupper {
|
||||
local($_) = @_;
|
||||
tr/a-z/A-Z/;
|
||||
return $_;
|
||||
}
|
||||
|
||||
sub tolower {
|
||||
local($_) = @_;
|
||||
tr/A-Z/a-z/;
|
||||
return $_;
|
||||
}
|
||||
|
||||
print '/* backend-kernel.h */';
|
||||
print "/* This is a generated file. Please modify `backend-kernel.pl' */";
|
||||
print '';
|
||||
|
||||
print '#ifndef __GLIBTOP_BACKEND_KERNEL_H__';
|
||||
print '#define __GLIBTOP_BACKEND_KERNEL_H__';
|
||||
print '';
|
||||
print '#include <glibtop.h>';
|
||||
print '#include <glibtop/union.h>';
|
||||
print '';
|
||||
print 'BEGIN_LIBGTOP_DECLS';
|
||||
print '';
|
||||
|
||||
$feature_count = 0;
|
||||
|
||||
while (<>) {
|
||||
chop; # strip record separator
|
||||
|
||||
if (/^[^#]/) {
|
||||
&output($_);
|
||||
}
|
||||
}
|
||||
|
||||
sub output {
|
||||
local($line) = @_;
|
||||
@line_fields = split(/\|/, $line, 9999);
|
||||
$retval = $line_fields[1];
|
||||
$feature = $line_fields[2];
|
||||
$param_def = $line_fields[4];
|
||||
|
||||
$orig = $feature;
|
||||
$feature =~ s/^@//;
|
||||
$space = $feature;
|
||||
$space =~ s/./ /g;
|
||||
|
||||
$features{++$feature_count} = $orig;
|
||||
|
||||
return if $orig =~ /^@/;
|
||||
|
||||
if ($retval eq 'retval') {
|
||||
$retval_param = '&retval';
|
||||
$call_prefix = '';
|
||||
$call_prefix_space = '';
|
||||
$prefix = 'retval = ';
|
||||
$prefix_space = ' ';
|
||||
$retval = 'int';
|
||||
}
|
||||
elsif ($retval !~ /^void$/) {
|
||||
$retval_param = 'NULL';
|
||||
$prefix = 'retval = ';
|
||||
$prefix_space = ' ';
|
||||
$call_prefix = 'retval = ';
|
||||
$call_prefix_space = ' ';
|
||||
}
|
||||
else {
|
||||
$retval_param = 'NULL';
|
||||
$call_prefix = '';
|
||||
$call_prefix_space = '';
|
||||
$prefix = '';
|
||||
$prefix_space = '';
|
||||
}
|
||||
|
||||
if ($retval =~ /^(array|pointer)\((.*)\)$/) {
|
||||
$retval = ($2 eq 'string') ? 'char **' : "$2 *";
|
||||
}
|
||||
|
||||
$need_temp_storage = $always_use_temp_storage;
|
||||
$first_param_name = '';
|
||||
|
||||
$call_param = '';
|
||||
$param_decl = '';
|
||||
$need_temp_len = 0;
|
||||
$nr_params = (@params = split(/:/, $param_def, 9999));
|
||||
for ($param = 1; $param <= $nr_params; $param++) {
|
||||
$list = $params[$param];
|
||||
$type = $params[$param];
|
||||
$type =~ s/\(.*//;
|
||||
$list =~ s/^.*\(//;
|
||||
$list =~ s/\)$//;
|
||||
$count = (@fields = split(/,/, $list, 9999));
|
||||
for ($field = 1; $field <= $count; $field++) {
|
||||
my $c_type = $typeinfo->{$type}->[1];
|
||||
|
||||
if ($first_param_name eq '') {
|
||||
$first_param_name = $fields[$field];
|
||||
}
|
||||
|
||||
if ($typeinfo->{$type}->[2]) {
|
||||
$need_temp_storage = 1;
|
||||
}
|
||||
|
||||
if ($param_decl eq '') {
|
||||
$param_decl = ",\n " . $space . ' ';
|
||||
}
|
||||
else {
|
||||
$param_decl = $param_decl . ', ';
|
||||
}
|
||||
$param_decl = $param_decl . $c_type . ' ' . $fields[$field];
|
||||
$call_param = $call_param . ', ' . $fields[$field];
|
||||
}
|
||||
}
|
||||
|
||||
$func_decl = sprintf ("int\nglibtop_init_%s_k (glibtop *server);\n\n",
|
||||
$feature);
|
||||
|
||||
$func_decl .= $retval."\n";
|
||||
if ($line_fields[3] eq '') {
|
||||
$func_decl .= sprintf ("glibtop_get_%s_k (glibtop *server%s);\n",
|
||||
$feature, $param_decl);
|
||||
} elsif ($line_fields[3] eq 'array') {
|
||||
$func_decl .= sprintf ("glibtop_get_%s_k (glibtop *server, glibtop_array *array%s);\n",
|
||||
$feature, $param_decl);
|
||||
} elsif ($line_fields[3] =~ /^array/) {
|
||||
$func_decl .= sprintf ("glibtop_get_%s_k (glibtop *server, glibtop_array *array, %s *buf%s);\n",
|
||||
$feature, 'glibtop_'.$feature, $param_decl);
|
||||
} else {
|
||||
$func_decl .= sprintf ("glibtop_get_%s_k (glibtop *server, %s *buf%s);\n",
|
||||
$feature, 'glibtop_'.$feature, $param_decl);
|
||||
}
|
||||
|
||||
$total_code = $func_decl;
|
||||
|
||||
print $total_code;
|
||||
}
|
||||
|
||||
print '';
|
||||
print 'END_LIBGTOP_DECLS';
|
||||
print '';
|
||||
print '#endif';
|
||||
print '';
|
@@ -1,93 +0,0 @@
|
||||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright (C) 1998-99 Martin Baulig
|
||||
This file is part of LibGTop 1.0.
|
||||
|
||||
Contributed by Martin Baulig <martin@home-of-linux.org>, March 1999.
|
||||
|
||||
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/cpu.h>
|
||||
|
||||
#include <glibtop_private.h>
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_cpu =
|
||||
(1L << GLIBTOP_CPU_TOTAL) + (1L << GLIBTOP_CPU_USER) +
|
||||
(1L << GLIBTOP_CPU_NICE) + (1L << GLIBTOP_CPU_SYS) +
|
||||
(1L << GLIBTOP_CPU_IDLE) + (1L << GLIBTOP_CPU_FREQUENCY);
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_cpu_smp =
|
||||
(1L << GLIBTOP_CPU_XCPU_TOTAL) + (1L << GLIBTOP_CPU_XCPU_USER) +
|
||||
(1L << GLIBTOP_CPU_XCPU_NICE) + (1L << GLIBTOP_CPU_XCPU_SYS) +
|
||||
(1L << GLIBTOP_CPU_XCPU_IDLE);
|
||||
|
||||
/* Init function. */
|
||||
|
||||
int
|
||||
glibtop_init_cpu_k (glibtop *server)
|
||||
{
|
||||
server->sysdeps.cpu = _glibtop_sysdeps_cpu;
|
||||
|
||||
if (server->ncpu)
|
||||
server->sysdeps.cpu |= _glibtop_sysdeps_cpu_smp;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Provides information about cpu usage. */
|
||||
|
||||
int
|
||||
glibtop_get_cpu_k (glibtop *server, glibtop_cpu *buf)
|
||||
{
|
||||
libgtop_stat_t stat;
|
||||
int retval, i;
|
||||
|
||||
memset (buf, 0, sizeof (glibtop_cpu));
|
||||
|
||||
retval = glibtop_get_proc_data_stat_k (server, &stat);
|
||||
if (retval)
|
||||
return retval;
|
||||
|
||||
buf->user = stat.cpu.user;
|
||||
buf->nice = stat.cpu.nice;
|
||||
buf->sys = stat.cpu.sys;
|
||||
buf->idle = stat.cpu.idle;
|
||||
|
||||
buf->total = buf->user + buf->nice + buf->sys + buf->idle;
|
||||
buf->frequency = stat.frequency;
|
||||
|
||||
buf->flags = _glibtop_sysdeps_cpu;
|
||||
|
||||
if (stat.ncpu) {
|
||||
for (i = 0; i < GLIBTOP_NCPU; i++) {
|
||||
buf->xcpu_user [i] = stat.xcpu [i].user;
|
||||
buf->xcpu_nice [i] = stat.xcpu [i].nice;
|
||||
buf->xcpu_sys [i] = stat.xcpu [i].sys;
|
||||
buf->xcpu_idle [i] = stat.xcpu [i].idle;
|
||||
|
||||
buf->xcpu_total [i] = buf->xcpu_user [i] + buf->xcpu_nice [i] +
|
||||
buf->xcpu_sys [i] + buf->xcpu_idle [i];
|
||||
}
|
||||
|
||||
buf->flags |= _glibtop_sysdeps_cpu_smp;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
@@ -1,34 +0,0 @@
|
||||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright (C) 1998-99 Martin Baulig
|
||||
This file is part of LibGTop 1.0.
|
||||
|
||||
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.
|
||||
*/
|
||||
|
||||
#ifndef __GLIBTOP_BACKEND_PRIVATE_H__
|
||||
#define __GLIBTOP_BACKEND_PRIVATE_H__
|
||||
|
||||
struct _glibtop_backend_private
|
||||
{
|
||||
u_int64_t flags;
|
||||
};
|
||||
|
||||
#endif
|
@@ -1,93 +0,0 @@
|
||||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright (C) 1998-99 Martin Baulig
|
||||
This file is part of LibGTop 1.0.
|
||||
|
||||
Contributed by Martin Baulig <martin@home-of-linux.org>, March 1999.
|
||||
|
||||
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.
|
||||
*/
|
||||
|
||||
#ifndef __GLIBTOP_PRIVATE_H__
|
||||
#define __GLIBTOP_PRIVATE_H__
|
||||
|
||||
#include <glibtop.h>
|
||||
#include <glibtop/error.h>
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/sysctl.h>
|
||||
#include <sys/user.h>
|
||||
|
||||
#undef LIBGTOP_VERSION
|
||||
#include <linux/libgtop.h>
|
||||
|
||||
BEGIN_LIBGTOP_DECLS
|
||||
|
||||
#include "backend-kernel.h"
|
||||
|
||||
int
|
||||
glibtop_get_proc_data_stat_k (glibtop *server, libgtop_stat_t *stat);
|
||||
|
||||
int
|
||||
glibtop_get_proc_data_mem_k (glibtop *server, libgtop_mem_t *mem);
|
||||
|
||||
int
|
||||
glibtop_get_proc_data_swap_k (glibtop *server, libgtop_swap_t *swap);
|
||||
|
||||
int
|
||||
glibtop_get_proc_data_proclist_k (glibtop *server,
|
||||
libgtop_proclist_t *proclist,
|
||||
u_int64_t which, u_int64_t arg);
|
||||
|
||||
int
|
||||
glibtop_get_proc_data_proc_state_k (glibtop *server,
|
||||
libgtop_proc_state_t *proc_state,
|
||||
pid_t pid);
|
||||
|
||||
int
|
||||
glibtop_get_proc_data_proc_mem_k (glibtop *server,
|
||||
libgtop_proc_mem_t *proc_mem,
|
||||
pid_t pid);
|
||||
|
||||
int
|
||||
glibtop_get_proc_data_proc_signal_k (glibtop *server,
|
||||
libgtop_proc_signal_t *proc_signal,
|
||||
pid_t pid);
|
||||
|
||||
int
|
||||
glibtop_get_proc_data_proc_kernel_k (glibtop *server,
|
||||
libgtop_proc_kernel_t *proc_kernel,
|
||||
pid_t pid);
|
||||
|
||||
int
|
||||
glibtop_get_proc_data_proc_args_k (glibtop *server, pid_t pid,
|
||||
char *result, size_t max_len);
|
||||
|
||||
int
|
||||
glibtop_get_proc_data_proc_maps_k (glibtop *server, pid_t pid,
|
||||
libgtop_proc_maps_t *result,
|
||||
size_t max_len);
|
||||
|
||||
int
|
||||
glibtop_get_proc_data_netload_k (glibtop *server,
|
||||
libgtop_netload_t *netload,
|
||||
const char *device);
|
||||
|
||||
END_LIBGTOP_DECLS
|
||||
|
||||
#endif /* __GLIBTOP_PRIVATE_H__ */
|
@@ -1,56 +0,0 @@
|
||||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright (C) 1998-99 Martin Baulig
|
||||
This file is part of LibGTop 1.0.
|
||||
|
||||
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.
|
||||
*/
|
||||
|
||||
#ifndef __GLIBTOP_SERVER_H__
|
||||
#define __GLIBTOP_SERVER_H__
|
||||
|
||||
BEGIN_LIBGTOP_DECLS
|
||||
|
||||
#define GLIBTOP_IMPL_CPU (1L << GLIBTOP_SYSDEPS_CPU)
|
||||
#define GLIBTOP_IMPL_MEM (1L << GLIBTOP_SYSDEPS_MEM)
|
||||
#define GLIBTOP_IMPL_SWAP (1L << GLIBTOP_SYSDEPS_SWAP)
|
||||
#define GLIBTOP_IMPL_UPTIME (1L << GLIBTOP_SYSDEPS_UPTIME)
|
||||
#define GLIBTOP_IMPL_LOADAVG (1L << GLIBTOP_SYSDEPS_LOADAVG)
|
||||
#define GLIBTOP_IMPL_SHM_LIMITS 0
|
||||
#define GLIBTOP_IMPL_MSG_LIMITS 0
|
||||
#define GLIBTOP_IMPL_SEM_LIMITS 0
|
||||
#define GLIBTOP_IMPL_PROCLIST (1L << GLIBTOP_SYSDEPS_PROCLIST)
|
||||
#define GLIBTOP_IMPL_PROC_STATE (1L << GLIBTOP_SYSDEPS_PROC_STATE)
|
||||
#define GLIBTOP_IMPL_PROC_UID (1L << GLIBTOP_SYSDEPS_PROC_UID)
|
||||
#define GLIBTOP_IMPL_PROC_MEM (1L << GLIBTOP_SYSDEPS_PROC_MEM)
|
||||
#define GLIBTOP_IMPL_PROC_TIME (1L << GLIBTOP_SYSDEPS_PROC_TIME)
|
||||
#define GLIBTOP_IMPL_PROC_SIGNAL (1L << GLIBTOP_SYSDEPS_PROC_SIGNAL)
|
||||
#define GLIBTOP_IMPL_PROC_KERNEL (1L << GLIBTOP_SYSDEPS_PROC_KERNEL)
|
||||
#define GLIBTOP_IMPL_PROC_SEGMENT (1L << GLIBTOP_SYSDEPS_PROC_SEGMENT)
|
||||
#define GLIBTOP_IMPL_PROC_ARGS (1L << GLIBTOP_SYSDEPS_PROC_ARGS)
|
||||
#define GLIBTOP_IMPL_PROC_MAP (1L << GLIBTOP_SYSDEPS_PROC_MAP)
|
||||
#define GLIBTOP_IMPL_NETLOAD (1L << GLIBTOP_SYSDEPS_NETLOAD)
|
||||
#define GLIBTOP_IMPL_NETINFO 0
|
||||
#define GLIBTOP_IMPL_INTERFACE_NAMES 0
|
||||
#define GLIBTOP_IMPL_PPP 0
|
||||
|
||||
END_LIBGTOP_DECLS
|
||||
|
||||
#endif
|
@@ -1,13 +0,0 @@
|
||||
<?xml version="1.0"?> <!-- -*-xml-*- -->
|
||||
<!DOCTYPE libgtop:backends SYSTEM 'libgtop-backends.dtd'>
|
||||
<libgtop:Backends xmlns:libgtop="http://www.home-of-linux.org/libgtop/1.1">
|
||||
|
||||
<libgtop:Backend>
|
||||
<libgtop:Name>glibtop-backend-kernel</libgtop:Name>
|
||||
<libgtop:Location>
|
||||
<libgtop:LibtoolName>libgtop_backend_kernel.la</libgtop:LibtoolName>
|
||||
<libgtop:ShlibName>libgtop_backend_kernel.so</libgtop:ShlibName>
|
||||
</libgtop:Location>
|
||||
</libgtop:Backend>
|
||||
|
||||
</libgtop:Backends>
|
@@ -1,65 +0,0 @@
|
||||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright (C) 1998-99 Martin Baulig
|
||||
This file is part of LibGTop 1.0.
|
||||
|
||||
Contributed by Martin Baulig <martin@home-of-linux.org>, March 1999.
|
||||
|
||||
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/loadavg.h>
|
||||
|
||||
#include <glibtop_private.h>
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_loadavg =
|
||||
(1L << GLIBTOP_LOADAVG_LOADAVG);
|
||||
|
||||
/* Init function. */
|
||||
|
||||
int
|
||||
glibtop_init_loadavg_k (glibtop *server)
|
||||
{
|
||||
server->sysdeps.loadavg = _glibtop_sysdeps_loadavg;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Provides load averange. */
|
||||
|
||||
int
|
||||
glibtop_get_loadavg_k (glibtop *server, glibtop_loadavg *buf)
|
||||
{
|
||||
libgtop_stat_t stat;
|
||||
int retval;
|
||||
|
||||
memset (buf, 0, sizeof (glibtop_loadavg));
|
||||
|
||||
retval = glibtop_get_proc_data_stat_k (server, &stat);
|
||||
if (retval)
|
||||
return retval;
|
||||
|
||||
buf->loadavg [0] = stat.loadavg [0];
|
||||
buf->loadavg [1] = stat.loadavg [1];
|
||||
buf->loadavg [2] = stat.loadavg [2];
|
||||
|
||||
buf->flags = _glibtop_sysdeps_loadavg;
|
||||
|
||||
return 0;
|
||||
}
|
@@ -1,201 +0,0 @@
|
||||
#!/usr/bin/perl
|
||||
|
||||
require 'c_types.pl';
|
||||
|
||||
$[ = 1; # set array base to 1
|
||||
$, = ' '; # set output field separator
|
||||
$\ = "\n"; # set output record separator
|
||||
|
||||
$always_use_temp_storage = 1;
|
||||
|
||||
sub toupper {
|
||||
local($_) = @_;
|
||||
tr/a-z/A-Z/;
|
||||
return $_;
|
||||
}
|
||||
|
||||
sub tolower {
|
||||
local($_) = @_;
|
||||
tr/A-Z/a-z/;
|
||||
return $_;
|
||||
}
|
||||
|
||||
print '/* marshal.c */';
|
||||
print "/* This is a generated file. Please modify `marshal.pl' */";
|
||||
print '';
|
||||
|
||||
print '#include <glibtop.h>';
|
||||
print '#include <glibtop/open.h>';
|
||||
print '#include <glibtop/xmalloc.h>';
|
||||
print '';
|
||||
print '#include <glibtop/sysdeps.h>';
|
||||
print '#include <glibtop/union.h>';
|
||||
print '';
|
||||
print '#include <glibtop/backend.h>';
|
||||
print '';
|
||||
print '#include <glibtop-backend-private.h>';
|
||||
print '#include <glibtop_private.h>';
|
||||
print '#include <glibtop_server.h>';
|
||||
print '';
|
||||
|
||||
$feature_count = 0;
|
||||
|
||||
while (<>) {
|
||||
chop; # strip record separator
|
||||
|
||||
if (/^[^#]/) {
|
||||
&output($_);
|
||||
}
|
||||
}
|
||||
|
||||
sub output {
|
||||
local($line) = @_;
|
||||
@line_fields = split(/\|/, $line, 9999);
|
||||
$retval = $line_fields[1];
|
||||
$feature = $line_fields[2];
|
||||
$param_def = $line_fields[4];
|
||||
|
||||
$orig = $feature;
|
||||
$feature =~ s/^@//;
|
||||
$space = $feature;
|
||||
$space =~ s/./ /g;
|
||||
|
||||
$features{++$feature_count} = $orig;
|
||||
|
||||
return if $orig =~ /^@/;
|
||||
|
||||
if ($retval eq 'retval') {
|
||||
$retval_param = '&retval';
|
||||
$call_prefix = '';
|
||||
$call_prefix_space = '';
|
||||
$prefix = 'retval = ';
|
||||
$prefix_space = ' ';
|
||||
$retval = 'int';
|
||||
}
|
||||
elsif ($retval !~ /^void$/) {
|
||||
$retval_param = 'NULL';
|
||||
$prefix = 'retval = ';
|
||||
$prefix_space = ' ';
|
||||
$call_prefix = 'retval = ';
|
||||
$call_prefix_space = ' ';
|
||||
}
|
||||
else {
|
||||
$retval_param = 'NULL';
|
||||
$call_prefix = '';
|
||||
$call_prefix_space = '';
|
||||
$prefix = '';
|
||||
$prefix_space = '';
|
||||
}
|
||||
|
||||
if ($retval =~ /^(array|pointer)\((.*)\)$/) {
|
||||
$retval = ($2 eq 'string') ? 'char **' : "$2 *";
|
||||
}
|
||||
|
||||
$need_temp_storage = $always_use_temp_storage;
|
||||
$first_param_name = '';
|
||||
|
||||
$call_param = '';
|
||||
$param_decl = '';
|
||||
$need_temp_len = 0;
|
||||
$nr_params = (@params = split(/:/, $param_def, 9999));
|
||||
for ($param = 1; $param <= $nr_params; $param++) {
|
||||
$list = $params[$param];
|
||||
$type = $params[$param];
|
||||
$type =~ s/\(.*//;
|
||||
$list =~ s/^.*\(//;
|
||||
$list =~ s/\)$//;
|
||||
$count = (@fields = split(/,/, $list, 9999));
|
||||
for ($field = 1; $field <= $count; $field++) {
|
||||
my $c_type = $typeinfo->{$type}->[1];
|
||||
|
||||
if ($first_param_name eq '') {
|
||||
$first_param_name = $fields[$field];
|
||||
}
|
||||
|
||||
if ($typeinfo->{$type}->[2]) {
|
||||
$need_temp_storage = 1;
|
||||
}
|
||||
|
||||
if ($param_decl eq '') {
|
||||
$param_decl = ",\n " . $space . ' ';
|
||||
}
|
||||
else {
|
||||
$param_decl = $param_decl . ', ';
|
||||
}
|
||||
$param_decl = $param_decl . $c_type . ' ' . $fields[$field];
|
||||
$call_param = $call_param . ', ' . $fields[$field];
|
||||
}
|
||||
}
|
||||
|
||||
if ($line_fields[3] eq '') {
|
||||
$total_code = sprintf
|
||||
("\treturn glibtop_get_%s_k (server%s);\n", $feature, $call_param);
|
||||
} elsif ($line_fields[3] eq 'array') {
|
||||
$total_code = sprintf
|
||||
("\treturn glibtop_get_%s_k (server, array%s);\n", $feature, $call_param);
|
||||
} elsif ($line_fields[3] =~ /^array/) {
|
||||
$total_code = sprintf
|
||||
("\treturn glibtop_get_%s_k (server, array, buf%s);\n", $feature, $call_param);
|
||||
} else {
|
||||
$total_code = sprintf
|
||||
("\treturn glibtop_get_%s_k (server, buf%s);\n", $feature, $call_param);
|
||||
}
|
||||
|
||||
$func_decl = 'static '.$retval."\n";
|
||||
if ($line_fields[3] eq '') {
|
||||
$func_decl .= sprintf ("_glibtop_get_%s_c (glibtop *server, glibtop_backend *backend%s)\n",
|
||||
$feature, $param_decl);
|
||||
} elsif ($line_fields[3] eq 'array') {
|
||||
$func_decl .= sprintf ("_glibtop_get_%s_c (glibtop *server, glibtop_backend *backend, glibtop_array *array%s)\n",
|
||||
$feature, $param_decl);
|
||||
} elsif ($line_fields[3] =~ /^array/) {
|
||||
$func_decl .= sprintf ("_glibtop_get_%s_c (glibtop *server, glibtop_backend *backend, glibtop_array *array, %s *buf%s)\n",
|
||||
$feature, 'glibtop_'.$feature, $param_decl);
|
||||
} else {
|
||||
$func_decl .= sprintf ("_glibtop_get_%s_c (glibtop *server, glibtop_backend *backend, %s *buf%s)\n",
|
||||
$feature, 'glibtop_'.$feature, $param_decl);
|
||||
}
|
||||
|
||||
$total_code = sprintf ("%s{\n%s\n%s}\n", $func_decl, $total_code);
|
||||
|
||||
$total_code = sprintf ("#if (GLIBTOP_IMPL_%s)\n\n%s\n#endif /* GLIBTOP_IMPL_%s */\n\n",
|
||||
&toupper($feature), $total_code,
|
||||
&toupper($feature));
|
||||
|
||||
print $total_code;
|
||||
}
|
||||
|
||||
$init_hook_code = '';
|
||||
$call_vector_code = '';
|
||||
for ($nr = 1; $nr <= $feature_count; $nr++) {
|
||||
$feature = $features{$nr};
|
||||
|
||||
if ($feature =~ /^@/) {
|
||||
$call_vector_code .= sprintf (qq[\tNULL,\n]);
|
||||
} else {
|
||||
$call_vector_code .= sprintf
|
||||
(qq[\#if GLIBTOP_IMPL_%s\n\t_glibtop_get_%s_c,\n\#else\n\tNULL,\n\#endif\n],
|
||||
&toupper($feature), $feature);
|
||||
}
|
||||
|
||||
if (!($feature =~ /^@/)) {
|
||||
$init_hook_code .= sprintf
|
||||
(qq[\#if GLIBTOP_IMPL_%s\n\tglibtop_init_%s_k,\n\#endif\n],
|
||||
&toupper($feature), $feature);
|
||||
}
|
||||
}
|
||||
$init_hook_code .= sprintf (qq[\tNULL\n]);
|
||||
|
||||
chop $init_hook_code;
|
||||
chop $call_vector_code;
|
||||
|
||||
print 'glibtop_call_vector glibtop_backend_kernel_call_vector = {';
|
||||
print $call_vector_code;
|
||||
print '};';
|
||||
print '';
|
||||
|
||||
print 'glibtop_init_func_t _glibtop_init_hook_k [] = {';
|
||||
print $init_hook_code;
|
||||
print '};';
|
||||
print '';
|
||||
|
@@ -1,70 +0,0 @@
|
||||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright (C) 1998-99 Martin Baulig
|
||||
This file is part of LibGTop 1.0.
|
||||
|
||||
Contributed by Martin Baulig <martin@home-of-linux.org>, March 1999.
|
||||
|
||||
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/mem.h>
|
||||
|
||||
#include <glibtop_private.h>
|
||||
|
||||
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) + (1L << GLIBTOP_MEM_CACHED);
|
||||
|
||||
/* Init function. */
|
||||
|
||||
int
|
||||
glibtop_init_mem_k (glibtop *server)
|
||||
{
|
||||
server->sysdeps.mem = _glibtop_sysdeps_mem;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Provides information about memory usage. */
|
||||
|
||||
int
|
||||
glibtop_get_mem_k (glibtop *server, glibtop_mem *buf)
|
||||
{
|
||||
libgtop_mem_t mem;
|
||||
int retval;
|
||||
|
||||
memset (buf, 0, sizeof (glibtop_mem));
|
||||
|
||||
retval = glibtop_get_proc_data_mem_k (server, &mem);
|
||||
if (retval)
|
||||
return retval;
|
||||
|
||||
buf->total = mem.totalram;
|
||||
buf->used = mem.totalram - mem.freeram;
|
||||
buf->free = mem.freeram;
|
||||
buf->shared = mem.sharedram;
|
||||
buf->buffer = mem.bufferram;
|
||||
buf->cached = mem.cachedram;
|
||||
|
||||
buf->flags = _glibtop_sysdeps_mem;
|
||||
|
||||
return 0;
|
||||
}
|
@@ -1,113 +0,0 @@
|
||||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright (C) 1998-99 Martin Baulig
|
||||
This file is part of LibGTop 1.0.
|
||||
|
||||
Contributed by Martin Baulig <martin@home-of-linux.org>, October 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/netload.h>
|
||||
|
||||
#include <glibtop_private.h>
|
||||
|
||||
#include <glibtop.h>
|
||||
#include <glibtop/error.h>
|
||||
#include <glibtop/netload.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/ioctl.h>
|
||||
|
||||
#if !defined (_LIBC) && defined (__GNU_LIBRARY__) && __GNU_LIBRARY__ > 1
|
||||
/* GNU LibC */
|
||||
#include <net/if.h>
|
||||
#include <netinet/ip_icmp.h>
|
||||
#include <netinet/in.h>
|
||||
#include <netinet/ip.h>
|
||||
#include <netinet/tcp.h>
|
||||
#include <netinet/udp.h>
|
||||
#include <net/if.h>
|
||||
#else /* Libc 5 */
|
||||
#include <linux/if.h>
|
||||
#include <linux/in.h>
|
||||
#include <linux/ip.h>
|
||||
#include <linux/icmp.h>
|
||||
#include <linux/tcp.h>
|
||||
#include <linux/udp.h>
|
||||
#endif
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_netload =
|
||||
(1L << GLIBTOP_NETLOAD_BYTES_IN) +
|
||||
(1L << GLIBTOP_NETLOAD_BYTES_OUT) +
|
||||
(1L << GLIBTOP_NETLOAD_BYTES_TOTAL) +
|
||||
(1L << GLIBTOP_NETLOAD_PACKETS_IN) +
|
||||
(1L << GLIBTOP_NETLOAD_PACKETS_OUT) +
|
||||
(1L << GLIBTOP_NETLOAD_PACKETS_TOTAL) +
|
||||
(1L << GLIBTOP_NETLOAD_ERRORS_IN) +
|
||||
(1L << GLIBTOP_NETLOAD_ERRORS_OUT) +
|
||||
(1L << GLIBTOP_NETLOAD_ERRORS_TOTAL) +
|
||||
(1L << GLIBTOP_NETLOAD_COLLISIONS);
|
||||
|
||||
/* Init function. */
|
||||
|
||||
int
|
||||
glibtop_init_netload_k (glibtop *server)
|
||||
{
|
||||
server->sysdeps.netload = _glibtop_sysdeps_netload;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Provides network statistics. */
|
||||
|
||||
int
|
||||
glibtop_get_netload_k (glibtop *server, glibtop_netload *buf,
|
||||
const char *interface, unsigned transport,
|
||||
unsigned protocol)
|
||||
{
|
||||
libgtop_netload_t netload;
|
||||
int retval;
|
||||
|
||||
memset (buf, 0, sizeof (glibtop_netload));
|
||||
|
||||
retval = glibtop_get_proc_data_netload_k (server, &netload, interface);
|
||||
if (retval)
|
||||
return retval;
|
||||
|
||||
buf->bytes_in = netload.rx_bytes;
|
||||
buf->bytes_out = netload.tx_bytes;
|
||||
buf->bytes_total = buf->bytes_in + buf->bytes_out;
|
||||
|
||||
buf->packets_in = netload.rx_packets;
|
||||
buf->packets_out = netload.tx_packets;
|
||||
buf->packets_total = buf->packets_in + buf->packets_out;
|
||||
|
||||
buf->errors_in = netload.rx_errors;
|
||||
buf->errors_out = netload.tx_errors;
|
||||
buf->errors_total = buf->errors_in + buf->errors_out;
|
||||
|
||||
buf->collisions = netload.collisions;
|
||||
|
||||
buf->flags |= _glibtop_sysdeps_netload;
|
||||
|
||||
return 0;
|
||||
}
|
@@ -1,90 +0,0 @@
|
||||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright (C) 1998-99 Martin Baulig
|
||||
This file is part of LibGTop 1.0.
|
||||
|
||||
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/xmalloc.h>
|
||||
#include <glibtop/procargs.h>
|
||||
|
||||
#include <glibtop_private.h>
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_proc_args =
|
||||
(1L << GLIBTOP_ARRAY_NUMBER) + (1L << GLIBTOP_ARRAY_SIZE);
|
||||
|
||||
/* Init function. */
|
||||
|
||||
int
|
||||
glibtop_init_proc_args_k (glibtop *server)
|
||||
{
|
||||
server->sysdeps.proc_args = _glibtop_sysdeps_proc_args;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Provides detailed information about a process. */
|
||||
|
||||
char **
|
||||
glibtop_get_proc_args_k (glibtop *server, glibtop_array *array, pid_t pid)
|
||||
{
|
||||
char *ptr = NULL, *pos, **ptrlist;
|
||||
size_t count = 0, max_len, total;
|
||||
int i, ret;
|
||||
|
||||
memset (array, 0, sizeof (glibtop_array));
|
||||
|
||||
max_len = PAGE_SIZE;
|
||||
ptr = glibtop_malloc_r (server, max_len + 1);
|
||||
|
||||
ret = glibtop_get_proc_data_proc_args_k (server, pid, ptr, max_len);
|
||||
if (ret < 0) {
|
||||
glibtop_free_r (server, ptr);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
total = ret;
|
||||
ptr [total] = '\0';
|
||||
|
||||
for (i = 0; i <= total; i++) {
|
||||
if (ptr [i]) continue;
|
||||
count++;
|
||||
}
|
||||
|
||||
ptrlist = glibtop_calloc_r (server, count+1, sizeof (char *));
|
||||
|
||||
for (i = 0, pos = ptr; i < count; i++) {
|
||||
ptrlist [i] = glibtop_strdup_r (server, pos);
|
||||
pos += strlen (pos) + 1;
|
||||
}
|
||||
|
||||
ptrlist [count] = NULL;
|
||||
|
||||
glibtop_free_r (server, ptr);
|
||||
|
||||
array->number = count;
|
||||
array->size = sizeof (char *);
|
||||
array->flags = _glibtop_sysdeps_proc_args;
|
||||
|
||||
return ptrlist;
|
||||
}
|
@@ -1,242 +0,0 @@
|
||||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright (C) 1998-99 Martin Baulig
|
||||
This file is part of LibGTop 1.0.
|
||||
|
||||
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_private.h>
|
||||
|
||||
int
|
||||
glibtop_get_proc_data_stat_k (glibtop *server, libgtop_stat_t *stat)
|
||||
{
|
||||
int name [2] = { CTL_LIBGTOP, LIBGTOP_STAT };
|
||||
size_t size = sizeof (libgtop_stat_t);
|
||||
|
||||
if (sysctl (name, 2, stat, &size, NULL, 0)) {
|
||||
if (errno == ENOTDIR)
|
||||
return -GLIBTOP_ERROR_NO_KERNEL_SUPPORT;
|
||||
else
|
||||
glibtop_warn_io_r (server, "sysctl (libgtop/stat)");
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
glibtop_get_proc_data_mem_k (glibtop *server, libgtop_mem_t *mem)
|
||||
{
|
||||
int name [2] = { CTL_LIBGTOP, LIBGTOP_MEM };
|
||||
size_t size = sizeof (libgtop_mem_t);
|
||||
|
||||
if (sysctl (name, 2, mem, &size, NULL, 0)) {
|
||||
if (errno == ENOTDIR)
|
||||
return -GLIBTOP_ERROR_NO_KERNEL_SUPPORT;
|
||||
else
|
||||
glibtop_warn_io_r (server, "sysctl (libgtop/mem)");
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
glibtop_get_proc_data_swap_k (glibtop *server, libgtop_swap_t *swap)
|
||||
{
|
||||
int name [2] = { CTL_LIBGTOP, LIBGTOP_SWAP };
|
||||
size_t size = sizeof (libgtop_swap_t);
|
||||
|
||||
if (sysctl (name, 2, swap, &size, NULL, 0)) {
|
||||
if (errno == ENOTDIR)
|
||||
return -GLIBTOP_ERROR_NO_KERNEL_SUPPORT;
|
||||
else
|
||||
glibtop_warn_io_r (server, "sysctl (libgtop/swap)");
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
glibtop_get_proc_data_proclist_k (glibtop *server,
|
||||
libgtop_proclist_t *proclist,
|
||||
u_int64_t which, u_int64_t arg)
|
||||
{
|
||||
int name [4] = { CTL_LIBGTOP, LIBGTOP_PROCLIST, which, arg };
|
||||
size_t size = sizeof (libgtop_proclist_t);
|
||||
|
||||
if (sysctl (name, 4, proclist, &size, NULL, 0)) {
|
||||
if (errno == ENOTDIR)
|
||||
return -GLIBTOP_ERROR_NO_KERNEL_SUPPORT;
|
||||
else
|
||||
glibtop_warn_io_r (server, "sysctl (libgtop/proclist)");
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
int
|
||||
glibtop_get_proc_data_proc_state_k (glibtop *server,
|
||||
libgtop_proc_state_t *proc_state,
|
||||
pid_t pid)
|
||||
{
|
||||
int name [3] = { CTL_LIBGTOP, LIBGTOP_PROC_STATE, pid };
|
||||
size_t size = sizeof (libgtop_proc_state_t);
|
||||
|
||||
if (sysctl (name, 3, proc_state, &size, NULL, 0)) {
|
||||
if (errno == ENOTDIR)
|
||||
return -GLIBTOP_ERROR_NO_KERNEL_SUPPORT;
|
||||
else if (errno == ESRCH)
|
||||
return -GLIBTOP_ERROR_NO_SUCH_PROCESS;
|
||||
else
|
||||
glibtop_warn_io_r (server, "sysctl (libgtop/proc_state)");
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
glibtop_get_proc_data_proc_mem_k (glibtop *server,
|
||||
libgtop_proc_mem_t *proc_mem,
|
||||
pid_t pid)
|
||||
{
|
||||
int name [3] = { CTL_LIBGTOP, LIBGTOP_PROC_MEM, pid };
|
||||
size_t size = sizeof (libgtop_proc_mem_t);
|
||||
|
||||
if (sysctl (name, 3, proc_mem, &size, NULL, 0)) {
|
||||
if (errno == ENOTDIR)
|
||||
return -GLIBTOP_ERROR_NO_KERNEL_SUPPORT;
|
||||
else if (errno == ESRCH)
|
||||
return -GLIBTOP_ERROR_NO_SUCH_PROCESS;
|
||||
else
|
||||
glibtop_warn_io_r (server, "sysctl (libgtop/proc_mem)");
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
glibtop_get_proc_data_proc_signal_k (glibtop *server,
|
||||
libgtop_proc_signal_t *proc_signal,
|
||||
pid_t pid)
|
||||
{
|
||||
int name [3] = { CTL_LIBGTOP, LIBGTOP_PROC_SIGNAL, pid };
|
||||
size_t size = sizeof (libgtop_proc_signal_t);
|
||||
|
||||
if (sysctl (name, 3, proc_signal, &size, NULL, 0)) {
|
||||
if (errno == ENOTDIR)
|
||||
return -GLIBTOP_ERROR_NO_KERNEL_SUPPORT;
|
||||
else if (errno == ESRCH)
|
||||
return -GLIBTOP_ERROR_NO_SUCH_PROCESS;
|
||||
else
|
||||
glibtop_warn_io_r (server, "sysctl (libgtop/proc_signal)");
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
glibtop_get_proc_data_proc_kernel_k (glibtop *server,
|
||||
libgtop_proc_kernel_t *proc_kernel,
|
||||
pid_t pid)
|
||||
{
|
||||
int name [3] = { CTL_LIBGTOP, LIBGTOP_PROC_KERNEL, pid };
|
||||
size_t size = sizeof (libgtop_proc_kernel_t);
|
||||
|
||||
if (sysctl (name, 3, proc_kernel, &size, NULL, 0)) {
|
||||
if (errno == ENOTDIR)
|
||||
return -GLIBTOP_ERROR_NO_KERNEL_SUPPORT;
|
||||
else if (errno == ESRCH)
|
||||
return -GLIBTOP_ERROR_NO_SUCH_PROCESS;
|
||||
else
|
||||
glibtop_warn_io_r (server, "sysctl (libgtop/proc_kernel)");
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
glibtop_get_proc_data_proc_args_k (glibtop *server, pid_t pid,
|
||||
char *result, size_t max_len)
|
||||
{
|
||||
int name [3] = { CTL_LIBGTOP, LIBGTOP_PROC_ARGS, pid };
|
||||
size_t size = max_len;
|
||||
|
||||
if (sysctl (name, 3, result, &size, NULL, 0)) {
|
||||
if (errno == ENOTDIR)
|
||||
return -GLIBTOP_ERROR_NO_KERNEL_SUPPORT;
|
||||
else if (errno == ESRCH)
|
||||
return -GLIBTOP_ERROR_NO_SUCH_PROCESS;
|
||||
else
|
||||
glibtop_warn_io_r (server, "sysctl (libgtop/proc_args)");
|
||||
return -1;
|
||||
}
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
int
|
||||
glibtop_get_proc_data_proc_maps_k (glibtop *server, pid_t pid,
|
||||
libgtop_proc_maps_t *result,
|
||||
size_t max_len)
|
||||
{
|
||||
int name [3] = { CTL_LIBGTOP, LIBGTOP_PROC_MAPS, pid };
|
||||
size_t size = max_len;
|
||||
|
||||
if (sysctl (name, 3, result, &size, NULL, 0)) {
|
||||
if (errno == ENOTDIR)
|
||||
return -GLIBTOP_ERROR_NO_KERNEL_SUPPORT;
|
||||
else if (errno == ESRCH)
|
||||
return -GLIBTOP_ERROR_NO_SUCH_PROCESS;
|
||||
else
|
||||
glibtop_warn_io_r (server, "sysctl (libgtop/proc_maps)");
|
||||
return -1;
|
||||
}
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
int
|
||||
glibtop_get_proc_data_netload_k (glibtop *server,
|
||||
libgtop_netload_t *netload,
|
||||
const char *device)
|
||||
{
|
||||
int name [2] = { CTL_LIBGTOP, LIBGTOP_NETLOAD };
|
||||
size_t size = sizeof (libgtop_netload_t);
|
||||
|
||||
if (sysctl (name, 2, netload, &size, (char *) device, strlen (device)+1)) {
|
||||
if (errno == ENOTDIR)
|
||||
return -GLIBTOP_ERROR_NO_KERNEL_SUPPORT;
|
||||
else
|
||||
glibtop_warn_io_r (server, "sysctl (libgtop/netload)");
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
@@ -1,86 +0,0 @@
|
||||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright (C) 1998-99 Martin Baulig
|
||||
This file is part of LibGTop 1.0.
|
||||
|
||||
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/prockernel.h>
|
||||
|
||||
#include <glibtop_private.h>
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_proc_kernel =
|
||||
(1L << GLIBTOP_PROC_KERNEL_MIN_FLT) +
|
||||
(1L << GLIBTOP_PROC_KERNEL_MAJ_FLT) +
|
||||
(1L << GLIBTOP_PROC_KERNEL_CMIN_FLT) +
|
||||
(1L << GLIBTOP_PROC_KERNEL_CMAJ_FLT) +
|
||||
(1L << GLIBTOP_PROC_KERNEL_KSTK_ESP) +
|
||||
(1L << GLIBTOP_PROC_KERNEL_KSTK_EIP);
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_proc_kernel_kernel =
|
||||
(1L << GLIBTOP_PROC_KERNEL_NWCHAN);
|
||||
|
||||
/* Init function. */
|
||||
|
||||
int
|
||||
glibtop_init_proc_kernel_k (glibtop *server)
|
||||
{
|
||||
server->sysdeps.proc_kernel = _glibtop_sysdeps_proc_kernel |
|
||||
_glibtop_sysdeps_proc_kernel_kernel;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Provides detailed information about a process. */
|
||||
|
||||
int
|
||||
glibtop_get_proc_kernel_k (glibtop *server, glibtop_proc_kernel *buf,
|
||||
pid_t pid)
|
||||
{
|
||||
libgtop_proc_state_t proc_state;
|
||||
libgtop_proc_kernel_t proc_kernel;
|
||||
int retval;
|
||||
|
||||
memset (buf, 0, sizeof (glibtop_proc_kernel));
|
||||
|
||||
retval = glibtop_get_proc_data_proc_state_k (server, &proc_state, pid);
|
||||
if (retval)
|
||||
return retval;
|
||||
|
||||
buf->min_flt = proc_state.min_flt;
|
||||
buf->maj_flt = proc_state.maj_flt;
|
||||
buf->cmin_flt = proc_state.cmin_flt;
|
||||
buf->cmaj_flt = proc_state.cmaj_flt;
|
||||
buf->kstk_esp = proc_state.kesp;
|
||||
buf->kstk_eip = proc_state.keip;
|
||||
|
||||
buf->flags = _glibtop_sysdeps_proc_kernel;
|
||||
|
||||
retval = glibtop_get_proc_data_proc_kernel_k (server, &proc_kernel, pid);
|
||||
if (retval)
|
||||
return retval;
|
||||
|
||||
buf->nwchan = proc_kernel.wchan;
|
||||
buf->flags |= _glibtop_sysdeps_proc_kernel_kernel;
|
||||
|
||||
return 0;
|
||||
}
|
@@ -1,80 +0,0 @@
|
||||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright (C) 1998-99 Martin Baulig
|
||||
This file is part of LibGTop 1.0.
|
||||
|
||||
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/xmalloc.h>
|
||||
#include <glibtop/proclist.h>
|
||||
|
||||
#include <glibtop_private.h>
|
||||
|
||||
#define GLIBTOP_PROCLIST_FLAGS 3
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_proclist =
|
||||
(1L << GLIBTOP_PROCLIST_NUMBER) + (1L << GLIBTOP_PROCLIST_SIZE) +
|
||||
(1L << GLIBTOP_PROCLIST_TOTAL);
|
||||
|
||||
/* Init function. */
|
||||
|
||||
int
|
||||
glibtop_init_proclist_k (glibtop *server)
|
||||
{
|
||||
server->sysdeps.proclist = _glibtop_sysdeps_proclist;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Fetch list of currently running processes.
|
||||
*
|
||||
* 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. */
|
||||
|
||||
unsigned *
|
||||
glibtop_get_proclist_k (glibtop *server, glibtop_proclist *buf,
|
||||
int64_t which, int64_t arg)
|
||||
{
|
||||
libgtop_proclist_t proclist;
|
||||
unsigned *ret;
|
||||
int i;
|
||||
|
||||
memset (buf, 0, sizeof (glibtop_proclist));
|
||||
|
||||
if (glibtop_get_proc_data_proclist_k (server, &proclist, which, arg))
|
||||
return NULL;
|
||||
|
||||
ret = glibtop_calloc_r (server, proclist.count, sizeof (unsigned));
|
||||
|
||||
buf->number = proclist.count;
|
||||
buf->size = sizeof (unsigned);
|
||||
buf->total = proclist.count * sizeof (unsigned);
|
||||
|
||||
for (i = 0; i < proclist.count; i++)
|
||||
ret [i] = proclist.pids [i];
|
||||
|
||||
buf->flags |= _glibtop_sysdeps_proclist;
|
||||
|
||||
return ret;
|
||||
}
|
@@ -1,134 +0,0 @@
|
||||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright (C) 1998-99 Martin Baulig
|
||||
This file is part of LibGTop 1.0.
|
||||
|
||||
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/xmalloc.h>
|
||||
#include <glibtop/procmap.h>
|
||||
|
||||
#include <glibtop_private.h>
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_proc_map =
|
||||
(1L << GLIBTOP_PROC_MAP_NUMBER) + (1L << GLIBTOP_PROC_MAP_TOTAL) +
|
||||
(1L << GLIBTOP_PROC_MAP_SIZE);
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_map_entry =
|
||||
(1L << GLIBTOP_MAP_ENTRY_START) + (1L << GLIBTOP_MAP_ENTRY_END) +
|
||||
(1L << GLIBTOP_MAP_ENTRY_OFFSET) + (1L << GLIBTOP_MAP_ENTRY_PERM);
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_map_entry_vmfile =
|
||||
(1L << GLIBTOP_MAP_ENTRY_INODE) + (1L << GLIBTOP_MAP_ENTRY_DEVICE) +
|
||||
(1L << GLIBTOP_MAP_ENTRY_FILENAME);
|
||||
|
||||
/* Init function. */
|
||||
|
||||
int
|
||||
glibtop_init_proc_map_k (glibtop *server)
|
||||
{
|
||||
server->sysdeps.proc_map = _glibtop_sysdeps_proc_map;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Provides detailed information about a process. */
|
||||
|
||||
glibtop_map_entry *
|
||||
glibtop_get_proc_map_k (glibtop *server, glibtop_proc_map *buf, pid_t pid)
|
||||
{
|
||||
glibtop_map_entry *retval = NULL;
|
||||
libgtop_proc_maps_t *maps;
|
||||
size_t count, max_len, i;
|
||||
int ret;
|
||||
|
||||
glibtop_init_s (&server, GLIBTOP_SYSDEPS_PROC_MAP, 0);
|
||||
|
||||
memset (buf, 0, sizeof (glibtop_proc_map));
|
||||
|
||||
/* Get number of map entries. */
|
||||
count = glibtop_get_proc_data_proc_maps_k (server, pid, NULL, 0);
|
||||
|
||||
/* Allocate memory. */
|
||||
maps = glibtop_calloc_r (server, count, sizeof (libgtop_proc_maps_t));
|
||||
max_len = count * sizeof (libgtop_proc_maps_t);
|
||||
|
||||
ret = glibtop_get_proc_data_proc_maps_k (server, pid, maps, max_len);
|
||||
if (ret < 0) {
|
||||
glibtop_free_r (server, maps);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Calculate number of map entries. */
|
||||
count = ret / sizeof (libgtop_proc_maps_t);
|
||||
|
||||
/* Allocate memory for the result. */
|
||||
retval = glibtop_calloc_r (server, count, sizeof (glibtop_map_entry));
|
||||
|
||||
for (i = 0; i < count; i++) {
|
||||
char *filename;
|
||||
|
||||
retval [i].start = maps [i].header.start;
|
||||
retval [i].end = maps [i].header.end;
|
||||
retval [i].offset = maps [i].header.offset;
|
||||
|
||||
if (maps [i].header.perm & LIBGTOP_VM_READ)
|
||||
retval [i].perm |= GLIBTOP_MAP_PERM_READ;
|
||||
if (maps [i].header.perm & LIBGTOP_VM_WRITE)
|
||||
retval [i].perm |= GLIBTOP_MAP_PERM_WRITE;
|
||||
if (maps [i].header.perm & LIBGTOP_VM_EXEC)
|
||||
retval [i].perm |= GLIBTOP_MAP_PERM_EXECUTE;
|
||||
if (maps [i].header.perm & LIBGTOP_VM_SHARED)
|
||||
retval [i].perm |= GLIBTOP_MAP_PERM_SHARED;
|
||||
if (!(maps [i].header.perm & LIBGTOP_VM_MAYSHARE))
|
||||
retval [i].perm |= GLIBTOP_MAP_PERM_PRIVATE;
|
||||
|
||||
retval [i].flags = _glibtop_sysdeps_map_entry;
|
||||
|
||||
if (maps [i].header.device || maps [i].header.inode) {
|
||||
retval [i].device = maps [i].header.device;
|
||||
retval [i].inode = maps [i].header.inode;
|
||||
|
||||
filename = maps [i].filename;
|
||||
filename += maps [i].header.filename_offset;
|
||||
|
||||
strncpy (retval [i].filename, filename, GLIBTOP_MAP_FILENAME_LEN);
|
||||
retval [i].filename [GLIBTOP_MAP_FILENAME_LEN-1] = '\0';
|
||||
|
||||
retval [i].flags |= _glibtop_sysdeps_map_entry_vmfile;
|
||||
}
|
||||
}
|
||||
|
||||
/* Free map entries. */
|
||||
glibtop_free_r (server, maps);
|
||||
|
||||
/* Write retval. */
|
||||
buf->number = count;
|
||||
buf->size = sizeof (glibtop_map_entry);
|
||||
buf->total = buf->number * sizeof (glibtop_map_entry);
|
||||
|
||||
buf->flags = _glibtop_sysdeps_proc_map;
|
||||
|
||||
return retval;
|
||||
}
|
@@ -1,99 +0,0 @@
|
||||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright (C) 1998-99 Martin Baulig
|
||||
This file is part of LibGTop 1.0.
|
||||
|
||||
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/procmem.h>
|
||||
|
||||
#include <glibtop_private.h>
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_proc_mem =
|
||||
(1L << GLIBTOP_PROC_MEM_VSIZE) + (1L << GLIBTOP_PROC_MEM_SIZE) +
|
||||
(1L << GLIBTOP_PROC_MEM_RESIDENT) + (1L << GLIBTOP_PROC_MEM_SHARE) +
|
||||
(1L << GLIBTOP_PROC_MEM_RSS) + (1L << GLIBTOP_PROC_MEM_RSS_RLIM);
|
||||
|
||||
#ifndef LOG1024
|
||||
#define LOG1024 10
|
||||
#endif
|
||||
|
||||
/* these are for getting the memory statistics */
|
||||
static int pageshift; /* log base 2 of the pagesize */
|
||||
|
||||
/* define pagetok in terms of pageshift */
|
||||
#define pagetok(size) ((size) << pageshift)
|
||||
|
||||
/* Init function. */
|
||||
|
||||
int
|
||||
glibtop_init_proc_mem_k (glibtop *server)
|
||||
{
|
||||
register int pagesize;
|
||||
|
||||
server->sysdeps.proc_mem = _glibtop_sysdeps_proc_mem;
|
||||
|
||||
/* get the page size with "getpagesize" and calculate pageshift. */
|
||||
pagesize = getpagesize ();
|
||||
pageshift = 0;
|
||||
while (pagesize > 1) {
|
||||
pageshift++;
|
||||
pagesize >>= 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Provides detailed information about a process. */
|
||||
|
||||
int
|
||||
glibtop_get_proc_mem_k (glibtop *server, glibtop_proc_mem *buf,
|
||||
pid_t pid)
|
||||
{
|
||||
libgtop_proc_mem_t proc_mem;
|
||||
int retval;
|
||||
|
||||
memset (buf, 0, sizeof (glibtop_proc_mem));
|
||||
|
||||
retval = glibtop_get_proc_data_proc_mem_k (server, &proc_mem, pid);
|
||||
if (retval)
|
||||
return retval;
|
||||
|
||||
buf->vsize = proc_mem.segment.vsize;
|
||||
|
||||
buf->size = proc_mem.size;
|
||||
buf->resident = proc_mem.resident;
|
||||
buf->share = proc_mem.share;
|
||||
|
||||
buf->rss = proc_mem.rss;
|
||||
buf->rss_rlim = proc_mem.rlim;
|
||||
|
||||
buf->vsize <<= pageshift;
|
||||
|
||||
buf->size <<= pageshift;
|
||||
buf->resident <<= pageshift;
|
||||
buf->share <<= pageshift;
|
||||
|
||||
buf->flags = _glibtop_sysdeps_proc_mem;
|
||||
|
||||
return 0;
|
||||
}
|
@@ -1,126 +0,0 @@
|
||||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright (C) 1998-99 Martin Baulig
|
||||
This file is part of LibGTop 1.0.
|
||||
|
||||
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/procsegment.h>
|
||||
|
||||
#include <glibtop_private.h>
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_proc_segment =
|
||||
(1L << GLIBTOP_PROC_SEGMENT_TEXT_RSS) +
|
||||
(1L << GLIBTOP_PROC_SEGMENT_SHLIB_RSS) +
|
||||
(1L << GLIBTOP_PROC_SEGMENT_DATA_RSS) +
|
||||
(1L << GLIBTOP_PROC_SEGMENT_STACK_RSS) +
|
||||
(1L << GLIBTOP_PROC_SEGMENT_DIRTY_SIZE);
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_proc_segment_state =
|
||||
(1L << GLIBTOP_PROC_SEGMENT_START_CODE) +
|
||||
(1L << GLIBTOP_PROC_SEGMENT_END_CODE) +
|
||||
(1L << GLIBTOP_PROC_SEGMENT_START_STACK);
|
||||
|
||||
#ifndef LOG1024
|
||||
#define LOG1024 10
|
||||
#endif
|
||||
|
||||
/* these are for getting the memory statistics */
|
||||
static int pageshift; /* log base 2 of the pagesize */
|
||||
|
||||
/* define pagetok in terms of pageshift */
|
||||
#define pagetok(size) ((size) << pageshift)
|
||||
|
||||
/* Init function. */
|
||||
|
||||
int
|
||||
glibtop_init_proc_segment_k (glibtop *server)
|
||||
{
|
||||
register int pagesize;
|
||||
|
||||
server->sysdeps.proc_segment = _glibtop_sysdeps_proc_segment |
|
||||
_glibtop_sysdeps_proc_segment_state;
|
||||
|
||||
/* get the page size with "getpagesize" and calculate pageshift. */
|
||||
pagesize = getpagesize ();
|
||||
pageshift = 0;
|
||||
while (pagesize > 1) {
|
||||
pageshift++;
|
||||
pagesize >>= 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Provides detailed information about a process. */
|
||||
|
||||
int
|
||||
glibtop_get_proc_segment_k (glibtop *server, glibtop_proc_segment *buf,
|
||||
pid_t pid)
|
||||
{
|
||||
libgtop_proc_mem_t proc_mem;
|
||||
libgtop_proc_state_t proc_state;
|
||||
int retval;
|
||||
|
||||
memset (buf, 0, sizeof (glibtop_proc_segment));
|
||||
|
||||
retval = glibtop_get_proc_data_proc_mem_k (server, &proc_mem, pid);
|
||||
if (retval)
|
||||
return retval;
|
||||
|
||||
buf->text_rss = proc_mem.trs;
|
||||
buf->shlib_rss = proc_mem.lrs;
|
||||
buf->data_rss = proc_mem.drs;
|
||||
buf->stack_rss = proc_mem.segment.stack;
|
||||
buf->dirty_size = proc_mem.dt;
|
||||
|
||||
buf->text_rss <<= pageshift;
|
||||
buf->shlib_rss <<= pageshift;
|
||||
buf->data_rss <<= pageshift;
|
||||
buf->stack_rss <<= pageshift;
|
||||
buf->dirty_size <<= pageshift;
|
||||
|
||||
buf->flags = _glibtop_sysdeps_proc_segment;
|
||||
|
||||
retval = glibtop_get_proc_data_proc_state_k (server, &proc_state, pid);
|
||||
if (retval)
|
||||
return retval;
|
||||
|
||||
buf->start_code = proc_state.start_code;
|
||||
buf->end_code = proc_state.end_code;
|
||||
buf->start_data = proc_state.start_data;
|
||||
buf->end_data = proc_state.end_data;
|
||||
buf->start_brk = proc_state.start_brk;
|
||||
buf->end_brk = proc_state.brk;
|
||||
|
||||
buf->start_stack = proc_state.start_stack;
|
||||
buf->start_mmap = proc_state.start_mmap;
|
||||
|
||||
buf->arg_start = proc_state.arg_start;
|
||||
buf->arg_end = proc_state.arg_end;
|
||||
buf->env_start = proc_state.env_start;
|
||||
buf->env_end = proc_state.env_end;
|
||||
|
||||
buf->flags |= _glibtop_sysdeps_proc_segment_state;
|
||||
|
||||
return 0;
|
||||
}
|
@@ -1,72 +0,0 @@
|
||||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright (C) 1998-99 Martin Baulig
|
||||
This file is part of LibGTop 1.0.
|
||||
|
||||
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/procsignal.h>
|
||||
|
||||
#include <glibtop_private.h>
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_proc_signal =
|
||||
(1L << GLIBTOP_PROC_SIGNAL_SIGNAL) +
|
||||
(1L << GLIBTOP_PROC_SIGNAL_BLOCKED) +
|
||||
(1L << GLIBTOP_PROC_SIGNAL_SIGIGNORE) +
|
||||
(1L << GLIBTOP_PROC_SIGNAL_SIGCATCH);
|
||||
|
||||
/* Init function. */
|
||||
|
||||
int
|
||||
glibtop_init_proc_signal_k (glibtop *server)
|
||||
{
|
||||
server->sysdeps.proc_signal = _glibtop_sysdeps_proc_signal;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Provides detailed information about a process. */
|
||||
|
||||
int
|
||||
glibtop_get_proc_signal_k (glibtop *server, glibtop_proc_signal *buf,
|
||||
pid_t pid)
|
||||
{
|
||||
libgtop_proc_signal_t proc_signal;
|
||||
int retval, i;
|
||||
|
||||
memset (buf, 0, sizeof (glibtop_proc_signal));
|
||||
|
||||
retval = glibtop_get_proc_data_proc_signal_k (server, &proc_signal, pid);
|
||||
if (retval)
|
||||
return retval;
|
||||
|
||||
for (i = 0; i < 1; i++) {
|
||||
buf->signal [i] = proc_signal.signal [i];
|
||||
buf->blocked [i] = proc_signal.blocked [i];
|
||||
buf->sigignore [i] = proc_signal.ignore [i];
|
||||
buf->sigcatch [i] = proc_signal.catch [i];
|
||||
}
|
||||
|
||||
buf->flags = _glibtop_sysdeps_proc_signal;
|
||||
|
||||
return 0;
|
||||
}
|
@@ -1,90 +0,0 @@
|
||||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright (C) 1998-99 Martin Baulig
|
||||
This file is part of LibGTop 1.0.
|
||||
|
||||
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/procstate.h>
|
||||
|
||||
#include <glibtop_private.h>
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_proc_state =
|
||||
(1L << GLIBTOP_PROC_STATE_UID) + (1L << GLIBTOP_PROC_STATE_GID) +
|
||||
(1L << GLIBTOP_PROC_STATE_RUID) + (1L << GLIBTOP_PROC_STATE_RGID) +
|
||||
(1L << GLIBTOP_PROC_STATE_CMD) + (1L << GLIBTOP_PROC_STATE_STATE) +
|
||||
(1L << GLIBTOP_PROC_STATE_HAS_CPU) + (1L << GLIBTOP_PROC_STATE_PROCESSOR) +
|
||||
(1L << GLIBTOP_PROC_STATE_LAST_PROCESSOR);
|
||||
|
||||
/* Init function. */
|
||||
|
||||
int
|
||||
glibtop_init_proc_state_k (glibtop *server)
|
||||
{
|
||||
server->sysdeps.proc_state = _glibtop_sysdeps_proc_state;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Provides detailed information about a process. */
|
||||
|
||||
int
|
||||
glibtop_get_proc_state_k (glibtop *server, glibtop_proc_state *buf,
|
||||
pid_t pid)
|
||||
{
|
||||
libgtop_proc_state_t proc_state;
|
||||
int retval;
|
||||
|
||||
memset (buf, 0, sizeof (glibtop_proc_state));
|
||||
|
||||
retval = glibtop_get_proc_data_proc_state_k (server, &proc_state, pid);
|
||||
if (retval)
|
||||
return retval;
|
||||
|
||||
memcpy (buf->cmd, proc_state.comm, sizeof (buf->cmd));
|
||||
|
||||
if (proc_state.state & LIBGTOP_TASK_RUNNING)
|
||||
buf->state |= GLIBTOP_PROCESS_RUNNING;
|
||||
if (proc_state.state & LIBGTOP_TASK_INTERRUPTIBLE)
|
||||
buf->state |= GLIBTOP_PROCESS_INTERRUPTIBLE;
|
||||
if (proc_state.state & LIBGTOP_TASK_UNINTERRUPTIBLE)
|
||||
buf->state |= GLIBTOP_PROCESS_UNINTERRUPTIBLE;
|
||||
if (proc_state.state & LIBGTOP_TASK_ZOMBIE)
|
||||
buf->state |= GLIBTOP_PROCESS_ZOMBIE;
|
||||
if (proc_state.state & LIBGTOP_TASK_STOPPED)
|
||||
buf->state |= GLIBTOP_PROCESS_STOPPED;
|
||||
if (proc_state.state & LIBGTOP_TASK_SWAPPING)
|
||||
buf->state |= GLIBTOP_PROCESS_SWAPPING;
|
||||
|
||||
buf->uid = proc_state.euid;
|
||||
buf->gid = proc_state.egid;
|
||||
buf->ruid = proc_state.uid;
|
||||
buf->rgid = proc_state.gid;
|
||||
|
||||
buf->has_cpu = proc_state.has_cpu;
|
||||
buf->processor = proc_state.processor;
|
||||
buf->last_processor = proc_state.last_processor;
|
||||
|
||||
buf->flags = _glibtop_sysdeps_proc_state;
|
||||
|
||||
return 0;
|
||||
}
|
@@ -1,86 +0,0 @@
|
||||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright (C) 1998-99 Martin Baulig
|
||||
This file is part of LibGTop 1.0.
|
||||
|
||||
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/proctime.h>
|
||||
|
||||
#include <glibtop_private.h>
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_proc_time =
|
||||
(1L << GLIBTOP_PROC_TIME_UTIME) + (1L << GLIBTOP_PROC_TIME_STIME) +
|
||||
(1L << GLIBTOP_PROC_TIME_CUTIME) + (1L << GLIBTOP_PROC_TIME_CSTIME) +
|
||||
(1L << GLIBTOP_PROC_TIME_START_TIME) + (1L << GLIBTOP_PROC_TIME_FREQUENCY);
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_proc_time_smp =
|
||||
(1L << GLIBTOP_PROC_TIME_XCPU_UTIME) + (1L << GLIBTOP_PROC_TIME_XCPU_STIME);
|
||||
|
||||
/* Init function. */
|
||||
|
||||
int
|
||||
glibtop_init_proc_time_k (glibtop *server)
|
||||
{
|
||||
server->sysdeps.proc_time = _glibtop_sysdeps_proc_time;
|
||||
|
||||
if (server->ncpu)
|
||||
server->sysdeps.proc_time |= _glibtop_sysdeps_proc_time_smp;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Provides detailed information about a process. */
|
||||
|
||||
int
|
||||
glibtop_get_proc_time_k (glibtop *server, glibtop_proc_time *buf,
|
||||
pid_t pid)
|
||||
{
|
||||
libgtop_proc_state_t proc_state;
|
||||
int retval, i;
|
||||
|
||||
memset (buf, 0, sizeof (glibtop_proc_time));
|
||||
|
||||
retval = glibtop_get_proc_data_proc_state_k (server, &proc_state, pid);
|
||||
if (retval)
|
||||
return retval;
|
||||
|
||||
buf->start_time = proc_state.start_time;
|
||||
buf->utime = proc_state.utime;
|
||||
buf->stime = proc_state.stime;
|
||||
buf->cutime = proc_state.cutime;
|
||||
buf->cstime = proc_state.cstime;
|
||||
|
||||
buf->frequency = 100;
|
||||
|
||||
buf->flags = _glibtop_sysdeps_proc_time;
|
||||
|
||||
for (i = 0; i < server->ncpu; i++) {
|
||||
buf->xcpu_utime [i] = proc_state.per_cpu_utime [i];
|
||||
buf->xcpu_stime [i] = proc_state.per_cpu_stime [i];
|
||||
}
|
||||
|
||||
if (server->ncpu)
|
||||
buf->flags |= _glibtop_sysdeps_proc_time_smp;
|
||||
|
||||
return 0;
|
||||
}
|
@@ -1,107 +0,0 @@
|
||||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright (C) 1998-99 Martin Baulig
|
||||
This file is part of LibGTop 1.0.
|
||||
|
||||
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/procuid.h>
|
||||
|
||||
#include <glibtop_private.h>
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_proc_uid =
|
||||
(1L << GLIBTOP_PROC_UID_UID) + (1L << GLIBTOP_PROC_UID_EUID) +
|
||||
(1L << GLIBTOP_PROC_UID_GID) + (1L << GLIBTOP_PROC_UID_EGID) +
|
||||
(1L << GLIBTOP_PROC_UID_SUID) + (1L << GLIBTOP_PROC_UID_SGID) +
|
||||
(1L << GLIBTOP_PROC_UID_FSUID) + (1L << GLIBTOP_PROC_UID_FSGID) +
|
||||
(1L << GLIBTOP_PROC_UID_PID) + (1L << GLIBTOP_PROC_UID_PPID) +
|
||||
(1L << GLIBTOP_PROC_UID_PGRP) + (1L << GLIBTOP_PROC_UID_SESSION) +
|
||||
(1L << GLIBTOP_PROC_UID_TTY) + (1L << GLIBTOP_PROC_UID_TPGID) +
|
||||
(1L << GLIBTOP_PROC_UID_PRIORITY) + (1L << GLIBTOP_PROC_UID_NICE) +
|
||||
(1L << GLIBTOP_PROC_UID_NGROUPS) + (1L << GLIBTOP_PROC_UID_GROUPS);
|
||||
|
||||
#ifndef min
|
||||
#define min(a,b) ((a < b) ? a : b)
|
||||
#endif
|
||||
|
||||
/* Init function. */
|
||||
|
||||
int
|
||||
glibtop_init_proc_uid_k (glibtop *server)
|
||||
{
|
||||
server->sysdeps.proc_uid = _glibtop_sysdeps_proc_uid;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Provides detailed information about a process. */
|
||||
|
||||
int
|
||||
glibtop_get_proc_uid_k (glibtop *server, glibtop_proc_uid *buf,
|
||||
pid_t pid)
|
||||
{
|
||||
libgtop_proc_state_t proc_state;
|
||||
long priority, nice;
|
||||
int retval, i;
|
||||
|
||||
memset (buf, 0, sizeof (glibtop_proc_uid));
|
||||
|
||||
retval = glibtop_get_proc_data_proc_state_k (server, &proc_state, pid);
|
||||
if (retval)
|
||||
return retval;
|
||||
|
||||
buf->uid = proc_state.uid;
|
||||
buf->euid = proc_state.euid;
|
||||
buf->gid = proc_state.gid;
|
||||
buf->egid = proc_state.egid;
|
||||
|
||||
buf->suid = proc_state.suid;
|
||||
buf->sgid = proc_state.sgid;
|
||||
buf->fsuid = proc_state.fsuid;
|
||||
buf->fsgid = proc_state.fsgid;
|
||||
|
||||
buf->pid = proc_state.pid;
|
||||
buf->ppid = proc_state.ppid;
|
||||
buf->pgrp = proc_state.pgrp;
|
||||
|
||||
buf->session = proc_state.session;
|
||||
buf->tty = proc_state.tty;
|
||||
buf->tpgid = proc_state.tpgid;
|
||||
|
||||
priority = proc_state.counter;
|
||||
priority = 20 - (priority * 10 + proc_state.def_priority / 2) /
|
||||
proc_state.def_priority;
|
||||
nice = proc_state.priority;
|
||||
nice = 20 - (nice * 20 + proc_state.def_priority / 2) /
|
||||
proc_state.def_priority;
|
||||
|
||||
buf->priority = priority;
|
||||
buf->nice = nice;
|
||||
|
||||
buf->ngroups = min (proc_state.ngroups, GLIBTOP_MAX_GROUPS);
|
||||
for (i = 0; i < buf->ngroups; i++)
|
||||
buf->groups [i] = proc_state.groups [i];
|
||||
|
||||
buf->flags = _glibtop_sysdeps_proc_uid;
|
||||
|
||||
return 0;
|
||||
}
|
@@ -1,80 +0,0 @@
|
||||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright (C) 1998-99 Martin Baulig
|
||||
This file is part of LibGTop 1.0.
|
||||
|
||||
Contributed by Martin Baulig <martin@home-of-linux.org>, March 1999.
|
||||
|
||||
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/swap.h>
|
||||
|
||||
#include <glibtop_private.h>
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_swap =
|
||||
(1L << GLIBTOP_SWAP_TOTAL) + (1L << GLIBTOP_SWAP_USED) +
|
||||
(1L << GLIBTOP_SWAP_FREE);
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_swap_stat =
|
||||
(1L << GLIBTOP_SWAP_PAGEIN) + (1L << GLIBTOP_SWAP_PAGEOUT);
|
||||
|
||||
/* Init function. */
|
||||
|
||||
int
|
||||
glibtop_init_swap_k (glibtop *server)
|
||||
{
|
||||
server->sysdeps.swap = _glibtop_sysdeps_swap |
|
||||
_glibtop_sysdeps_swap_stat;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Provides information about swap usage. */
|
||||
|
||||
int
|
||||
glibtop_get_swap_k (glibtop *server, glibtop_swap *buf)
|
||||
{
|
||||
libgtop_stat_t stat;
|
||||
libgtop_swap_t swap;
|
||||
int retval;
|
||||
|
||||
memset (buf, 0, sizeof (glibtop_swap));
|
||||
|
||||
retval = glibtop_get_proc_data_swap_k (server, &swap);
|
||||
if (retval)
|
||||
return retval;
|
||||
|
||||
buf->total = swap.totalswap;
|
||||
buf->free = swap.freeswap;
|
||||
buf->used = swap.totalswap - swap.freeswap;
|
||||
|
||||
buf->flags = _glibtop_sysdeps_swap;
|
||||
|
||||
retval = glibtop_get_proc_data_stat_k (server, &stat);
|
||||
if (retval)
|
||||
return retval;
|
||||
|
||||
buf->pagein = stat.pswpin;
|
||||
buf->pageout = stat.pswpout;
|
||||
|
||||
buf->flags |= _glibtop_sysdeps_swap_stat;
|
||||
|
||||
return 0;
|
||||
}
|
@@ -1,70 +0,0 @@
|
||||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright (C) 1998-99 Martin Baulig
|
||||
This file is part of LibGTop 1.0.
|
||||
|
||||
Contributed by Martin Baulig <martin@home-of-linux.org>, March 1999.
|
||||
|
||||
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/uptime.h>
|
||||
|
||||
#include <glibtop_private.h>
|
||||
|
||||
static unsigned long _glibtop_sysdeps_uptime =
|
||||
(1L << GLIBTOP_UPTIME_UPTIME) + (1L << GLIBTOP_UPTIME_IDLETIME) +
|
||||
(1L << GLIBTOP_UPTIME_BOOT_TIME);
|
||||
|
||||
/* Init function. */
|
||||
|
||||
int
|
||||
glibtop_init_uptime_k (glibtop *server)
|
||||
{
|
||||
server->sysdeps.uptime = _glibtop_sysdeps_uptime;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Provides uptime and idle time. */
|
||||
|
||||
int
|
||||
glibtop_get_uptime_k (glibtop *server, glibtop_uptime *buf)
|
||||
{
|
||||
libgtop_stat_t stat;
|
||||
unsigned long total;
|
||||
int retval;
|
||||
|
||||
memset (buf, 0, sizeof (glibtop_uptime));
|
||||
|
||||
retval = glibtop_get_proc_data_stat_k (server, &stat);
|
||||
if (retval)
|
||||
return retval;
|
||||
|
||||
total = stat.cpu.user + stat.cpu.nice + stat.cpu.sys + stat.cpu.idle;
|
||||
|
||||
buf->uptime = (double) total / (double) stat.frequency;
|
||||
buf->idletime = (double) stat.cpu.idle / (double) stat.frequency;
|
||||
|
||||
buf->boot_time = stat.boot_time;
|
||||
|
||||
buf->flags = _glibtop_sysdeps_uptime;
|
||||
|
||||
return 0;
|
||||
}
|
@@ -1,6 +0,0 @@
|
||||
.deps
|
||||
.libs
|
||||
Makefile
|
||||
Makefile.in
|
||||
libgtop_sysdeps.la
|
||||
*.lo
|
@@ -1,160 +0,0 @@
|
||||
2000-04-24 Martin Baulig <baulig@suse.de>
|
||||
|
||||
* proc_cwd.c: New file. This feature was requested by Nautilus
|
||||
hacker Maciej Stachowiak and it returns the current working
|
||||
directory of a process.
|
||||
|
||||
2000-02-22 Martin Baulig <martin@home-of-linux.org>
|
||||
|
||||
* Makefile.am: Only install the libs in $(LIBGTOP_BACKEND_DIR)
|
||||
when we LIBGTOP_USE_GMODULE and in $(libdir) otherwise.
|
||||
|
||||
2000-02-06 Martin Baulig <martin@home-of-linux.org>
|
||||
|
||||
* ppp.c: Make this work with multiple ISDN devices.
|
||||
|
||||
2000-01-22 Martin Baulig <martin@home-of-linux.org>
|
||||
|
||||
* Makefile.am: Install the library in $(backenddir).
|
||||
|
||||
1999-12-11 Martin Baulig <martin@home-of-linux.org>
|
||||
|
||||
* cpu.c: Only set smp flags when we're really on a SMP machine.
|
||||
|
||||
1999-11-28 Martin Baulig <martin@home-of-linux.org>
|
||||
|
||||
* procstate.c (glibtop_get_procstate_s): Stat "/proc/<pid>" instead
|
||||
of "/proc/<pid>/state" to get `uid' and `gid'. Thanks to Jason Becker
|
||||
for pointing out that GTop reported wrong uid's.
|
||||
|
||||
1999-11-21 Martin Baulig <martin@home-of-linux.org>
|
||||
|
||||
* interfaces.c: New file.
|
||||
(glibtop_init_interface_names_s): New function.
|
||||
(glibtop_get_interface_names_s): New function.
|
||||
|
||||
1999-11-21 Martin Baulig <martin@home-of-linux.org>
|
||||
|
||||
* proclist.c: (glibtop_get_proclist_s): Support GLIBTOP_KERN_PROC_PPID.
|
||||
|
||||
1999-10-19 Martin Baulig <martin@home-of-linux.org>
|
||||
|
||||
* uptime.c (glibtop_get_uptime_s): Don't cast uptime and idletime
|
||||
to float as suggested by John Kodis.
|
||||
|
||||
1999-09-28 Radek Doulik <rodo@praha.eridan.cz>
|
||||
|
||||
* proclist.c (glibtop_get_proclist_s): fixed idle processes filtering
|
||||
|
||||
1999-07-29 Martin Baulig <martin@home-of-linux.org>
|
||||
|
||||
* proctime.c (glibtop_get_proctime_s): Don't provide `rtime'
|
||||
any longer since we must not use `rtime = utime + stime'.
|
||||
|
||||
1999-02-20 Martin Baulig <martin@home-of-linux.org>
|
||||
|
||||
* netload.c: Don't include <linux/ip_fw.h> for libc5 systems
|
||||
since it is no longer required and makes trouble on Slakware.
|
||||
|
||||
1999-01-06 Martin Baulig <martin@home-of-linux.org>
|
||||
|
||||
* netload.c (glibtop_get_netload_s): Use `server->os_version_code'
|
||||
instead of GLIBTOP_LINUX_VERSION_CODE.
|
||||
|
||||
1999-01-06 Martin Baulig <martin@home-of-linux.org>
|
||||
|
||||
Unconditionally enable SMP support for linux.
|
||||
|
||||
* open.c (_glibtop_open_s): Always determine the number of CPUs
|
||||
we have here, not only when SMP support was enabled.
|
||||
|
||||
* cpu.c, proctime.c: Use `server->ncpu' to determine whether to
|
||||
enable SMP support.
|
||||
|
||||
1998-12-28 Martin Baulig <martin@home-of-linux.org>
|
||||
|
||||
* netload.c: When using glibc, don't include <netinet/ip_fw.h>
|
||||
any longer but all headers that were included there; we only
|
||||
needed this file to get those headers.
|
||||
|
||||
1998-12-09 Martin Baulig <martin@home-of-linux.org>
|
||||
|
||||
* procargs.c (glibtop_get_proc_args_s): Added implementation
|
||||
for this function.
|
||||
|
||||
1998-12-03 Martin Baulig <martin@home-of-linux.org>
|
||||
|
||||
* netload.c: No longer include <linux/version.h>, but use
|
||||
GLIBTOP_LINUX_VERSION_CODE which is set by configure instead.
|
||||
Define _GLIBTOP_IP_FW_ACCTIN and _GLIBTOP_IP_FW_ACCTOUT here
|
||||
and use them instead of IP_FW_F_ACCTIN and IP_FW_F_ACCTOUT.
|
||||
|
||||
1998-11-30 Martin Baulig <martin@home-of-linux.org>
|
||||
|
||||
* netload.c: Use correct header files both for libc5 and glibc.
|
||||
With Linux >= 2.1.114 we no longer use IP accounting since it
|
||||
already has byte counts in /proc/net/dev.
|
||||
|
||||
1998-11-22 Martin Baulig <baulig@merkur.uni-trier.de>
|
||||
|
||||
* netload.c (glibtop_get_netload_s): Added implementation
|
||||
for this function.
|
||||
|
||||
The code here is smart enough to use /proc/net/ip_acct if
|
||||
IP accounting is enabled in the kernel and activated on the
|
||||
requested device and /proc/net/dev if not.
|
||||
|
||||
To get separate statistics for received and transmitted
|
||||
packets you need to use two accounting rules:
|
||||
|
||||
ipfwadm -A in -a -P all -W eth0
|
||||
ipfwadm -A out -a -P all -W eth0
|
||||
|
||||
But before you activate IP accounting, please have a look
|
||||
at /proc/net/dev - if if already contains byte counters,
|
||||
then don't use IP accounting.
|
||||
|
||||
1998-10-28 Martin Baulig <martin@home-of-linux.org>
|
||||
|
||||
* ppp.c: Added code for ISDN here.
|
||||
|
||||
1998-10-26 Martin Baulig <martin@home-of-linux.org>
|
||||
|
||||
* netload.c: New file. Currently empty.
|
||||
|
||||
1998-10-26 Martin Baulig <martin@home-of-linux.org>
|
||||
|
||||
* procargs.c: New file. Currently empty.
|
||||
|
||||
1998-10-25 Martin Baulig <martin@home-of-linux.org>
|
||||
|
||||
* ppp.c: New file. Currently empty.
|
||||
|
||||
1998-10-11 Martin Baulig <martin@home-of-linux.org>
|
||||
|
||||
* procdata.c: Removed this obsolete file.
|
||||
|
||||
1998-10-02 Martin Baulig <martin@home-of-linux.org>
|
||||
|
||||
* proclist.c (glibtop_init_proclist_s): You can now also use the
|
||||
`GLIBTOP_EXCLUDE_*' flags for the `which' parameter.
|
||||
|
||||
1998-10-01 Martin Baulig <baulig@Stud.Informatik.uni-trier.de>
|
||||
|
||||
* proclist.c (glibtop_init_proclist_s): Honor the `which' parameter
|
||||
to select which processes to fetch.
|
||||
|
||||
1998-09-12 Martin Baulig <martin@home-of-linux.org>
|
||||
|
||||
* sysinfo.c: New file.
|
||||
|
||||
1998-09-09 Martin Baulig <baulig@Stud.Informatik.uni-trier.de>
|
||||
|
||||
* proctime.c (glibtop_get_proc_time_s): Added SMP support.
|
||||
|
||||
* open.c (glibtop_init_s): Initialize `ncpu' on SMP systems.
|
||||
|
||||
* cpu.c (glibtop_get_cpu_s): Added SMP support.
|
||||
|
||||
* ChangeLog: New file.
|
||||
|
@@ -1,27 +0,0 @@
|
||||
LINK = $(LIBTOOL) --mode=link $(CC) $(CFLAGS) $(LDFLAGS) -o $@
|
||||
|
||||
INCLUDES = @INCLUDES@
|
||||
|
||||
dynamic_ldflags = @libgtop_dynamic_ldflags@
|
||||
|
||||
backenddir = @LIBGTOP_BACKEND_DIR@
|
||||
|
||||
if LIBGTOP_USE_GMODULE
|
||||
backendlibdir = $(backenddir)
|
||||
else
|
||||
backendlibdir = $(libdir)
|
||||
endif
|
||||
|
||||
backendlib_LTLIBRARIES = libgtop_sysdeps.la
|
||||
|
||||
libgtop_sysdeps_la_SOURCES = 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 proccwd.c procargs.c procmap.c \
|
||||
sysinfo.c interfaces.c netinfo.c netload.c ppp.c
|
||||
libgtop_sysdeps_la_LIBADD = @GLIB_LIBS@
|
||||
|
||||
libgtop_sysdeps_la_LDFLAGS = $(LT_VERSION_INFO) $(dynamic_ldflags)
|
||||
|
||||
include_HEADERS = glibtop_server.h glibtop_machine.h
|
@@ -1,37 +0,0 @@
|
||||
<?xml version="1.0"?> <!-- -*-xml-*- -->
|
||||
<!DOCTYPE libgtop:backendinfo SYSTEM 'libgtop-backend-info.dtd'>
|
||||
<libgtop:BackendInfo xmlns:libgtop="http://www.home-of-linux.org/libgtop/1.1">
|
||||
|
||||
<name>
|
||||
<short_name>
|
||||
linux-sysdeps
|
||||
</short_name>
|
||||
|
||||
<long_name>
|
||||
Linux sysdeps port.
|
||||
</long_name>
|
||||
</name>
|
||||
|
||||
<description>
|
||||
This is the Linux sysdeps port which uses the /proc filesystem
|
||||
to get all the data.
|
||||
</description>
|
||||
|
||||
<authors>
|
||||
<author>
|
||||
<author_name>
|
||||
Martin Baulig
|
||||
</author_name>
|
||||
<author_email>
|
||||
martin@home-of-linux.org
|
||||
</author_email>
|
||||
</author>
|
||||
</authors>
|
||||
|
||||
<legalnotice>
|
||||
<license>
|
||||
GNU General Public License
|
||||
</license>
|
||||
</legalnotice>
|
||||
|
||||
</libgtop:BackendInfo>
|
@@ -1,32 +0,0 @@
|
||||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright (C) 1998-99 Martin Baulig
|
||||
This file is part of LibGTop 1.0.
|
||||
|
||||
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/close.h>
|
||||
|
||||
/* Closes pipe to gtop server. */
|
||||
|
||||
void
|
||||
glibtop_close_s (glibtop *server)
|
||||
{ }
|
@@ -1,125 +0,0 @@
|
||||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright (C) 1998-99 Martin Baulig
|
||||
This file is part of LibGTop 1.0.
|
||||
|
||||
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 <config.h>
|
||||
#include <glibtop/error.h>
|
||||
#include <glibtop/cpu.h>
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_cpu =
|
||||
(1L << GLIBTOP_CPU_TOTAL) + (1L << GLIBTOP_CPU_USER) +
|
||||
(1L << GLIBTOP_CPU_NICE) + (1L << GLIBTOP_CPU_SYS) +
|
||||
(1L << GLIBTOP_CPU_IDLE) + (1L << GLIBTOP_CPU_FREQUENCY);
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_cpu_smp =
|
||||
(1L << GLIBTOP_CPU_XCPU_TOTAL) + (1L << GLIBTOP_CPU_XCPU_USER) +
|
||||
(1L << GLIBTOP_CPU_XCPU_NICE) + (1L << GLIBTOP_CPU_XCPU_SYS) +
|
||||
(1L << GLIBTOP_CPU_XCPU_IDLE) + (1L << GLIBTOP_CPU_XCPU_FLAGS);
|
||||
|
||||
/* Init function. */
|
||||
|
||||
int
|
||||
glibtop_init_cpu_s (glibtop *server)
|
||||
{
|
||||
server->sysdeps.cpu = _glibtop_sysdeps_cpu;
|
||||
|
||||
if (server->ncpu)
|
||||
server->sysdeps.cpu |= _glibtop_sysdeps_cpu_smp;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Provides information about cpu usage. */
|
||||
|
||||
#define FILENAME "/proc/stat"
|
||||
|
||||
int
|
||||
glibtop_get_cpu_s (glibtop *server, glibtop_cpu *buf)
|
||||
{
|
||||
char buffer [BUFSIZ], *p;
|
||||
int fd, len, i;
|
||||
u_int64_t total;
|
||||
|
||||
glibtop_init_s (&server, GLIBTOP_SYSDEPS_CPU, 0);
|
||||
|
||||
memset (buf, 0, sizeof (glibtop_cpu));
|
||||
|
||||
fd = open (FILENAME, O_RDONLY);
|
||||
if (fd < 0) {
|
||||
glibtop_warn_io_r (server, "open (%s)", FILENAME);
|
||||
return -1;
|
||||
}
|
||||
|
||||
len = read (fd, buffer, BUFSIZ-1);
|
||||
if (len < 0) {
|
||||
close (fd);
|
||||
glibtop_warn_io_r (server, "read (%s)", FILENAME);
|
||||
return -1;
|
||||
}
|
||||
|
||||
close (fd);
|
||||
|
||||
buffer [len] = '\0';
|
||||
|
||||
p = skip_token (buffer); /* "cpu" */
|
||||
|
||||
buf->user = strtoul (p, &p, 0);
|
||||
buf->nice = strtoul (p, &p, 0);
|
||||
buf->sys = strtoul (p, &p, 0);
|
||||
buf->idle = strtoul (p, &p, 0);
|
||||
|
||||
total = buf->user;
|
||||
total += buf->nice;
|
||||
total += buf->sys;
|
||||
total += buf->idle;
|
||||
buf->total = total;
|
||||
|
||||
buf->frequency = 100;
|
||||
buf->flags = _glibtop_sysdeps_cpu;
|
||||
|
||||
for (i = 0; i < server->ncpu; i++) {
|
||||
if (strncmp (p+1, "cpu", 3) || !isdigit (p [4]))
|
||||
break;
|
||||
|
||||
buf->xcpu_flags |= (1L << (u_int64_t) i);
|
||||
|
||||
p += 6;
|
||||
buf->xcpu_user [i] = strtoul (p, &p, 0);
|
||||
buf->xcpu_nice [i] = strtoul (p, &p, 0);
|
||||
buf->xcpu_sys [i] = strtoul (p, &p, 0);
|
||||
buf->xcpu_idle [i] = strtoul (p, &p, 0);
|
||||
|
||||
total = buf->xcpu_user [i];
|
||||
total += buf->xcpu_nice [i];
|
||||
total += buf->xcpu_sys [i];
|
||||
total += buf->xcpu_idle [i];
|
||||
|
||||
buf->xcpu_total [i] = total;
|
||||
}
|
||||
|
||||
if (buf->xcpu_flags)
|
||||
buf->flags |= _glibtop_sysdeps_cpu_smp;
|
||||
|
||||
return 0;
|
||||
}
|
@@ -1,60 +0,0 @@
|
||||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright (C) 1998-99 Martin Baulig
|
||||
This file is part of LibGTop 1.0.
|
||||
|
||||
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.
|
||||
*/
|
||||
|
||||
#ifndef __GLIBTOP_MACHINE_H__
|
||||
#define __GLIBTOP_MACHINE_H__
|
||||
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <ctype.h>
|
||||
|
||||
BEGIN_LIBGTOP_DECLS
|
||||
|
||||
#if _IN_LIBGTOP
|
||||
|
||||
static inline char *
|
||||
skip_token(const char *p)
|
||||
{
|
||||
while (isspace(*p)) p++;
|
||||
while (*p && !isspace(*p)) p++;
|
||||
return (char *)p;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
typedef struct _glibtop_machine glibtop_machine;
|
||||
|
||||
struct _glibtop_machine
|
||||
{
|
||||
pid_t last_pid;
|
||||
int no_update;
|
||||
int fd_stat, fd_meminfo, fd_loadavg;
|
||||
char proc_stat [BUFSIZ], proc_statm [BUFSIZ];
|
||||
char proc_status [BUFSIZ];
|
||||
};
|
||||
|
||||
END_LIBGTOP_DECLS
|
||||
|
||||
#endif
|
@@ -1,139 +0,0 @@
|
||||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright (C) 1998-99 Martin Baulig
|
||||
This file is part of LibGTop 1.0.
|
||||
|
||||
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.
|
||||
*/
|
||||
|
||||
#ifndef __GLIBTOP_SERVER_H__
|
||||
#define __GLIBTOP_SERVER_H__
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <ctype.h>
|
||||
|
||||
BEGIN_LIBGTOP_DECLS
|
||||
|
||||
#ifdef _IN_LIBGTOP
|
||||
|
||||
static inline char *
|
||||
skip_token (const char *p)
|
||||
{
|
||||
while (isspace(*p)) p++;
|
||||
while (*p && !isspace(*p)) p++;
|
||||
return (char *)p;
|
||||
}
|
||||
|
||||
static inline char *
|
||||
skip_multiple_token (const char *p, int count)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < count; i++)
|
||||
p = skip_token (p);
|
||||
|
||||
return (char *)p;
|
||||
}
|
||||
|
||||
static inline char *
|
||||
skip_line (const char *p)
|
||||
{
|
||||
while (*p != '\n') p++;
|
||||
return (char *) ++p;
|
||||
}
|
||||
|
||||
static inline int
|
||||
proc_file_to_buffer (char *buffer, const char *fmt, pid_t pid)
|
||||
{
|
||||
char filename [BUFSIZ];
|
||||
int fd, len;
|
||||
|
||||
sprintf (filename, fmt, pid);
|
||||
|
||||
fd = open (filename, O_RDONLY);
|
||||
if (fd < 0) return -1;
|
||||
|
||||
len = read (fd, buffer, BUFSIZ-1);
|
||||
close (fd);
|
||||
|
||||
if (len < 0)
|
||||
return -1;
|
||||
|
||||
buffer [len] = '\0';
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static inline int
|
||||
proc_stat_to_buffer (char *buffer, pid_t pid)
|
||||
{
|
||||
return proc_file_to_buffer (buffer, "/proc/%d/stat", pid);
|
||||
}
|
||||
|
||||
static inline int
|
||||
proc_status_to_buffer (char *buffer, pid_t pid)
|
||||
{
|
||||
return proc_file_to_buffer (buffer, "/proc/%d/status", pid);
|
||||
}
|
||||
|
||||
static inline int
|
||||
proc_statm_to_buffer (char *buffer, pid_t pid)
|
||||
{
|
||||
return proc_file_to_buffer (buffer, "/proc/%d/statm", pid);
|
||||
}
|
||||
|
||||
static inline char *
|
||||
proc_stat_after_cmd (char *p)
|
||||
{
|
||||
p = strrchr (p, ')');
|
||||
if (!p) return p;
|
||||
|
||||
*p++ = '\0';
|
||||
return p;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#define GLIBTOP_SUID_CPU 0
|
||||
#define GLIBTOP_SUID_MEM 0
|
||||
#define GLIBTOP_SUID_SWAP 0
|
||||
#define GLIBTOP_SUID_UPTIME 0
|
||||
#define GLIBTOP_SUID_LOADAVG 0
|
||||
#define GLIBTOP_SUID_SHM_LIMITS 0
|
||||
#define GLIBTOP_SUID_MSG_LIMITS 0
|
||||
#define GLIBTOP_SUID_SEM_LIMITS 0
|
||||
#define GLIBTOP_SUID_PROCLIST 0
|
||||
#define GLIBTOP_SUID_PROC_STATE 0
|
||||
#define GLIBTOP_SUID_PROC_UID 0
|
||||
#define GLIBTOP_SUID_PROC_MEM 0
|
||||
#define GLIBTOP_SUID_PROC_TIME 0
|
||||
#define GLIBTOP_SUID_PROC_SIGNAL 0
|
||||
#define GLIBTOP_SUID_PROC_KERNEL 0
|
||||
#define GLIBTOP_SUID_PROC_SEGMENT 0
|
||||
#define GLIBTOP_SUID_PROC_ARGS 0
|
||||
#define GLIBTOP_SUID_PROC_MAP 0
|
||||
#define GLIBTOP_SUID_NETINFO 0
|
||||
#define GLIBTOP_SUID_NETLOAD 0
|
||||
#define GLIBTOP_SUID_INTERFACE_NAMES 0
|
||||
#define GLIBTOP_SUID_PPP 0
|
||||
|
||||
END_LIBGTOP_DECLS
|
||||
|
||||
#endif
|
@@ -1,131 +0,0 @@
|
||||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright (C) 1998-99 Martin Baulig
|
||||
This file is part of LibGTop 1.0.
|
||||
|
||||
Contributed by Martin Baulig <martin@home-of-linux.org>, October 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/xmalloc.h>
|
||||
#include <glibtop/interfaces.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <netinet/in.h>
|
||||
#include <net/if.h>
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_interface_names =
|
||||
(1L << GLIBTOP_INTERFACE_NAMES_NUMBER) +
|
||||
(1L << GLIBTOP_INTERFACE_NAMES_SIZE);
|
||||
|
||||
/* Init function. */
|
||||
|
||||
int
|
||||
glibtop_init_interface_names_s (glibtop *server)
|
||||
{
|
||||
server->sysdeps.interface_names = _glibtop_sysdeps_interface_names;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Provides network statistics. */
|
||||
|
||||
glibtop_interface *
|
||||
glibtop_get_interface_names_s (glibtop *server, glibtop_array *array,
|
||||
u_int64_t interface, u_int64_t number,
|
||||
u_int64_t instance, u_int64_t strategy)
|
||||
{
|
||||
GPtrArray *parray;
|
||||
u_int64_t strategy_flags;
|
||||
glibtop_interface *retval = NULL;
|
||||
int skfd, i, n, numreqs = 30;
|
||||
struct ifconf ifc;
|
||||
struct ifreq *ifr;
|
||||
|
||||
glibtop_init_s (&server, GLIBTOP_SYSDEPS_INTERFACE_NAMES, 0);
|
||||
|
||||
memset (array, 0, sizeof (glibtop_array));
|
||||
|
||||
strategy_flags = strategy & GLIBTOP_STRATEGY_FLAGS_MASK;
|
||||
strategy &= ~GLIBTOP_STRATEGY_FLAGS_MASK;
|
||||
|
||||
parray = g_ptr_array_new ();
|
||||
|
||||
skfd = socket (AF_INET, SOCK_DGRAM, 0);
|
||||
if (!skfd) {
|
||||
glibtop_error_io_r (server, "socket (AF_INET, SOCK_DGRAM, 0)");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ifc.ifc_buf = NULL;
|
||||
for (;;) {
|
||||
ifc.ifc_len = sizeof (struct ifreq) * numreqs;
|
||||
ifc.ifc_buf = glibtop_realloc_r (server, ifc.ifc_buf, ifc.ifc_len);
|
||||
|
||||
if (ioctl (skfd, SIOCGIFCONF, &ifc) < 0) {
|
||||
glibtop_error_io_r (server, "SIOCGIFCONF");
|
||||
glibtop_free_r (server, ifc.ifc_buf);
|
||||
return NULL;
|
||||
}
|
||||
if (ifc.ifc_len == sizeof (struct ifreq) * numreqs) {
|
||||
/* assume it overflowed and try again */
|
||||
numreqs += 10;
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
ifr = ifc.ifc_req;
|
||||
for (n = 0; n < ifc.ifc_len; n += sizeof(struct ifreq), ifr++) {
|
||||
glibtop_interface *interface_ptr;
|
||||
|
||||
if (strchr (ifr->ifr_name, ':')) {
|
||||
/* This is a logical interface */
|
||||
if (!(strategy_flags & GLIBTOP_INTERFACES_INCLUDE_LOGICAL))
|
||||
continue;
|
||||
}
|
||||
|
||||
interface_ptr = g_new0 (glibtop_interface, 1);
|
||||
|
||||
strcpy (interface_ptr->name, ifr->ifr_name);
|
||||
|
||||
g_ptr_array_add (parray, interface_ptr);
|
||||
}
|
||||
|
||||
glibtop_free_r (server, ifc.ifc_buf);
|
||||
|
||||
close (skfd);
|
||||
|
||||
retval = glibtop_calloc_r (server, parray->len, sizeof (glibtop_interface));
|
||||
|
||||
for (i = 0; i < parray->len; i++)
|
||||
retval [i] = *(glibtop_interface *) parray->pdata [i];
|
||||
|
||||
array->number = parray->len;
|
||||
array->size = sizeof (glibtop_interface);
|
||||
array->total = array->number * array->size;
|
||||
|
||||
g_ptr_array_free (parray, TRUE);
|
||||
|
||||
return retval;
|
||||
}
|
@@ -1,105 +0,0 @@
|
||||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright (C) 1998-99 Martin Baulig
|
||||
This file is part of LibGTop 1.0.
|
||||
|
||||
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 <config.h>
|
||||
#include <glibtop/error.h>
|
||||
#include <glibtop/loadavg.h>
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_loadavg =
|
||||
(1L << GLIBTOP_LOADAVG_LOADAVG);
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_loadavg_tasks =
|
||||
(1L << GLIBTOP_LOADAVG_NR_RUNNING) +
|
||||
(1L << GLIBTOP_LOADAVG_NR_TASKS) +
|
||||
(1L << GLIBTOP_LOADAVG_LAST_PID);
|
||||
|
||||
/* Init function. */
|
||||
|
||||
int
|
||||
glibtop_init_loadavg_s (glibtop *server)
|
||||
{
|
||||
server->sysdeps.loadavg = _glibtop_sysdeps_loadavg;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Provides load load averange. */
|
||||
|
||||
#define FILENAME "/proc/loadavg"
|
||||
|
||||
int
|
||||
glibtop_get_loadavg_s (glibtop *server, glibtop_loadavg *buf)
|
||||
{
|
||||
char buffer [BUFSIZ], *p, *old;
|
||||
int fd, len;
|
||||
|
||||
glibtop_init_s (&server, GLIBTOP_SYSDEPS_LOADAVG, 0);
|
||||
|
||||
memset (buf, 0, sizeof (glibtop_loadavg));
|
||||
|
||||
fd = open (FILENAME, O_RDONLY);
|
||||
if (fd < 0) {
|
||||
glibtop_warn_io_r (server, "open (%s)", FILENAME);
|
||||
return -1;
|
||||
}
|
||||
|
||||
len = read (fd, buffer, BUFSIZ-1);
|
||||
if (len < 0) {
|
||||
close (fd);
|
||||
glibtop_warn_io_r (server, "read (%s)", FILENAME);
|
||||
return -1;
|
||||
}
|
||||
|
||||
close (fd);
|
||||
|
||||
buffer [len] = '\0';
|
||||
|
||||
buf->loadavg [0] = (float) strtod (buffer, &p);
|
||||
buf->loadavg [1] = (float) strtod (p, &p);
|
||||
buf->loadavg [2] = (float) strtod (p, &p);
|
||||
|
||||
buf->flags = _glibtop_sysdeps_loadavg;
|
||||
|
||||
while (isspace(*p)) p++;
|
||||
|
||||
/* Older Linux versions don't have the nr_running/nr_tasks fields. */
|
||||
|
||||
old = p;
|
||||
while (*p) {
|
||||
if (*p == '/')
|
||||
break;
|
||||
if (!isdigit (*p))
|
||||
return 0;
|
||||
p++;
|
||||
}
|
||||
|
||||
buf->nr_running = strtoul (old, &p, 0); p++;
|
||||
buf->nr_tasks = strtoul (p, &p, 0);
|
||||
buf->last_pid = strtoul (p, &p, 0);
|
||||
|
||||
buf->flags |= _glibtop_sysdeps_loadavg_tasks;
|
||||
|
||||
return 0;
|
||||
}
|
@@ -1,93 +0,0 @@
|
||||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright (C) 1998-99 Martin Baulig
|
||||
This file is part of LibGTop 1.0.
|
||||
|
||||
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 <config.h>
|
||||
#include <glibtop/error.h>
|
||||
#include <glibtop/mem.h>
|
||||
|
||||
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) + (1L << GLIBTOP_MEM_CACHED) +
|
||||
(1L << GLIBTOP_MEM_USER);
|
||||
|
||||
/* Init function. */
|
||||
|
||||
int
|
||||
glibtop_init_mem_s (glibtop *server)
|
||||
{
|
||||
server->sysdeps.mem = _glibtop_sysdeps_mem;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Provides information about memory usage. */
|
||||
|
||||
#define FILENAME "/proc/meminfo"
|
||||
|
||||
int
|
||||
glibtop_get_mem_s (glibtop *server, glibtop_mem *buf)
|
||||
{
|
||||
char buffer [BUFSIZ], *p;
|
||||
int fd, len;
|
||||
|
||||
glibtop_init_s (&server, GLIBTOP_SYSDEPS_MEM, 0);
|
||||
|
||||
memset (buf, 0, sizeof (glibtop_mem));
|
||||
|
||||
fd = open (FILENAME, O_RDONLY);
|
||||
if (fd < 0) {
|
||||
glibtop_warn_io_r (server, "open (%s)", FILENAME);
|
||||
return -1;
|
||||
|
||||
}
|
||||
|
||||
len = read (fd, buffer, BUFSIZ-1);
|
||||
if (len < 0) {
|
||||
close (fd);
|
||||
glibtop_warn_io_r (server, "read (%s)", FILENAME);
|
||||
return -1;
|
||||
}
|
||||
|
||||
close (fd);
|
||||
|
||||
buffer [len] = '\0';
|
||||
|
||||
p = skip_line (buffer);
|
||||
p = skip_token (p); /* "Mem:" */
|
||||
|
||||
buf->total = strtoul (p, &p, 0);
|
||||
buf->used = strtoul (p, &p, 0);
|
||||
buf->free = strtoul (p, &p, 0);
|
||||
buf->shared = strtoul (p, &p, 0);
|
||||
buf->buffer = strtoul (p, &p, 0);
|
||||
buf->cached = strtoul (p, &p, 0);
|
||||
|
||||
buf->user = buf->total - buf->free - buf->shared - buf->buffer;
|
||||
|
||||
buf->flags = _glibtop_sysdeps_mem;
|
||||
|
||||
return 0;
|
||||
}
|
@@ -1,71 +0,0 @@
|
||||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright (C) 1998-99 Martin Baulig
|
||||
This file is part of LibGTop 1.0.
|
||||
|
||||
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/msg_limits.h>
|
||||
|
||||
#include <sys/ipc.h>
|
||||
#include <sys/msg.h>
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_msg_limits =
|
||||
(1L << GLIBTOP_MSG_LIMITS_MSGPOOL) + (1L << GLIBTOP_MSG_LIMITS_MSGMAP) +
|
||||
(1L << GLIBTOP_MSG_LIMITS_MSGMAX) + (1L << GLIBTOP_MSG_LIMITS_MSGMNB) +
|
||||
(1L << GLIBTOP_MSG_LIMITS_MSGMNI) + (1L << GLIBTOP_MSG_LIMITS_MSGSSZ) +
|
||||
(1L << GLIBTOP_MSG_LIMITS_MSGTQL);
|
||||
|
||||
/* Init function. */
|
||||
|
||||
int
|
||||
glibtop_init_msg_limits_s (glibtop *server)
|
||||
{
|
||||
server->sysdeps.msg_limits = _glibtop_sysdeps_msg_limits;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Provides information about sysv ipc limits. */
|
||||
|
||||
int
|
||||
glibtop_get_msg_limits_s (glibtop *server, glibtop_msg_limits *buf)
|
||||
{
|
||||
struct msginfo msginfo;
|
||||
|
||||
glibtop_init_s (&server, GLIBTOP_SYSDEPS_MSG_LIMITS, 0);
|
||||
|
||||
memset (buf, 0, sizeof (glibtop_msg_limits));
|
||||
|
||||
buf->flags = _glibtop_sysdeps_msg_limits;
|
||||
|
||||
msgctl (0, IPC_INFO, (struct msqid_ds *) &msginfo);
|
||||
|
||||
buf->msgpool = msginfo.msgpool;
|
||||
buf->msgmap = msginfo.msgmap;
|
||||
buf->msgmax = msginfo.msgmax;
|
||||
buf->msgmnb = msginfo.msgmnb;
|
||||
buf->msgmni = msginfo.msgmni;
|
||||
buf->msgssz = msginfo.msgssz;
|
||||
buf->msgtql = msginfo.msgtql;
|
||||
|
||||
return 0;
|
||||
}
|
@@ -1,383 +0,0 @@
|
||||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright (C) 1998-99 Martin Baulig
|
||||
This file is part of LibGTop 1.0.
|
||||
|
||||
Contributed by Martin Baulig <martin@home-of-linux.org>, October 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/xmalloc.h>
|
||||
#include <glibtop/netinfo.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/ioctl.h>
|
||||
|
||||
#include <sys/sysctl.h>
|
||||
|
||||
#ifndef HAVE_AFINET
|
||||
#define HAVE_AFINET 1
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_AFINET6
|
||||
#define HAVE_AFINET6 1
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_AFINET6
|
||||
|
||||
#define _PATH_PROCNET_IFINET6 "/proc/net/if_inet6"
|
||||
|
||||
#define IPV6_ADDR_LOOPBACK 0x0010U
|
||||
#define IPV6_ADDR_LINKLOCAL 0x0020U
|
||||
#define IPV6_ADDR_SITELOCAL 0x0040U
|
||||
|
||||
#define IPV6_ADDR_COMPATv4 0x0080U
|
||||
|
||||
#endif /* HAVE_AFINET6 */
|
||||
|
||||
#if !defined (_LIBC) && defined (__GNU_LIBRARY__) && __GNU_LIBRARY__ > 1
|
||||
/* GNU LibC */
|
||||
#include <net/if.h>
|
||||
#include <netinet/ip_icmp.h>
|
||||
#include <netinet/in.h>
|
||||
#include <netinet/ip.h>
|
||||
#include <netinet/tcp.h>
|
||||
#include <netinet/udp.h>
|
||||
#include <net/if.h>
|
||||
#else /* Libc 5 */
|
||||
#include <linux/if.h>
|
||||
#include <linux/in.h>
|
||||
#include <linux/ip.h>
|
||||
#include <linux/icmp.h>
|
||||
#include <linux/tcp.h>
|
||||
#include <linux/udp.h>
|
||||
#endif
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_netinfo =
|
||||
(1L << GLIBTOP_NETINFO_TRANSPORT) +
|
||||
(1L << GLIBTOP_NETINFO_IF_FLAGS) +
|
||||
(1L << GLIBTOP_NETINFO_ADDRESS) +
|
||||
(1L << GLIBTOP_NETINFO_SUBNET) +
|
||||
(1L << GLIBTOP_NETINFO_MTU);
|
||||
|
||||
/* Init function. */
|
||||
|
||||
int
|
||||
glibtop_init_netinfo_s (glibtop *server)
|
||||
{
|
||||
server->sysdeps.netinfo = _glibtop_sysdeps_netinfo;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef HAVE_AFINET
|
||||
|
||||
static int
|
||||
_netinfo_ipv4 (glibtop *server, glibtop_netinfo *buf,
|
||||
const char *interface, glibtop_ifaddr *address)
|
||||
{
|
||||
int skfd;
|
||||
|
||||
skfd = socket (AF_INET, SOCK_DGRAM, 0);
|
||||
if (skfd) {
|
||||
struct ifreq ifr;
|
||||
unsigned flags;
|
||||
|
||||
if (address) {
|
||||
address->transport = GLIBTOP_TRANSPORT_IPV4;
|
||||
address->flags |= (1L << GLIBTOP_IFADDR_TRANSPORT);
|
||||
|
||||
buf->transport = GLIBTOP_TRANSPORT_IPV4;
|
||||
buf->flags |= (1L << GLIBTOP_NETINFO_TRANSPORT);
|
||||
}
|
||||
|
||||
strcpy (ifr.ifr_name, interface);
|
||||
if (!ioctl (skfd, SIOCGIFFLAGS, &ifr)) {
|
||||
buf->flags |= (1L << GLIBTOP_NETINFO_IF_FLAGS);
|
||||
flags = ifr.ifr_flags;
|
||||
} else
|
||||
flags = 0;
|
||||
|
||||
if (flags & IFF_UP)
|
||||
buf->if_flags |= (1L << GLIBTOP_IF_FLAGS_UP);
|
||||
|
||||
if (flags & IFF_BROADCAST)
|
||||
buf->if_flags |= (1L << GLIBTOP_IF_FLAGS_BROADCAST);
|
||||
|
||||
if (flags & IFF_DEBUG)
|
||||
buf->if_flags |= (1L << GLIBTOP_IF_FLAGS_DEBUG);
|
||||
|
||||
if (flags & IFF_LOOPBACK)
|
||||
buf->if_flags |= (1L << GLIBTOP_IF_FLAGS_LOOPBACK);
|
||||
|
||||
if (flags & IFF_POINTOPOINT)
|
||||
buf->if_flags |= (1L << GLIBTOP_IF_FLAGS_POINTOPOINT);
|
||||
|
||||
if (flags & IFF_RUNNING)
|
||||
buf->if_flags |= (1L << GLIBTOP_IF_FLAGS_RUNNING);
|
||||
|
||||
if (flags & IFF_NOARP)
|
||||
buf->if_flags |= (1L << GLIBTOP_IF_FLAGS_NOARP);
|
||||
|
||||
if (flags & IFF_PROMISC)
|
||||
buf->if_flags |= (1L << GLIBTOP_IF_FLAGS_PROMISC);
|
||||
|
||||
if (flags & IFF_ALLMULTI)
|
||||
buf->if_flags |= (1L << GLIBTOP_IF_FLAGS_ALLMULTI);
|
||||
|
||||
if (flags & IFF_MULTICAST)
|
||||
buf->if_flags |= (1L << GLIBTOP_IF_FLAGS_MULTICAST);
|
||||
|
||||
if (address) {
|
||||
strcpy (ifr.ifr_name, interface);
|
||||
if (!ioctl (skfd, SIOCGIFADDR, &ifr)) {
|
||||
struct sockaddr_in addr =
|
||||
*(struct sockaddr_in *) &ifr.ifr_addr;
|
||||
|
||||
address->addr_len = 4;
|
||||
memcpy (&address->address, &addr.sin_addr.s_addr, 4);
|
||||
|
||||
address->flags |= (1L << GLIBTOP_IFADDR_ADDRESS);
|
||||
address->flags |= (1L << GLIBTOP_IFADDR_ADDR_LEN);
|
||||
}
|
||||
|
||||
strcpy (ifr.ifr_name, interface);
|
||||
if (!ioctl (skfd, SIOCGIFNETMASK, &ifr)) {
|
||||
struct sockaddr_in addr =
|
||||
*(struct sockaddr_in *) &ifr.ifr_addr;
|
||||
|
||||
memcpy (&address->subnet, &addr.sin_addr.s_addr, 4);
|
||||
address->flags |= (1L << GLIBTOP_IFADDR_SUBNET);
|
||||
}
|
||||
}
|
||||
|
||||
strcpy (ifr.ifr_name, interface);
|
||||
if (!ioctl (skfd, SIOCGIFMTU, &ifr)) {
|
||||
buf->mtu = ifr.ifr_mtu;
|
||||
buf->flags |= (1L << GLIBTOP_NETINFO_MTU);
|
||||
}
|
||||
|
||||
close (skfd);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif /* HAVE_AFINET */
|
||||
|
||||
#ifdef HAVE_AFINET6
|
||||
|
||||
static int
|
||||
_parse_ipv6_address (const char *addr_string, u_int8_t *dest)
|
||||
{
|
||||
int i;
|
||||
|
||||
if (strlen (addr_string) != 32)
|
||||
return -1;
|
||||
|
||||
for (i = 0; i < 16; i++) {
|
||||
char c1, c2;
|
||||
int d1, d2;
|
||||
|
||||
c1 = tolower (addr_string [(i<<1)]);
|
||||
c2 = tolower (addr_string [(i<<1)+1]);
|
||||
|
||||
if ((c1 >= '0') && (c1 <= '9'))
|
||||
d1 = c1-'0';
|
||||
else if ((c1 >= 'a') && (c1 <= 'f'))
|
||||
d1 = c1-'a'+10;
|
||||
else
|
||||
return -1;
|
||||
|
||||
if ((c2 >= '0') && (c2 <= '9'))
|
||||
d2 = c2-'0';
|
||||
else if ((c2 >= 'a') && (c2 <= 'f'))
|
||||
d2 = c2-'a'+10;
|
||||
else
|
||||
return -1;
|
||||
|
||||
dest [i] = (d1 << 4) + d2;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
_netinfo_ipv6 (glibtop *server, glibtop_netinfo *buf,
|
||||
const char *interface, GPtrArray *parray)
|
||||
{
|
||||
FILE *f;
|
||||
char addr6[40], devname[20];
|
||||
int plen, scope, dad_status, if_idx;
|
||||
|
||||
#ifdef HAVE_AFINET6
|
||||
/* get common things such as mtu and if_flags */
|
||||
_netinfo_ipv4 (server, buf, interface, NULL);
|
||||
#endif
|
||||
|
||||
buf->transport = GLIBTOP_TRANSPORT_IPV6;
|
||||
buf->flags |= (1L << GLIBTOP_NETINFO_TRANSPORT);
|
||||
|
||||
f = fopen (_PATH_PROCNET_IFINET6, "r");
|
||||
|
||||
if (f != NULL) {
|
||||
while (fscanf (f, "%64s %02x %02x %02x %02x %20s\n",
|
||||
addr6, &if_idx, &plen, &scope, &dad_status,
|
||||
devname) != EOF) {
|
||||
glibtop_ifaddr address;
|
||||
|
||||
memset (&address, 0, sizeof (glibtop_ifaddr));
|
||||
|
||||
if (strcmp (devname, interface))
|
||||
continue;
|
||||
|
||||
if (!_parse_ipv6_address (addr6, address.address))
|
||||
address.flags |= (1L << GLIBTOP_IFADDR_ADDRESS);
|
||||
|
||||
address.transport = GLIBTOP_TRANSPORT_IPV6;
|
||||
address.subnet = plen;
|
||||
|
||||
switch (scope) {
|
||||
case 0:
|
||||
address.scope = GLIBTOP_IPV6_SCOPE_GLOBAL;
|
||||
break;
|
||||
case IPV6_ADDR_LINKLOCAL:
|
||||
address.scope = GLIBTOP_IPV6_SCOPE_LINKLOCAL;
|
||||
break;
|
||||
case IPV6_ADDR_SITELOCAL:
|
||||
address.scope = GLIBTOP_IPV6_SCOPE_SITELOCAL;
|
||||
break;
|
||||
case IPV6_ADDR_COMPATv4:
|
||||
address.scope = GLIBTOP_IPV6_SCOPE_COMPATv4;
|
||||
break;
|
||||
case IPV6_ADDR_LOOPBACK:
|
||||
address.scope = GLIBTOP_IPV6_SCOPE_LOOPBACK;
|
||||
break;
|
||||
default:
|
||||
address.scope = GLIBTOP_IPV6_SCOPE_UNKNOWN;
|
||||
break;
|
||||
}
|
||||
|
||||
address.addr_len = 8;
|
||||
|
||||
address.flags |= (1L << GLIBTOP_IFADDR_TRANSPORT) |
|
||||
(1L << GLIBTOP_IFADDR_ADDR_LEN) |
|
||||
(1L << GLIBTOP_IFADDR_SUBNET) |
|
||||
(1L << GLIBTOP_IFADDR_SCOPE);
|
||||
|
||||
g_ptr_array_add (parray, g_memdup (&address, sizeof (address)));
|
||||
}
|
||||
}
|
||||
|
||||
fclose (f);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif /* HAVE_AFINET6 */
|
||||
|
||||
/* Provides network statistics. */
|
||||
|
||||
glibtop_ifaddr *
|
||||
glibtop_get_netinfo_s (glibtop *server, glibtop_array *array,
|
||||
glibtop_netinfo *buf, const char *interface,
|
||||
u_int64_t transport)
|
||||
{
|
||||
GPtrArray *parray;
|
||||
glibtop_ifaddr *retval = NULL;
|
||||
int i;
|
||||
|
||||
memset (buf, 0, sizeof (glibtop_netinfo));
|
||||
|
||||
if (strlen (interface) >= GLIBTOP_INTERFACE_LEN)
|
||||
return NULL;
|
||||
|
||||
/* Assume IPv4 is the standard until IPv6 becomes more popular. */
|
||||
if (transport == GLIBTOP_TRANSPORT_DEFAULT)
|
||||
transport = GLIBTOP_TRANSPORT_ALL;
|
||||
|
||||
/* Get information about all possible transport methods. */
|
||||
if (transport == GLIBTOP_TRANSPORT_ALL) {
|
||||
char buffer [BUFSIZ];
|
||||
struct stat statb;
|
||||
|
||||
/* We may get a little speed improvement when we use sysctl ()
|
||||
* directly, but the following piece of code seems very stable
|
||||
* and reliable to me.
|
||||
*
|
||||
* The first stat() on "/proc/sys/net" is done to find out whether
|
||||
* the kernel has sysctl support.
|
||||
*
|
||||
* January 23, 1999
|
||||
* Martin
|
||||
*/
|
||||
|
||||
if (!stat ("/proc/sys/net", &statb) && S_ISDIR (statb.st_mode)) {
|
||||
buf->flags |= (1L << GLIBTOP_NETINFO_TRANSPORT);
|
||||
|
||||
sprintf (buffer, "/proc/sys/net/ipv4/conf/%s", interface);
|
||||
if (!stat (buffer, &statb) && S_ISDIR (statb.st_mode))
|
||||
buf->transport |= GLIBTOP_TRANSPORT_IPV4;
|
||||
|
||||
sprintf (buffer, "/proc/sys/net/ipv6/conf/%s", interface);
|
||||
if (!stat (buffer, &statb) && S_ISDIR (statb.st_mode))
|
||||
buf->transport |= GLIBTOP_TRANSPORT_IPV6;
|
||||
}
|
||||
}
|
||||
|
||||
parray = g_ptr_array_new ();
|
||||
|
||||
#ifdef HAVE_AFINET
|
||||
if (transport & GLIBTOP_TRANSPORT_IPV4) {
|
||||
glibtop_ifaddr address;
|
||||
|
||||
memset (&address, 0, sizeof (glibtop_ifaddr));
|
||||
|
||||
_netinfo_ipv4 (server, buf, interface, &address);
|
||||
if (address.flags & (1L << GLIBTOP_IFADDR_ADDRESS))
|
||||
g_ptr_array_add (parray, g_memdup (&address, sizeof (address)));
|
||||
}
|
||||
#endif /* HAVE_AFINET */
|
||||
|
||||
#ifdef HAVE_AFINET6
|
||||
if (transport & GLIBTOP_TRANSPORT_IPV6)
|
||||
_netinfo_ipv6 (server, buf, interface, parray);
|
||||
#endif /* HAVE_AFINET6 */
|
||||
|
||||
if (!parray->len) {
|
||||
g_ptr_array_free (parray, TRUE);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
retval = glibtop_calloc_r (server, parray->len, sizeof (glibtop_ifaddr));
|
||||
|
||||
for (i = 0; i < parray->len; i++)
|
||||
retval [i] = *(glibtop_ifaddr *) parray->pdata [i];
|
||||
|
||||
array->number = parray->len;
|
||||
array->size = sizeof (glibtop_ifaddr);
|
||||
array->total = array->number * array->size;
|
||||
|
||||
g_ptr_array_free (parray, TRUE);
|
||||
|
||||
return retval;
|
||||
}
|
@@ -1,288 +0,0 @@
|
||||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright (C) 1998-99 Martin Baulig
|
||||
This file is part of LibGTop 1.0.
|
||||
|
||||
Contributed by Martin Baulig <martin@home-of-linux.org>, October 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/netload.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/ioctl.h>
|
||||
|
||||
#if !defined (_LIBC) && defined (__GNU_LIBRARY__) && __GNU_LIBRARY__ > 1
|
||||
/* GNU LibC */
|
||||
#include <net/if.h>
|
||||
#include <netinet/ip_icmp.h>
|
||||
#include <netinet/in.h>
|
||||
#include <netinet/ip.h>
|
||||
#include <netinet/tcp.h>
|
||||
#include <netinet/udp.h>
|
||||
#include <net/if.h>
|
||||
#else /* Libc 5 */
|
||||
#include <linux/if.h>
|
||||
#include <linux/in.h>
|
||||
#include <linux/ip.h>
|
||||
#include <linux/icmp.h>
|
||||
#include <linux/tcp.h>
|
||||
#include <linux/udp.h>
|
||||
#endif
|
||||
|
||||
#define _GLIBTOP_IP_FW_ACCTIN 0x1000 /* Account incoming packets only. */
|
||||
#define _GLIBTOP_IP_FW_ACCTOUT 0x2000 /* Account outgoing packets only. */
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_netload =
|
||||
(1L << GLIBTOP_NETLOAD_ERRORS_IN) +
|
||||
(1L << GLIBTOP_NETLOAD_ERRORS_OUT) +
|
||||
(1L << GLIBTOP_NETLOAD_COLLISIONS);
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_netload_bytes =
|
||||
(1L << GLIBTOP_NETLOAD_BYTES_IN) +
|
||||
(1L << GLIBTOP_NETLOAD_BYTES_OUT) +
|
||||
(1L << GLIBTOP_NETLOAD_BYTES_TOTAL);
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_netload_packets =
|
||||
(1L << GLIBTOP_NETLOAD_PACKETS_IN) +
|
||||
(1L << GLIBTOP_NETLOAD_PACKETS_OUT) +
|
||||
(1L << GLIBTOP_NETLOAD_PACKETS_TOTAL);
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_netload_total =
|
||||
(1L << GLIBTOP_NETLOAD_PACKETS_TOTAL) +
|
||||
(1L << GLIBTOP_NETLOAD_BYTES_TOTAL);
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_netload_in =
|
||||
(1L << GLIBTOP_NETLOAD_PACKETS_TOTAL) +
|
||||
(1L << GLIBTOP_NETLOAD_BYTES_TOTAL) +
|
||||
(1L << GLIBTOP_NETLOAD_PACKETS_IN) +
|
||||
(1L << GLIBTOP_NETLOAD_BYTES_IN);
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_netload_out =
|
||||
(1L << GLIBTOP_NETLOAD_PACKETS_TOTAL) +
|
||||
(1L << GLIBTOP_NETLOAD_BYTES_TOTAL) +
|
||||
(1L << GLIBTOP_NETLOAD_PACKETS_OUT) +
|
||||
(1L << GLIBTOP_NETLOAD_BYTES_OUT);
|
||||
|
||||
/* Init function. */
|
||||
|
||||
int
|
||||
glibtop_init_netload_s (glibtop *server)
|
||||
{
|
||||
server->sysdeps.netload = _glibtop_sysdeps_netload |
|
||||
_glibtop_sysdeps_netload_bytes |
|
||||
_glibtop_sysdeps_netload_packets;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Provides network statistics. */
|
||||
|
||||
int
|
||||
glibtop_get_netload_s (glibtop *server, glibtop_netload *buf,
|
||||
const char *interface, unsigned transport,
|
||||
unsigned protocol)
|
||||
{
|
||||
char buffer [BUFSIZ], *p;
|
||||
int have_bytes, fields;
|
||||
FILE *f;
|
||||
|
||||
memset (buf, 0, sizeof (glibtop_netload));
|
||||
|
||||
/* Linux 2.1.114 - don't know where exactly this was added, but
|
||||
* recent kernels have byte count in /proc/net/dev so we don't
|
||||
* need IP accounting.
|
||||
*/
|
||||
|
||||
if (server->os_version_code < 131442) {
|
||||
|
||||
/* If IP accounting is enabled in the kernel and it is
|
||||
* enabled for the requested interface, we use it to
|
||||
* get the data. In this case, we don't use /proc/net/dev
|
||||
* to get errors and collisions.
|
||||
*/
|
||||
|
||||
f = fopen ("/proc/net/ip_acct", "r");
|
||||
if (f) {
|
||||
int success = 0;
|
||||
|
||||
/* Skip over the header line. */
|
||||
fgets (buffer, BUFSIZ-1, f);
|
||||
|
||||
while (fgets (buffer, BUFSIZ-1, f)) {
|
||||
unsigned long flags, packets, bytes;
|
||||
char *p, *dev;
|
||||
|
||||
/* Skip over the network thing. */
|
||||
dev = skip_token (buffer) + 1;
|
||||
p = skip_token (dev);
|
||||
*p++ = 0;
|
||||
|
||||
if (strcmp (dev, interface))
|
||||
continue;
|
||||
|
||||
success = 1;
|
||||
|
||||
p = skip_token (p);
|
||||
|
||||
flags = strtoul (p, &p, 16);
|
||||
|
||||
p = skip_multiple_token (p, 2);
|
||||
|
||||
packets = strtoul (p, &p, 0);
|
||||
bytes = strtoul (p, &p, 0);
|
||||
|
||||
if (flags & _GLIBTOP_IP_FW_ACCTIN) {
|
||||
/* Incoming packets only. */
|
||||
|
||||
buf->packets_total += packets;
|
||||
buf->packets_in += packets;
|
||||
|
||||
buf->bytes_total += bytes;
|
||||
buf->bytes_in += bytes;
|
||||
|
||||
buf->flags |= _glibtop_sysdeps_netload_in;
|
||||
|
||||
} else if (flags & _GLIBTOP_IP_FW_ACCTOUT) {
|
||||
/* Outgoing packets only. */
|
||||
|
||||
buf->packets_total += packets;
|
||||
buf->packets_out += packets;
|
||||
|
||||
buf->bytes_total += bytes;
|
||||
buf->bytes_out += bytes;
|
||||
|
||||
buf->flags |= _glibtop_sysdeps_netload_out;
|
||||
|
||||
} else {
|
||||
/* Only have total values. */
|
||||
|
||||
buf->packets_total += packets;
|
||||
buf->bytes_total += bytes;
|
||||
|
||||
buf->flags |= _glibtop_sysdeps_netload_total;
|
||||
}
|
||||
}
|
||||
|
||||
fclose (f);
|
||||
|
||||
if (success) return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* Ok, either IP accounting is not enabled in the kernel or
|
||||
* it was not enabled for the requested interface. */
|
||||
|
||||
f = fopen ("/proc/net/dev", "r");
|
||||
if (!f) return -1;
|
||||
|
||||
/* Skip over the header line. */
|
||||
fgets (buffer, BUFSIZ-1, f);
|
||||
fgets (buffer, BUFSIZ-1, f);
|
||||
|
||||
/* Starting with 2.1.xx (don't know exactly which version)
|
||||
* /proc/net/dev contains both byte and package counters. */
|
||||
|
||||
p = strchr (buffer, '|');
|
||||
if (!p) {
|
||||
fclose (f);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Do we already have byte counters ? */
|
||||
have_bytes = strncmp (++p, "bytes", 5) == 0;
|
||||
|
||||
/* Count remaining 'Receive' fields so we know where
|
||||
* the first 'Transmit' field starts. */
|
||||
|
||||
fields = 0;
|
||||
while (*p != '|') {
|
||||
if (!isspace (*p++)) continue;
|
||||
while (isspace (*p++)) ;
|
||||
fields++;
|
||||
}
|
||||
|
||||
/* Should never happen. */
|
||||
if (fields < 2) {
|
||||
fclose (f);
|
||||
return -1;
|
||||
}
|
||||
fields--;
|
||||
|
||||
while (fgets (buffer, BUFSIZ-1, f)) {
|
||||
char *p, *dev;
|
||||
|
||||
dev = buffer;
|
||||
while (isspace (*dev)) dev++;
|
||||
|
||||
p = strchr (dev, ':');
|
||||
if (!p) continue;
|
||||
*p++ = 0;
|
||||
|
||||
/* If it's not a digit, then it's most likely an error
|
||||
* message like 'No statistics available'. */
|
||||
while (isspace (*p)) p++;
|
||||
if (!isdigit (*p)) continue;
|
||||
|
||||
if (strcmp (dev, interface))
|
||||
continue;
|
||||
|
||||
/* Only read byte counts if we really have them. */
|
||||
|
||||
if (have_bytes) {
|
||||
buf->bytes_in = strtoul (p, &p, 0);
|
||||
fields--;
|
||||
}
|
||||
|
||||
buf->packets_in = strtoul (p, &p, 0);
|
||||
buf->errors_in = strtoul (p, &p, 0);
|
||||
|
||||
p = skip_multiple_token (p, fields);
|
||||
|
||||
if (have_bytes)
|
||||
buf->bytes_out = strtoul (p, &p, 0);
|
||||
|
||||
buf->packets_out = strtoul (p, &p, 0);
|
||||
buf->errors_out = strtoul (p, &p, 0);
|
||||
|
||||
p = skip_multiple_token (p, 2);
|
||||
|
||||
buf->collisions = strtoul (p, &p, 0);
|
||||
|
||||
/* Compute total valules. */
|
||||
|
||||
buf->bytes_total = buf->bytes_in + buf->bytes_out;
|
||||
buf->packets_total = buf->packets_in + buf->packets_out;
|
||||
|
||||
/* And now the flags. */
|
||||
|
||||
buf->flags |= _glibtop_sysdeps_netload;
|
||||
buf->flags |= _glibtop_sysdeps_netload_packets;
|
||||
|
||||
if (have_bytes)
|
||||
buf->flags |= _glibtop_sysdeps_netload_bytes;
|
||||
}
|
||||
|
||||
fclose (f);
|
||||
|
||||
return 0;
|
||||
}
|
@@ -1,103 +0,0 @@
|
||||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright (C) 1998-99 Martin Baulig
|
||||
This file is part of LibGTop 1.0.
|
||||
|
||||
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/cpu.h>
|
||||
#include <glibtop/open.h>
|
||||
|
||||
/* =====================================================
|
||||
* Linux kernel version information for procps utilities
|
||||
* Copyright (c) 1996 Charles Blake <cblake@bbn.com>
|
||||
*/
|
||||
#include <sys/utsname.h>
|
||||
|
||||
#define LINUX_VERSION(x,y,z) (0x10000*(x) + 0x100*(y) + z)
|
||||
|
||||
static int linux_version_code = 0;
|
||||
|
||||
static void set_linux_version(void) {
|
||||
static struct utsname uts;
|
||||
int x = 0, y = 0, z = 0; /* cleared in case sscanf() < 3 */
|
||||
|
||||
if (linux_version_code) return;
|
||||
if (uname(&uts) == -1) /* failure most likely implies impending death */
|
||||
exit(1);
|
||||
if (sscanf(uts.release, "%d.%d.%d", &x, &y, &z) < 3)
|
||||
fprintf(stderr, /* *very* unlikely to happen by accident */
|
||||
"Non-standard uts for running kernel:\n"
|
||||
"release %s=%d.%d.%d gives version code %d\n",
|
||||
uts.release, x, y, z, LINUX_VERSION(x,y,z));
|
||||
linux_version_code = LINUX_VERSION(x, y, z);
|
||||
}
|
||||
|
||||
/* ======================================================= */
|
||||
|
||||
/* Opens pipe to gtop server. Returns 0 on success and -1 on error. */
|
||||
|
||||
#define FILENAME "/proc/stat"
|
||||
|
||||
void
|
||||
glibtop_open_s (glibtop_server *server, const char *program_name,
|
||||
const unsigned long features,
|
||||
const unsigned flags)
|
||||
{
|
||||
char buffer [BUFSIZ], *p;
|
||||
int fd, len, i;
|
||||
|
||||
server->name = program_name;
|
||||
|
||||
set_linux_version ();
|
||||
server->_priv->os_version_code = (unsigned long) linux_version_code;
|
||||
|
||||
server->ncpu = 0;
|
||||
|
||||
fd = open (FILENAME, O_RDONLY);
|
||||
if (fd < 0)
|
||||
glibtop_error_io_r (server, "open (%s)", FILENAME);
|
||||
|
||||
len = read (fd, buffer, BUFSIZ-1);
|
||||
if (len < 0)
|
||||
glibtop_error_io_r (server, "read (%s)", FILENAME);
|
||||
|
||||
close (fd);
|
||||
|
||||
buffer [len] = '\0';
|
||||
|
||||
p = skip_multiple_token (buffer, 5) + 1;
|
||||
|
||||
for (i = 0; i < GLIBTOP_NCPU; i++) {
|
||||
|
||||
if (strncmp (p, "cpu", 3) || !isdigit (p [3]))
|
||||
break;
|
||||
|
||||
server->ncpu++;
|
||||
|
||||
p = skip_multiple_token (p, 5) + 1;
|
||||
}
|
||||
|
||||
#if DEBUG
|
||||
printf ("\nThis machine has %d CPUs.\n\n", server->ncpu);
|
||||
#endif
|
||||
}
|
@@ -1,324 +0,0 @@
|
||||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright (C) 1998-99 Martin Baulig
|
||||
This file is part of LibGTop 1.0.
|
||||
|
||||
Contributed by Martin Baulig <martin@home-of-linux.org>, October 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/xmalloc.h>
|
||||
#include <glibtop/ppp.h>
|
||||
|
||||
#include <linux/isdn.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
#include <ctype.h>
|
||||
|
||||
#include <glib.h>
|
||||
|
||||
#if !defined (_LIBC) && defined (__GNU_LIBRARY__) && __GNU_LIBRARY__ > 1
|
||||
/* GNU LibC */
|
||||
#include <net/if.h>
|
||||
#include <netinet/ip_icmp.h>
|
||||
#include <netinet/in.h>
|
||||
#include <netinet/ip.h>
|
||||
#include <netinet/tcp.h>
|
||||
#include <netinet/udp.h>
|
||||
#include <net/if.h>
|
||||
#include <net/if_ppp.h>
|
||||
#else /* Libc 5 */
|
||||
#include <linux/if.h>
|
||||
#include <linux/in.h>
|
||||
#include <linux/ip.h>
|
||||
#include <linux/icmp.h>
|
||||
#include <linux/tcp.h>
|
||||
#include <linux/udp.h>
|
||||
#include <linux/isdn.h>
|
||||
#endif
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_ppp =
|
||||
(1L << GLIBTOP_PPP_STATE) + (1L << GLIBTOP_PPP_BYTES_IN) +
|
||||
(1L << GLIBTOP_PPP_BYTES_OUT);
|
||||
|
||||
#ifdef SIOCDEVPRIVATE
|
||||
static int ip_socket;
|
||||
#endif
|
||||
|
||||
/* Init function. */
|
||||
|
||||
int
|
||||
glibtop_init_ppp_s (glibtop *server)
|
||||
{
|
||||
server->sysdeps.ppp = _glibtop_sysdeps_ppp;
|
||||
|
||||
#ifdef SIOCDEVPRIVATE
|
||||
/* open ip socket */
|
||||
if ((ip_socket = socket (AF_INET, SOCK_DGRAM, 0)) < 0)
|
||||
return -GLIBTOP_ERROR_NO_KERNEL_SUPPORT; /* should never happen */
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
get_ISDN_stats (glibtop *server, int *in, int *out)
|
||||
{
|
||||
unsigned long *isdn_stats, *ptr;
|
||||
int fd, i;
|
||||
|
||||
*in = *out = 0;
|
||||
|
||||
isdn_stats = glibtop_calloc_r (server, ISDN_MAX_CHANNELS * 2,
|
||||
sizeof (unsigned long));
|
||||
|
||||
fd = open ("/dev/isdninfo", O_RDONLY);
|
||||
if (fd < 0) {
|
||||
glibtop_free_r (server, isdn_stats);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if ((ioctl (fd, IIOCGETCPS, isdn_stats) < 0) && (errno != 0)) {
|
||||
glibtop_free_r (server, isdn_stats);
|
||||
close (fd);
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
for (i = 0, ptr = isdn_stats; i < ISDN_MAX_CHANNELS; i++) {
|
||||
*in += *ptr++; *out += *ptr++;
|
||||
}
|
||||
|
||||
glibtop_free_r (server, isdn_stats);
|
||||
close (fd);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static int
|
||||
is_ISDN_on (glibtop *server, int device, int *online)
|
||||
{
|
||||
FILE *f = 0;
|
||||
char buffer [BUFSIZ], *p;
|
||||
int i;
|
||||
|
||||
/* Perhaps I should try to explain this code a little bit.
|
||||
*
|
||||
* ------------------------------------------------------------
|
||||
* This is from the manpage of isdninfo(4):
|
||||
*
|
||||
* DESCRIPTION
|
||||
* /dev/isdninfo is a character device with major number 45
|
||||
* and minor number 255. It delivers status information from
|
||||
* the Linux ISDN subsystem to user level.
|
||||
*
|
||||
* DATA FORMAT
|
||||
* When reading from this device, the current status of the
|
||||
* Linux ISDN subsystem is delivered in 6 lines of text. Each
|
||||
* line starts with a tag string followed by a colon and
|
||||
* whitespace. After that the status values are appended sep-
|
||||
* arated by whitespace.
|
||||
*
|
||||
* flags is the tag of line 5. In this line for every driver
|
||||
* slot, it's B-Channel status is shown. If no driver
|
||||
* is registered in a slot, a ? is shown. For every
|
||||
* established B-Channel of the driver, a bit is set
|
||||
* in the shown value. The driver's first channel is
|
||||
* mapped to bit 0, the second channel to bit 1 and so
|
||||
* on.
|
||||
* ------------------------------------------------------------
|
||||
*
|
||||
* So we open /dev/isdninfo, discard the first four lines of text
|
||||
* and then check whether we have something that is not `0' or `?'
|
||||
* in one of the flags fields.
|
||||
*
|
||||
* Sounds complicated, but I don't see any other way to check whether
|
||||
* we are connected. Also, this is the method some other ISDN tools
|
||||
* for Linux use.
|
||||
*
|
||||
* Martin
|
||||
*/
|
||||
|
||||
f = fopen ("/dev/isdninfo", "r");
|
||||
|
||||
if (!f) return FALSE;
|
||||
|
||||
for (i = 0; i < 5; i++) {
|
||||
if (fgets (buffer, BUFSIZ, f) == NULL) {
|
||||
fclose (f);
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
if (strncmp (buffer, "flags:", 6)) {
|
||||
fclose (f);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
p = buffer+6;
|
||||
|
||||
for (i = 0; i <= device; i++) {
|
||||
char *end = p;
|
||||
|
||||
while (isspace (*p))
|
||||
p++;
|
||||
|
||||
for (end = p; *end && !isspace (*end); end++)
|
||||
;
|
||||
|
||||
if (*end == 0)
|
||||
break;
|
||||
else
|
||||
*end++ = 0;
|
||||
|
||||
if (i < device) {
|
||||
p = end;
|
||||
continue;
|
||||
}
|
||||
|
||||
fclose (f);
|
||||
|
||||
if (strlen (p) != 1)
|
||||
return FALSE;
|
||||
|
||||
if (*p == '0') {
|
||||
*online = FALSE;
|
||||
return TRUE;
|
||||
} else if (*p == '1') {
|
||||
*online = TRUE;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
fclose (f);
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static int
|
||||
is_Modem_on (glibtop *server, int device)
|
||||
{
|
||||
gchar buf[64], lock_file [BUFSIZ];
|
||||
pid_t pid = -1;
|
||||
FILE *f = 0;
|
||||
|
||||
sprintf (lock_file, LIBGTOP_MODEM_LOCKFILE, device);
|
||||
|
||||
f = fopen (lock_file, "r");
|
||||
|
||||
if(!f) return FALSE;
|
||||
|
||||
if (fgets (buf, sizeof(buf), f) == NULL) {
|
||||
fclose (f);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
fclose (f);
|
||||
|
||||
pid = (pid_t) strtol (buf, NULL, 10);
|
||||
if (pid < 1 || (kill (pid, 0) == -1 && errno != EPERM)) return FALSE;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static int
|
||||
get_Modem_stats (int device, int *in, int *out)
|
||||
{
|
||||
struct ifreq ifreq;
|
||||
struct ppp_stats stats;
|
||||
char device_name [IFNAMSIZ];
|
||||
|
||||
sprintf (device_name, "ppp%d", device);
|
||||
|
||||
memset (&ifreq, 0, sizeof(ifreq));
|
||||
strncpy (ifreq.ifr_ifrn.ifrn_name, device_name, IFNAMSIZ);
|
||||
ifreq.ifr_ifru.ifru_data = (caddr_t)&stats;
|
||||
|
||||
#ifdef SIOCDEVPRIVATE
|
||||
/* open ip socket */
|
||||
if ((ip_socket = socket(AF_INET, SOCK_DGRAM, 0)) < 0)
|
||||
{
|
||||
g_print("could not open an ip socket\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
if ((ioctl (ip_socket, SIOCDEVPRIVATE, (caddr_t)&ifreq) < 0)) {
|
||||
*in = *out = 0; /* failure means ppp is not up */
|
||||
return FALSE;
|
||||
} else {
|
||||
*in = stats.p.ppp_ibytes;
|
||||
*out = stats.p.ppp_obytes;
|
||||
return TRUE;
|
||||
}
|
||||
#else /* not SIOCDEVPRIVATE */
|
||||
*in = *out = 0;
|
||||
return FALSE;
|
||||
#endif /* not SIOCDEVPRIVATE */
|
||||
}
|
||||
|
||||
/* Provides PPP/ISDN information. */
|
||||
|
||||
int
|
||||
glibtop_get_ppp_s (glibtop *server, glibtop_ppp *buf, unsigned short device,
|
||||
unsigned short use_isdn)
|
||||
{
|
||||
int in, out, online;
|
||||
|
||||
glibtop_init_s (&server, GLIBTOP_SYSDEPS_PPP, 0);
|
||||
|
||||
memset (buf, 0, sizeof (glibtop_ppp));
|
||||
|
||||
if (use_isdn) {
|
||||
/* ISDN */
|
||||
if (is_ISDN_on (server, device, &online)) {
|
||||
buf->state = online ? GLIBTOP_PPP_STATE_ONLINE :
|
||||
GLIBTOP_PPP_STATE_HANGUP;
|
||||
buf->flags |= (1L << GLIBTOP_PPP_STATE);
|
||||
}
|
||||
|
||||
if (get_ISDN_stats (server, &in, &out)) {
|
||||
buf->bytes_in = in;
|
||||
buf->bytes_out = out;
|
||||
buf->flags |= (1L << GLIBTOP_PPP_BYTES_IN) |
|
||||
(1L << GLIBTOP_PPP_BYTES_OUT);
|
||||
}
|
||||
} else {
|
||||
/* Modem */
|
||||
buf->state = is_Modem_on (server, device) ?
|
||||
GLIBTOP_PPP_STATE_ONLINE : GLIBTOP_PPP_STATE_HANGUP;
|
||||
buf->flags |= (1L << GLIBTOP_PPP_STATE);
|
||||
|
||||
if (get_Modem_stats (device, &in, &out)) {
|
||||
buf->bytes_in = in;
|
||||
buf->bytes_out = out;
|
||||
buf->flags |= (1L << GLIBTOP_PPP_BYTES_IN) |
|
||||
(1L << GLIBTOP_PPP_BYTES_OUT);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
@@ -1,107 +0,0 @@
|
||||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright (C) 1998-99 Martin Baulig
|
||||
This file is part of LibGTop 1.0.
|
||||
|
||||
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/xmalloc.h>
|
||||
#include <glibtop/procargs.h>
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_proc_args =
|
||||
(1L << GLIBTOP_ARRAY_NUMBER) + (1L << GLIBTOP_ARRAY_SIZE);
|
||||
|
||||
/* Init function. */
|
||||
|
||||
int
|
||||
glibtop_init_proc_args_s (glibtop *server)
|
||||
{
|
||||
server->sysdeps.proc_args = _glibtop_sysdeps_proc_args;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Provides detailed information about a process. */
|
||||
|
||||
char **
|
||||
glibtop_get_proc_args_s (glibtop *server, glibtop_array *array, pid_t pid)
|
||||
{
|
||||
char fn [BUFSIZ], buffer [BUFSIZ], *ptr = NULL, *pos, **ptrlist;
|
||||
size_t count = 0, max_len, total = 0, len;
|
||||
int cmdline, i;
|
||||
|
||||
glibtop_init_s (&server, GLIBTOP_SYSDEPS_PROC_ARGS, 0);
|
||||
|
||||
memset (array, 0, sizeof (glibtop_array));
|
||||
|
||||
max_len = BUFSIZ;
|
||||
ptr = glibtop_malloc_r (server, max_len + 1);
|
||||
|
||||
sprintf (fn, "/proc/%d/cmdline", pid);
|
||||
|
||||
cmdline = open (fn, O_RDONLY);
|
||||
if (cmdline < 0) return NULL;
|
||||
|
||||
while (1) {
|
||||
len = read (cmdline, buffer, BUFSIZ-1);
|
||||
if (len < 0) {
|
||||
close (cmdline);
|
||||
glibtop_free_r (server, ptr);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (len == 0)
|
||||
break;
|
||||
|
||||
ptr = glibtop_realloc_r (server, ptr, total+len+1);
|
||||
memcpy (ptr+total, buffer, len);
|
||||
*(ptr+total+len) = 0;
|
||||
total += len;
|
||||
}
|
||||
|
||||
close (cmdline);
|
||||
|
||||
ptr [total] = '\0';
|
||||
|
||||
for (i = 0; i <= total; i++) {
|
||||
if (ptr [i]) continue;
|
||||
count++;
|
||||
}
|
||||
|
||||
ptrlist = glibtop_calloc_r (server, count+1, sizeof (char *));
|
||||
|
||||
for (i = 0, pos = ptr; i < count; i++) {
|
||||
ptrlist [i] = glibtop_strdup_r (server, pos);
|
||||
pos += strlen (pos) + 1;
|
||||
}
|
||||
|
||||
ptrlist [count] = NULL;
|
||||
|
||||
glibtop_free_r (server, ptr);
|
||||
|
||||
array->number = count;
|
||||
array->size = sizeof (char *);
|
||||
array->flags = _glibtop_sysdeps_proc_args;
|
||||
|
||||
return ptrlist;
|
||||
}
|
@@ -1,91 +0,0 @@
|
||||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright (C) 1998-99 Martin Baulig
|
||||
This file is part of LibGTop 1.0.
|
||||
|
||||
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/xmalloc.h>
|
||||
#include <glibtop/proccwd.h>
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_proc_cwd =
|
||||
(1L << GLIBTOP_PROC_CWD_SIZE);
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_proc_cwd_stat =
|
||||
(1L << GLIBTOP_PROC_CWD_DEVICE) + (1L << GLIBTOP_PROC_CWD_INODE);
|
||||
|
||||
/* Init function. */
|
||||
|
||||
int
|
||||
glibtop_init_proc_cwd_s (glibtop *server)
|
||||
{
|
||||
server->sysdeps.proc_cwd = _glibtop_sysdeps_proc_cwd |
|
||||
_glibtop_sysdeps_proc_cwd_stat;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Provides detailed information about a process. */
|
||||
|
||||
char *
|
||||
glibtop_get_proc_cwd_s (glibtop *server, glibtop_proc_cwd *buf, pid_t pid)
|
||||
{
|
||||
char fn [BUFSIZ], buffer [BUFSIZ], *retval = NULL;
|
||||
struct stat statb;
|
||||
int len;
|
||||
|
||||
glibtop_init_s (&server, GLIBTOP_SYSDEPS_PROC_CWD, 0);
|
||||
|
||||
memset (buf, 0, sizeof (glibtop_proc_cwd));
|
||||
|
||||
sprintf (fn, "/proc/%d/cwd", pid);
|
||||
|
||||
if (stat (fn, &statb)) {
|
||||
/* If we can't even stat () than we can't readlink (). */
|
||||
if (errno != EACCES) {
|
||||
/* Don't make too much unnecessary noise here. */
|
||||
glibtop_warn_io_r (server, "stat (%s)", fn);
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
|
||||
buf->device = statb.st_dev;
|
||||
buf->inode = statb.st_ino;
|
||||
buf->flags = _glibtop_sysdeps_proc_cwd_stat;
|
||||
|
||||
len = readlink (fn, buffer, BUFSIZ-1);
|
||||
|
||||
if (len < 0) {
|
||||
glibtop_warn_io_r (server, "readlink (%s)", fn);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
buffer [len] = '\0';
|
||||
|
||||
retval = glibtop_strdup_r (server, buffer);
|
||||
|
||||
buf->size = len+1;
|
||||
buf->flags |= _glibtop_sysdeps_proc_cwd;
|
||||
|
||||
return retval;
|
||||
}
|
@@ -1,83 +0,0 @@
|
||||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright (C) 1998-99 Martin Baulig
|
||||
This file is part of LibGTop 1.0.
|
||||
|
||||
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/prockernel.h>
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_proc_kernel =
|
||||
(1L << GLIBTOP_PROC_KERNEL_K_FLAGS) + (1L << GLIBTOP_PROC_KERNEL_MIN_FLT) +
|
||||
(1L << GLIBTOP_PROC_KERNEL_MAJ_FLT) + (1L << GLIBTOP_PROC_KERNEL_CMIN_FLT) +
|
||||
(1L << GLIBTOP_PROC_KERNEL_CMAJ_FLT) + (1L << GLIBTOP_PROC_KERNEL_KSTK_ESP) +
|
||||
(1L << GLIBTOP_PROC_KERNEL_KSTK_EIP) + (1L << GLIBTOP_PROC_KERNEL_WCHAN);
|
||||
|
||||
/* Init function. */
|
||||
|
||||
int
|
||||
glibtop_init_proc_kernel_s (glibtop *server)
|
||||
{
|
||||
server->sysdeps.proc_kernel = _glibtop_sysdeps_proc_kernel;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Provides detailed information about a process. */
|
||||
|
||||
int
|
||||
glibtop_get_proc_kernel_s (glibtop *server, glibtop_proc_kernel *buf, pid_t pid)
|
||||
{
|
||||
char buffer [BUFSIZ], *p;
|
||||
|
||||
glibtop_init_s (&server, GLIBTOP_SYSDEPS_PROC_KERNEL, 0);
|
||||
|
||||
memset (buf, 0, sizeof (glibtop_proc_kernel));
|
||||
|
||||
if (proc_stat_to_buffer (buffer, pid))
|
||||
return -1;
|
||||
|
||||
p = proc_stat_after_cmd (buffer);
|
||||
if (!p) return -1;
|
||||
|
||||
p = skip_multiple_token (p, 6);
|
||||
|
||||
buf->k_flags = strtoul (p, &p, 0);
|
||||
buf->min_flt = strtoul (p, &p, 0);
|
||||
buf->cmin_flt = strtoul (p, &p, 0);
|
||||
buf->maj_flt = strtoul (p, &p, 0);
|
||||
buf->cmaj_flt = strtoul (p, &p, 0);
|
||||
|
||||
p = skip_multiple_token (p, 15);
|
||||
|
||||
buf->kstk_esp = strtoul (p, &p, 0);
|
||||
buf->kstk_eip = strtoul (p, &p, 0);
|
||||
|
||||
p = skip_multiple_token (p, 4);
|
||||
|
||||
buf->nwchan = strtoul (p, &p, 0);
|
||||
|
||||
buf->flags = _glibtop_sysdeps_proc_kernel;
|
||||
|
||||
return 0;
|
||||
}
|
@@ -1,244 +0,0 @@
|
||||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright (C) 1998-99 Martin Baulig
|
||||
This file is part of LibGTop 1.0.
|
||||
|
||||
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 <config.h>
|
||||
#include <glibtop/xmalloc.h>
|
||||
#include <glibtop/proclist.h>
|
||||
|
||||
#include <glibtop/procuid.h>
|
||||
#include <glibtop/procstate.h>
|
||||
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#include <dirent.h>
|
||||
#include <ctype.h>
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_proclist =
|
||||
(1L << GLIBTOP_PROCLIST_TOTAL) + (1L << GLIBTOP_PROCLIST_NUMBER) +
|
||||
(1L << GLIBTOP_PROCLIST_SIZE);
|
||||
|
||||
/* Init function. */
|
||||
|
||||
int
|
||||
glibtop_init_proclist_s (glibtop *server)
|
||||
{
|
||||
server->sysdeps.proclist = _glibtop_sysdeps_proclist;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#define BLOCK_COUNT 256
|
||||
#define BLOCK_SIZE (BLOCK_COUNT * sizeof (unsigned))
|
||||
|
||||
/* 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.
|
||||
*
|
||||
* On error, NULL is returned and buf->flags is zero. */
|
||||
|
||||
unsigned *
|
||||
glibtop_get_proclist_s (glibtop *server, glibtop_proclist *buf,
|
||||
int64_t which, int64_t arg)
|
||||
{
|
||||
DIR *proc;
|
||||
struct dirent *entry;
|
||||
char buffer [BUFSIZ];
|
||||
unsigned count, total, pid;
|
||||
unsigned pids [BLOCK_COUNT], *pids_chain = NULL;
|
||||
unsigned pids_size = 0, pids_offset = 0, new_size;
|
||||
struct stat statb;
|
||||
int len, i, ok;
|
||||
|
||||
glibtop_proc_uid procuid;
|
||||
glibtop_proc_state procstate;
|
||||
|
||||
glibtop_init_s (&server, GLIBTOP_SYSDEPS_PROCLIST, 0);
|
||||
|
||||
memset (buf, 0, sizeof (glibtop_proclist));
|
||||
|
||||
proc = opendir ("/proc");
|
||||
if (!proc) return NULL;
|
||||
|
||||
/* read every every entry in /proc */
|
||||
|
||||
for (count = total = 0, entry = readdir (proc);
|
||||
entry; entry = readdir (proc)) {
|
||||
ok = 1; len = strlen (entry->d_name);
|
||||
|
||||
/* does it consist entirely of digits? */
|
||||
|
||||
for (i = 0; i < len; i++)
|
||||
if (!isdigit (entry->d_name [i])) ok = 0;
|
||||
if (!ok) continue;
|
||||
|
||||
/* convert it in a number */
|
||||
|
||||
if (sscanf (entry->d_name, "%u", &pid) != 1) continue;
|
||||
|
||||
/* is it really a directory? */
|
||||
|
||||
sprintf (buffer, "/proc/%d", pid);
|
||||
|
||||
if (stat (buffer, &statb)) continue;
|
||||
|
||||
if (!S_ISDIR (statb.st_mode)) continue;
|
||||
|
||||
switch (which & GLIBTOP_KERN_PROC_MASK) {
|
||||
case GLIBTOP_KERN_PROC_ALL:
|
||||
break;
|
||||
case GLIBTOP_KERN_PROC_PID:
|
||||
if ((unsigned) arg != pid)
|
||||
continue;
|
||||
break;
|
||||
case GLIBTOP_KERN_PROC_UID:
|
||||
if ((uid_t) arg != statb.st_uid)
|
||||
continue;
|
||||
break;
|
||||
case GLIBTOP_KERN_PROC_PGRP:
|
||||
/* Do you really, really need this ? */
|
||||
glibtop_get_proc_uid_s (server, &procuid, pid);
|
||||
if (procuid.flags & (1L << GLIBTOP_PROC_UID_PGRP))
|
||||
if ((int) arg != procuid.pgrp)
|
||||
continue;
|
||||
break;
|
||||
case GLIBTOP_KERN_PROC_PPID:
|
||||
/* Do you really, really need this ? */
|
||||
glibtop_get_proc_uid_s (server, &procuid, pid);
|
||||
if (procuid.flags & (1L << GLIBTOP_PROC_UID_PPID))
|
||||
if ((int) arg != procuid.ppid)
|
||||
continue;
|
||||
break;
|
||||
case GLIBTOP_KERN_PROC_SESSION:
|
||||
/* Do you really, really need this ? */
|
||||
glibtop_get_proc_uid_s (server, &procuid, pid);
|
||||
if (procuid.flags & (1L << GLIBTOP_PROC_UID_SESSION))
|
||||
if ((int) arg != procuid.session)
|
||||
continue;
|
||||
break;
|
||||
case GLIBTOP_KERN_PROC_TTY:
|
||||
/* Do you really, really need this ? */
|
||||
glibtop_get_proc_uid_s (server, &procuid, pid);
|
||||
if (procuid.flags & (1L << GLIBTOP_PROC_UID_TTY))
|
||||
if ((int) arg != procuid.tty)
|
||||
continue;
|
||||
break;
|
||||
case GLIBTOP_KERN_PROC_RUID:
|
||||
/* Do you really, really need this ? */
|
||||
glibtop_get_proc_uid_s (server, &procuid, pid);
|
||||
if (procuid.flags & (1L << GLIBTOP_PROC_UID_EUID))
|
||||
if ((int) arg != procuid.euid)
|
||||
continue;
|
||||
break;
|
||||
}
|
||||
|
||||
if (which & GLIBTOP_EXCLUDE_NOTTY) {
|
||||
glibtop_get_proc_uid_s (server, &procuid, pid);
|
||||
if (procuid.flags & (1L << GLIBTOP_PROC_UID_TTY))
|
||||
if (procuid.tty == -1) continue;
|
||||
}
|
||||
|
||||
if (which & GLIBTOP_EXCLUDE_IDLE) {
|
||||
glibtop_get_proc_state_s (server, &procstate, pid);
|
||||
if (procstate.flags & (1L << GLIBTOP_PROC_STATE_STATE))
|
||||
if (!(procstate.state & GLIBTOP_PROCESS_RUNNING)) continue;
|
||||
}
|
||||
|
||||
if (which & GLIBTOP_EXCLUDE_SYSTEM) {
|
||||
glibtop_get_proc_uid_s (server, &procuid, pid);
|
||||
if (procuid.flags & (1L << GLIBTOP_PROC_UID_UID))
|
||||
if (procuid.uid == 0) continue;
|
||||
}
|
||||
|
||||
/* Fine. Now we first try to store it in pids. If this buffer is
|
||||
* full, we copy it to the pids_chain. */
|
||||
|
||||
if (count >= BLOCK_COUNT) {
|
||||
/* The following call to glibtop_realloc will be
|
||||
* equivalent to glibtop_malloc () if `pids_chain' is
|
||||
* NULL. We just calculate the new size and copy `pids'
|
||||
* to the beginning of the newly allocated block. */
|
||||
|
||||
new_size = pids_size + BLOCK_SIZE;
|
||||
|
||||
pids_chain = glibtop_realloc_r
|
||||
(server, pids_chain, new_size);
|
||||
|
||||
memcpy (pids_chain + pids_offset, pids, BLOCK_SIZE);
|
||||
|
||||
pids_size = new_size;
|
||||
|
||||
pids_offset += BLOCK_COUNT;
|
||||
|
||||
count = 0;
|
||||
}
|
||||
|
||||
/* pids is now big enough to hold at least one single pid. */
|
||||
|
||||
pids [count++] = pid;
|
||||
|
||||
total++;
|
||||
}
|
||||
|
||||
closedir (proc);
|
||||
|
||||
/* count is only zero if an error occured (one a running Linux system,
|
||||
* we have at least one single process). */
|
||||
|
||||
if (!count) return NULL;
|
||||
|
||||
/* The following call to glibtop_realloc will be equivalent to
|
||||
* glibtop_malloc if pids_chain is NULL. We just calculate the
|
||||
* new size and copy pids to the beginning of the newly allocated
|
||||
* block. */
|
||||
|
||||
new_size = pids_size + count * sizeof (unsigned);
|
||||
|
||||
pids_chain = glibtop_realloc_r (server, pids_chain, new_size);
|
||||
|
||||
memcpy (pids_chain + pids_offset, pids, count * sizeof (unsigned));
|
||||
|
||||
pids_size = new_size;
|
||||
|
||||
pids_offset += BLOCK_COUNT;
|
||||
|
||||
/* Since everything is ok now, we can set buf->flags, fill in the
|
||||
* remaining fields and return the `pids_chain'. */
|
||||
|
||||
buf->flags = _glibtop_sysdeps_proclist;
|
||||
|
||||
buf->size = sizeof (unsigned);
|
||||
buf->number = total;
|
||||
|
||||
buf->total = total * sizeof (unsigned);
|
||||
|
||||
return pids_chain;
|
||||
}
|
@@ -1,142 +0,0 @@
|
||||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright (C) 1998-99 Martin Baulig
|
||||
This file is part of LibGTop 1.0.
|
||||
|
||||
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/xmalloc.h>
|
||||
#include <glibtop/procmap.h>
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_proc_map =
|
||||
(1L << GLIBTOP_PROC_MAP_NUMBER) + (1L << GLIBTOP_PROC_MAP_TOTAL) +
|
||||
(1L << GLIBTOP_PROC_MAP_SIZE);
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_map_entry =
|
||||
(1L << GLIBTOP_MAP_ENTRY_START) + (1L << GLIBTOP_MAP_ENTRY_END) +
|
||||
(1L << GLIBTOP_MAP_ENTRY_OFFSET) + (1L << GLIBTOP_MAP_ENTRY_PERM) +
|
||||
(1L << GLIBTOP_MAP_ENTRY_INODE) + (1L << GLIBTOP_MAP_ENTRY_DEVICE) +
|
||||
(1L << GLIBTOP_MAP_ENTRY_FILENAME);
|
||||
|
||||
/* Init function. */
|
||||
|
||||
int
|
||||
glibtop_init_proc_map_s (glibtop *server)
|
||||
{
|
||||
server->sysdeps.proc_map = _glibtop_sysdeps_proc_map;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Provides detailed information about a process. */
|
||||
|
||||
glibtop_map_entry *
|
||||
glibtop_get_proc_map_s (glibtop *server, glibtop_proc_map *buf, pid_t pid)
|
||||
{
|
||||
char fn [BUFSIZ];
|
||||
glibtop_map_entry *entry_list = NULL;
|
||||
int rv, n = 0;
|
||||
FILE *maps;
|
||||
|
||||
glibtop_init_s (&server, GLIBTOP_SYSDEPS_PROC_MAP, 0);
|
||||
|
||||
memset (buf, 0, sizeof (glibtop_proc_map));
|
||||
|
||||
sprintf (fn, "/proc/%d/maps", pid);
|
||||
|
||||
maps = fopen (fn, "r");
|
||||
if (!maps) return NULL;
|
||||
|
||||
do {
|
||||
short dev_major, dev_minor;
|
||||
unsigned long start, end, offset, inode, perm;
|
||||
char flags [5], *format;
|
||||
size_t size;
|
||||
|
||||
if (sizeof (void*) == 8)
|
||||
format = "%16lx-%16lx %4c\n %16lx %02hx:%02hx %ld";
|
||||
else
|
||||
format = "%08lx-%08lx %4c\n %08lx %02hx:%02hx %ld";
|
||||
|
||||
rv = fscanf (maps, format,
|
||||
&start, &end, flags, &offset,
|
||||
&dev_major, &dev_minor, &inode);
|
||||
|
||||
flags [4] = 0;
|
||||
|
||||
/* Compute access permissions. */
|
||||
|
||||
perm = 0;
|
||||
|
||||
if (flags [0] == 'r')
|
||||
perm |= GLIBTOP_MAP_PERM_READ;
|
||||
if (flags [1] == 'w')
|
||||
perm |= GLIBTOP_MAP_PERM_WRITE;
|
||||
if (flags [2] == 'x')
|
||||
perm |= GLIBTOP_MAP_PERM_EXECUTE;
|
||||
if (flags [3] == 's')
|
||||
perm |= GLIBTOP_MAP_PERM_SHARED;
|
||||
if (flags [3] == 'p')
|
||||
perm |= GLIBTOP_MAP_PERM_PRIVATE;
|
||||
|
||||
/* Read filename. */
|
||||
|
||||
fn [0] = fgetc (maps);
|
||||
|
||||
if (fn [0] != '\n' && fn [0] != EOF) {
|
||||
|
||||
fscanf (maps, "%*[ ]%[^\n]\n", fn);
|
||||
|
||||
} else fn [0] = 0;
|
||||
|
||||
size = (n+1) * sizeof (glibtop_map_entry);
|
||||
|
||||
entry_list = glibtop_realloc_r (server, entry_list, size);
|
||||
|
||||
memset (&(entry_list [n]), 0, sizeof (glibtop_map_entry));
|
||||
|
||||
entry_list [n].flags = _glibtop_sysdeps_map_entry;
|
||||
|
||||
entry_list [n].start = (u_int64_t) start;
|
||||
entry_list [n].end = (u_int64_t) end;
|
||||
entry_list [n].offset = (u_int64_t) offset;
|
||||
entry_list [n].perm = (u_int64_t) perm;
|
||||
entry_list [n].device = (u_int64_t) (dev_major << 8) +
|
||||
(u_int64_t) dev_minor;
|
||||
entry_list [n].inode = (u_int64_t) inode;
|
||||
|
||||
strncpy (entry_list [n].filename, fn, GLIBTOP_MAP_FILENAME_LEN);
|
||||
entry_list [n].filename [GLIBTOP_MAP_FILENAME_LEN] = 0;
|
||||
|
||||
n++;
|
||||
|
||||
} while (rv != EOF && rv && fn [0] != EOF);
|
||||
|
||||
fclose (maps);
|
||||
|
||||
buf->number = n;
|
||||
buf->size = sizeof (glibtop_map_entry);
|
||||
buf->total = n * sizeof (glibtop_map_entry);
|
||||
|
||||
return entry_list;
|
||||
}
|
@@ -1,110 +0,0 @@
|
||||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright (C) 1998-99 Martin Baulig
|
||||
This file is part of LibGTop 1.0.
|
||||
|
||||
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/procmem.h>
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_proc_mem =
|
||||
(1L << GLIBTOP_PROC_MEM_VSIZE) + (1L << GLIBTOP_PROC_MEM_RSS) +
|
||||
(1L << GLIBTOP_PROC_MEM_RSS_RLIM);
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_proc_mem_statm =
|
||||
(1L << GLIBTOP_PROC_MEM_SIZE) + (1L << GLIBTOP_PROC_MEM_RESIDENT) +
|
||||
(1L << GLIBTOP_PROC_MEM_SHARE);
|
||||
|
||||
#ifndef LOG1024
|
||||
#define LOG1024 10
|
||||
#endif
|
||||
|
||||
/* these are for getting the memory statistics */
|
||||
static int pageshift; /* log base 2 of the pagesize */
|
||||
|
||||
/* define pagetok in terms of pageshift */
|
||||
#define pagetok(size) ((size) << pageshift)
|
||||
|
||||
/* Init function. */
|
||||
|
||||
int
|
||||
glibtop_init_proc_mem_s (glibtop *server)
|
||||
{
|
||||
register int pagesize;
|
||||
|
||||
server->sysdeps.proc_mem = _glibtop_sysdeps_proc_mem |
|
||||
_glibtop_sysdeps_proc_mem_statm;
|
||||
|
||||
/* get the page size with "getpagesize" and calculate pageshift
|
||||
* from it */
|
||||
pagesize = getpagesize ();
|
||||
pageshift = 0;
|
||||
while (pagesize > 1) {
|
||||
pageshift++;
|
||||
pagesize >>= 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Provides detailed information about a process. */
|
||||
|
||||
int
|
||||
glibtop_get_proc_mem_s (glibtop *server, glibtop_proc_mem *buf, pid_t pid)
|
||||
{
|
||||
char buffer [BUFSIZ], *p;
|
||||
|
||||
glibtop_init_s (&server, GLIBTOP_SYSDEPS_MEM, 0);
|
||||
|
||||
memset (buf, 0, sizeof (glibtop_proc_mem));
|
||||
|
||||
if (proc_stat_to_buffer (buffer, pid))
|
||||
return -1;
|
||||
|
||||
p = proc_stat_after_cmd (buffer);
|
||||
if (!p) return -1;
|
||||
|
||||
p = skip_multiple_token (p, 20);
|
||||
|
||||
buf->vsize = strtoul (p, &p, 0);
|
||||
buf->rss = strtoul (p, &p, 0);
|
||||
buf->rss_rlim = strtoul (p, &p, 0);
|
||||
|
||||
buf->flags = _glibtop_sysdeps_proc_mem;
|
||||
|
||||
if (proc_statm_to_buffer (buffer, pid))
|
||||
return -1;
|
||||
|
||||
buf->size = strtoul (buffer, &p, 0);
|
||||
buf->resident = strtoul (p, &p, 0);
|
||||
buf->share = strtoul (p, &p, 0);
|
||||
|
||||
buf->size <<= pageshift;
|
||||
buf->resident <<= pageshift;
|
||||
buf->share <<= pageshift;
|
||||
buf->rss <<= pageshift;
|
||||
|
||||
buf->flags |= _glibtop_sysdeps_proc_mem_statm;
|
||||
|
||||
return 0;
|
||||
}
|
@@ -1,121 +0,0 @@
|
||||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright (C) 1998-99 Martin Baulig
|
||||
This file is part of LibGTop 1.0.
|
||||
|
||||
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 <config.h>
|
||||
#include <glibtop/error.h>
|
||||
#include <glibtop/procsegment.h>
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_proc_segment =
|
||||
(1L << GLIBTOP_PROC_SEGMENT_START_CODE) +
|
||||
(1L << GLIBTOP_PROC_SEGMENT_END_CODE) +
|
||||
(1L << GLIBTOP_PROC_SEGMENT_START_STACK);
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_proc_segment_statm =
|
||||
(1L << GLIBTOP_PROC_SEGMENT_TEXT_RSS) +
|
||||
/* Disabled due to bug in the Linux Kernel. */
|
||||
/* (1L << GLIBTOP_PROC_SEGMENT_SHLIB_RSS) + */
|
||||
(1L << GLIBTOP_PROC_SEGMENT_DATA_RSS) +
|
||||
(1L << GLIBTOP_PROC_SEGMENT_DIRTY_SIZE);
|
||||
|
||||
#ifndef LOG1024
|
||||
#define LOG1024 10
|
||||
#endif
|
||||
|
||||
/* these are for getting the memory statistics */
|
||||
static int pageshift; /* log base 2 of the pagesize */
|
||||
|
||||
/* define pagetok in terms of pageshift */
|
||||
#define pagetok(size) ((size) << pageshift)
|
||||
|
||||
/* Init function. */
|
||||
|
||||
int
|
||||
glibtop_init_proc_segment_s (glibtop *server)
|
||||
{
|
||||
register int pagesize;
|
||||
|
||||
server->sysdeps.proc_segment = _glibtop_sysdeps_proc_segment |
|
||||
_glibtop_sysdeps_proc_segment_statm;
|
||||
|
||||
/* get the page size with "getpagesize" and calculate pageshift
|
||||
* from it */
|
||||
pagesize = getpagesize ();
|
||||
pageshift = 0;
|
||||
while (pagesize > 1) {
|
||||
pageshift++;
|
||||
pagesize >>= 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Provides detailed information about a process. */
|
||||
|
||||
int
|
||||
glibtop_get_proc_segment_s (glibtop *server, glibtop_proc_segment *buf,
|
||||
pid_t pid)
|
||||
{
|
||||
char buffer [BUFSIZ], *p;
|
||||
|
||||
glibtop_init_s (&server, GLIBTOP_SYSDEPS_PROC_SEGMENT, 0);
|
||||
|
||||
memset (buf, 0, sizeof (glibtop_proc_segment));
|
||||
|
||||
if (proc_stat_to_buffer (buffer, pid))
|
||||
return -1;
|
||||
|
||||
p = proc_stat_after_cmd (buffer);
|
||||
if (!p) return -1;
|
||||
|
||||
p = skip_multiple_token (p, 23);
|
||||
|
||||
buf->start_code = strtoul (p, &p, 0);
|
||||
buf->end_code = strtoul (p, &p, 0);
|
||||
buf->start_stack = strtoul (p, &p, 0);
|
||||
|
||||
buf->flags = _glibtop_sysdeps_proc_segment;
|
||||
|
||||
if (proc_statm_to_buffer (buffer, pid))
|
||||
return 0;
|
||||
|
||||
p = skip_multiple_token (buffer, 3);
|
||||
|
||||
/* This doesn't work very well due to a bug in the Linux kernel.
|
||||
* I'll submit a patch to the kernel mailing list soon. */
|
||||
|
||||
buf->text_rss = strtoul (p, &p, 0);
|
||||
buf->shlib_rss = strtoul (p, &p, 0);
|
||||
buf->data_rss = strtoul (p, &p, 0);
|
||||
buf->dirty_size = strtoul (p, &p, 0);
|
||||
|
||||
buf->text_rss <<= pageshift;
|
||||
buf->shlib_rss <<= pageshift;
|
||||
buf->data_rss <<= pageshift;
|
||||
buf->dirty_size <<= pageshift;
|
||||
|
||||
buf->flags |= _glibtop_sysdeps_proc_segment_statm;
|
||||
|
||||
return 0;
|
||||
}
|
@@ -1,71 +0,0 @@
|
||||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright (C) 1998-99 Martin Baulig
|
||||
This file is part of LibGTop 1.0.
|
||||
|
||||
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/procsignal.h>
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_proc_signal =
|
||||
(1L << GLIBTOP_PROC_SIGNAL_SIGNAL) + (1L << GLIBTOP_PROC_SIGNAL_BLOCKED) +
|
||||
(1L << GLIBTOP_PROC_SIGNAL_SIGIGNORE) + (1L << GLIBTOP_PROC_SIGNAL_SIGCATCH);
|
||||
|
||||
/* Init function. */
|
||||
|
||||
int
|
||||
glibtop_init_proc_signal_s (glibtop *server)
|
||||
{
|
||||
server->sysdeps.proc_signal = _glibtop_sysdeps_proc_signal;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Provides detailed information about a process. */
|
||||
|
||||
int
|
||||
glibtop_get_proc_signal_s (glibtop *server, glibtop_proc_signal *buf, pid_t pid)
|
||||
{
|
||||
char buffer [BUFSIZ], *p;
|
||||
|
||||
glibtop_init_s (&server, GLIBTOP_SYSDEPS_PROC_SIGNAL, 0);
|
||||
|
||||
memset (buf, 0, sizeof (glibtop_proc_signal));
|
||||
|
||||
if (proc_stat_to_buffer (buffer, pid))
|
||||
return -1;
|
||||
|
||||
p = proc_stat_after_cmd (buffer);
|
||||
if (!p) return -1;
|
||||
|
||||
p = skip_multiple_token (p, 28);
|
||||
|
||||
buf->signal [0] = strtoul (p, &p, 0);
|
||||
buf->blocked [0] = strtoul (p, &p, 0);
|
||||
buf->sigignore [0] = strtoul (p, &p, 0);
|
||||
buf->sigcatch [0] = strtoul (p, &p, 0);
|
||||
|
||||
buf->flags = _glibtop_sysdeps_proc_signal;
|
||||
|
||||
return 0;
|
||||
}
|
@@ -1,124 +0,0 @@
|
||||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright (C) 1998-99 Martin Baulig
|
||||
This file is part of LibGTop 1.0.
|
||||
|
||||
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/procstate.h>
|
||||
|
||||
#include <sys/stat.h>
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_proc_state =
|
||||
(1L << GLIBTOP_PROC_STATE_CMD);
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_proc_state_uid =
|
||||
(1L << GLIBTOP_PROC_STATE_UID) + (1L << GLIBTOP_PROC_STATE_GID);
|
||||
|
||||
/* Init function. */
|
||||
|
||||
int
|
||||
glibtop_init_proc_state_s (glibtop *server)
|
||||
{
|
||||
server->sysdeps.proc_state = _glibtop_sysdeps_proc_state |
|
||||
_glibtop_sysdeps_proc_state_uid;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Provides detailed information about a process. */
|
||||
|
||||
int
|
||||
glibtop_get_proc_state_s (glibtop *server, glibtop_proc_state *buf, pid_t pid)
|
||||
{
|
||||
char buffer [BUFSIZ], state, *p;
|
||||
struct stat statb;
|
||||
|
||||
glibtop_init_s (&server, GLIBTOP_SYSDEPS_PROC_STATE, 0);
|
||||
|
||||
memset (buf, 0, sizeof (glibtop_proc_state));
|
||||
|
||||
/* IMPORTANT NOTICE: For security reasons it is extremely important
|
||||
* that the 'uid' and 'gid' fields have correct
|
||||
* values; NEVER set their flags values if this
|
||||
* is not the case !!! */
|
||||
|
||||
sprintf (buffer, "/proc/%d", pid);
|
||||
|
||||
if (stat (buffer, &statb))
|
||||
return -1;
|
||||
|
||||
/* For security reasons we use stat () since it is
|
||||
* more failsafe than parsing the file. */
|
||||
|
||||
buf->uid = statb.st_uid;
|
||||
buf->gid = statb.st_gid;
|
||||
|
||||
buf->flags = _glibtop_sysdeps_proc_state_uid;
|
||||
|
||||
sprintf (buffer, "/proc/%d", pid);
|
||||
|
||||
/* Now we read the remaining fields. */
|
||||
|
||||
if (proc_stat_to_buffer (buffer, pid))
|
||||
return -1;
|
||||
|
||||
p = strrchr (buffer, ')'); *p = '\0';
|
||||
state = p [2];
|
||||
|
||||
p = skip_token (buffer); p++; /* pid */
|
||||
if (*p++ != '(')
|
||||
glibtop_error_r (server, "Bad data in /proc/%d/stat", pid);
|
||||
|
||||
strncpy (buf->cmd, p, sizeof (buf->cmd)-1);
|
||||
buf->cmd [sizeof (buf->cmd)-1] = 0;
|
||||
|
||||
buf->flags |= _glibtop_sysdeps_proc_state;
|
||||
|
||||
switch (state) {
|
||||
case 'R':
|
||||
buf->state = GLIBTOP_PROCESS_RUNNING;
|
||||
break;
|
||||
case 'S':
|
||||
buf->state = GLIBTOP_PROCESS_INTERRUPTIBLE;
|
||||
break;
|
||||
case 'D':
|
||||
buf->state = GLIBTOP_PROCESS_UNINTERRUPTIBLE;
|
||||
break;
|
||||
case 'Z':
|
||||
buf->state = GLIBTOP_PROCESS_ZOMBIE;
|
||||
break;
|
||||
case 'T':
|
||||
buf->state = GLIBTOP_PROCESS_STOPPED;
|
||||
break;
|
||||
case 'W':
|
||||
buf->state = GLIBTOP_PROCESS_SWAPPING;
|
||||
break;
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
|
||||
buf->flags |= (1L << GLIBTOP_PROC_STATE_STATE);
|
||||
|
||||
return 0;
|
||||
}
|
@@ -1,109 +0,0 @@
|
||||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright (C) 1998-99 Martin Baulig
|
||||
This file is part of LibGTop 1.0.
|
||||
|
||||
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/proctime.h>
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_proc_time =
|
||||
(1L << GLIBTOP_PROC_TIME_UTIME) + (1L << GLIBTOP_PROC_TIME_CUTIME) +
|
||||
(1L << GLIBTOP_PROC_TIME_STIME) + (1L << GLIBTOP_PROC_TIME_CSTIME) +
|
||||
(1L << GLIBTOP_PROC_TIME_FREQUENCY) + (1L << GLIBTOP_PROC_TIME_TIMEOUT) +
|
||||
(1L << GLIBTOP_PROC_TIME_IT_REAL_VALUE) + (1L << GLIBTOP_PROC_TIME_START_TIME);
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_proc_time_smp =
|
||||
(1L << GLIBTOP_PROC_TIME_XCPU_UTIME) + (1L << GLIBTOP_PROC_TIME_XCPU_STIME);
|
||||
|
||||
/* Init function. */
|
||||
|
||||
int
|
||||
glibtop_init_proc_time_s (glibtop *server)
|
||||
{
|
||||
server->sysdeps.proc_time = _glibtop_sysdeps_proc_time;
|
||||
|
||||
if (server->ncpu)
|
||||
server->sysdeps.proc_time |= _glibtop_sysdeps_proc_time_smp;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Provides detailed information about a process. */
|
||||
|
||||
int
|
||||
glibtop_get_proc_time_s (glibtop *server, glibtop_proc_time *buf, pid_t pid)
|
||||
{
|
||||
char buffer [BUFSIZ], *p;
|
||||
int i;
|
||||
|
||||
glibtop_init_s (&server, GLIBTOP_SYSDEPS_PROC_TIME, 0);
|
||||
|
||||
memset (buf, 0, sizeof (glibtop_proc_time));
|
||||
|
||||
if (proc_stat_to_buffer (buffer, pid))
|
||||
return -1;
|
||||
|
||||
p = proc_stat_after_cmd (buffer);
|
||||
if (!p) return -1;
|
||||
|
||||
p = skip_multiple_token (p, 11);
|
||||
|
||||
buf->utime = strtoul (p, &p, 0);
|
||||
buf->stime = strtoul (p, &p, 0);
|
||||
buf->cutime = strtoul (p, &p, 0);
|
||||
buf->cstime = strtoul (p, &p, 0);
|
||||
|
||||
p = skip_multiple_token (p, 2);
|
||||
|
||||
buf->timeout = strtoul (p, &p, 0);
|
||||
buf->it_real_value = strtoul (p, &p, 0);
|
||||
buf->start_time = strtoul (p, &p, 0);
|
||||
|
||||
buf->frequency = 100;
|
||||
|
||||
buf->flags = _glibtop_sysdeps_proc_time;
|
||||
|
||||
if (!server->ncpu)
|
||||
return 0;
|
||||
|
||||
if (proc_file_to_buffer (buffer, "/proc/%d/cpu", pid))
|
||||
return -1;
|
||||
|
||||
p = skip_token (buffer);
|
||||
buf->utime = strtoul (p, &p, 0);
|
||||
buf->stime = strtoul (p, &p, 0);
|
||||
|
||||
for (i = 0; i < GLIBTOP_NCPU; i++) {
|
||||
if (strncmp (p+1, "cpu", 3) || !isdigit (p [4]))
|
||||
break;
|
||||
|
||||
p += 6;
|
||||
buf->xcpu_utime [i] = strtoul (p, &p, 0);
|
||||
buf->xcpu_stime [i] = strtoul (p, &p, 0);
|
||||
}
|
||||
|
||||
buf->flags |= _glibtop_sysdeps_proc_time_smp;
|
||||
|
||||
return 0;
|
||||
}
|
@@ -1,132 +0,0 @@
|
||||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright (C) 1998-99 Martin Baulig
|
||||
This file is part of LibGTop 1.0.
|
||||
|
||||
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/procuid.h>
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_proc_uid =
|
||||
(1L << GLIBTOP_PROC_UID_UID) + (1L << GLIBTOP_PROC_UID_EUID) +
|
||||
(1L << GLIBTOP_PROC_UID_GID) + (1L << GLIBTOP_PROC_UID_EGID);
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_proc_uid_stat =
|
||||
(1L << GLIBTOP_PROC_UID_PID) + (1L << GLIBTOP_PROC_UID_PPID) +
|
||||
(1L << GLIBTOP_PROC_UID_PGRP) + (1L << GLIBTOP_PROC_UID_SESSION) +
|
||||
(1L << GLIBTOP_PROC_UID_TTY) + (1L << GLIBTOP_PROC_UID_TPGID) +
|
||||
(1L << GLIBTOP_PROC_UID_PRIORITY) + (1L << GLIBTOP_PROC_UID_NICE);
|
||||
|
||||
#define LINUX_VERSION(x,y,z) (0x10000*(x) + 0x100*(y) + z)
|
||||
|
||||
/* Init function. */
|
||||
|
||||
int
|
||||
glibtop_init_proc_uid_s (glibtop *server)
|
||||
{
|
||||
server->sysdeps.proc_uid = _glibtop_sysdeps_proc_uid |
|
||||
_glibtop_sysdeps_proc_uid_stat;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Provides detailed information about a process. */
|
||||
|
||||
int
|
||||
glibtop_get_proc_uid_s (glibtop *server, glibtop_proc_uid *buf, pid_t pid)
|
||||
{
|
||||
char buffer [BUFSIZ], *p;
|
||||
|
||||
glibtop_init_s (&server, GLIBTOP_SYSDEPS_PROC_UID, 0);
|
||||
|
||||
memset (buf, 0, sizeof (glibtop_proc_uid));
|
||||
|
||||
if (proc_status_to_buffer (buffer, pid))
|
||||
return -1;
|
||||
|
||||
/* Search substring 'Pid:' */
|
||||
|
||||
p = strstr (buffer, "\nPid:");
|
||||
if (!p) return -1;
|
||||
|
||||
p = skip_token (p); /* "Pid:" */
|
||||
buf->pid = strtoul (p, &p, 0);
|
||||
|
||||
p = skip_token (p); /* "PPid:" */
|
||||
buf->ppid = strtoul (p, &p, 0);
|
||||
|
||||
/* Maybe future Linux versions place something between
|
||||
* "PPid" and "Uid", so we catch this here. */
|
||||
p = strstr (p, "\nUid:");
|
||||
if (!p) return -1;
|
||||
|
||||
p = skip_token (p); /* "Uid:" */
|
||||
buf->uid = strtoul (p, &p, 0);
|
||||
buf->euid = strtoul (p, &p, 0);
|
||||
|
||||
/* We don't know how many entries on the "Uid:" line
|
||||
* future Linux version will have, so we catch this here. */
|
||||
p = strstr (p, "\nGid:");
|
||||
if (!p) return -1;
|
||||
|
||||
p = skip_token (p); /* "Gid:" */
|
||||
buf->gid = strtoul (p, &p, 0);
|
||||
buf->egid = strtoul (p, &p, 0);
|
||||
|
||||
buf->flags = _glibtop_sysdeps_proc_uid;
|
||||
|
||||
if (proc_stat_to_buffer (buffer, pid))
|
||||
return -1;
|
||||
|
||||
p = proc_stat_after_cmd (buffer);
|
||||
if (!p) return -1;
|
||||
|
||||
p = skip_multiple_token (p, 2);
|
||||
|
||||
buf->pgrp = strtoul (p, &p, 0);
|
||||
buf->session = strtoul (p, &p, 0);
|
||||
buf->tty = strtoul (p, &p, 0);
|
||||
buf->tpgid = strtoul (p, &p, 0);
|
||||
|
||||
p = skip_multiple_token (p, 9);
|
||||
|
||||
buf->priority = strtoul (p, &p, 0);
|
||||
buf->nice = strtoul (p, &p, 0);
|
||||
|
||||
if (buf->tty == 0)
|
||||
/* the old notty val, update elsewhere bef. moving to 0 */
|
||||
buf->tty = -1;
|
||||
|
||||
if (server->_param.os_version_code < LINUX_VERSION(1,3,39)) {
|
||||
/* map old meanings to new */
|
||||
buf->priority = 2*15 - buf->priority;
|
||||
buf->nice = 15 - buf->nice;
|
||||
}
|
||||
if (server->os_version_code < LINUX_VERSION(1,1,30) && buf->tty != -1)
|
||||
/* when tty wasn't full devno */
|
||||
buf->tty = 4*0x100 + buf->tty;
|
||||
|
||||
buf->flags |= _glibtop_sysdeps_proc_uid_stat;
|
||||
|
||||
return 0;
|
||||
}
|
@@ -1,92 +0,0 @@
|
||||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright (C) 1998-99 Martin Baulig
|
||||
This file is part of LibGTop 1.0.
|
||||
|
||||
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/sem_limits.h>
|
||||
|
||||
#include <sys/ipc.h>
|
||||
#include <sys/sem.h>
|
||||
|
||||
#ifdef _SEM_SEMUN_UNDEFINED
|
||||
|
||||
/* glibc 2.1 will no longer defines semun, instead it defines
|
||||
* _SEM_SEMUN_UNDEFINED so users can define semun on their own.
|
||||
* Thanks to Albert K T Hui <avatar@deva.net>. */
|
||||
|
||||
union semun
|
||||
{
|
||||
int val;
|
||||
struct semid_ds *buf;
|
||||
unsigned short int *array;
|
||||
struct seminfo *__buf;
|
||||
};
|
||||
#endif
|
||||
|
||||
static unsigned long _glibtop_sysdeps_sem_limits =
|
||||
(1L << GLIBTOP_SEM_LIMITS_SEMMAP) + (1L << GLIBTOP_SEM_LIMITS_SEMMNI) +
|
||||
(1L << GLIBTOP_SEM_LIMITS_SEMMNS) + (1L << GLIBTOP_SEM_LIMITS_SEMMNU) +
|
||||
(1L << GLIBTOP_SEM_LIMITS_SEMMSL) + (1L << GLIBTOP_SEM_LIMITS_SEMOPM) +
|
||||
(1L << GLIBTOP_SEM_LIMITS_SEMUME) + (1L << GLIBTOP_SEM_LIMITS_SEMUSZ) +
|
||||
(1L << GLIBTOP_SEM_LIMITS_SEMVMX) + (1L << GLIBTOP_SEM_LIMITS_SEMAEM);
|
||||
|
||||
/* Init function. */
|
||||
|
||||
int
|
||||
glibtop_init_sem_limits_s (glibtop *server)
|
||||
{
|
||||
server->sysdeps.sem_limits = _glibtop_sysdeps_sem_limits;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Provides information about sysv ipc limits. */
|
||||
|
||||
int
|
||||
glibtop_get_sem_limits_s (glibtop *server, glibtop_sem_limits *buf)
|
||||
{
|
||||
struct seminfo seminfo;
|
||||
union semun arg;
|
||||
|
||||
glibtop_init_s (&server, GLIBTOP_SYSDEPS_SEM_LIMITS, 0);
|
||||
|
||||
memset (buf, 0, sizeof (glibtop_sem_limits));
|
||||
|
||||
buf->flags = _glibtop_sysdeps_sem_limits;
|
||||
|
||||
arg.array = (ushort *) &seminfo;
|
||||
semctl (0, 0, IPC_INFO, arg);
|
||||
|
||||
buf->semmap = seminfo.semmap;
|
||||
buf->semmni = seminfo.semmni;
|
||||
buf->semmns = seminfo.semmns;
|
||||
buf->semmnu = seminfo.semmnu;
|
||||
buf->semmsl = seminfo.semmsl;
|
||||
buf->semopm = seminfo.semopm;
|
||||
buf->semume = seminfo.semume;
|
||||
buf->semusz = seminfo.semusz;
|
||||
buf->semvmx = seminfo.semvmx;
|
||||
buf->semaem = seminfo.semaem;
|
||||
|
||||
return 0;
|
||||
}
|
@@ -1,68 +0,0 @@
|
||||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright (C) 1998-99 Martin Baulig
|
||||
This file is part of LibGTop 1.0.
|
||||
|
||||
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/shm_limits.h>
|
||||
|
||||
#include <sys/ipc.h>
|
||||
#include <sys/shm.h>
|
||||
|
||||
static unsigned long _glibtop_sysdeps_shm_limits =
|
||||
(1L << GLIBTOP_SHM_LIMITS_SHMMAX) + (1L << GLIBTOP_SHM_LIMITS_SHMMIN) +
|
||||
(1L << GLIBTOP_SHM_LIMITS_SHMMNI) + (1L << GLIBTOP_SHM_LIMITS_SHMSEG) +
|
||||
(1L << GLIBTOP_SHM_LIMITS_SHMALL);
|
||||
|
||||
/* Init function. */
|
||||
|
||||
int
|
||||
glibtop_init_shm_limits_s (glibtop *server)
|
||||
{
|
||||
server->sysdeps.shm_limits = _glibtop_sysdeps_shm_limits;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Provides information about sysv ipc limits. */
|
||||
|
||||
int
|
||||
glibtop_get_shm_limits_s (glibtop *server, glibtop_shm_limits *buf)
|
||||
{
|
||||
struct shminfo shminfo;
|
||||
|
||||
glibtop_init_s (&server, GLIBTOP_SYSDEPS_SHM_LIMITS, 0);
|
||||
|
||||
memset (buf, 0, sizeof (glibtop_shm_limits));
|
||||
|
||||
buf->flags = _glibtop_sysdeps_shm_limits;
|
||||
|
||||
shmctl (0, IPC_INFO, (struct shmid_ds *) &shminfo);
|
||||
|
||||
buf->shmmax = shminfo.shmmax;
|
||||
buf->shmmin = shminfo.shmmin;
|
||||
buf->shmmni = shminfo.shmmni;
|
||||
buf->shmseg = shminfo.shmseg;
|
||||
buf->shmall = shminfo.shmall;
|
||||
|
||||
return 0;
|
||||
}
|
@@ -1,120 +0,0 @@
|
||||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright (C) 1998-99 Martin Baulig
|
||||
This file is part of LibGTop 1.0.
|
||||
|
||||
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 <config.h>
|
||||
#include <glibtop/error.h>
|
||||
#include <glibtop/swap.h>
|
||||
|
||||
#include <fcntl.h>
|
||||
|
||||
static unsigned long _glibtop_sysdeps_swap =
|
||||
(1L << GLIBTOP_SWAP_TOTAL) + (1L << GLIBTOP_SWAP_USED) +
|
||||
(1L << GLIBTOP_SWAP_FREE);
|
||||
|
||||
static unsigned long _glibtop_sysdeps_swap_paging =
|
||||
(1L << GLIBTOP_SWAP_PAGEIN) + (1L << GLIBTOP_SWAP_PAGEOUT);
|
||||
|
||||
/* Init function. */
|
||||
|
||||
int
|
||||
glibtop_init_swap_s (glibtop *server)
|
||||
{
|
||||
server->sysdeps.swap = _glibtop_sysdeps_swap |
|
||||
_glibtop_sysdeps_swap_paging;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Provides information about swap usage. */
|
||||
|
||||
#define MEMINFO "/proc/meminfo"
|
||||
#define PROC_STAT "/proc/stat"
|
||||
|
||||
int
|
||||
glibtop_get_swap_s (glibtop *server, glibtop_swap *buf)
|
||||
{
|
||||
char buffer [BUFSIZ], *p;
|
||||
int fd, len;
|
||||
|
||||
glibtop_init_s (&server, GLIBTOP_SYSDEPS_SWAP, 0);
|
||||
|
||||
memset (buf, 0, sizeof (glibtop_swap));
|
||||
|
||||
fd = open (MEMINFO, O_RDONLY);
|
||||
if (fd < 0) {
|
||||
glibtop_warn_io_r (server, "open (%s)", MEMINFO);
|
||||
return -1;
|
||||
}
|
||||
|
||||
len = read (fd, buffer, BUFSIZ-1);
|
||||
if (len < 0) {
|
||||
close (fd);
|
||||
glibtop_warn_io_r (server, "read (%s)", MEMINFO);
|
||||
return -1;
|
||||
}
|
||||
|
||||
close (fd);
|
||||
|
||||
buffer [len] = '\0';
|
||||
|
||||
p = skip_line (buffer);
|
||||
p = skip_line (p);
|
||||
p = skip_token (p); /* "Swap:" */
|
||||
|
||||
buf->total = strtoul (p, &p, 0);
|
||||
buf->used = strtoul (p, &p, 0);
|
||||
buf->free = strtoul (p, &p, 0);
|
||||
|
||||
buf->flags = _glibtop_sysdeps_swap;
|
||||
|
||||
fd = open (PROC_STAT, O_RDONLY);
|
||||
if (fd < 0) {
|
||||
glibtop_warn_io_r (server, "open (%s)", PROC_STAT);
|
||||
return -1;
|
||||
}
|
||||
|
||||
len = read (fd, buffer, BUFSIZ-1);
|
||||
if (len < 0) {
|
||||
close (fd);
|
||||
glibtop_warn_io_r (server, "read (%s)", PROC_STAT);
|
||||
return -1;
|
||||
}
|
||||
|
||||
close (fd);
|
||||
|
||||
buffer [len] = '\0';
|
||||
|
||||
p = strstr (buffer, "\nswap");
|
||||
if (p == NULL) return 0;
|
||||
|
||||
p = skip_token (p);
|
||||
|
||||
buf->pagein = strtoul (p, &p, 0);
|
||||
buf->pageout = strtoul (p, &p, 0);
|
||||
|
||||
buf->flags |= _glibtop_sysdeps_swap_paging;
|
||||
|
||||
return 0;
|
||||
}
|
@@ -1,96 +0,0 @@
|
||||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright (C) 1998-99 Martin Baulig
|
||||
This file is part of LibGTop 1.0.
|
||||
|
||||
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 <config.h>
|
||||
#include <glibtop/cpu.h>
|
||||
#include <glibtop/sysinfo.h>
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_sysinfo =
|
||||
(1L << GLIBTOP_SYSINFO_CPUINFO);
|
||||
|
||||
static glibtop_sysinfo sysinfo;
|
||||
|
||||
static void
|
||||
init_sysinfo (glibtop *server)
|
||||
{
|
||||
char buffer [BUFSIZ];
|
||||
static int init = 0;
|
||||
glibtop_entry *cpuinfo = NULL;
|
||||
FILE *f;
|
||||
|
||||
if (init) return;
|
||||
|
||||
init = TRUE;
|
||||
|
||||
glibtop_init_s (&server, GLIBTOP_SYSDEPS_CPU, 0);
|
||||
|
||||
memset (&sysinfo, 0, sizeof (glibtop_sysinfo));
|
||||
|
||||
g_return_if_fail (f = fopen ("/proc/cpuinfo", "r"));
|
||||
|
||||
while (fgets (buffer, BUFSIZ, f)) {
|
||||
char *p, *start, *key, *value;
|
||||
|
||||
if (cpuinfo == NULL) {
|
||||
cpuinfo = &sysinfo.cpuinfo [sysinfo.ncpu++];
|
||||
|
||||
cpuinfo->labels = g_ptr_array_new ();
|
||||
|
||||
cpuinfo->values = g_hash_table_new (NULL, NULL);
|
||||
|
||||
if (sysinfo.ncpu > GLIBTOP_NCPU)
|
||||
sysinfo.ncpu = GLIBTOP_NCPU;
|
||||
}
|
||||
|
||||
p = strchr (buffer, ':');
|
||||
if (!p) continue;
|
||||
|
||||
/* Remove leading spaces from `p'. */
|
||||
*p = '\0'; start = p; p++;
|
||||
while (isspace (*p)) p++;
|
||||
|
||||
/* Remove trailing spaces from `buffer'. */
|
||||
while ((start > buffer) && (*start) && isspace (*start))
|
||||
*start-- = '\0';
|
||||
|
||||
key = g_strdup (buffer);
|
||||
value = g_strdup (p);
|
||||
|
||||
g_ptr_array_add (cpuinfo->labels, key);
|
||||
|
||||
g_hash_table_insert (cpuinfo->values, key, value);
|
||||
}
|
||||
|
||||
fclose (f);
|
||||
|
||||
sysinfo.flags = _glibtop_sysdeps_sysinfo;
|
||||
}
|
||||
|
||||
glibtop_sysinfo *
|
||||
glibtop_get_sysinfo_s (glibtop *server)
|
||||
{
|
||||
init_sysinfo (server);
|
||||
return &sysinfo;
|
||||
}
|
@@ -1,80 +0,0 @@
|
||||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright (C) 1998-99 Martin Baulig
|
||||
This file is part of LibGTop 1.0.
|
||||
|
||||
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 <config.h>
|
||||
#include <glibtop/error.h>
|
||||
#include <glibtop/uptime.h>
|
||||
|
||||
static unsigned long _glibtop_sysdeps_uptime =
|
||||
(1L << GLIBTOP_UPTIME_UPTIME) + (1L << GLIBTOP_UPTIME_IDLETIME);
|
||||
|
||||
/* Init function. */
|
||||
|
||||
int
|
||||
glibtop_init_uptime_s (glibtop *server)
|
||||
{
|
||||
server->sysdeps.uptime = _glibtop_sysdeps_uptime;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Provides uptime and idle time. */
|
||||
|
||||
#define FILENAME "/proc/uptime"
|
||||
|
||||
int
|
||||
glibtop_get_uptime_s (glibtop *server, glibtop_uptime *buf)
|
||||
{
|
||||
char buffer [BUFSIZ], *p;
|
||||
int fd, len;
|
||||
|
||||
glibtop_init_s (&server, GLIBTOP_SYSDEPS_UPTIME, 0);
|
||||
|
||||
memset (buf, 0, sizeof (glibtop_uptime));
|
||||
|
||||
fd = open (FILENAME, O_RDONLY);
|
||||
if (fd < 0) {
|
||||
glibtop_warn_io_r (server, "open (%s)", FILENAME);
|
||||
return -1;
|
||||
}
|
||||
|
||||
len = read (fd, buffer, BUFSIZ-1);
|
||||
if (len < 0) {
|
||||
close (fd);
|
||||
glibtop_warn_io_r (server, "read (%s)", FILENAME);
|
||||
return -1;
|
||||
}
|
||||
|
||||
close (fd);
|
||||
|
||||
buffer [len] = '\0';
|
||||
|
||||
buf->uptime = strtod (buffer, &p);
|
||||
buf->idletime = strtod (p, &p);
|
||||
|
||||
buf->flags = _glibtop_sysdeps_uptime;
|
||||
|
||||
return 0;
|
||||
}
|
@@ -1,21 +0,0 @@
|
||||
.deps
|
||||
.libs
|
||||
Makefile
|
||||
Makefile.in
|
||||
close.lo
|
||||
cpu.lo
|
||||
libgtop_sysdeps.la
|
||||
libsysdeps.la
|
||||
loadavg.lo
|
||||
mem.lo
|
||||
msg_limits.lo
|
||||
open.lo
|
||||
proclist.lo
|
||||
sem_limits.lo
|
||||
shm_limits.lo
|
||||
swap.lo
|
||||
sysdeps.lo
|
||||
uptime.lo
|
||||
so_locations
|
||||
*.lo
|
||||
*.la
|
@@ -1 +0,0 @@
|
||||
Martin Baulig (martin@home-of-linux.org)
|
@@ -1,23 +0,0 @@
|
||||
2000-02-24 Martin Baulig <martin@home-of-linux.org>
|
||||
|
||||
Applied a patch from Aron Griffis <agriffis@bigfoot.com>.
|
||||
|
||||
* glibtop_machine.h: Don't declare table () here.
|
||||
* netinfo.c: Reflect latest interface changes.
|
||||
|
||||
1999-05-11 Martin Baulig <martin@home-of-linux.org>
|
||||
|
||||
* procstate.c: Fixed implementation of the `state' field; added
|
||||
`ruid' and `rgid' fields.
|
||||
|
||||
1999-02-19 Martin Baulig <martin@home-of-linux.org>
|
||||
|
||||
* procmap.c, procargs.c, netload.c: Copied from stub_suid.
|
||||
|
||||
* proclist.c, procsegment.c: Make them compile again.
|
||||
|
||||
1998-10-25 Martin Baulig <martin@home-of-linux.org>
|
||||
|
||||
* ChangeLog: New file.
|
||||
* ppp.c: New file.
|
||||
|
@@ -1,23 +0,0 @@
|
||||
LINK = $(LIBTOOL) --mode=link $(CC) $(CFLAGS) $(LDFLAGS) -o $@
|
||||
|
||||
INCLUDES = @INCLUDES@
|
||||
|
||||
lib_LTLIBRARIES = libgtop_sysdeps.la libgtop_sysdeps_suid.la
|
||||
|
||||
libgtop_sysdeps_la_SOURCES = open.c close.c cpu.c mem.c swap.c \
|
||||
uptime.c loadavg.c shm_limits.c msg_limits.c \
|
||||
sem_limits.c ppp.c
|
||||
libgtop_sysdeps_la_LDFLAGS = $(LT_VERSION_INFO)
|
||||
libgtop_sysdeps_la_LIBADD = -lmach
|
||||
|
||||
libgtop_sysdeps_suid_la_SOURCES = open_suid.c close_suid.c proclist.c \
|
||||
procstate.c procuid.c proctime.c procmem.c \
|
||||
procsignal.c prockernel.c procsegment.c \
|
||||
procmap.c procargs.c netload.c netinfo.c \
|
||||
interfaces.c
|
||||
libgtop_sysdeps_suid_la_LDFLAGS = $(LT_VERSION_INFO)
|
||||
libgtop_sysdeps_suid_la_LIBADD = -lmach
|
||||
|
||||
include_HEADERS = glibtop_server.h glibtop_machine.h
|
||||
|
||||
noinst_HEADERS = glibtop_suid.h
|
@@ -1,32 +0,0 @@
|
||||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright (C) 1998-99 Martin Baulig
|
||||
This file is part of LibGTop 1.0.
|
||||
|
||||
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/close.h>
|
||||
|
||||
/* Closes pipe to gtop server. */
|
||||
|
||||
void
|
||||
glibtop_close_s (glibtop *server)
|
||||
{ }
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user