New upstream version 2.38.0

This commit is contained in:
Jeremy Bicha
2017-12-18 17:12:27 -05:00
839 changed files with 183284 additions and 0 deletions

3
sysdeps/freebsd/AUTHORS Normal file
View File

@@ -0,0 +1,3 @@
Martin Baulig (martin@home-of-linux.org)
Josh Sled (jsled@scam.XCF.Berkeley.EDU)
Joe Marcus Clarke (marcus@FreeBSD.org)

477
sysdeps/freebsd/ChangeLog Normal file
View File

@@ -0,0 +1,477 @@
2007-07-01 Benoît Dejean <benoit@placenet.org>
Fixe some problems as well as implements procwd and procopenfiles
for FreeBSD using a wrapper around lsof. This same backend should
also work on kFreeBSD.
Patch by Joe Marcus Clarke <marcus@freebsd.org>
2007-02-18 Benoît Dejean <benoit@placenet.org>
* AUTHORS:
* Makefile.am:
* NOTES:
* cpu.c: (glibtop_init_cpu_s), (glibtop_get_cpu_s):
* fsusage.c: (_glibtop_freebsd_get_fsusage_read_write):
* glibtop_machine.h:
* glibtop_server.h:
* init.c:
* loadavg.c: (glibtop_init_loadavg_s), (glibtop_get_loadavg_s):
* mem.c: (glibtop_init_mem_s), (glibtop_get_mem_s):
* msg_limits.c: (glibtop_init_msg_limits_s),
(glibtop_get_msg_limits_s):
* netload.c: (glibtop_init_netload_p), (glibtop_get_netload_p):
* open.c: (glibtop_open_p):
* ppp.c: (glibtop_init_ppp_p), (glibtop_get_ppp_p):
* procargs.c: (glibtop_get_proc_args_p):
* procdata.c:
* prockernel.c: (glibtop_init_proc_kernel_p),
(glibtop_get_proc_kernel_p):
* proclist.c: (glibtop_get_proclist_p):
* procmap.c: (_glibtop_sysdeps_freebsd_dev_inode),
(glibtop_get_proc_map_p):
* procmem.c: (glibtop_init_proc_mem_p), (glibtop_get_proc_mem_p):
* procsegment.c: (glibtop_init_proc_segment_p),
(glibtop_get_proc_segment_p):
* procsignal.c: (glibtop_get_proc_signal_p):
* procstate.c: (glibtop_init_proc_state_p),
(glibtop_get_proc_state_p):
* proctime.c: (glibtop_get_proc_time_p):
* procuid.c: (glibtop_init_proc_uid_p), (glibtop_get_proc_uid_p):
* sem_limits.c: (glibtop_init_sem_limits_s),
(glibtop_get_sem_limits_s):
* shm_limits.c: (glibtop_init_shm_limits_s),
(glibtop_get_shm_limits_s):
* swap.c: (glibtop_init_swap_p), (glibtop_get_swap_p):
* sysinfo.c: (init_sysinfo):
* uptime.c: (glibtop_init_uptime_s), (glibtop_get_uptime_s):
Huge (k)FreeBSD update.
(k)FreeBSD support is freebsd/
Other BSD are in bsd/
Patch by Joe Marcus Clarke <marcus@freebsd.org>
Alexander Nedotsukov <bland@FreeBSD.org>
Closes #407693.
2007-01-31 Benoît Dejean <benoit@placenet.org>
* fsusage.c: (_glibtop_freebsd_get_fsusage_read_write):
* netload.c: (glibtop_get_netload_p):
* prockernel.c: (glibtop_get_proc_kernel_p):
* procmap.c: (glibtop_get_proc_map_p):
* proctime.c:
* siglist.c:
* /libgtop-sysdeps.m4:
Various FreeBSD and kFreeBSD updates.
Patch by Roy Marples <uberlord@gentoo.org>.
Reviewed by Petr Salinger <Petr.Salinger@seznam.cz>.
Closes #387200.
2006-11-27 Benoît Dejean <benoit@placenet.org>
* fsusage.c: (_glibtop_freebsd_get_fsusage_read_write):
* mem.c: (glibtop_get_mem_p):
* prockernel.c: (glibtop_get_proc_kernel_p):
* proclist.c: (glibtop_get_proclist_p):
* procmap.c: (glibtop_get_proc_map_p):
* procmem.c: (glibtop_get_proc_mem_p):
* procsignal.c: (glibtop_get_proc_signal_p):
* procstate.c: (glibtop_get_proc_state_p):
* proctime.c:
* procuid.c: (glibtop_get_proc_uid_p):
* swap.c: (glibtop_init_swap_p), (glibtop_get_swap_p):
Added kfreebsd support.
Patch by Petr Salinger <Petr.Salinger@seznam.cz>.
2006-04-09 Benoît Dejean <benoit@placenet.org>
* fsusage.c: (_glibtop_freebsd_get_fsusage_read_write):
Fixed typo.
2006-04-04 Julio M. Merino Vidal <jmmv@NetBSD.org>
* sysdeps/freebsd/fsusage.c:
Use statvfs(2) if available instead of statfs(2). The latter was
replaced by the former and is no longer available under, e.g. NetBSD.
Fixes bug #337235.
2006-04-04 Benoît Dejean <benoit@placenet.org>
* sysinfo.c: (init_sysinfo):
Store only strings in values' values. g_strdup these strings.
Even if values is never destroyed, set key_destroy_func to NULL.
Leave description to NULL.
2006-04-04 Julio M. Merino Vidal <jmmv@NetBSD.org>
* sysdeps/freebsd/Makefile.am:
* sysdeps/freebsd/sysinfo.c:
Bring back to life (from the 1.x versions) the sysinfo.c file for
the freebsd sysdeps. The new file comes from the FreeBSD ports
repository and has some minor style changes by me. This is required
to get the glibtop_get_sysinfo_s function used by the sysdeps common
code.
Fixes bug #337251.
2006-04-04 Julio M. Merino Vidal <jmmv@NetBSD.org>
* sysdeps/freebsd/proctime.c:
Remove obsolete and non-functional code that breaks the build under
NetBSD. It was guarded by a conditional but could not compile
anyway because it referred to an undefined variable.
Fixes bug #337234.
2005-02-28 Benoît Dejean <TazForEver@dlfp.org>
* fsusage.c: (_glibtop_freebsd_get_fsusage_read_write): Forgot to add
this file :)
2005-02-28 Benoît Dejean <TazForEver@dlfp.org>
* Makefile.am:
* cpu.c: (glibtop_get_cpu_p):
* netlist.c: (glibtop_get_netlist_s):
* netload.c: (glibtop_get_netload_p):
* procmem.c: (glibtop_get_proc_mem_p):
Fix a bug in netlist where glibtop_netlist.number was never initialized to 0
(this resulted in a NULL pointer dereference in the network load feature
of the multiload applet)
* Add support for getting interface flags and packet counts even on interfaces
without IP addresses (needed for the network load feature of the multiload applet)
* Restore per-process limits in the !FreeBSD or __FreeBSD_version < 500013
case
* Add CPU interrupt time as IOWAIT to get support for the cpu load feature of
the multiload applet.
Patch from marcus@freebsd.org (Joe Marcus Clarke).
Closes #168704.
2005-02-23 Benoît Dejean <TazForEver@dlfp.org>
* Makefile.am:
* netlist.c: (glibtop_get_netlist_s):
* procmap.c: (glibtop_get_proc_map_p):
* procmem.c: (glibtop_get_proc_mem_p):
* procopenfiles.c: (glibtop_init_proc_open_files_s),
(glibtop_get_proc_open_files_s):
* proctime.c:
Add support for FreeBSD 6-CURRENT.
Use the more portable getrlimit to obtain process memory limits.
Correctly determine process time.
Stub out the procopenfiles() function (this is not yet implemented, however).
Fix a nasty infinite loop and memory leak due to a forgot pointer increment.
Patch from marcus@freebsd.org (Joe Marcus Clarke).
Closes #168232.
2004-12-05 Benoît Dejean <tazforever@dlfp.org>
* Makefile.am:
* netlist.c: (glibtop_init_netlist_s), (glibtop_get_netlist_s):
Added glibtop_get_netlist. Patch from marcus@freebsd.org (Joe Marcus Clarke).
2004-08-28 Benoît Dejean <tazforever@dlfp.org>
* mem.c: (glibtop_get_mem_p):
* ppp.c:
* swap.c: (glibtop_init_swap_p), (glibtop_get_swap_p):
* uptime.c: (glibtop_get_uptime_p): Merge a bunch of trivial OpenBSD
patchs. To *BSD maintainers : please report bugs ! don't be selfish, share
your patchs.
2004-08-22 Benoît Dejean <tazforever@dlfp.org>
* procstate.c:
* uptime.c: (glibtop_get_uptime_p): Merged Marcus' patches.
2004-07-15 Benoît Dejean <tazforever@dlfp.org>
* procstate.c: (glibtop_get_proc_state_p): Fixed copy/paste error
while setting buf->state.
2004-06-07 Benoît Dejean <tazforever@dlfp.org>
* netload.c: (glibtop_get_netload_p):
* procstate.c: (glibtop_get_proc_state_p):
* prockernel.c: (glibtop_get_proc_kernel_p): s/strncpy/g_strlcpy/.
* procargs.c: (glibtop_get_proc_args_p):
* procmap.c: (glibtop_get_proc_map_p): Cleaned.
2004-05-26 Benoît Dejean <tazforever@dlfp.org>
* procdata.c: (glibtop_get_procdata_s): Removed Linux related code.
2004-04-07 Bastien Nocera <hadess@hadess.net>
* prockernel.c: (glibtop_get_proc_kernel_p): patch for NetBSD/AMD64
support (Julio M. Merino Vidal <jmmv@menta.net>)
2004-03-09 Bastien Nocera <hadess@hadess.net>
* Makefile.am:
* cpu.c: (glibtop_init_cpu_p), (glibtop_get_cpu_p):
* glibtop_machine.h:
* mem.c:
* netload.c: (glibtop_get_netload_p):
* prockernel.c: (glibtop_get_proc_kernel_p):
* proclist.c: (glibtop_get_proclist_p):
* procmap.c: (glibtop_get_proc_map_p):
* procmem.c: (glibtop_get_proc_mem_p):
* procsignal.c: (glibtop_get_proc_signal_p):
* procstate.c: (glibtop_get_proc_state_p):
* proctime.c:
* procuid.c: (glibtop_get_proc_uid_p):
* uptime.c: (glibtop_get_uptime_p): implement NetBSD support, and
some build problems on FreeBSD (Closes: #135674)
2004-03-09 Bastien Nocera <hadess@hadess.net>
* procargs.c: (glibtop_get_proc_args_p):
* procmap.c: (glibtop_get_proc_map_p):
* swap.c: (glibtop_get_swap_p): fix g_malloc usage on non-Linux
platforms (patch by Benoît Dejean <bnet@ifrance.com>)
2003-10-21 Bastien Nocera <hadess@hadess.net>
* Makefile.am: install only one library, libgtop-2.0
Fix build-time warnings due to the redefinition of guint64
2003-10-20 Bastien Nocera <hadess@hadess.net>
* mem.c: (glibtop_get_mem_p):
* prockernel.c: (glibtop_get_proc_kernel_p):
* procmem.c: (glibtop_get_proc_mem_p):
* proctime.c: (glibtop_get_proc_time_p): s/u_int64_t/guint64/
2003-10-20 Bastien Nocera <hadess@hadess.net>
* swap.c: (glibtop_get_swap_p): fix swap sizes in FreeBSD,
patch by edwin@mavetju.org
2003-10-20 Bastien Nocera <hadess@hadess.net>
* glibtop_machine.h:
* glibtop_server.h:
* glibtop_suid.h:
* open.c:
* procargs.c:
* proclist.c:
* procmap.c:
* swap.c: fixed compilation
2003-10-20 Bastien Nocera <hadess@hadess.net>
* procargs.c: (glibtop_get_proc_args_p):
* proclist.c: (glibtop_get_proclist_p):
* procmap.c: (glibtop_get_proc_map_p):
* swap.c: (glibtop_get_swap_p): replace all the xmalloc crap by glib
memory management functions
2001-10-17 Abel Cheung <maddog@linux.org.hk>
* Makefile.am: move header to $(includedir)/libgtop-1.0/glibtop.
2001-02-27 Martin Baulig <baulig@suse.de>
* netload.c: Comment out the `subnet' field on BSDI; this should
make it compile. Bug #13345.
* shm_limits.c, msg_limits.c, sem_limits.c: Applied a patch
from Rolf Grossmann (grossman@securitas.net) for FreeBSD 4.2.
Fixes #51334.
2001-02-14 Martin Baulig <baulig@suse.de>
* proctime.c (glibtop_get_proc_time_p): Make things work on
OpenBSD 2.6; this is basically the same than on NetBSD.
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.
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.

View File

@@ -0,0 +1,29 @@
AM_CPPFLAGS = @AM_CPPFLAGS@
noinst_LTLIBRARIES = libgtop_sysdeps-2.0.la libgtop_sysdeps_suid-2.0.la
libgtop_sysdeps_2_0_la_SOURCES = nosuid.c siglist.c sysinfo.c shm_limits.c \
cpu.c msg_limits.c sem_limits.c loadavg.c \
uptime.c netlist.c fsusage.c mem.c \
mountlist.c procopenfiles.c procwd.c \
procaffinity.c glibtop_private.c open.c
libgtop_sysdeps_2_0_la_LDFLAGS = $(LT_VERSION_INFO)
libgtop_sysdeps_suid_2_0_la_LIBADD = $(KVM_LIBS)
libgtop_sysdeps_suid_2_0_la_SOURCES = suid_open.c close.c swap.c \
proclist.c procstate.c procuid.c \
proctime.c procmem.c procsignal.c \
prockernel.c procsegment.c procargs.c \
procio.c \
procmap.c netload.c ppp.c
libgtop_sysdeps_suid_2_0_la_LDFLAGS = $(LT_VERSION_INFO)
libgtopinclude_HEADERS = glibtop_server.h glibtop_machine.h \
glibtop_suid.h
libgtopincludedir = $(includedir)/libgtop-2.0
noinst_HEADERS = glibtop_private.h

795
sysdeps/freebsd/Makefile.in Normal file
View File

@@ -0,0 +1,795 @@
# Makefile.in generated by automake 1.15 from Makefile.am.
# @configure_input@
# Copyright (C) 1994-2014 Free Software Foundation, Inc.
# This Makefile.in is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE.
@SET_MAKE@
VPATH = @srcdir@
am__is_gnu_make = { \
if test -z '$(MAKELEVEL)'; then \
false; \
elif test -n '$(MAKE_HOST)'; then \
true; \
elif test -n '$(MAKE_VERSION)' && test -n '$(CURDIR)'; then \
true; \
else \
false; \
fi; \
}
am__make_running_with_option = \
case $${target_option-} in \
?) ;; \
*) echo "am__make_running_with_option: internal error: invalid" \
"target option '$${target_option-}' specified" >&2; \
exit 1;; \
esac; \
has_opt=no; \
sane_makeflags=$$MAKEFLAGS; \
if $(am__is_gnu_make); then \
sane_makeflags=$$MFLAGS; \
else \
case $$MAKEFLAGS in \
*\\[\ \ ]*) \
bs=\\; \
sane_makeflags=`printf '%s\n' "$$MAKEFLAGS" \
| sed "s/$$bs$$bs[$$bs $$bs ]*//g"`;; \
esac; \
fi; \
skip_next=no; \
strip_trailopt () \
{ \
flg=`printf '%s\n' "$$flg" | sed "s/$$1.*$$//"`; \
}; \
for flg in $$sane_makeflags; do \
test $$skip_next = yes && { skip_next=no; continue; }; \
case $$flg in \
*=*|--*) continue;; \
-*I) strip_trailopt 'I'; skip_next=yes;; \
-*I?*) strip_trailopt 'I';; \
-*O) strip_trailopt 'O'; skip_next=yes;; \
-*O?*) strip_trailopt 'O';; \
-*l) strip_trailopt 'l'; skip_next=yes;; \
-*l?*) strip_trailopt 'l';; \
-[dEDm]) skip_next=yes;; \
-[JT]) skip_next=yes;; \
esac; \
case $$flg in \
*$$target_option*) has_opt=yes; break;; \
esac; \
done; \
test $$has_opt = yes
am__make_dryrun = (target_option=n; $(am__make_running_with_option))
am__make_keepgoing = (target_option=k; $(am__make_running_with_option))
pkgdatadir = $(datadir)/@PACKAGE@
pkgincludedir = $(includedir)/@PACKAGE@
pkglibdir = $(libdir)/@PACKAGE@
pkglibexecdir = $(libexecdir)/@PACKAGE@
am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd
install_sh_DATA = $(install_sh) -c -m 644
install_sh_PROGRAM = $(install_sh) -c
install_sh_SCRIPT = $(install_sh) -c
INSTALL_HEADER = $(INSTALL_DATA)
transform = $(program_transform_name)
NORMAL_INSTALL = :
PRE_INSTALL = :
POST_INSTALL = :
NORMAL_UNINSTALL = :
PRE_UNINSTALL = :
POST_UNINSTALL = :
build_triplet = @build@
host_triplet = @host@
subdir = sysdeps/freebsd
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
am__aclocal_m4_deps = $(top_srcdir)/m4/gettext.m4 \
$(top_srcdir)/m4/gtk-doc.m4 $(top_srcdir)/m4/iconv.m4 \
$(top_srcdir)/m4/intlmacosx.m4 \
$(top_srcdir)/m4/introspection.m4 $(top_srcdir)/m4/lib-ld.m4 \
$(top_srcdir)/m4/lib-link.m4 $(top_srcdir)/m4/lib-prefix.m4 \
$(top_srcdir)/m4/libtool.m4 $(top_srcdir)/m4/ltoptions.m4 \
$(top_srcdir)/m4/ltsugar.m4 $(top_srcdir)/m4/ltversion.m4 \
$(top_srcdir)/m4/lt~obsolete.m4 $(top_srcdir)/m4/nls.m4 \
$(top_srcdir)/m4/po.m4 $(top_srcdir)/m4/progtest.m4 \
$(top_srcdir)/acinclude.m4 $(top_srcdir)/libgtop-sysdeps.m4 \
$(top_srcdir)/configure.ac
am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
$(ACLOCAL_M4)
DIST_COMMON = $(srcdir)/Makefile.am $(libgtopinclude_HEADERS) \
$(noinst_HEADERS) $(am__DIST_COMMON)
mkinstalldirs = $(install_sh) -d
CONFIG_HEADER = $(top_builddir)/config.h
CONFIG_CLEAN_FILES =
CONFIG_CLEAN_VPATH_FILES =
LTLIBRARIES = $(noinst_LTLIBRARIES)
libgtop_sysdeps_2_0_la_LIBADD =
am_libgtop_sysdeps_2_0_la_OBJECTS = nosuid.lo siglist.lo sysinfo.lo \
shm_limits.lo cpu.lo msg_limits.lo sem_limits.lo loadavg.lo \
uptime.lo netlist.lo fsusage.lo mem.lo mountlist.lo \
procopenfiles.lo procwd.lo procaffinity.lo glibtop_private.lo \
open.lo
libgtop_sysdeps_2_0_la_OBJECTS = $(am_libgtop_sysdeps_2_0_la_OBJECTS)
AM_V_lt = $(am__v_lt_@AM_V@)
am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@)
am__v_lt_0 = --silent
am__v_lt_1 =
libgtop_sysdeps_2_0_la_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC \
$(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=link $(CCLD) \
$(AM_CFLAGS) $(CFLAGS) $(libgtop_sysdeps_2_0_la_LDFLAGS) \
$(LDFLAGS) -o $@
am__DEPENDENCIES_1 =
libgtop_sysdeps_suid_2_0_la_DEPENDENCIES = $(am__DEPENDENCIES_1)
am_libgtop_sysdeps_suid_2_0_la_OBJECTS = suid_open.lo close.lo swap.lo \
proclist.lo procstate.lo procuid.lo proctime.lo procmem.lo \
procsignal.lo prockernel.lo procsegment.lo procargs.lo \
procio.lo procmap.lo netload.lo ppp.lo
libgtop_sysdeps_suid_2_0_la_OBJECTS = \
$(am_libgtop_sysdeps_suid_2_0_la_OBJECTS)
libgtop_sysdeps_suid_2_0_la_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC \
$(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=link $(CCLD) \
$(AM_CFLAGS) $(CFLAGS) $(libgtop_sysdeps_suid_2_0_la_LDFLAGS) \
$(LDFLAGS) -o $@
AM_V_P = $(am__v_P_@AM_V@)
am__v_P_ = $(am__v_P_@AM_DEFAULT_V@)
am__v_P_0 = false
am__v_P_1 = :
AM_V_GEN = $(am__v_GEN_@AM_V@)
am__v_GEN_ = $(am__v_GEN_@AM_DEFAULT_V@)
am__v_GEN_0 = @echo " GEN " $@;
am__v_GEN_1 =
AM_V_at = $(am__v_at_@AM_V@)
am__v_at_ = $(am__v_at_@AM_DEFAULT_V@)
am__v_at_0 = @
am__v_at_1 =
DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)
depcomp = $(SHELL) $(top_srcdir)/depcomp
am__depfiles_maybe = depfiles
am__mv = mv -f
COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
$(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
LTCOMPILE = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \
$(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) \
$(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) \
$(AM_CFLAGS) $(CFLAGS)
AM_V_CC = $(am__v_CC_@AM_V@)
am__v_CC_ = $(am__v_CC_@AM_DEFAULT_V@)
am__v_CC_0 = @echo " CC " $@;
am__v_CC_1 =
CCLD = $(CC)
LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \
$(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
$(AM_LDFLAGS) $(LDFLAGS) -o $@
AM_V_CCLD = $(am__v_CCLD_@AM_V@)
am__v_CCLD_ = $(am__v_CCLD_@AM_DEFAULT_V@)
am__v_CCLD_0 = @echo " CCLD " $@;
am__v_CCLD_1 =
SOURCES = $(libgtop_sysdeps_2_0_la_SOURCES) \
$(libgtop_sysdeps_suid_2_0_la_SOURCES)
DIST_SOURCES = $(libgtop_sysdeps_2_0_la_SOURCES) \
$(libgtop_sysdeps_suid_2_0_la_SOURCES)
am__can_run_installinfo = \
case $$AM_UPDATE_INFO_DIR in \
n|no|NO) false;; \
*) (install-info --version) >/dev/null 2>&1;; \
esac
am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`;
am__vpath_adj = case $$p in \
$(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \
*) f=$$p;; \
esac;
am__strip_dir = f=`echo $$p | sed -e 's|^.*/||'`;
am__install_max = 40
am__nobase_strip_setup = \
srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*|]/\\\\&/g'`
am__nobase_strip = \
for p in $$list; do echo "$$p"; done | sed -e "s|$$srcdirstrip/||"
am__nobase_list = $(am__nobase_strip_setup); \
for p in $$list; do echo "$$p $$p"; done | \
sed "s| $$srcdirstrip/| |;"' / .*\//!s/ .*/ ./; s,\( .*\)/[^/]*$$,\1,' | \
$(AWK) 'BEGIN { files["."] = "" } { files[$$2] = files[$$2] " " $$1; \
if (++n[$$2] == $(am__install_max)) \
{ print $$2, files[$$2]; n[$$2] = 0; files[$$2] = "" } } \
END { for (dir in files) print dir, files[dir] }'
am__base_list = \
sed '$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;s/\n/ /g' | \
sed '$$!N;$$!N;$$!N;$$!N;s/\n/ /g'
am__uninstall_files_from_dir = { \
test -z "$$files" \
|| { test ! -d "$$dir" && test ! -f "$$dir" && test ! -r "$$dir"; } \
|| { echo " ( cd '$$dir' && rm -f" $$files ")"; \
$(am__cd) "$$dir" && rm -f $$files; }; \
}
am__installdirs = "$(DESTDIR)$(libgtopincludedir)"
HEADERS = $(libgtopinclude_HEADERS) $(noinst_HEADERS)
am__tagged_files = $(HEADERS) $(SOURCES) $(TAGS_FILES) $(LISP)
# Read a list of newline-separated strings from the standard input,
# and print each of them once, without duplicates. Input order is
# *not* preserved.
am__uniquify_input = $(AWK) '\
BEGIN { nonempty = 0; } \
{ items[$$0] = 1; nonempty = 1; } \
END { if (nonempty) { for (i in items) print i; }; } \
'
# Make sure the list of sources is unique. This is necessary because,
# e.g., the same source file might be shared among _SOURCES variables
# for different programs/libraries.
am__define_uniq_tagged_files = \
list='$(am__tagged_files)'; \
unique=`for i in $$list; do \
if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
done | $(am__uniquify_input)`
ETAGS = etags
CTAGS = ctags
am__DIST_COMMON = $(srcdir)/Makefile.in $(top_srcdir)/depcomp AUTHORS \
ChangeLog
DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
ACLOCAL = @ACLOCAL@
ACLOCAL_AMFLAGS = @ACLOCAL_AMFLAGS@
ALLOCA = @ALLOCA@
AMTAR = @AMTAR@
AM_CPPFLAGS = @AM_CPPFLAGS@
AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@
AR = @AR@
AS = @AS@
AUTOCONF = @AUTOCONF@
AUTOHEADER = @AUTOHEADER@
AUTOMAKE = @AUTOMAKE@
AWK = @AWK@
CC = @CC@
CCDEPMODE = @CCDEPMODE@
CFLAGS = @CFLAGS@
CPP = @CPP@
CPPFLAGS = @CPPFLAGS@
CYGPATH_W = @CYGPATH_W@
DEFS = @DEFS@
DEPDIR = @DEPDIR@
DLLTOOL = @DLLTOOL@
DL_LIB = @DL_LIB@
DSYMUTIL = @DSYMUTIL@
DUMPBIN = @DUMPBIN@
ECHO_C = @ECHO_C@
ECHO_N = @ECHO_N@
ECHO_T = @ECHO_T@
EGREP = @EGREP@
EXEEXT = @EXEEXT@
FGREP = @FGREP@
GETTEXT_MACRO_VERSION = @GETTEXT_MACRO_VERSION@
GETTEXT_PACKAGE = @GETTEXT_PACKAGE@
GLIB_CFLAGS = @GLIB_CFLAGS@
GLIB_LIBS = @GLIB_LIBS@
GMSGFMT = @GMSGFMT@
GMSGFMT_015 = @GMSGFMT_015@
GREP = @GREP@
GTKDOC_CHECK = @GTKDOC_CHECK@
GTKDOC_CHECK_PATH = @GTKDOC_CHECK_PATH@
GTKDOC_DEPS_CFLAGS = @GTKDOC_DEPS_CFLAGS@
GTKDOC_DEPS_LIBS = @GTKDOC_DEPS_LIBS@
GTKDOC_MKPDF = @GTKDOC_MKPDF@
GTKDOC_REBASE = @GTKDOC_REBASE@
HTML_DIR = @HTML_DIR@
INSTALL = @INSTALL@
INSTALL_DATA = @INSTALL_DATA@
INSTALL_PROGRAM = @INSTALL_PROGRAM@
INSTALL_SCRIPT = @INSTALL_SCRIPT@
INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
INTLLIBS = @INTLLIBS@
INTL_MACOSX_LIBS = @INTL_MACOSX_LIBS@
INTROSPECTION_CFLAGS = @INTROSPECTION_CFLAGS@
INTROSPECTION_COMPILER = @INTROSPECTION_COMPILER@
INTROSPECTION_GENERATE = @INTROSPECTION_GENERATE@
INTROSPECTION_GIRDIR = @INTROSPECTION_GIRDIR@
INTROSPECTION_LIBS = @INTROSPECTION_LIBS@
INTROSPECTION_MAKEFILE = @INTROSPECTION_MAKEFILE@
INTROSPECTION_SCANNER = @INTROSPECTION_SCANNER@
INTROSPECTION_TYPELIBDIR = @INTROSPECTION_TYPELIBDIR@
KVM_LIBS = @KVM_LIBS@
LD = @LD@
LDFLAGS = @LDFLAGS@
LIBGTOP_BINDIR = @LIBGTOP_BINDIR@
LIBGTOP_EXTRA_LIBS = @LIBGTOP_EXTRA_LIBS@
LIBGTOP_INCS = @LIBGTOP_INCS@
LIBGTOP_LIBS = @LIBGTOP_LIBS@
LIBGTOP_MAJOR_VERSION = @LIBGTOP_MAJOR_VERSION@
LIBGTOP_MICRO_VERSION = @LIBGTOP_MICRO_VERSION@
LIBGTOP_MINOR_VERSION = @LIBGTOP_MINOR_VERSION@
LIBGTOP_SERVER = @LIBGTOP_SERVER@
LIBGTOP_SERVER_VERSION = @LIBGTOP_SERVER_VERSION@
LIBGTOP_VERSION = @LIBGTOP_VERSION@
LIBGTOP_VERSION_CODE = @LIBGTOP_VERSION_CODE@
LIBICONV = @LIBICONV@
LIBINTL = @LIBINTL@
LIBOBJS = @LIBOBJS@
LIBS = @LIBS@
LIBTOOL = @LIBTOOL@
LIPO = @LIPO@
LN_S = @LN_S@
LTLIBICONV = @LTLIBICONV@
LTLIBINTL = @LTLIBINTL@
LTLIBOBJS = @LTLIBOBJS@
LT_SYS_LIBRARY_PATH = @LT_SYS_LIBRARY_PATH@
LT_VERSION_INFO = @LT_VERSION_INFO@
MAKEINFO = @MAKEINFO@
MANIFEST_TOOL = @MANIFEST_TOOL@
MKDIR_P = @MKDIR_P@
MSGFMT = @MSGFMT@
MSGFMT_015 = @MSGFMT_015@
MSGMERGE = @MSGMERGE@
NM = @NM@
NMEDIT = @NMEDIT@
OBJDUMP = @OBJDUMP@
OBJEXT = @OBJEXT@
OTOOL = @OTOOL@
OTOOL64 = @OTOOL64@
PACKAGE = @PACKAGE@
PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@
PACKAGE_NAME = @PACKAGE_NAME@
PACKAGE_STRING = @PACKAGE_STRING@
PACKAGE_TARNAME = @PACKAGE_TARNAME@
PACKAGE_URL = @PACKAGE_URL@
PACKAGE_VERSION = @PACKAGE_VERSION@
PATH_SEPARATOR = @PATH_SEPARATOR@
PERL = @PERL@
PKG_CONFIG = @PKG_CONFIG@
PKG_CONFIG_LIBDIR = @PKG_CONFIG_LIBDIR@
PKG_CONFIG_PATH = @PKG_CONFIG_PATH@
POSUB = @POSUB@
RANLIB = @RANLIB@
SED = @SED@
SET_MAKE = @SET_MAKE@
SHELL = @SHELL@
STRIP = @STRIP@
USE_NLS = @USE_NLS@
VERSION = @VERSION@
XGETTEXT = @XGETTEXT@
XGETTEXT_015 = @XGETTEXT_015@
XGETTEXT_EXTRA_OPTIONS = @XGETTEXT_EXTRA_OPTIONS@
XMKMF = @XMKMF@
X_CFLAGS = @X_CFLAGS@
X_EXTRA_LIBS = @X_EXTRA_LIBS@
X_LIBS = @X_LIBS@
X_PRE_LIBS = @X_PRE_LIBS@
abs_builddir = @abs_builddir@
abs_srcdir = @abs_srcdir@
abs_top_builddir = @abs_top_builddir@
abs_top_srcdir = @abs_top_srcdir@
ac_ct_AR = @ac_ct_AR@
ac_ct_CC = @ac_ct_CC@
ac_ct_DUMPBIN = @ac_ct_DUMPBIN@
am__include = @am__include@
am__leading_dot = @am__leading_dot@
am__quote = @am__quote@
am__tar = @am__tar@
am__untar = @am__untar@
bindir = @bindir@
build = @build@
build_alias = @build_alias@
build_cpu = @build_cpu@
build_os = @build_os@
build_vendor = @build_vendor@
builddir = @builddir@
datadir = @datadir@
datarootdir = @datarootdir@
docdir = @docdir@
dvidir = @dvidir@
exec_prefix = @exec_prefix@
host = @host@
host_alias = @host_alias@
host_cpu = @host_cpu@
host_os = @host_os@
host_vendor = @host_vendor@
htmldir = @htmldir@
includedir = @includedir@
infodir = @infodir@
install_sh = @install_sh@
libdir = @libdir@
libexecdir = @libexecdir@
libgtop_have_sysinfo = @libgtop_have_sysinfo@
libgtop_need_server = @libgtop_need_server@
libgtop_postinstall = @libgtop_postinstall@
libgtop_sysdeps_dir = @libgtop_sysdeps_dir@
libgtop_top_builddir = @libgtop_top_builddir@
libs_xauth = @libs_xauth@
localedir = @localedir@
localstatedir = @localstatedir@
mandir = @mandir@
mkdir_p = @mkdir_p@
oldincludedir = @oldincludedir@
pdfdir = @pdfdir@
prefix = @prefix@
program_transform_name = @program_transform_name@
psdir = @psdir@
sbindir = @sbindir@
server_programs = @server_programs@
sharedstatedir = @sharedstatedir@
srcdir = @srcdir@
sysconfdir = @sysconfdir@
sysdeps_dir = @sysdeps_dir@
sysdeps_suid_lib = @sysdeps_suid_lib@
target_alias = @target_alias@
top_build_prefix = @top_build_prefix@
top_builddir = @top_builddir@
top_srcdir = @top_srcdir@
noinst_LTLIBRARIES = libgtop_sysdeps-2.0.la libgtop_sysdeps_suid-2.0.la
libgtop_sysdeps_2_0_la_SOURCES = nosuid.c siglist.c sysinfo.c shm_limits.c \
cpu.c msg_limits.c sem_limits.c loadavg.c \
uptime.c netlist.c fsusage.c mem.c \
mountlist.c procopenfiles.c procwd.c \
procaffinity.c glibtop_private.c open.c
libgtop_sysdeps_2_0_la_LDFLAGS = $(LT_VERSION_INFO)
libgtop_sysdeps_suid_2_0_la_LIBADD = $(KVM_LIBS)
libgtop_sysdeps_suid_2_0_la_SOURCES = suid_open.c close.c swap.c \
proclist.c procstate.c procuid.c \
proctime.c procmem.c procsignal.c \
prockernel.c procsegment.c procargs.c \
procio.c \
procmap.c netload.c ppp.c
libgtop_sysdeps_suid_2_0_la_LDFLAGS = $(LT_VERSION_INFO)
libgtopinclude_HEADERS = glibtop_server.h glibtop_machine.h \
glibtop_suid.h
libgtopincludedir = $(includedir)/libgtop-2.0
noinst_HEADERS = glibtop_private.h
all: all-am
.SUFFIXES:
.SUFFIXES: .c .lo .o .obj
$(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps)
@for dep in $?; do \
case '$(am__configure_deps)' in \
*$$dep*) \
( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \
&& { if test -f $@; then exit 0; else break; fi; }; \
exit 1;; \
esac; \
done; \
echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu sysdeps/freebsd/Makefile'; \
$(am__cd) $(top_srcdir) && \
$(AUTOMAKE) --gnu sysdeps/freebsd/Makefile
Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
@case '$?' in \
*config.status*) \
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \
*) \
echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \
cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \
esac;
$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES)
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
$(top_srcdir)/configure: $(am__configure_deps)
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
$(ACLOCAL_M4): $(am__aclocal_m4_deps)
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
$(am__aclocal_m4_deps):
clean-noinstLTLIBRARIES:
-test -z "$(noinst_LTLIBRARIES)" || rm -f $(noinst_LTLIBRARIES)
@list='$(noinst_LTLIBRARIES)'; \
locs=`for p in $$list; do echo $$p; done | \
sed 's|^[^/]*$$|.|; s|/[^/]*$$||; s|$$|/so_locations|' | \
sort -u`; \
test -z "$$locs" || { \
echo rm -f $${locs}; \
rm -f $${locs}; \
}
libgtop_sysdeps-2.0.la: $(libgtop_sysdeps_2_0_la_OBJECTS) $(libgtop_sysdeps_2_0_la_DEPENDENCIES) $(EXTRA_libgtop_sysdeps_2_0_la_DEPENDENCIES)
$(AM_V_CCLD)$(libgtop_sysdeps_2_0_la_LINK) $(libgtop_sysdeps_2_0_la_OBJECTS) $(libgtop_sysdeps_2_0_la_LIBADD) $(LIBS)
libgtop_sysdeps_suid-2.0.la: $(libgtop_sysdeps_suid_2_0_la_OBJECTS) $(libgtop_sysdeps_suid_2_0_la_DEPENDENCIES) $(EXTRA_libgtop_sysdeps_suid_2_0_la_DEPENDENCIES)
$(AM_V_CCLD)$(libgtop_sysdeps_suid_2_0_la_LINK) $(libgtop_sysdeps_suid_2_0_la_OBJECTS) $(libgtop_sysdeps_suid_2_0_la_LIBADD) $(LIBS)
mostlyclean-compile:
-rm -f *.$(OBJEXT)
distclean-compile:
-rm -f *.tab.c
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/close.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpu.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/fsusage.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/glibtop_private.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/loadavg.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/mem.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/mountlist.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/msg_limits.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/netlist.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/netload.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/nosuid.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/open.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ppp.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/procaffinity.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/procargs.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/procio.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/prockernel.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/proclist.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/procmap.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/procmem.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/procopenfiles.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/procsegment.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/procsignal.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/procstate.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/proctime.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/procuid.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/procwd.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sem_limits.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/shm_limits.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/siglist.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/suid_open.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/swap.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sysinfo.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/uptime.Plo@am__quote@
.c.o:
@am__fastdepCC_TRUE@ $(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(COMPILE) -c -o $@ $<
.c.obj:
@am__fastdepCC_TRUE@ $(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'`
@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(COMPILE) -c -o $@ `$(CYGPATH_W) '$<'`
.c.lo:
@am__fastdepCC_TRUE@ $(AM_V_CC)$(LTCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Plo
@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LTCOMPILE) -c -o $@ $<
mostlyclean-libtool:
-rm -f *.lo
clean-libtool:
-rm -rf .libs _libs
install-libgtopincludeHEADERS: $(libgtopinclude_HEADERS)
@$(NORMAL_INSTALL)
@list='$(libgtopinclude_HEADERS)'; test -n "$(libgtopincludedir)" || list=; \
if test -n "$$list"; then \
echo " $(MKDIR_P) '$(DESTDIR)$(libgtopincludedir)'"; \
$(MKDIR_P) "$(DESTDIR)$(libgtopincludedir)" || exit 1; \
fi; \
for p in $$list; do \
if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \
echo "$$d$$p"; \
done | $(am__base_list) | \
while read files; do \
echo " $(INSTALL_HEADER) $$files '$(DESTDIR)$(libgtopincludedir)'"; \
$(INSTALL_HEADER) $$files "$(DESTDIR)$(libgtopincludedir)" || exit $$?; \
done
uninstall-libgtopincludeHEADERS:
@$(NORMAL_UNINSTALL)
@list='$(libgtopinclude_HEADERS)'; test -n "$(libgtopincludedir)" || list=; \
files=`for p in $$list; do echo $$p; done | sed -e 's|^.*/||'`; \
dir='$(DESTDIR)$(libgtopincludedir)'; $(am__uninstall_files_from_dir)
ID: $(am__tagged_files)
$(am__define_uniq_tagged_files); mkid -fID $$unique
tags: tags-am
TAGS: tags
tags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files)
set x; \
here=`pwd`; \
$(am__define_uniq_tagged_files); \
shift; \
if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \
test -n "$$unique" || unique=$$empty_fix; \
if test $$# -gt 0; then \
$(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
"$$@" $$unique; \
else \
$(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
$$unique; \
fi; \
fi
ctags: ctags-am
CTAGS: ctags
ctags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files)
$(am__define_uniq_tagged_files); \
test -z "$(CTAGS_ARGS)$$unique" \
|| $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \
$$unique
GTAGS:
here=`$(am__cd) $(top_builddir) && pwd` \
&& $(am__cd) $(top_srcdir) \
&& gtags -i $(GTAGS_ARGS) "$$here"
cscopelist: cscopelist-am
cscopelist-am: $(am__tagged_files)
list='$(am__tagged_files)'; \
case "$(srcdir)" in \
[\\/]* | ?:[\\/]*) sdir="$(srcdir)" ;; \
*) sdir=$(subdir)/$(srcdir) ;; \
esac; \
for i in $$list; do \
if test -f "$$i"; then \
echo "$(subdir)/$$i"; \
else \
echo "$$sdir/$$i"; \
fi; \
done >> $(top_builddir)/cscope.files
distclean-tags:
-rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags
distdir: $(DISTFILES)
@srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
list='$(DISTFILES)'; \
dist_files=`for file in $$list; do echo $$file; done | \
sed -e "s|^$$srcdirstrip/||;t" \
-e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \
case $$dist_files in \
*/*) $(MKDIR_P) `echo "$$dist_files" | \
sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \
sort -u` ;; \
esac; \
for file in $$dist_files; do \
if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \
if test -d $$d/$$file; then \
dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \
if test -d "$(distdir)/$$file"; then \
find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \
fi; \
if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \
cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \
find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \
fi; \
cp -fpR $$d/$$file "$(distdir)$$dir" || exit 1; \
else \
test -f "$(distdir)/$$file" \
|| cp -p $$d/$$file "$(distdir)/$$file" \
|| exit 1; \
fi; \
done
check-am: all-am
check: check-am
all-am: Makefile $(LTLIBRARIES) $(HEADERS)
installdirs:
for dir in "$(DESTDIR)$(libgtopincludedir)"; do \
test -z "$$dir" || $(MKDIR_P) "$$dir"; \
done
install: install-am
install-exec: install-exec-am
install-data: install-data-am
uninstall: uninstall-am
install-am: all-am
@$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
installcheck: installcheck-am
install-strip:
if test -z '$(STRIP)'; then \
$(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
install; \
else \
$(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
"INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'" install; \
fi
mostlyclean-generic:
clean-generic:
distclean-generic:
-test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES)
-test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES)
maintainer-clean-generic:
@echo "This command is intended for maintainers to use"
@echo "it deletes files that may require special tools to rebuild."
clean: clean-am
clean-am: clean-generic clean-libtool clean-noinstLTLIBRARIES \
mostlyclean-am
distclean: distclean-am
-rm -rf ./$(DEPDIR)
-rm -f Makefile
distclean-am: clean-am distclean-compile distclean-generic \
distclean-tags
dvi: dvi-am
dvi-am:
html: html-am
html-am:
info: info-am
info-am:
install-data-am: install-libgtopincludeHEADERS
install-dvi: install-dvi-am
install-dvi-am:
install-exec-am:
install-html: install-html-am
install-html-am:
install-info: install-info-am
install-info-am:
install-man:
install-pdf: install-pdf-am
install-pdf-am:
install-ps: install-ps-am
install-ps-am:
installcheck-am:
maintainer-clean: maintainer-clean-am
-rm -rf ./$(DEPDIR)
-rm -f Makefile
maintainer-clean-am: distclean-am maintainer-clean-generic
mostlyclean: mostlyclean-am
mostlyclean-am: mostlyclean-compile mostlyclean-generic \
mostlyclean-libtool
pdf: pdf-am
pdf-am:
ps: ps-am
ps-am:
uninstall-am: uninstall-libgtopincludeHEADERS
.MAKE: install-am install-strip
.PHONY: CTAGS GTAGS TAGS all all-am check check-am clean clean-generic \
clean-libtool clean-noinstLTLIBRARIES cscopelist-am ctags \
ctags-am distclean distclean-compile distclean-generic \
distclean-libtool distclean-tags distdir dvi dvi-am html \
html-am info info-am install install-am install-data \
install-data-am install-dvi install-dvi-am install-exec \
install-exec-am install-html install-html-am install-info \
install-info-am install-libgtopincludeHEADERS install-man \
install-pdf install-pdf-am install-ps install-ps-am \
install-strip installcheck installcheck-am installdirs \
maintainer-clean maintainer-clean-generic mostlyclean \
mostlyclean-compile mostlyclean-generic mostlyclean-libtool \
pdf pdf-am ps ps-am tags tags-am uninstall uninstall-am \
uninstall-libgtopincludeHEADERS
.PRECIOUS: Makefile
# Tell versions [3.59,3.63) of GNU make to not export all variables.
# Otherwise a system limit (for SysV at least) may be exceeded.
.NOEXPORT:

30
sysdeps/freebsd/close.c Normal file
View File

@@ -0,0 +1,30 @@
/* 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., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include <config.h>
#include <glibtop.h>
#include <glibtop/close.h>
/* Closes pipe to gtop server. */
void
glibtop_close_p (glibtop *server)
{ }

133
sysdeps/freebsd/cpu.c Normal file
View File

@@ -0,0 +1,133 @@
/* 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., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include <config.h>
#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) +
(1L << GLIBTOP_CPU_IRQ);
static const unsigned long _glibtop_sysdeps_cpu_smp =
(1L << GLIBTOP_XCPU_TOTAL) + (1L << GLIBTOP_XCPU_USER) +
(1L << GLIBTOP_XCPU_NICE) + (1L << GLIBTOP_XCPU_SYS) +
(1L << GLIBTOP_XCPU_IDLE) + (1L << GLIBTOP_XCPU_IRQ);
/* Init function. */
void
_glibtop_init_cpu_s (glibtop *server)
{
server->sysdeps.cpu = _glibtop_sysdeps_cpu;
if (server->ncpu)
server->sysdeps.cpu |= _glibtop_sysdeps_cpu_smp;
}
/* Provides information about cpu usage. */
void
glibtop_get_cpu_s (glibtop *server, glibtop_cpu *buf)
{
long cpts [CPUSTATES];
long *cp_times = NULL;
struct clockinfo ci;
size_t length;
int ncpu, i;
memset (buf, 0, sizeof (glibtop_cpu));
length = sizeof (cpts);
if (sysctlbyname ("kern.cp_time", cpts, &length, NULL, 0)) {
glibtop_warn_io_r (server, "sysctl (kern.cp_time)");
return;
}
/* Get the clockrate data */
length = sizeof (ci);
if (sysctlbyname ("kern.clockrate", &ci, &length, NULL, 0)) {
glibtop_warn_io_r (server, "sysctl (kern.cockrate)");
return;
}
length = 0;
if (sysctlbyname ("kern.cp_times", NULL, &length, NULL, 0) == 0) {
cp_times = g_malloc (length);
length = sizeof(long) * CPUSTATES * (length / (sizeof(long) * CPUSTATES));
if (sysctlbyname ("kern.cp_times", cp_times, &length, NULL, 0)) {
g_free (cp_times);
cp_times = NULL;
}
}
/* 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 irq */
buf->irq = cpts [CP_INTR];
/* set frequency */
buf->frequency = (ci.stathz ? ci.stathz : ci.hz);
/* set total */
buf->total = cpts [CP_USER] + cpts [CP_NICE] \
+ cpts [CP_SYS] + cpts [CP_IDLE] + cpts [CP_INTR];
ncpu = server->ncpu + 1;
for (i = 0; i < ncpu; i++) {
if (cp_times) {
buf->xcpu_user[i] = cp_times[i * CPUSTATES + CP_USER];
buf->xcpu_nice[i] = cp_times[i * CPUSTATES + CP_NICE];
buf->xcpu_sys[i] = cp_times[i * CPUSTATES + CP_SYS];
buf->xcpu_idle[i] = cp_times[i * CPUSTATES + CP_IDLE];
buf->xcpu_irq[i] = cp_times[i * CPUSTATES + CP_INTR];
} else {
buf->xcpu_user[i] = cpts [CP_USER] / ncpu;
buf->xcpu_nice[i] = cpts [CP_NICE] / ncpu;
buf->xcpu_sys[i] = cpts [CP_SYS] / ncpu;
buf->xcpu_idle[i] = cpts [CP_IDLE] / ncpu;
buf->xcpu_irq[i] = cpts [CP_INTR] / ncpu;
}
buf->xcpu_total[i] = buf->xcpu_user[i] + buf->xcpu_nice[i] \
+ buf->xcpu_sys[i] + buf->xcpu_idle[i] \
+ buf->xcpu_irq[i];
}
g_free (cp_times);
/* Set the flags last. */
buf->flags = _glibtop_sysdeps_cpu;
if (ncpu > 1) {
buf->flags |= _glibtop_sysdeps_cpu_smp;
}
}

161
sysdeps/freebsd/fsusage.c Normal file
View File

@@ -0,0 +1,161 @@
#include <config.h>
#include <glibtop.h>
#include <glibtop/error.h>
#include <glibtop/fsusage.h>
#include <glibtop_suid.h>
#include <glib.h>
#include <unistd.h>
#include <sys/param.h>
#include <sys/mount.h>
#include <sys/statvfs.h>
#if 0
#include <libgeom.h>
#include <sys/resource.h>
#include <devstat.h>
#include <sys/devicestat.h>
#endif
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
static const unsigned long _glibtop_sysdeps_fsusage =
(1L << GLIBTOP_FSUSAGE_BLOCKS) + (1L << GLIBTOP_FSUSAGE_BFREE)
+ (1L << GLIBTOP_FSUSAGE_BAVAIL) + (1L << GLIBTOP_FSUSAGE_FILES)
+ (1L << GLIBTOP_FSUSAGE_FFREE) + (1L << GLIBTOP_FSUSAGE_BLOCK_SIZE);
static void
_glibtop_get_fsusage_read_write (glibtop *server, glibtop_fsusage *buf, const char *path)
{
int result;
struct statfs sfs;
#if 0
struct devstat *ds;
void *sc;
struct timespec ts;
struct gprovider *gp;
struct gident *gid;
struct gmesh gmp;
double etime;
uint64_t ld[2];
#endif
result = statfs (path, &sfs);
if (result == -1) {
glibtop_warn_io_r (server, "statfs");
return;
}
#if 0
ld[0] = 0;
ld[1] = 0;
result = geom_gettree (&gmp);
if (result != 0) {
glibtop_warn_io_r (server, "geom_gettree = %d", result);
return;
}
result = geom_stats_open ();
if (result != 0) {
glibtop_warn_io_r (server, "geom_stats_open()");
geom_deletetree (&gmp);
return;
}
sc = NULL;
sc = geom_stats_snapshot_get ();
if (sc == NULL) {
glibtop_warn_io_r (server, "geom_stats_snapshot_get()");
geom_stats_close ();
geom_deletetree (&gmp);
return;
}
geom_stats_snapshot_timestamp (sc, &ts);
etime = ts.tv_sec + (ts.tv_nsec * 1e-9);
geom_stats_snapshot_reset (sc);
for (;;) {
ds = geom_stats_snapshot_next (sc);
if (ds == NULL) {
break;
}
if (ds->id == NULL) {
continue;
}
gid = geom_lookupid (&gmp, ds->id);
if (gid == NULL) {
geom_deletetree (&gmp);
result = geom_gettree (&gmp);
gid = geom_lookupid (&gmp, ds->id);
}
if (gid == NULL) {
continue;
}
if (gid->lg_what == ISCONSUMER) {
continue;
}
gp = gid->lg_ptr;
if (!g_str_has_suffix (sfs.f_mntfromname, gp->lg_name)) {
continue;
} else {
result = devstat_compute_statistics (ds, NULL, etime,
DSM_TOTAL_TRANSFERS_READ,
&ld[0],
DSM_TOTAL_TRANSFERS_WRITE,
&ld[1], DSM_NONE);
if (result != 0) {
glibtop_warn_io_r (server,
"devstat_compute_statistics()");
geom_stats_snapshot_free (sc);
geom_stats_close ();
geom_deletetree (&gmp);
return;
}
break;
}
}
geom_stats_snapshot_free (sc);
geom_stats_close ();
geom_deletetree (&gmp);
buf->read = ld[0];
buf->write = ld[1];
#else
buf->read = sfs.f_syncreads + sfs.f_asyncreads;
buf->write = sfs.f_syncwrites + sfs.f_asyncwrites;
#endif
if (buf->read || buf->write) {
buf->flags |= (1 << GLIBTOP_FSUSAGE_READ) | (1 << GLIBTOP_FSUSAGE_WRITE);
}
}
void
glibtop_get_fsusage_s(glibtop *server, glibtop_fsusage *buf, const char *path)
{
struct statvfs fsd;
memset (buf, 0, sizeof (glibtop_fsusage));
if (statvfs (path, &fsd) < 0)
return;
buf->block_size = fsd.f_frsize;
buf->blocks = fsd.f_blocks;
buf->bfree = fsd.f_bfree;
buf->bavail = (fsd.f_bavail > fsd.f_bfree) ? 0 : fsd.f_bavail;
buf->files = fsd.f_files;
buf->ffree = fsd.f_ffree;
buf->flags = _glibtop_sysdeps_fsusage;
_glibtop_get_fsusage_read_write(server, buf, path);
}

View File

@@ -0,0 +1,54 @@
/* 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., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#ifndef __GLIBTOP_MACHINE_H__
#define __GLIBTOP_MACHINE_H__
#include <sys/param.h>
#include <nlist.h>
#include <limits.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>
#include <osreldate.h>
G_BEGIN_DECLS
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;
};
G_END_DECLS
#endif /* __GLIBTOP_MACHINE_H__ */

View File

@@ -0,0 +1,54 @@
#include <config.h>
#include <glibtop.h>
#include <glibtop/error.h>
#include "glibtop_private.h"
#include <sys/types.h>
#include <unistd.h>
#include <string.h>
#include <glib.h>
#include <errno.h>
char *
execute_lsof(pid_t pid) {
char *output = NULL;
char *lsof;
char *command;
int exit_status;
lsof = g_find_program_in_path("lsof");
if (lsof == NULL)
return NULL;
command = g_strdup_printf("%s -n -P -Fftn -p %d", lsof, pid);
g_free(lsof);
if (g_spawn_command_line_sync (command, &output, NULL, &exit_status, NULL)) {
if (exit_status != 0) {
g_warning("Could not execute \"%s\" (%i)", command,
exit_status);
output = NULL;
}
}
g_free(command);
return output;
}
/* Ported from linux/glibtop_private.c */
gboolean
safe_readlink(const char *path, char *buf, int bufsiz)
{
int ret;
ret = readlink(path, buf, bufsiz - 1);
if (ret == -1) {
g_warning("Could not read link %s : %s", path, strerror(errno));
return FALSE;
}
buf[ret] = '\0';
return TRUE;
}

View File

@@ -0,0 +1,40 @@
/* Copyright (C) 2007 Joe Marcus Clarke
This file is part of LibGTop 2.0.
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., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#ifndef __FREEBSD__GLIBTOP_PRIVATE_H__
#define __FREEBSD__GLIBTOP_PRIVATE_H__
#include <glibtop.h>
#include <glibtop/error.h>
#include <glib.h>
#include <sys/types.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
G_BEGIN_DECLS
char *execute_lsof(pid_t pid);
gboolean safe_readlink(const char *path, char *buf, int bufsiz);
G_END_DECLS
#endif /* __FREEBSD__GLIBTOP_PRIVATE_H__ */

View File

@@ -0,0 +1,54 @@
/* 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., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#ifndef __FREEBSD__GLIBTOP_SERVER_H__
#define __FREEBSD__GLIBTOP_SERVER_H__
G_BEGIN_DECLS
#define GLIBTOP_SUID_SWAP (1 << GLIBTOP_SYSDEPS_SWAP)
#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_PPP (1 << GLIBTOP_SYSDEPS_PPP)
#define GLIBTOP_SUID_CPU 0
#define GLIBTOP_SUID_MEM 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_NETLIST 0
#define GLIBTOP_SUID_PROC_WD 0
#define GLIBTOP_SUID_PROC_AFFINITY 0
#define GLIBTOP_SUID_PROC_IO (1 << GLIBTOP_SYSDEPS_PROC_IO)
G_END_DECLS
#endif

View File

@@ -0,0 +1,62 @@
/* 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., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#ifndef __GLIBTOP_SUID_H__
#define __GLIBTOP_SUID_H__
G_BEGIN_DECLS
#if _IN_LIBGTOP
#include <sys/param.h>
#endif
#include <glibtop_machine.h>
#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) {
glibtop_debug ("uid=%d euid=%d gid=%d egid=%d", getuid(), geteuid(), getgid(), getegid());
setregid (server->machine->gid, server->machine->egid);
glibtop_debug ("uid=%d euid=%d gid=%d egid=%d", getuid(), geteuid(), getgid(), getegid());
};
static inline void glibtop_suid_leave (glibtop *server) {
glibtop_debug ("uid=%d euid=%d gid=%d egid=%d", getuid(), geteuid(), getgid(), getegid());
if (setregid (server->machine->egid, server->machine->gid))
_exit (1);
glibtop_debug ("uid=%d euid=%d gid=%d egid=%d", getuid(), geteuid(), getgid(), getegid());
};
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);
G_END_DECLS
#endif

70
sysdeps/freebsd/loadavg.c Normal file
View File

@@ -0,0 +1,70 @@
/* 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., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include <config.h>
#include <stdlib.h>
#include <glibtop.h>
#include <glibtop/error.h>
#include <glibtop/loadavg.h>
#include <sys/types.h>
#include <sys/sysctl.h>
static const unsigned long _glibtop_sysdeps_loadavg =
(1L << GLIBTOP_LOADAVG_LOADAVG);
static const unsigned long _glibtop_sysdeps_last_pid =
(1L << GLIBTOP_LOADAVG_LAST_PID);
/* Init function. */
void
_glibtop_init_loadavg_s (glibtop *server)
{
server->sysdeps.loadavg = _glibtop_sysdeps_loadavg |
_glibtop_sysdeps_last_pid;
}
/* Provides load averange. */
void
glibtop_get_loadavg_s (glibtop *server, glibtop_loadavg *buf)
{
pid_t last_pid;
size_t len;
memset (buf, 0, sizeof (glibtop_loadavg));
if (getloadavg (buf->loadavg, G_N_ELEMENTS(buf->loadavg)) == -1)
return;
buf->flags = _glibtop_sysdeps_loadavg;
len = sizeof (last_pid);
if (sysctlbyname ("kern.lastpid", &last_pid, &len, NULL, 0)) {
glibtop_warn_io_r (server, "sysctl (kern.lastpid)");
return;
}
buf->last_pid = last_pid;
buf->flags |= _glibtop_sysdeps_last_pid;
}

99
sysdeps/freebsd/mem.c Normal file
View File

@@ -0,0 +1,99 @@
/* 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., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include <config.h>
#include <glibtop.h>
#include <glibtop/error.h>
#include <glibtop/mem.h>
#include <sys/types.h>
#include <sys/sysctl.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);
/* these are for getting the memory statistics */
static int pagesize;
/* Init function. */
void
_glibtop_init_mem_s (glibtop *server)
{
pagesize = getpagesize ();
server->sysdeps.mem = _glibtop_sysdeps_mem;
}
static gulong mem_get_by_bytes (glibtop *server, const char *name) {
gulong result = 0;
size_t len = sizeof (result);
if (sysctlbyname (name, &result, &len, NULL, 0)) {
glibtop_warn_io_r (server, "sysctl (%s)", name);
}
return result;
}
static gulong mem_get_by_pages (glibtop *server, const char *name) {
guint result = 0;
size_t len = sizeof (result);
if (sysctlbyname (name, &result, &len, NULL, 0)) {
glibtop_warn_io_r (server, "sysctl (%s)", name);
}
return (gulong) result * pagesize;
}
void
glibtop_get_mem_s (glibtop *server, glibtop_mem *buf)
{
gulong memtotal;
gulong memactive;
gulong meminactive;
gulong memwired;
gulong memcached;
gulong membuffer;
gulong memfree;
memset (buf, 0, sizeof *buf);
memtotal = mem_get_by_bytes (server, "hw.physmem");
memactive = mem_get_by_pages (server, "vm.stats.vm.v_active_count");
meminactive = mem_get_by_pages (server, "vm.stats.vm.v_inactive_count");
memwired = mem_get_by_pages (server, "vm.stats.vm.v_wire_count");
memcached = mem_get_by_pages (server, "vm.stats.vm.v_cache_count");
membuffer = mem_get_by_bytes (server, "vfs.bufspace");
memfree = mem_get_by_pages (server, "vm.stats.vm.v_free_count");
buf->total = memtotal;
buf->used = memtotal - memfree;
buf->free = memfree;
buf->shared = 0;
buf->buffer = membuffer;
buf->cached = memcached;
buf->locked = 0;
buf->user = memactive + memwired;
buf->flags = _glibtop_sysdeps_mem;
}

167
sysdeps/freebsd/mountlist.c Normal file
View File

@@ -0,0 +1,167 @@
/* mountlist.c -- return a list of mounted filesystems
Copyright (C) 1991, 1992 Free Software Foundation, Inc.
This program 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, or (at your option)
any later version.
This program 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 this program; if not, write to the Free Software Foundation,
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
#include <config.h>
#include <glib.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/param.h>
#include <sys/mount.h>
#include <string.h>
#include <glibtop.h>
#include <glibtop/mountlist.h>
/* A mount table entry. */
struct mount_entry
{
char *me_devname; /* Device node pathname, including "/dev/". */
char *me_mountdir; /* Mount point directory pathname. */
char *me_type; /* "nfs", "4.2", etc. */
dev_t me_dev; /* Device number of me_mountdir. */
struct mount_entry *me_next;
};
static struct mount_entry *read_filesystem_list (void);
/* Return a list of the currently mounted filesystems, or NULL on error.
Add each entry to the tail of the list so that they stay in order.
*/
static struct mount_entry *
read_filesystem_list (void)
{
struct mount_entry *mount_list;
struct mount_entry *me;
struct mount_entry *mtail;
/* Start the list off with a dummy entry. */
me = g_new (struct mount_entry, 1);
me->me_next = NULL;
mount_list = mtail = me;
{
struct statfs *fsp;
int entries;
entries = getmntinfo (&fsp, MNT_NOWAIT);
if (entries < 0)
return NULL;
while (entries-- > 0)
{
me = (struct mount_entry *) g_malloc (sizeof (struct mount_entry));
me->me_devname = g_strdup (fsp->f_mntfromname);
me->me_mountdir = g_strdup (fsp->f_mntonname);
me->me_type = g_strdup (fsp->f_fstypename);
me->me_dev = (dev_t) -1; /* Magic; means not known yet. */
me->me_next = NULL;
/* Add to the linked list. */
mtail->me_next = me;
mtail = me;
fsp++;
}
}
/* Free the dummy head. */
me = mount_list;
mount_list = mount_list->me_next;
g_free (me);
return mount_list;
}
static gboolean ignore_mount_entry(const struct mount_entry *me)
{
/* keep sorted */
static const char ignored[][17] = {
"autofs",
"devfs",
"fdescfs",
"fusectl",
"linprocfs",
"linsysfs",
"mfs",
"none",
"nfs",
"nullfs",
"nwfs",
"portalfs",
"proc",
"procfs",
"smbfs",
"tmpfs",
"unionfs",
"unknown"
};
typedef int (*Comparator)(const void*, const void*);
return bsearch(me->me_type,
ignored, G_N_ELEMENTS(ignored), sizeof ignored[0],
(Comparator) strcmp) != NULL;
}
glibtop_mountentry *
glibtop_get_mountlist_s (glibtop *server, glibtop_mountlist *buf, int all_fs)
{
struct mount_entry *entries, *cur, *next;
GArray *mount_array = g_array_new(FALSE, FALSE,
sizeof(glibtop_mountentry));
memset (buf, 0, sizeof (glibtop_mountlist));
/* Read filesystem list. */
if((entries = read_filesystem_list ()) == NULL)
return NULL;
for (cur = &entries[0]; cur != NULL; cur = next) {
if(all_fs || !ignore_mount_entry(cur)) {
/* add a new glibtop_mountentry */
glibtop_mountentry e;
g_strlcpy(e.devname, cur->me_devname, sizeof e.devname);
g_strlcpy(e.mountdir, cur->me_mountdir, sizeof e.mountdir);
g_strlcpy(e.type, cur->me_type, sizeof e.type);
e.dev = cur->me_dev;
g_array_append_val(mount_array, e);
}
/* free current mount_entry and move to the next */
next = cur->me_next;
g_free(cur->me_devname);
g_free(cur->me_mountdir);
g_free(cur->me_type);
g_free(cur);
}
buf->size = sizeof (glibtop_mountentry);
buf->number = mount_array->len;
buf->total = buf->number * buf->size;
buf->flags = (1 << GLIBTOP_MOUNTLIST_SIZE)
| (1 << GLIBTOP_MOUNTLIST_NUMBER)
| (1 << GLIBTOP_MOUNTLIST_TOTAL);
return (glibtop_mountentry*) g_array_free(mount_array, FALSE);
}

View File

@@ -0,0 +1,100 @@
/* 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., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include <config.h>
#include <glibtop.h>
#include <glibtop/error.h>
#include <glibtop/msg_limits.h>
#include <sys/types.h>
#include <sys/sysctl.h>
static const unsigned long _glibtop_sysdeps_msg_limits =
(1L << GLIBTOP_IPC_MSGMAX) + (1L << GLIBTOP_IPC_MSGMNI) +
(1L << GLIBTOP_IPC_MSGMNB) + (1L << GLIBTOP_IPC_MSGTQL) +
(1L << GLIBTOP_IPC_MSGSSZ) + (1L << GLIBTOP_IPC_MSGPOOL);
/* Init function. */
void
_glibtop_init_msg_limits_s (glibtop *server)
{
server->sysdeps.msg_limits = _glibtop_sysdeps_msg_limits;
}
/* Provides information about sysv ipc limits. */
void
glibtop_get_msg_limits_s (glibtop *server, glibtop_msg_limits *buf)
{
size_t len;
int msgmax, msgmni, msgmnb, msgtql, msgssz, msgseg;
memset (buf, 0, sizeof (glibtop_msg_limits));
if (server->sysdeps.msg_limits == 0)
return;
len = sizeof (msgseg);
if (sysctlbyname ("kern.ipc.msgseg", &msgseg, &len, NULL, 0)) {
glibtop_warn_io_r (server, "sysctl (kern.ipc.msgseg)");
return;
}
len = sizeof (msgssz);
if (sysctlbyname ("kern.ipc.msgssz", &msgssz, &len, NULL, 0)) {
glibtop_warn_io_r (server, "sysctl (kern.ipc.msgssz)");
return;
}
len = sizeof (msgtql);
if (sysctlbyname ("kern.ipc.msgtql", &msgtql, &len, NULL, 0)) {
glibtop_warn_io_r (server, "sysctl (kern.ipc.msgtql)");
return;
}
len = sizeof (msgmnb);
if (sysctlbyname ("kern.ipc.msgmnb", &msgmnb, &len, NULL, 0)) {
glibtop_warn_io_r (server, "sysctl (kern.ipc.msgmnb)");
return;
}
len = sizeof (msgmni);
if (sysctlbyname ("kern.ipc.msgmni", &msgmni, &len, NULL, 0)) {
glibtop_warn_io_r (server, "sysctl (kern.ipc.msgmni)");
return;
}
len = sizeof (msgmax);
if (sysctlbyname ("kern.ipc.msgmax", &msgmax, &len, NULL, 0)) {
glibtop_warn_io_r (server, "sysctl (kern.ipc.msgmax)");
return;
}
buf->msgmax = msgmax;
buf->msgmni = msgmni;
buf->msgmnb = msgmnb;
buf->msgtql = msgtql;
buf->msgssz = msgssz;
buf->msgpool = msgseg;
buf->flags = _glibtop_sysdeps_msg_limits;
}

64
sysdeps/freebsd/netlist.c Normal file
View File

@@ -0,0 +1,64 @@
/*
This file is part of LibGTop 2.0.
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., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include <config.h>
#include <glibtop/netlist.h>
#include <glibtop/error.h>
#include <net/if.h>
static const unsigned long _glibtop_sysdeps_netlist = (1 << GLIBTOP_NETLIST_NUMBER);
/* Init function. */
void
_glibtop_init_netlist_s (glibtop *server)
{
server->sysdeps.netlist = _glibtop_sysdeps_netlist;
}
char**
glibtop_get_netlist_s (glibtop *server, glibtop_netlist *buf)
{
struct if_nameindex *ifstart, *ifs;
GPtrArray *devices;
memset (buf, 0, sizeof (glibtop_netlist));
ifs = ifstart = if_nameindex();
devices = g_ptr_array_new();
while(ifs && ifs->if_name) {
g_ptr_array_add(devices, g_strdup(ifs->if_name));
buf->number++;
ifs++;
}
if_freenameindex(ifstart);
buf->flags = _glibtop_sysdeps_netlist;
g_ptr_array_add(devices, NULL);
return (char **) g_ptr_array_free(devices, FALSE);
}

214
sysdeps/freebsd/netload.c Normal file
View File

@@ -0,0 +1,214 @@
/* Copyright (C) 1998-99 Martin Baulig
Copyright (C) 2014 Gleb Smirnoff
This file is part of LibGTop 1.0.
Contributed by Martin Baulig <martin@home-of-linux.org>, October 1998.
Contributed by Gleb Smirnoff <glebius@FreeBSD.org>, September 2014
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., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include <config.h>
#include <glibtop.h>
#include <glibtop/error.h>
#include <glibtop/netload.h>
#include <glibtop_suid.h>
#include <sys/ioctl.h>
#include <sys/sockio.h>
#include <netinet/in.h>
#include <net/if.h>
#include <net/if_dl.h>
#include <net/if_media.h>
#include <ifaddrs.h>
static const unsigned long _glibtop_sysdeps_netload =
(1L << GLIBTOP_NETLOAD_IF_FLAGS) +
(1L << GLIBTOP_NETLOAD_MTU) +
(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) +
(1L << GLIBTOP_NETLOAD_HWADDRESS);
static const unsigned long _glibtop_sysdeps_netload_data =
(1L << GLIBTOP_NETLOAD_SUBNET) +
(1L << GLIBTOP_NETLOAD_ADDRESS);
static const unsigned long _glibtop_sysdeps_netload6 =
(1L << GLIBTOP_NETLOAD_ADDRESS6) +
(1L << GLIBTOP_NETLOAD_PREFIX6) +
(1L << GLIBTOP_NETLOAD_SCOPE6);
/* Init function. */
void
_glibtop_init_netload_p (glibtop *server)
{
server->sysdeps.netload = _glibtop_sysdeps_netload;
}
/* Provides Network statistics. */
void
glibtop_get_netload_p (glibtop *server, glibtop_netload *buf,
const char *interface)
{
struct ifaddrs *ifap, *ifa;
memset (buf, 0, sizeof (glibtop_netload));
if (server->sysdeps.netload == 0)
return;
if (getifaddrs(&ifap) != 0) {
glibtop_warn_io_r (server, "getifaddrs");
return;
}
#define IFA_STAT(s) (((struct if_data *)ifa->ifa_data)->ifi_ ## s)
for (ifa = ifap; ifa; ifa = ifa->ifa_next) {
if (strcmp (ifa->ifa_name, interface) != 0)
continue;
switch (ifa->ifa_addr->sa_family) {
case AF_LINK: {
struct sockaddr_dl *sdl;
struct ifmediareq ifmr;
struct ifreq ifr;
int s, flags;
s = socket(AF_INET, SOCK_DGRAM, 0);
if (s < 0) {
glibtop_warn_io_r(server, "socket(AF_INET)");
break;
}
memset(&ifmr, 0, sizeof(ifmr));
(void)strlcpy(ifmr.ifm_name, ifa->ifa_name,
sizeof(ifmr.ifm_name));
if (ioctl(s, SIOCGIFXMEDIA, (caddr_t)&ifmr) < 0 &&
ioctl(s, SIOCGIFMEDIA, (caddr_t)&ifmr) < 0) {
glibtop_warn_io_r(server, "ioctl(SIOCGIFMEDIA)");
} else {
if (IFM_TYPE (ifmr.ifm_current) & IFM_IEEE80211)
buf->if_flags |= (1L << GLIBTOP_IF_FLAGS_WIRELESS);
if (IFM_TYPE (ifmr.ifm_active) & IFM_IEEE80211)
buf->if_flags |= (1L << GLIBTOP_IF_FLAGS_WIRELESS);
}
memset(&ifr, 0, sizeof(ifr));
(void)strlcpy(ifr.ifr_name, ifa->ifa_name,
sizeof(ifr.ifr_name));
if (ioctl(s, SIOCGIFFLAGS, (caddr_t)&ifr) < 0) {
glibtop_warn_io_r(server, "ioctl(SIOCGIFFLAGS)");
close(s);
break;
}
close(s);
flags = (ifr.ifr_flags & 0xffff) | (ifr.ifr_flagshigh << 16);
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_OACTIVE)
buf->if_flags |= (1L << GLIBTOP_IF_FLAGS_OACTIVE);
if (flags & IFF_SIMPLEX)
buf->if_flags |= (1L << GLIBTOP_IF_FLAGS_SIMPLEX);
if (flags & IFF_LINK0)
buf->if_flags |= (1L << GLIBTOP_IF_FLAGS_LINK0);
if (flags & IFF_LINK1)
buf->if_flags |= (1L << GLIBTOP_IF_FLAGS_LINK1);
if (flags & IFF_LINK2)
buf->if_flags |= (1L << GLIBTOP_IF_FLAGS_LINK2);
if (flags & IFF_ALTPHYS)
buf->if_flags |= (1L << GLIBTOP_IF_FLAGS_ALTPHYS);
if (flags & IFF_MULTICAST)
buf->if_flags |= (1L << GLIBTOP_IF_FLAGS_MULTICAST);
buf->packets_in = IFA_STAT(ipackets);
buf->packets_out = IFA_STAT(opackets);
buf->packets_total = buf->packets_in + buf->packets_out;
buf->bytes_in = IFA_STAT(ibytes);
buf->bytes_out = IFA_STAT(obytes);
buf->bytes_total = buf->bytes_in + buf->bytes_out;
buf->errors_in = IFA_STAT(ierrors);
buf->errors_out = IFA_STAT(oerrors);
buf->errors_total = buf->errors_in + buf->errors_out;
buf->collisions = IFA_STAT(collisions);
sdl = (struct sockaddr_dl *)(void *)ifa->ifa_addr;
memcpy(buf->hwaddress, LLADDR(sdl),
sizeof(buf->hwaddress));
buf->mtu = IFA_STAT(mtu);
buf->flags |= _glibtop_sysdeps_netload;
break;
}
case AF_INET: {
struct sockaddr_in *sin;
sin = (struct sockaddr_in *)(void *)ifa->ifa_addr;
buf->address = sin->sin_addr.s_addr;
sin = (struct sockaddr_in *)(void *)ifa->ifa_netmask;
buf->subnet = sin->sin_addr.s_addr & buf->address;
buf->flags |= _glibtop_sysdeps_netload_data;
break;
}
case AF_INET6: {
struct sockaddr_in6 *sin6;
sin6 = (struct sockaddr_in6 *)(void *)ifa->ifa_addr;
memcpy(buf->address6, &sin6->sin6_addr,
sizeof(buf->address6));
buf->scope6 = (guint8 )sin6->sin6_scope_id;
sin6 = (struct sockaddr_in6 *)(void *)ifa->ifa_netmask;
memcpy(buf->prefix6, &sin6->sin6_addr,
sizeof(buf->prefix6));
buf->flags |= _glibtop_sysdeps_netload6;
break;
}
} // switch() end
}
freeifaddrs(ifap);
}

28
sysdeps/freebsd/nosuid.c Normal file
View File

@@ -0,0 +1,28 @@
/* 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., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include <config.h>
#include <glibtop.h>
#include <glibtop/close.h>
void
glibtop_close_s (glibtop *server)
{ }

48
sysdeps/freebsd/open.c Normal file
View File

@@ -0,0 +1,48 @@
/* 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., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include <config.h>
#include <sys/types.h>
#include <sys/sysctl.h>
#include <glibtop.h>
#include <glibtop/open.h>
#include <glibtop/cpu.h>
#include <glibtop/error.h>
#include <glibtop_private.h>
void
glibtop_open_s (glibtop *server, const char *program_name,
const unsigned long features,
const unsigned flags)
{
int ncpus;
size_t len;
len = sizeof (ncpus);
sysctlbyname ("hw.ncpu", &ncpus, &len, NULL, 0);
server->real_ncpu = ncpus - 1;
server->ncpu = MIN(GLIBTOP_NCPU - 1, server->real_ncpu);
server->os_version_code = __FreeBSD_version;
}

143
sysdeps/freebsd/ppp.c Normal file
View File

@@ -0,0 +1,143 @@
/* 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., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include <config.h>
#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>
#include <net/if_sppp.h>
/* 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. */
void
_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->machine->kd, nlst) < 0) {
glibtop_warn_io_r (server, "kvm_nlist");
server->sysdeps.ppp = 0;
}
}
/* Provides information about ppp usage. */
void
glibtop_get_ppp_p (glibtop *server, glibtop_ppp *buf, unsigned short device)
{
#ifdef HAVE_I4B
#ifdef HAVE_I4B_ACCT
struct i4bisppp_softc data;
#else
struct sppp data;
#endif
int phase;
memset (buf, 0, sizeof (glibtop_ppp));
if (server->sysdeps.ppp == 0) return;
if (kvm_read (server->machine->kd, nlst [0].n_value,
&data, sizeof (data)) != sizeof (data)) {
glibtop_warn_io_r (server, "kvm_read (i4bisppp_softc)");
return;
}
#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 */
}

View File

@@ -0,0 +1,84 @@
/* Copyright (C) 2007 Joe Marcus Clarke <marcus@FreeBSD.org>
This file is part of LibGTop 2.
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., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include <config.h>
#include <glibtop/procaffinity.h>
#include <glibtop/error.h>
#include <glibtop_private.h>
#include <sys/param.h>
#if __FreeBSD_version > 800024
#include <sys/cpuset.h>
#endif
void
_glibtop_init_proc_affinity_s(glibtop *server)
{
server->sysdeps.proc_affinity =
(1 << GLIBTOP_PROC_AFFINITY_NUMBER) |
(1 << GLIBTOP_PROC_AFFINITY_ALL);
}
guint16 *
glibtop_get_proc_affinity_s(glibtop *server, glibtop_proc_affinity *buf, pid_t pid)
{
#if __FreeBSD_version > 800024
id_t id;
cpulevel_t level;
cpuwhich_t which;
cpuset_t mask;
size_t i;
GArray* cpus;
memset(buf, 0, sizeof *buf);
which = CPU_WHICH_PID;
level = CPU_LEVEL_WHICH;
id = pid;
if (cpuset_getaffinity(level, which, id, sizeof(mask), &mask) != 0) {
glibtop_error_r(server, "cpuset_getaffinity failed");
return NULL;
}
cpus = g_array_new(FALSE, FALSE, sizeof(guint16));
for (i = 0; i < MIN(CPU_SETSIZE, (size_t)(server->ncpu + 1)); i++) {
if (CPU_ISSET(i, &mask)) {
guint16 n = i;
g_array_append_val(cpus, n);
}
}
buf->number = cpus->len;
buf->all = (cpus->len == (size_t)(server->ncpu + 1));
buf->flags = (1 << GLIBTOP_PROC_AFFINITY_NUMBER)
| (1 << GLIBTOP_PROC_AFFINITY_ALL);
return (guint16*) g_array_free(cpus, FALSE);
#else
memset(buf, 0, sizeof *buf);
return NULL;
#endif
}

View File

@@ -0,0 +1,96 @@
/* 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., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include <config.h>
#include <glibtop.h>
#include <glibtop/error.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_PROC_ARGS_SIZE);
/* Init function. */
void
_glibtop_init_proc_args_p (glibtop *server)
{
server->sysdeps.proc_args = _glibtop_sysdeps_proc_args;
}
/* Provides detailed information about a process. */
char *
glibtop_get_proc_args_p (glibtop *server, glibtop_proc_args *buf,
pid_t pid, unsigned max_len)
{
struct kinfo_proc *pinfo;
char *retval, **args, **ptr;
size_t size = 0, pos = 0;
int count;
memset (buf, 0, sizeof (glibtop_proc_args));
/* swapper, init, pagedaemon, vmdaemon, update - this doen't work. */
if (pid < 5) return NULL;
glibtop_suid_enter (server);
/* Get the process data */
pinfo = kvm_getprocs (server->machine->kd, KERN_PROC_PID, pid, &count);
if ((pinfo == NULL) || (count < 1)) {
glibtop_warn_io_r (server, "kvm_getprocs (%d)", pid);
glibtop_suid_leave (server);
return NULL;
}
args = kvm_getargv (server->machine->kd, pinfo, max_len);
if (args == NULL) {
glibtop_warn_io_r (server, "kvm_getargv (%d)", pid);
glibtop_suid_leave (server);
return NULL;
}
glibtop_suid_leave (server);
for (ptr = args; *ptr; ptr++)
size += strlen (*ptr)+1;
size += 2;
retval = g_malloc0 (size);
for (ptr = args; *ptr; ptr++) {
const size_t len = strlen (*ptr)+1;
memcpy (retval+pos, *ptr, len);
pos += len;
}
buf->size = pos ? pos-1 : 0;
buf->flags = _glibtop_sysdeps_proc_args;
return retval;
}

80
sysdeps/freebsd/procio.c Normal file
View File

@@ -0,0 +1,80 @@
/* Copyright (C) 2017 Robert Roth
This file is part of LibGTop.
Contributed by Robert Roth <robert.roth.off@gmail.com>, February 2017.
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., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include <config.h>
#include <glibtop.h>
#include <glibtop/procio.h>
#include <glibtop/error.h>
#include <glibtop_suid.h>
static const unsigned long _glibtop_sysdeps_proc_io =
(1UL << GLIBTOP_PROC_IO_DISK_RBYTES) + (1UL << GLIBTOP_PROC_IO_DISK_WBYTES);
/* Init function. */
void
_glibtop_init_proc_io_p (glibtop *server)
{
server->sysdeps.proc_io = _glibtop_sysdeps_proc_io;
}
/* Provides detailed information about a process. */
void
glibtop_get_proc_io_p (glibtop *server, glibtop_proc_io *buf,
pid_t pid)
{
memset (buf, 0, sizeof (glibtop_proc_io));
struct kinfo_proc *pinfo;
int count;
glibtop_suid_enter (server);
/* Get the process information */
pinfo = kvm_getprocs (server->machine->kd, KERN_PROC_PID, pid, &count);
if ((pinfo == NULL) || (count != 1)) {
glibtop_warn_io_r (server, "kvm_getprocs (%d)", pid);
glibtop_suid_leave (server);
return;
}
glibtop_suid_leave (server);
/* man getrusage
long ru_inblock; == block input operations
long ru_oublock; == block output operations
ru_inblock the number of times the file system had to perform input.
ru_oublock the number of times the file system had to perform output.
And then it says 'account only for real IO'.
But if I write 1MB in a process, I can see ru_oublock increased
1024. So it's neither a number of operations or times.
FIXME: seems the blocksize is 1024 but ...
*/
buf->disk_rbytes = pinfo->ki_rusage.ru_inblock << 10;
buf->disk_wbytes = pinfo->ki_rusage.ru_oublock << 10;
buf->flags = _glibtop_sysdeps_proc_io;
}

View File

@@ -0,0 +1,119 @@
/* 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., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include <config.h>
#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>
#include <sys/user.h>
#include <unistd.h>
#include <fcntl.h>
#include <osreldate.h>
static const unsigned long _glibtop_sysdeps_proc_kernel_pstats =
(1L << GLIBTOP_PROC_KERNEL_K_FLAGS) +
(1L << GLIBTOP_PROC_KERNEL_MIN_FLT) +
(1L << GLIBTOP_PROC_KERNEL_MAJ_FLT) +
#if (__FreeBSD_version >= 600006) || defined(__FreeBSD_kernel__)
(1L << GLIBTOP_PROC_KERNEL_CMIN_FLT) +
(1L << GLIBTOP_PROC_KERNEL_CMAJ_FLT);
#else
0;
#endif
static const unsigned long _glibtop_sysdeps_proc_kernel_wchan =
(1L << GLIBTOP_PROC_KERNEL_WCHAN) +
(1L << GLIBTOP_PROC_KERNEL_NWCHAN);
/* Init function. */
void
_glibtop_init_proc_kernel_p (glibtop *server)
{
server->sysdeps.proc_kernel = _glibtop_sysdeps_proc_kernel_pstats |
_glibtop_sysdeps_proc_kernel_wchan;
}
void
glibtop_get_proc_kernel_p (glibtop *server,
glibtop_proc_kernel *buf,
pid_t pid)
{
struct kinfo_proc *pinfo;
int count;
memset (buf, 0, sizeof (glibtop_proc_kernel));
if (server->sysdeps.proc_time == 0)
return;
/* It does not work for the swapper task. */
if (pid == 0) return;
glibtop_suid_enter (server);
/* Get the process information */
pinfo = kvm_getprocs (server->machine->kd, KERN_PROC_PID, pid, &count);
if ((pinfo == NULL) || (count != 1)) {
glibtop_warn_io_r (server, "kvm_getprocs (%d)", pid);
glibtop_suid_leave (server);
return;
}
glibtop_suid_leave (server);
#define PROC_WCHAN ki_wchan
#define PROC_WMESG ki_wmesg
#define PROC_WMESG ki_wmesg
buf->nwchan = (unsigned long) pinfo [0].PROC_WCHAN;
buf->flags |= (1L << GLIBTOP_PROC_KERNEL_NWCHAN);
if (pinfo [0].PROC_WCHAN && pinfo [0].PROC_WMESG[0] != 0) {
g_strlcpy (buf->wchan, pinfo [0].PROC_WMESG,
sizeof buf->wchan);
buf->flags |= (1L << GLIBTOP_PROC_KERNEL_WCHAN);
} else {
buf->wchan [0] = 0;
}
buf->k_flags = (unsigned long) pinfo [0].ki_flag;
buf->min_flt = (unsigned long) pinfo [0].ki_rusage.ru_minflt;
buf->maj_flt = (unsigned long) pinfo [0].ki_rusage.ru_majflt;
#if (__FreeBSD_version >= 600006) || defined(__FreeBSD_kernel__)
buf->cmin_flt = (unsigned long) buf->min_flt + pinfo [0].ki_rusage_ch.ru_minflt;
buf->cmaj_flt = (unsigned long) buf->maj_flt + pinfo [0].ki_rusage_ch.ru_majflt;
#endif
buf->flags |= _glibtop_sysdeps_proc_kernel_pstats;
return;
}

165
sysdeps/freebsd/proclist.c Normal file
View File

@@ -0,0 +1,165 @@
/* 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., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include <config.h>
#include <glibtop.h>
#include <glibtop/error.h>
#include <glibtop/proclist.h>
#include <glibtop/procstate.h>
#include <glibtop_suid.h>
#include <sys/types.h>
#include <sys/sysctl.h>
#include <sys/user.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 (pid_t)). 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. */
void
_glibtop_init_proclist_p (glibtop *server)
{
server->sysdeps.proclist = _glibtop_sysdeps_proclist;
}
pid_t *
glibtop_get_proclist_p (glibtop *server, glibtop_proclist *buf,
gint64 which, gint64 arg)
{
struct kinfo_proc *pinfo;
GArray *pids;
glibtop_proc_state procstate;
size_t len;
unsigned int i;
pid_t prev;
memset (buf, 0, sizeof (glibtop_proclist));
if (sysctlbyname ("kern.proc.all", NULL, &len, NULL, 0)) {
glibtop_warn_io_r (server, "sysctl (kern.proc.all)");
return NULL;
}
pinfo = (struct kinfo_proc *) g_malloc0 (len);
if (sysctlbyname ("kern.proc.all", pinfo, &len, NULL, 0)) {
glibtop_warn_io_r (server, "sysctl (kern.proc.all)");
g_free (pinfo);
return NULL;
}
len /= sizeof (struct kinfo_proc);
pids = g_array_sized_new (FALSE, FALSE, sizeof (pid_t), len);
for (i = 0; i < len; i++) {
pid_t pid;
pid = (pid_t) pinfo[i].ki_pid;
/* If a process has many threads, kern.proc.all reports multiple
times the same pid. So don't look twice at the same pid.
FIXME?: not sure that kern.proc.all reports a partially sorted
list (all pid/threads grouped).
*/
if (i > 0 && pid == prev) {
continue;
}
prev = pid;
switch (which & GLIBTOP_KERN_PROC_MASK) {
case GLIBTOP_KERN_PROC_ALL:
break;
case GLIBTOP_KERN_PROC_PID:
if ((pid_t) arg != pid)
continue;
break;
case GLIBTOP_KERN_PROC_UID:
if ((uid_t) arg != pinfo[i].ki_ruid)
continue;
break;
case GLIBTOP_KERN_PROC_PGRP:
if ((pid_t) arg != pinfo[i].ki_pgid)
continue;
break;
case GLIBTOP_KERN_PROC_SESSION:
if ((pid_t) arg != pinfo[i].ki_sid)
continue;
break;
case GLIBTOP_KERN_PROC_TTY:
if ((dev_t) arg != pinfo[i].ki_tdev)
continue;
break;
case GLIBTOP_KERN_PROC_RUID:
if ((uid_t) arg != pinfo[i].ki_ruid)
continue;
break;
}
if (which & GLIBTOP_EXCLUDE_NOTTY)
if (pinfo[i].ki_tdev == (dev_t) -1) continue;
if (which & GLIBTOP_EXCLUDE_IDLE) {
glibtop_get_proc_state_p (server, &procstate, pid);
if (procstate.flags & (1L << GLIBTOP_PROC_STATE_STATE))
if (procstate.state != GLIBTOP_PROCESS_RUNNING) continue;
if (pinfo[i].ki_ppid == 0 && !strcmp(pinfo[i].ki_comm, "idle"))
continue;
}
if (which & GLIBTOP_EXCLUDE_SYSTEM)
if (pinfo[i].ki_ruid == (uid_t) 0) continue;
g_array_append_val (pids, pid);
}
g_free (pinfo);
buf->flags = _glibtop_sysdeps_proclist;
buf->size = sizeof (pid_t);
buf->number = pids->len;
buf->total = buf->number * buf->size;
return (pid_t *) g_array_free (pids, FALSE);
}

391
sysdeps/freebsd/procmap.c Normal file
View File

@@ -0,0 +1,391 @@
/* 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., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include <config.h>
#include <glibtop.h>
#include <glibtop/error.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_map.h>
#include <vm/vm.h>
#define _KVM_VNODE
#include <sys/vnode.h>
#undef _KVM_VNODE
#include <sys/conf.h>
#if (__FreeBSD_version >= 800038) || (__FreeBSD_kernel_version >= 800038)
#define _WANT_FILE
#include <sys/file.h>
#undef _WANT_FILE
#else
#define _KERNEL
#include <sys/file.h>
#undef _KERNEL
#endif
#define _KERNEL
#include <sys/mount.h>
#include <ufs/ufs/quota.h>
#include <ufs/ufs/inode.h>
#include <fs/devfs/devfs.h>
#if (__FreeBSD_version >= 600006) || defined(__FreeBSD_kernel__)
#include <fs/devfs/devfs_int.h>
#endif
#undef _KERNEL
#if (__FreeBSD_version >= 1101001)
#define _KERNEL
#include <ufs/ufs/extattr.h>
#include <ufs/ufs/ufsmount.h>
#undef _KERNEL
#endif
#include <sys/ucred.h>
#include <sys/sysctl.h>
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);
#if (__FreeBSD_version >= 600006) || defined(__FreeBSD_kernel__)
void _glibtop_sysdeps_freebsd_dev_inode (glibtop *server, struct vnode *vnode, struct vnode *vn, guint64 *inum, guint64 *dev);
void
_glibtop_sysdeps_freebsd_dev_inode (glibtop *server, struct vnode *vnode,
struct vnode *vn, guint64 *inum,
guint64 *dev)
{
char *tagptr;
char tagstr[12];
enum FS_TYPE { UNKNOWN, IS_UFS, IS_ZFS };
int fs_type = UNKNOWN;
struct inode inode;
struct cdev_priv priv;
#if __FreeBSD_version < 800039
struct cdev si;
#endif
*inum = 0;
*dev = 0;
if (kvm_read (server->machine->kd, (gulong) &vnode->v_tag,
(char *) &tagptr, sizeof (tagptr)) != sizeof (tagptr) ||
kvm_read (server->machine->kd, (gulong) tagptr,
(char *) tagstr, sizeof (tagstr)) != sizeof (tagstr))
{
glibtop_warn_io_r (server, "kvm_read (tagptr)");
return;
}
tagstr[sizeof(tagstr) - 1] = '\0';
if (!strcmp(tagstr, "ufs")) {
fs_type = IS_UFS;
} else if (!strcmp(tagstr, "zfs")) {
fs_type = IS_ZFS;
} else {
glibtop_warn_io_r (server, "ignoring fstype %s", tagstr);
return;
}
if (kvm_read (server->machine->kd, (gulong) VTOI(vn), (char *) &inode,
sizeof (inode)) != sizeof (inode))
{
glibtop_warn_io_r (server, "kvm_read (inode)");
return;
}
if (fs_type == IS_ZFS) {
/* FIXME: I have no idea about what is the actual layout of what we've read
but the inode number is definitely at offset 16, 8 bytes of amd64.
*inum = *(guint64*) ((unsigned char*)&inode + 16);
So this is really hugly, but I don't have anything better for now.
Actually, this looks like a znode_t as described in kernel's zfs_znode.h.
I don't have that header file, so let's just mimic that.
*/
struct my_zfsvfs {
/* vfs_t */ void *z_vfs;
/* zfsvfs_t */ void *z_parent;
/* objset_t */ void *z_os;
uint64_t z_root;
/* ... */
};
typedef struct my_znode {
struct my_zfsvfs *z_zfsvfs;
/* vnode_t */ void *z_vnode;
uint64_t z_id;
/* ... */
} my_znode_t;
G_STATIC_ASSERT(sizeof(my_znode_t) <= sizeof(struct inode));
my_znode_t* znode = (my_znode_t*)&inode;
*inum = znode->z_id;
struct my_zfsvfs zvfs;
if (kvm_read(server->machine->kd,
(unsigned long)(znode->z_zfsvfs),
&zvfs, sizeof zvfs) != sizeof zvfs) {
glibtop_warn_io_r(server, "kvm_read (z_zfsvfs)");
return;
}
*dev = zvfs.z_root;
}
else if (fs_type == IS_UFS) {
/* Set inum as soon as possible, so that if the next kvm_reads fail
we still have something */
*inum = inode.i_number;
#if (__FreeBSD_version >= 1101001)
/*
The ufs struct inode changed between 11.0 and 11.1.
commit 20f1e8ac63b58708989267ea34a6aefa90b46577
Author: kib <kib@FreeBSD.org>
Date: Sat Sep 17 16:47:34 2016 +0000
Reduce size of ufs inode.
[...]
*/
struct ufsmount um;
if (kvm_read(server->machine->kd, (gulong)inode.i_ump, &um, sizeof um) != sizeof um) {
glibtop_warn_io_r (server, "kvm_read (ufsmount)");
return;
}
if (kvm_read(server->machine->kd, (gulong)cdev2priv(um.um_dev), &priv, sizeof priv) != sizeof priv) {
glibtop_warn_io_r (server, "kvm_read (priv)");
return;
}
*dev = priv.cdp_inode;
#else /* older versions */
#if (__FreeBSD_version >= 800039) || (__FreeBSD_kernel_version >= 800039)
if (kvm_read (server->machine->kd, (gulong) cdev2priv(inode.i_dev), (char *) &priv,
sizeof (priv))
#else
if (kvm_read (server->machine->kd, (gulong) inode.i_dev, (char *) &si,
sizeof (si)) != sizeof (si) ||
kvm_read (server->machine->kd, (gulong) si.si_priv, (char *) &priv,
sizeof (priv))
#endif
!= sizeof (priv))
{
glibtop_warn_io_r (server, "kvm_read (priv)");
return;
}
*dev = (guint64) priv.cdp_inode;
#endif /* older versions */
} /* end-if IS_UFS */
}
#endif
/* Init function. */
void
_glibtop_init_proc_map_p (glibtop *server)
{
server->sysdeps.proc_map = _glibtop_sysdeps_proc_map;
}
/* 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;
struct vm_object object;
GArray *maps;
struct vnode vnode;
int count;
int update = 0;
memset (buf, 0, sizeof (glibtop_proc_map));
/* It does not work for the swapper task. */
if (pid == 0) return NULL;
/*return (glibtop_map_entry*) g_array_free(maps, TRUE);*/
glibtop_suid_enter (server);
/* Get the process data */
pinfo = kvm_getprocs (server->machine->kd, KERN_PROC_PID, pid, &count);
if ((pinfo == NULL) || (count < 1)) {
glibtop_warn_io_r (server, "kvm_getprocs (%d)", pid);
glibtop_suid_leave (server);
return NULL;
}
/* Now we get the memory maps. */
if (kvm_read (server->machine->kd,
(gulong) pinfo [0].ki_vmspace,
(char *) &vmspace, sizeof (vmspace)) != sizeof (vmspace)) {
glibtop_warn_io_r (server, "kvm_read (vmspace)");
glibtop_suid_leave (server);
return NULL;
}
first = vmspace.vm_map.header.next;
if (kvm_read (server->machine->kd,
(gulong) vmspace.vm_map.header.next,
(char *) &entry, sizeof (entry)) != sizeof (entry)) {
glibtop_warn_io_r (server, "kvm_read (entry)");
glibtop_suid_leave (server);
return NULL;
}
/* 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. */
maps = g_array_sized_new(FALSE, FALSE, sizeof(glibtop_map_entry),
vmspace.vm_map.nentries);
do {
glibtop_map_entry *mentry;
guint64 inum, dev;
guint len;
if (update) {
if (kvm_read (server->machine->kd,
(gulong) entry.next,
(char *) &entry, sizeof (entry)) != sizeof (entry)) {
glibtop_warn_io_r (server, "kvm_read (entry)");
continue;
}
} else {
update = 1;
}
if (entry.eflags & (MAP_ENTRY_IS_SUB_MAP))
continue;
if (!entry.object.vm_object)
continue;
/* We're only interested in `vm_object's */
if (kvm_read (server->machine->kd,
(gulong) entry.object.vm_object,
(char *) &object, sizeof (object)) != sizeof (object)) {
glibtop_warn_io_r (server, "kvm_read (object)");
continue;
}
/* If the object is of type vnode, add its size */
if (object.type != OBJT_VNODE)
continue;
if (!object.handle)
continue;
if (kvm_read (server->machine->kd,
(gulong) object.handle,
(char *) &vnode, sizeof (vnode)) != sizeof (vnode)) {
glibtop_warn_io_r (server, "kvm_read (vnode)");
continue;
}
switch (vnode.v_type) {
case VNON:
case VBAD:
continue;
default:
#if (__FreeBSD_version < 600006) && !defined(__FreeBSD_kernel__)
inum = vnode.v_cachedid;
dev = vnode.v_cachedfs;
#else
_glibtop_sysdeps_freebsd_dev_inode (server,
(struct vnode *) object.handle,
&vnode, &inum, &dev);
#endif
break;
}
len = maps->len;
g_array_set_size(maps, len + 1);
mentry = &g_array_index(maps, glibtop_map_entry, len);
memset (mentry, 0, sizeof (glibtop_map_entry));
mentry->flags = _glibtop_sysdeps_map_entry;
mentry->start = (guint64) entry.start;
mentry->end = (guint64) entry.end;
mentry->offset = (guint64) entry.offset;
mentry->device = (guint64) dev;
mentry->inode = (guint64) inum;
mentry->perm = (guint64) 0;
if (entry.protection & VM_PROT_READ)
mentry->perm |= GLIBTOP_MAP_PERM_READ;
if (entry.protection & VM_PROT_WRITE)
mentry->perm |= GLIBTOP_MAP_PERM_WRITE;
if (entry.protection & VM_PROT_EXECUTE)
mentry->perm |= GLIBTOP_MAP_PERM_EXECUTE;
} while (entry.next != first);
glibtop_suid_leave (server);
buf->flags = _glibtop_sysdeps_proc_map;
buf->number = (guint64) maps->len;
buf->size = (guint64) sizeof (glibtop_map_entry);
buf->total = (guint64) (buf->number * buf->size);
return (glibtop_map_entry*) g_array_free(maps, FALSE);
}

164
sysdeps/freebsd/procmem.c Normal file
View File

@@ -0,0 +1,164 @@
/* 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., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include <config.h>
#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>
#include <sys/user.h>
#include <sys/sysctl.h>
#include <vm/vm.h>
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 =
(1L << GLIBTOP_PROC_MEM_SHARE);
/* define pagetok in terms of pageshift */
#define ps_pgtok(a) (((a) * getpagesize()) / 1024)
/* Init function. */
void
_glibtop_init_proc_mem_p (glibtop *server)
{
server->sysdeps.proc_mem = _glibtop_sysdeps_proc_mem;
}
/* Provides detailed information about a process. */
void
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 vmspace;
struct vm_object object;
int count;
memset (buf, 0, sizeof (glibtop_proc_mem));
if (server->sysdeps.proc_mem == 0)
return;
/* It does not work for the swapper task. */
if (pid == 0) return;
/* Get the process data */
pinfo = kvm_getprocs (server->machine->kd, KERN_PROC_PID, pid, &count);
if ((pinfo == NULL) || (count < 1)) {
glibtop_warn_io_r (server, "kvm_getprocs (%d)", pid);
return;
}
#define PROC_VMSPACE ki_vmspace
buf->rss_rlim = pinfo [0].ki_rssize;
buf->vsize = buf->size = (guint64)
pinfo [0].ki_size;
buf->resident = buf->rss = (guint64)
ps_pgtok (pinfo [0].ki_rssize) * 1024;
buf->flags |= _glibtop_sysdeps_proc_mem;
#if 0
/*
* It doesn't make any sense to count as shared each and every mmaped file
*/
/* Now we get the shared memory. */
if (kvm_read (server->machine->kd,
(unsigned long) pinfo [0].PROC_VMSPACE,
(char *) &vmspace, sizeof (vmspace)) != sizeof (vmspace)) {
glibtop_warn_io_r (server, "kvm_read (vmspace)");
return;
}
first = vmspace.vm_map.header.next;
if (kvm_read (server->machine->kd,
(unsigned long) vmspace.vm_map.header.next,
(char *) &entry, sizeof (entry)) != sizeof (entry)) {
glibtop_warn_io_r (server, "kvm_read (entry)");
return;
}
/* 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->machine->kd,
(unsigned long) entry.next,
(char *) &entry, sizeof (entry)) != sizeof (entry)) {
glibtop_warn_io_r (server, "kvm_read (entry)");
return;
}
if (entry.eflags & (MAP_ENTRY_IS_SUB_MAP))
continue;
if (!entry.object.vm_object)
continue;
/* We're only interested in `vm_object's */
if (kvm_read (server->machine->kd,
(unsigned long) entry.object.vm_object,
(char *) &object, sizeof (object)) != sizeof (object)) {
glibtop_warn_io_r (server, "kvm_read (object)");
return;
}
if (object.type != OBJT_VNODE)
continue;
buf->share += object.un_pager.vnp.vnp_size;
}
buf->flags |= _glibtop_sysdeps_proc_mem_share;
#endif
}

View File

@@ -0,0 +1,389 @@
/* Copyright (C) 1998-99 Martin Baulig
Copyright (C) 2004 Nicol<6F>s Lichtmaier
Copyright (C) 2007 Joe Marcus Clarke
This file is part of LibGTop 1.0.
Modified by Nicol<6F>s Lichtmaier to give a process open files.
Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
LibGTop is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License,
or (at your option) any later version.
LibGTop is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with LibGTop; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include <config.h>
#include <glibtop.h>
#include <glibtop/error.h>
#include <glibtop/procopenfiles.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/param.h>
#include <sys/sysctl.h>
#include <sys/un.h>
#include <sys/user.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#ifdef HAVE_KINFO_GETFILE
#include <libutil.h>
#endif
#include <string.h>
#include <stdlib.h>
#include "glibtop_private.h"
static const unsigned long _glibtop_sysdeps_proc_open_files =
(1L << GLIBTOP_PROC_OPEN_FILES_NUMBER)|
(1L << GLIBTOP_PROC_OPEN_FILES_TOTAL)|
(1L << GLIBTOP_PROC_OPEN_FILES_SIZE);
/* Init function. */
void
_glibtop_init_proc_open_files_s (glibtop *server)
{
server->sysdeps.proc_open_files = _glibtop_sysdeps_proc_open_files;
}
#if __FreeBSD_version > 800018 || (__FreeBSD_version < 800000 && __FreeBSD_version >= 700104)
static char *
addr_to_string(struct sockaddr_storage *ss)
{
char *buffer = NULL;
char buffer2[INET6_ADDRSTRLEN];
struct sockaddr_in6 *sin6;
struct sockaddr_in *sin;
struct sockaddr_un *sun;
switch (ss->ss_family) {
case AF_LOCAL:
sun = (struct sockaddr_un *)ss;
if (strlen(sun->sun_path) == 0)
buffer = g_strdup("-");
else
buffer = g_strdup(sun->sun_path);
break;
case AF_INET:
sin = (struct sockaddr_in *)ss;
buffer = g_strdup(inet_ntoa(sin->sin_addr));
break;
case AF_INET6:
sin6 = (struct sockaddr_in6 *)ss;
if (inet_ntop(AF_INET6, &sin6->sin6_addr, buffer2,
sizeof(buffer2)) != NULL)
buffer = g_strdup(buffer2);
else
buffer = g_strdup("-");
break;
}
return buffer;
}
static int
addr_to_port(struct sockaddr_storage *ss)
{
int port = 0;
struct sockaddr_in6 *sin6;
struct sockaddr_in *sin;
switch (ss->ss_family) {
case AF_INET:
sin = (struct sockaddr_in *)ss;
port = ntohs(sin->sin_port);
break;
case AF_INET6:
sin6 = (struct sockaddr_in6 *)ss;
port = ntohs(sin6->sin6_port);
break;
}
return port;
}
#else
static GArray *
parse_output(const char *output) {
GArray *entries;
char **lines;
char *ftype = NULL;
char *fname = NULL;
guint i;
guint len;
int fd = -1;
entries = g_array_new(FALSE, FALSE, sizeof(glibtop_open_files_entry));
lines = g_strsplit(output, "\n", 0);
len = g_strv_length(lines);
for (i = 0; i < len && lines[i]; i++) {
glibtop_open_files_entry entry = {0};
if (strlen(lines[i]) < 2)
continue;
if (!g_str_has_prefix(lines[i], "f") &&
!g_str_has_prefix(lines[i], "t") &&
!g_str_has_prefix(lines[i], "n"))
continue;
if (g_str_has_prefix(lines[i], "f")) {
if (!g_ascii_isdigit(*(lines[i] + 1)))
i += 2;
else
fd = atoi(lines[i] + 1);
continue;
}
if (g_str_has_prefix(lines[i], "t")) {
ftype = lines[i];
ftype++;
continue;
} else {
fname = lines[i];
fname++;
}
if (ftype == NULL || fname == NULL)
continue;
if (!strcmp(ftype, "unix")) {
entry.type = GLIBTOP_FILE_TYPE_LOCALSOCKET;
g_strlcpy(entry.info.localsock.name, fname,
sizeof(entry.info.localsock.name));
} else if (!strcmp(ftype, "PIPE")) {
entry.type = GLIBTOP_FILE_TYPE_PIPE;
} else if (!strcmp(ftype, "VREG") ||
!strcmp(ftype, "GDIR") ||
!strcmp(ftype, "GREG") ||
!strcmp(ftype, "VCHR") ||
!strcmp(ftype, "VBLK") ||
!strcmp(ftype, "DIR") ||
!strcmp(ftype, "LINK") ||
!strcmp(ftype, "REG") ||
!strcmp(ftype, "VDIR")) {
entry.type = GLIBTOP_FILE_TYPE_FILE;
g_strlcpy(entry.info.file.name, fname,
sizeof(entry.info.file.name));
} else if (!strcmp(ftype, "IPv4")) {
char **hosts;
char **remote_host;
if (!strstr(fname, "->")) {
remote_host = g_strsplit(fname, ":", 0);
} else {
hosts = g_strsplit(fname, "->", 0);
if (g_strv_length(hosts) < 2) {
g_strfreev(hosts);
continue;
}
remote_host = g_strsplit(hosts[1], ":", 0);
g_strfreev(hosts);
}
if (g_strv_length(remote_host) < 2) {
g_strfreev(remote_host);
continue;
}
entry.type = GLIBTOP_FILE_TYPE_INETSOCKET;
if (!strcmp(remote_host[0], "*"))
g_strlcpy(entry.info.sock.dest_host, "0.0.0.0",
sizeof(entry.info.sock.dest_host));
else
g_strlcpy(entry.info.sock.dest_host,
remote_host[0],
sizeof(entry.info.sock.dest_host));
entry.info.sock.dest_port = atoi(remote_host[1]);
g_strfreev(remote_host);
} else if (!strcmp(ftype, "IPv6")) {
char **hosts;
char **remote_host;
if (!strstr(fname, "->")) {
remote_host = g_strsplit(fname, ":", 0);
} else {
hosts = g_strsplit(fname, "->", 0);
if (g_strv_length(hosts) < 2) {
g_strfreev(hosts);
continue;
}
remote_host = g_strsplit(hosts[1], "]", 0);
g_strfreev(hosts);
}
if (g_strv_length(remote_host) < 2) {
g_strfreev(remote_host);
continue;
}
entry.type = GLIBTOP_FILE_TYPE_INET6SOCKET;
if (!strcmp(remote_host[0], "*"))
g_strlcpy(entry.info.sock.dest_host, "0.0.0.0",
sizeof(entry.info.sock.dest_host));
else
g_strlcpy(entry.info.sock.dest_host,
remote_host[0] + 1,
sizeof(entry.info.sock.dest_host));
entry.info.sock.dest_port = atoi(remote_host[1] + 1);
g_strfreev(remote_host);
} else
continue;
entry.fd = fd;
fd = -1;
ftype = NULL;
fname = NULL;
g_array_append_val(entries, entry);
}
g_strfreev(lines);
return entries;
}
#endif
glibtop_open_files_entry *
glibtop_get_proc_open_files_s (glibtop *server, glibtop_proc_open_files *buf, pid_t pid)
{
#if __FreeBSD_version > 800018 || (__FreeBSD_version < 800000 && __FreeBSD_version >= 700104)
struct kinfo_file *freep, *kif;
#ifndef HAVE_KINFO_GETFILE
int name[4];
size_t len;
#else
int cnt;
#endif
ssize_t i;
#else
char *output;
#endif
GArray *entries;
memset(buf, 0, sizeof (glibtop_proc_open_files));
#if __FreeBSD_version > 800018 || (__FreeBSD_version < 800000 && __FreeBSD_version >= 700104)
#ifndef HAVE_KINFO_GETFILE
name[0] = CTL_KERN;
name[1] = KERN_PROC;
name[2] = KERN_PROC_FILEDESC;
name[3] = pid;
if (sysctl(name, 4, NULL, &len, NULL, 0) < 0)
return NULL;
freep = kif = g_malloc(len);
if (sysctl(name, 4, kif, &len, NULL, 0) < 0) {
g_free(freep);
return NULL;
}
#else
freep = kinfo_getfile(pid, &cnt);
#endif
entries = g_array_new(FALSE, FALSE, sizeof(glibtop_open_files_entry));
#ifndef HAVE_KINFO_GETFILE
for (i = 0; i < len / sizeof(*kif); i++, kif++) {
glibtop_open_files_entry entry = {0};
if (kif->kf_structsize != sizeof(*kif))
continue;
#else
for (i = 0; i < cnt; i++) {
glibtop_open_files_entry entry = {0};
kif = &freep[i];
#endif
if (kif->kf_fd < 0)
continue;
if (kif->kf_type == KF_TYPE_SOCKET) {
if (kif->kf_sock_domain == AF_LOCAL) {
struct sockaddr_un *sun;
entry.type = GLIBTOP_FILE_TYPE_LOCALSOCKET;
sun = (struct sockaddr_un *)&kif->kf_sa_local;
if (sun->sun_path[0]) {
char *addrstr;
addrstr = addr_to_string(&kif->kf_sa_local);
g_strlcpy(entry.info.localsock.name,
addrstr,
sizeof(entry.info.localsock.name));
g_free(addrstr);
} else {
char *addrstr;
addrstr = addr_to_string(&kif->kf_sa_peer);
g_strlcpy(entry.info.localsock.name,
addrstr,
sizeof(entry.info.localsock.name));
g_free(addrstr);
}
} else if (kif->kf_sock_domain == AF_INET ||
kif->kf_sock_domain == AF_INET6) {
char *addrstr;
if (kif->kf_sock_domain == AF_INET)
entry.type = GLIBTOP_FILE_TYPE_INETSOCKET;
else
entry.type = GLIBTOP_FILE_TYPE_INET6SOCKET;
addrstr = addr_to_string(&kif->kf_sa_peer);
g_strlcpy(entry.info.sock.dest_host,
addrstr,
sizeof(entry.info.sock.dest_host));
g_free(addrstr);
entry.info.sock.dest_port = addr_to_port(&kif->kf_sa_peer);
}
} else if (kif->kf_type == KF_TYPE_PIPE) {
entry.type = GLIBTOP_FILE_TYPE_PIPE;
} else if (kif->kf_type == KF_TYPE_VNODE) {
entry.type = GLIBTOP_FILE_TYPE_FILE;
g_strlcpy(entry.info.file.name, kif->kf_path,
sizeof(entry.info.file.name));
} else
continue;
entry.fd = kif->kf_fd;
g_array_append_val(entries, entry);
}
g_free(freep);
#else
output = execute_lsof(pid);
if (output == NULL) return NULL;
entries = parse_output(output);
g_free(output);
#endif
buf->flags = _glibtop_sysdeps_proc_open_files;
buf->number = entries->len;
buf->size = sizeof(glibtop_open_files_entry);
buf->total = buf->number * buf->size;
return (glibtop_open_files_entry*)g_array_free(entries, FALSE);
}

View File

@@ -0,0 +1,74 @@
/* 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., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include <config.h>
#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 =
(1L << GLIBTOP_PROC_SEGMENT_TEXT_RSS) +
(1L << GLIBTOP_PROC_SEGMENT_DATA_RSS);
static int pagesize;
/* Init function. */
void
_glibtop_init_proc_segment_p (glibtop *server)
{
pagesize = getpagesize ();
server->sysdeps.proc_segment = _glibtop_sysdeps_proc_segment;
}
/* Provides detailed information about a process. */
void
glibtop_get_proc_segment_p (glibtop *server,
glibtop_proc_segment *buf,
pid_t pid)
{
struct kinfo_proc *pinfo;
int count = 0;
memset (buf, 0, sizeof (glibtop_proc_segment));
/* It does not work for the swapper task. */
if (pid == 0) return;
/* Get the process info from the kernel */
pinfo = kvm_getprocs (server->machine->kd, KERN_PROC_PID, pid, &count);
if ((pinfo == NULL) || (count != 1)) {
glibtop_warn_io_r (server, "kvm_getprocs (%d)", pid);
return;
}
buf->text_rss = pinfo[0].ki_tsize * pagesize;
buf->data_rss = pinfo[0].ki_dsize * pagesize;
buf->flags = _glibtop_sysdeps_proc_segment;
}

View File

@@ -0,0 +1,93 @@
/* 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., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include <config.h>
#include <glibtop.h>
#include <glibtop/error.h>
#include <glibtop/procsignal.h>
#include <glibtop_suid.h>
#include <sys/param.h>
#include <osreldate.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. */
void
_glibtop_init_proc_signal_p (glibtop *server)
{
server->sysdeps.proc_signal = _glibtop_sysdeps_proc_signal;
}
void
glibtop_get_proc_signal_p (glibtop *server,
glibtop_proc_signal *buf,
pid_t pid)
{
struct kinfo_proc *pinfo;
int count = 0;
memset (buf, 0, sizeof (glibtop_proc_signal));
/* It does not work for the swapper task. */
if (pid == 0) return;
/* Get the process information */
pinfo = kvm_getprocs (server->machine->kd, KERN_PROC_PID, pid, &count);
if ((pinfo == NULL) || (count != 1)) {
glibtop_warn_io_r (server, "kvm_getprocs (%d)", pid);
return;
}
#define PROC_SIGLIST ki_siglist
#define PROC_SIGMASK ki_sigmask
#define PROC_SIGIGNORE ki_sigignore
#define PROC_SIGCATCH ki_sigcatch
/* signal: mask of pending signals.
* pinfo [0].kp_proc.p_siglist
*/
buf->signal [0] = pinfo [0].PROC_SIGLIST.__bits[0];
/* blocked: mask of blocked signals.
* pinfo [0].kp_proc.p_sigmask
*/
buf->blocked [0] = pinfo [0].PROC_SIGMASK.__bits[0];
/* sigignore: mask of ignored signals.
* pinfo [0].kp_proc.p_sigignore
*/
buf->sigignore [0] = pinfo [0].PROC_SIGIGNORE.__bits[0];
/* sigcatch: mask of caught signals.
* pinfo [0].kp_proc.p_sigcatch
*/
buf->sigcatch [0] = pinfo [0].PROC_SIGCATCH.__bits[0];
buf->flags = _glibtop_sysdeps_proc_signal;
}

View File

@@ -0,0 +1,91 @@
/* 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., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include <config.h>
#include <glibtop.h>
#include <glibtop/error.h>
#include <glibtop/procstate.h>
#include <glibtop_suid.h>
#include <sys/user.h>
static const unsigned long _glibtop_sysdeps_proc_state =
(1L << GLIBTOP_PROC_STATE_CMD) + (1L << GLIBTOP_PROC_STATE_STATE) +
(1L << GLIBTOP_PROC_STATE_UID) + (1L << GLIBTOP_PROC_STATE_GID);
/* Init function. */
void
_glibtop_init_proc_state_p (glibtop *server)
{
server->sysdeps.proc_state = _glibtop_sysdeps_proc_state;
}
/* Provides detailed information about a process. */
void
glibtop_get_proc_state_p (glibtop *server,
glibtop_proc_state *buf,
pid_t pid)
{
struct kinfo_proc *pinfo;
int count = 0;
memset (buf, 0, sizeof (glibtop_proc_state));
/* Get the process information */
pinfo = kvm_getprocs (server->machine->kd, KERN_PROC_PID, pid, &count);
if ((pinfo == NULL) || (count != 1)) {
glibtop_warn_io_r (server, "kvm_getprocs (%d)", pid);
return;
}
buf->uid = pinfo[0].ki_ruid;
buf->gid = pinfo[0].ki_rgid;
g_strlcpy (buf->cmd, pinfo[0].ki_comm, sizeof (buf->cmd));
switch (pinfo[0].ki_stat) {
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;
case SWAIT:
case SLOCK:
buf->state = GLIBTOP_PROCESS_UNINTERRUPTIBLE;
break;
case SIDL:
default:
buf->state = 0;
break;
}
buf->flags = _glibtop_sysdeps_proc_state;
}

114
sysdeps/freebsd/proctime.c Normal file
View File

@@ -0,0 +1,114 @@
/* 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., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include <config.h>
#include <glibtop.h>
#include <glibtop/error.h>
#include <glibtop/proctime.h>
#include <glibtop_suid.h>
#include <sys/time.h>
#include <osreldate.h>
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);
static guint64 tv2sec_freq(struct timeval tv, guint64 freq)
{
return tv.tv_sec * freq + tv.tv_usec * freq / 1000000;
}
#define tv2sec(tv) tv2sec_freq(tv, 1)
/* Init function. */
void
_glibtop_init_proc_time_p (glibtop *server)
{
server->sysdeps.proc_time = _glibtop_sysdeps_proc_time |
_glibtop_sysdeps_proc_time_user;
}
/* Taken from /usr/src/sys/kern/kern_resource.c */
/* Provides detailed information about a process. */
void
glibtop_get_proc_time_p (glibtop *server, glibtop_proc_time *buf,
pid_t pid)
{
struct kinfo_proc *pinfo;
struct clockinfo ci;
int count;
size_t len;
memset (buf, 0, sizeof (glibtop_proc_time));
/* It does not work for the swapper task. */
if (pid == 0) return;
glibtop_suid_enter (server);
/* Get the process information */
pinfo = kvm_getprocs (server->machine->kd, KERN_PROC_PID, pid, &count);
if ((pinfo == NULL) || (count != 1)) {
glibtop_warn_io_r (server, "kvm_getprocs (%d)", pid);
glibtop_suid_leave (server);
return;
}
glibtop_suid_leave (server);
len = sizeof (ci);
if (sysctlbyname ("kern.clockrate", &ci, &len, NULL, 0)) {
glibtop_warn_io_r (server, "sysctl (kern.clockrate) (%d)", pid);
glibtop_suid_leave (server);
return;
}
buf->frequency = (ci.stathz ? ci.stathz : ci.hz);
buf->rtime = pinfo [0].ki_runtime * buf->frequency / 1000000;
buf->flags = _glibtop_sysdeps_proc_time;
/*
All the following used to be 'if (pinfo [0].ki_flag & PS_INMEM)'
but it was never entered.
I have no idea what this PS_INMEM is, but it works perfectly
without this check.
*/
buf->utime = tv2sec_freq (pinfo [0].ki_rusage.ru_utime, buf->frequency);
buf->stime = tv2sec_freq (pinfo [0].ki_rusage.ru_stime, buf->frequency);
buf->cutime = tv2sec_freq (pinfo [0].ki_childtime, buf->frequency);
#if (__FreeBSD_version >= 600006) || defined(__FreeBSD_kernel__)
buf->cstime = tv2sec_freq (pinfo [0].ki_rusage_ch.ru_stime, buf->frequency);
#else
buf->cstime = 0;
#endif
buf->start_time = tv2sec (pinfo [0].ki_start);
buf->flags |= _glibtop_sysdeps_proc_time_user;
}

88
sysdeps/freebsd/procuid.c Normal file
View File

@@ -0,0 +1,88 @@
/* 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., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include <config.h>
#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) + (1L << GLIBTOP_PROC_UID_GID);
/* Init function. */
void
_glibtop_init_proc_uid_p (glibtop *server)
{
server->sysdeps.proc_uid = _glibtop_sysdeps_proc_uid;
}
/* Provides detailed information about a process. */
void
glibtop_get_proc_uid_p (glibtop *server, glibtop_proc_uid *buf,
pid_t pid)
{
struct kinfo_proc *pinfo;
int count = 0;
memset (buf, 0, sizeof (glibtop_proc_uid));
/* It does not work for the swapper task. */
if (pid == 0) return;
/* Get the process information */
pinfo = kvm_getprocs (server->machine->kd, KERN_PROC_PID, pid, &count);
if ((pinfo == NULL) || (count != 1)) {
glibtop_warn_io_r (server, "kvm_getprocs (%d)", pid);
return;
}
#define PROC_RUID ki_ruid
#define PROC_EUID ki_uid
#define PROC_RGID ki_rgid
#define PROC_SVGID ki_svgid
#define PROC_PPID ki_ppid
#define PROC_PGID ki_pgid
#define PROC_TPGID ki_tpgid
#define PROC_NICE ki_nice
#define PROC_PRIORITY ki_pri.pri_user
buf->uid = pinfo [0].PROC_RUID;
buf->euid = pinfo [0].PROC_EUID;
buf->gid = pinfo [0].PROC_RGID;
buf->egid = pinfo [0].PROC_SVGID;
buf->ppid = pinfo [0].PROC_PPID;
buf->pgrp = pinfo [0].PROC_PGID;
buf->tpgid = pinfo [0].PROC_TPGID;
buf->nice = pinfo [0].PROC_NICE;
buf->priority = pinfo [0].PROC_PRIORITY;
buf->flags = _glibtop_sysdeps_proc_uid;
}

200
sysdeps/freebsd/procwd.c Normal file
View File

@@ -0,0 +1,200 @@
/* Copyright (C) 2007 Joe Marcus Clarke
This file is part of LibGTop 2.
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., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include <config.h>
#include <glibtop/procwd.h>
#include <glibtop/error.h>
#include <glibtop_private.h>
#include <sys/types.h>
#include <sys/sysctl.h>
#include <sys/param.h>
#include <sys/user.h>
#ifdef HAVE_KINFO_GETFILE
#include <libutil.h>
#endif
#include <string.h>
static const unsigned long _glibtop_sysdeps_proc_wd =
(1 << GLIBTOP_PROC_WD_EXE) |
(1 << GLIBTOP_PROC_WD_ROOT) |
(1 << GLIBTOP_PROC_WD_NUMBER);
void
_glibtop_init_proc_wd_s(glibtop *server)
{
server->sysdeps.proc_wd = _glibtop_sysdeps_proc_wd;
}
#if (__FreeBSD_version >= 800000 && __FreeBSD_version < 800019) || __FreeBSD_version < 700104
static GPtrArray *
parse_output(const char *output, glibtop_proc_wd *buf)
{
GPtrArray *dirs;
char **lines;
gboolean nextwd = FALSE;
gboolean nextrtd = FALSE;
gboolean havertd = FALSE;
guint i;
guint len;
dirs = g_ptr_array_sized_new(1);
lines = g_strsplit(output, "\n", 0);
len = g_strv_length(lines);
for (i = 0; i < len && lines[i]; i++) {
if (strlen(lines[i]) < 2)
continue;
if (!strcmp(lines[i], "fcwd")) {
nextwd = TRUE;
continue;
}
if (!strcmp(lines[i], "frtd")) {
nextrtd = TRUE;
continue;
}
if (!g_str_has_prefix(lines[i], "n"))
continue;
if (nextwd) {
g_ptr_array_add(dirs, g_strdup(lines[i] + 1));
nextwd = FALSE;
}
if (nextrtd && !havertd) {
g_strlcpy(buf->root, lines[i] + 1,
sizeof(buf->root));
buf->flags |= (1 << GLIBTOP_PROC_WD_ROOT);
nextrtd = FALSE;
havertd = TRUE;
}
}
g_strfreev(lines);
return dirs;
}
#endif
char**
glibtop_get_proc_wd_s(glibtop *server, glibtop_proc_wd *buf, pid_t pid)
{
int exe_mib[4];
size_t len;
#if __FreeBSD_version > 800018 || (__FreeBSD_version < 800000 && __FreeBSD_version >= 700104)
struct kinfo_file *freep, *kif;
GPtrArray *dirs;
#ifndef HAVE_KINFO_GETFILE
int name[4];
#else
int cnt;
#endif
int i;
#else
char *output;
#endif
memset (buf, 0, sizeof (glibtop_proc_wd));
len = 0;
exe_mib[0] = CTL_KERN;
exe_mib[1] = KERN_PROC;
exe_mib[2] = KERN_PROC_PATHNAME;
exe_mib[3] = pid;
if (sysctl(exe_mib, 4, NULL, &len, NULL, 0) == 0) {
if (len > sizeof(buf->exe))
len = sizeof(buf->exe);
if (sysctl(exe_mib, 4, buf->exe, &len, NULL, 0) == 0)
buf->flags |= (1 << GLIBTOP_PROC_WD_EXE);
}
#if __FreeBSD_version > 800018 || (__FreeBSD_version < 800000 && __FreeBSD_version >= 700104)
#ifndef HAVE_KINFO_GETFILE
len = 0;
name[0] = CTL_KERN;
name[1] = KERN_PROC;
name[2] = KERN_PROC_FILEDESC;
name[3] = pid;
if (sysctl(name, 4, NULL, &len, NULL, 0) < 0)
return NULL;
freep = kif = g_malloc(len);
if (sysctl(name, 4, kif, &len, NULL, 0) < 0) {
g_free(freep);
return NULL;
}
#else
freep = kinfo_getfile(pid, &cnt);
#endif
dirs = g_ptr_array_sized_new(1);
#ifndef HAVE_KINFO_GETFILE
for (i = 0; i < len / sizeof(*kif); i++, kif++) {
if (kif->kf_structsize != sizeof(*kif))
continue;
#else
for (i = 0; i < cnt; i++) {
kif = &freep[i];
#endif
switch (kif->kf_fd) {
case KF_FD_TYPE_ROOT:
g_strlcpy(buf->root, kif->kf_path,
sizeof(buf->root));
buf->flags |= (1 << GLIBTOP_PROC_WD_ROOT);
break;
case KF_FD_TYPE_CWD:
g_ptr_array_add(dirs, g_strdup (kif->kf_path));
break;
}
}
g_free(freep);
buf->number = dirs->len;
buf->flags |= (1 << GLIBTOP_PROC_WD_NUMBER);
g_ptr_array_add(dirs, NULL);
return (char **)g_ptr_array_free(dirs, FALSE);
#else
output = execute_lsof(pid);
if (output != NULL) {
GPtrArray *dirs;
dirs = parse_output(output, buf);
g_free(output);
buf->number = dirs->len;
buf->flags |= (1 << GLIBTOP_PROC_WD_NUMBER);
g_ptr_array_add(dirs, NULL);
return (char **)g_ptr_array_free(dirs, FALSE);
}
#endif
return NULL;
}

View File

@@ -0,0 +1,132 @@
/* 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., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include <config.h>
#include <glibtop.h>
#include <glibtop/error.h>
#include <glibtop/sem_limits.h>
#include <sys/types.h>
#include <sys/sysctl.h>
static unsigned long _glibtop_sysdeps_sem_limits =
(1L << GLIBTOP_IPC_SEMMAP) + (1L << GLIBTOP_IPC_SEMMNI) +
(1L << GLIBTOP_IPC_SEMMNS) + (1L << GLIBTOP_IPC_SEMMNU) +
(1L << GLIBTOP_IPC_SEMMSL) + (1L << GLIBTOP_IPC_SEMOPM) +
(1L << GLIBTOP_IPC_SEMUME) + (1L << GLIBTOP_IPC_SEMUSZ) +
(1L << GLIBTOP_IPC_SEMVMX) + (1L << GLIBTOP_IPC_SEMAEM);
/* Init function. */
void
_glibtop_init_sem_limits_s (glibtop *server)
{
server->sysdeps.sem_limits = _glibtop_sysdeps_sem_limits;
}
/* Provides information about sysv sem limits. */
void
glibtop_get_sem_limits_s (glibtop *server, glibtop_sem_limits *buf)
{
size_t len;
int semmap, semmni, semmns, semmnu, semmsl, semopm, semume, semusz;
int semvmx, semaem;
memset (buf, 0, sizeof (glibtop_sem_limits));
if (server->sysdeps.sem_limits == 0)
return;
len = sizeof (semmap);
if (sysctlbyname ("kern.ipc.semmap", &semmap, &len, NULL, 0)) {
glibtop_warn_io_r (server, "sysctl (kern.ipc.semmap)");
return;
}
len = sizeof (semmni);
if (sysctlbyname ("kern.ipc.semmni", &semmni, &len, NULL, 0)) {
glibtop_warn_io_r (server, "sysctl (kern.ipc.semmni)");
return;
}
len = sizeof (semmns);
if (sysctlbyname ("kern.ipc.semmns", &semmns, &len, NULL, 0)) {
glibtop_warn_io_r (server, "sysctl (kern.ipc.semmns)");
return;
}
len = sizeof (semmnu);
if (sysctlbyname ("kern.ipc.semmnu", &semmnu, &len, NULL, 0)) {
glibtop_warn_io_r (server, "sysctl (kern.ipc.semmnu)");
return;
}
len = sizeof (semmsl);
if (sysctlbyname ("kern.ipc.semmsl", &semmsl, &len, NULL, 0)) {
glibtop_warn_io_r (server, "sysctl (kern.ipc.semmsl)");
return;
}
len = sizeof (semopm);
if (sysctlbyname ("kern.ipc.semopm", &semopm, &len, NULL, 0)) {
glibtop_warn_io_r (server, "sysctl (kern.ipc.semopm)");
return;
}
len = sizeof (semume);
if (sysctlbyname ("kern.ipc.semume", &semume, &len, NULL, 0)) {
glibtop_warn_io_r (server, "sysctl (kern.ipc.semume)");
return;
}
len = sizeof (semusz);
if (sysctlbyname ("kern.ipc.semusz", &semusz, &len, NULL, 0)) {
glibtop_warn_io_r (server, "sysctl (kern.ipc.semusz)");
return;
}
len = sizeof (semvmx);
if (sysctlbyname ("kern.ipc.semvmx", &semvmx, &len, NULL, 0)) {
glibtop_warn_io_r (server, "sysctl (kern.ipc.semvmx)");
return;
}
len = sizeof (semaem);
if (sysctlbyname ("kern.ipc.semaem", &semaem, &len, NULL, 0)) {
glibtop_warn_io_r (server, "sysctl (kern.ipc.semaem)");
return;
}
buf->semmap = semmap;
buf->semmni = semmni;
buf->semmns = semmns;
buf->semmnu = semmnu;
buf->semmsl = semmsl;
buf->semopm = semopm;
buf->semume = semume;
buf->semusz = semusz;
buf->semvmx = semvmx;
buf->semaem = semaem;
buf->flags = _glibtop_sysdeps_sem_limits;
}

View File

@@ -0,0 +1,98 @@
/* 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., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include <config.h>
#include <glibtop.h>
#include <glibtop/error.h>
#include <glibtop/shm_limits.h>
#include <sys/types.h>
#include <sys/param.h>
#include <sys/sysctl.h>
static unsigned long _glibtop_sysdeps_shm_limits =
(1L << GLIBTOP_IPC_SHMMAX) + (1L << GLIBTOP_IPC_SHMMIN) +
(1L << GLIBTOP_IPC_SHMMNI) + (1L << GLIBTOP_IPC_SHMSEG) +
(1L << GLIBTOP_IPC_SHMALL);
/* Init function. */
void
_glibtop_init_shm_limits_s (glibtop *server)
{
server->sysdeps.shm_limits = _glibtop_sysdeps_shm_limits;
}
/* Provides information about sysv ipc limits. */
void
glibtop_get_shm_limits_s (glibtop *server, glibtop_shm_limits *buf)
{
size_t len;
#if __FreeBSD_version < 700002
int shmmax, shmmin, shmmni, shmseg, shmall;
#else
unsigned long shmmax, shmmin, shmmni, shmseg, shmall;
#endif
memset (buf, 0, sizeof (glibtop_shm_limits));
if (server->sysdeps.shm_limits == 0)
return;
len = sizeof (shmmax);
if (sysctlbyname ("kern.ipc.shmmax", &shmmax, &len, NULL, 0)) {
glibtop_warn_io_r (server, "sysctl (kern.ipc.shmmax)");
return;
}
len = sizeof (shmmin);
if (sysctlbyname ("kern.ipc.shmmin", &shmmin, &len, NULL, 0)) {
glibtop_warn_io_r (server, "sysctl (kern.ipc.shmmin)");
return;
}
len = sizeof (shmmni);
if (sysctlbyname ("kern.ipc.shmmni", &shmmni, &len, NULL, 0)) {
glibtop_warn_io_r (server, "sysctl (kern.ipc.shmmni)");
return;
}
len = sizeof (shmseg);
if (sysctlbyname ("kern.ipc.shmseg", &shmseg, &len, NULL, 0)) {
glibtop_warn_io_r (server, "sysctl (kern.ipc.shmseg)");
return;
}
len = sizeof (shmall);
if (sysctlbyname ("kern.ipc.shmall", &shmall, &len, NULL, 0)) {
glibtop_warn_io_r (server, "sysctl (kern.ipc.shmall)");
return;
}
buf->shmmax = shmmax;
buf->shmmin = shmmin;
buf->shmmni = shmmni;
buf->shmseg = shmseg;
buf->shmall = shmall;
buf->flags = _glibtop_sysdeps_shm_limits;
}

60
sysdeps/freebsd/siglist.c Normal file
View File

@@ -0,0 +1,60 @@
/* 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., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include <config.h>
#include <glibtop.h>
#include <glibtop/signal.h>
const glibtop_signame glibtop_sys_siglist [] =
{ { 1, "SIGHUP", "Hangup" },
{ 2, "SIGINT", "Interrupt" },
{ 3, "SIGQUIT", "Quit" },
{ 4, "SIGILL", "Illegal Instruction" },
{ 5, "SIGTRAP", "Trace/Breakpoint Trap" },
{ 6, "SIGABRT", "Abort" },
{ 7, "SIGEMT", "Emulation Trap" },
{ 8, "SIGFPE", "Arithmetic Exception" },
{ 9, "SIGKILL", "Killed" },
{ 10, "SIGBUS", "Bus Error" },
{ 11, "SIGSEGV", "Segmentation Fault" },
{ 12, "SIGSYS", "Bad System Call" },
{ 13, "SIGPIPE", "Broken Pipe" },
{ 14, "SIGALRM", "Alarm Clock" },
{ 15, "SIGTERM", "Terminated" },
{ 16, "SIGURG", "Urgent Condition Present On Socket" },
{ 17, "SIGSTOP", "Stop (cannot be caught or ignored)" },
{ 18, "SIGTSTP", "Stop Signal Generated From Keyboard" },
{ 19, "SIGCONT", "Continue After Stop" },
{ 20, "SIGCHLD", "Child Status Has Changed" },
{ 21, "SIGTTIN", "Background Read Attempted From Control Terminal" },
{ 22, "SIGTTOU", "Background Write Attempted To Control Terminal" },
{ 23, "SIGIO", "I/O Is Possible On A Descriptor" },
{ 24, "SIGXCPU", "CPU Time Limit Exceeded" },
{ 25, "SIGXFSZ", "File Size Limit Exceeded" },
{ 26, "SIGVTALRM","Virtual Time Alarm" },
{ 27, "SIGPROF", "Profiling Timer Alarm" },
{ 28, "SIGWINCH","Window Size Change" },
{ 29, "SIGINFO", "Status Request From Keyboard" },
{ 30, "SIGUSR1", "User Defined Signal 1" },
{ 31, "SIGUSR2", "User Defined Signal 2" },
{ 32, "SIGTHR", "Thread Interrupt" },
{ 0, NULL, NULL }
};

View File

@@ -0,0 +1,95 @@
/* 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., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include <config.h>
#include <glibtop.h>
#include <glibtop/error.h>
#include <glibtop/cpu.h>
#include <glibtop/open.h>
#include <glibtop/init_hooks.h>
#include <glibtop/machine.h>
/* !!! THIS FUNCTION RUNS SUID ROOT - CHANGE WITH CAUTION !!! */
void
glibtop_init_p (glibtop *server, const unsigned long features,
const unsigned flags)
{
const _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)
{
char errbuf[_POSIX2_LINE_MAX];
glibtop_debug ("glibtop_open_p ()");
/* !!! WE ARE ROOT HERE - CHANGE WITH CAUTION !!! */
server->machine->uid = getuid ();
server->machine->euid = geteuid ();
server->machine->gid = getgid ();
server->machine->egid = getegid ();
/* Setup machine-specific data */
server->machine->kd = kvm_openfiles (NULL, NULL, NULL, O_RDONLY, errbuf);
if (server->machine->kd == NULL)
glibtop_error_io_r (server, "kvm_open");
/* Drop priviledges. */
glibtop_debug ("uid=%d euid=%d gid=%d egid=%d", getuid(), geteuid(), getgid(), getegid());
if (setreuid (server->machine->euid, server->machine->uid))
_exit (1);
if (setregid (server->machine->egid, server->machine->gid))
_exit (1);
glibtop_debug ("uid=%d euid=%d gid=%d egid=%d", getuid(), geteuid(), getgid(), getegid());
/* !!! 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. */
}

92
sysdeps/freebsd/swap.c Normal file
View File

@@ -0,0 +1,92 @@
/* 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., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include <config.h>
#include <glibtop.h>
#include <glibtop/error.h>
#include <glibtop/swap.h>
#include <glibtop_suid.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_paging =
(1L << GLIBTOP_SWAP_PAGEIN) + (1L << GLIBTOP_SWAP_PAGEOUT);
static int pagesize;
/* Init function. */
void
_glibtop_init_swap_p (glibtop *server)
{
pagesize = getpagesize ();
server->sysdeps.swap = _glibtop_sysdeps_swap |
_glibtop_sysdeps_swap_paging;
}
/* Provides information about swap usage. */
void
glibtop_get_swap_p (glibtop *server, glibtop_swap *buf)
{
size_t len;
unsigned int swappgsout, swappgsin;
int nswdev;
struct kvm_swap kvmsw[16];
memset (buf, 0, sizeof (glibtop_swap));
memset (kvmsw, 0, sizeof (kvmsw));
nswdev = kvm_getswapinfo (server->machine->kd, kvmsw, 16, 0);
if (nswdev < 1) return;
buf->flags = _glibtop_sysdeps_swap;
/* See the man page for kvm_getswapinfo(3) to see why we can do this. */
buf->used = kvmsw[nswdev].ksw_used;
buf->total = kvmsw[nswdev].ksw_total;
buf->total *= pagesize;
buf->used *= pagesize;
buf->free = buf->total - buf->used;
len = sizeof (swappgsout);
if (sysctlbyname ("vm.stats.vm.v_swappgsout", &swappgsout, &len, NULL, 0)) {
glibtop_warn_io_r (server, "sysctl (vm.stats.vm.v_swappgsout)");
return;
}
len = sizeof (swappgsin);
if (sysctlbyname ("vm.stats.vm.v_swappgsin", &swappgsin, &len, NULL, 0)) {
glibtop_warn_io_r (server, "sysctl (vm.stats.vm.v_swappgsin)");
return;
}
buf->pagein = (guint64) swappgsin;
buf->pageout = (guint64) swappgsout;
buf->flags |= _glibtop_sysdeps_swap_paging;
}

93
sysdeps/freebsd/sysinfo.c Normal file
View File

@@ -0,0 +1,93 @@
/* 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., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include <config.h>
#include <sys/param.h>
#include <sys/types.h>
#include <sys/sysctl.h>
#include <glibtop/error.h>
#include <glibtop/cpu.h>
#include <glibtop/sysinfo.h>
static const unsigned long _glibtop_sysdeps_sysinfo =
(1L << GLIBTOP_SYSINFO_CPUINFO);
static glibtop_sysinfo sysinfo = { .flags = 0 };
static void
init_sysinfo (glibtop *server)
{
char *model;
guint64 ncpus = 1;
int mhz = 0;
size_t len;
if (G_LIKELY (sysinfo.flags))
return;
ncpus = server->ncpu + 1;
len = 0;
sysctlbyname ("hw.model", NULL, &len, NULL, 0);
model = g_malloc (len);
sysctlbyname ("hw.model", model, &len, NULL, 0);
len = sizeof (mhz);
sysctlbyname ("hw.clockrate", &mhz, &len, NULL, 0);
for (sysinfo.ncpu = 0;
sysinfo.ncpu < GLIBTOP_NCPU && sysinfo.ncpu < ncpus;
sysinfo.ncpu++) {
glibtop_entry * const cpuinfo = &sysinfo.cpuinfo[sysinfo.ncpu];
cpuinfo->labels = g_ptr_array_new ();
cpuinfo->values = g_hash_table_new_full(g_str_hash,
g_str_equal,
NULL, g_free);
g_ptr_array_add (cpuinfo->labels, "processor");
g_hash_table_insert (cpuinfo->values, "processor",
g_strdup_printf("%u", (guint)sysinfo.ncpu));
g_ptr_array_add (cpuinfo->labels, "vendor_id");
g_hash_table_insert (cpuinfo->values, "vendor_id",
g_strdup(model));
g_ptr_array_add (cpuinfo->labels, "model name");
g_hash_table_insert (cpuinfo->values, "model name",
g_strdup(model));
g_ptr_array_add (cpuinfo->labels, "cpu MHz");
g_hash_table_insert (cpuinfo->values, "cpu MHz",
g_strdup_printf("%d", mhz));
}
g_free (model);
sysinfo.flags = _glibtop_sysdeps_sysinfo;
}
const glibtop_sysinfo *
glibtop_get_sysinfo_s (glibtop *server)
{
init_sysinfo (server);
return &sysinfo;
}

86
sysdeps/freebsd/uptime.c Normal file
View File

@@ -0,0 +1,86 @@
/* 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., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include <config.h>
#include <glibtop.h>
#include <glibtop/error.h>
#include <glibtop/uptime.h>
#include <glibtop/cpu.h>
#include <sys/types.h>
#include <sys/sysctl.h>
static const unsigned long _glibtop_sysdeps_uptime =
(1L << GLIBTOP_UPTIME_UPTIME);
static const unsigned long _glibtop_sysdeps_idletime =
(1L << GLIBTOP_UPTIME_IDLETIME);
static const unsigned long _required_cpu_flags =
(1L << GLIBTOP_CPU_IDLE) +
(1L << GLIBTOP_CPU_FREQUENCY);
/* Init function. */
void
_glibtop_init_uptime_s (glibtop *server)
{
server->sysdeps.uptime = _glibtop_sysdeps_uptime;
}
/* Provides uptime and idle time. */
void
glibtop_get_uptime_s (glibtop *server, glibtop_uptime *buf)
{
time_t now;
int mib[2];
struct timeval boottime;
size_t size;
glibtop_cpu cpu;
memset (buf, 0, sizeof (glibtop_uptime));
mib[0] = CTL_KERN;
mib[1] = KERN_BOOTTIME;
size = sizeof(boottime);
if (sysctl(mib, 2, &boottime, &size, NULL, 0) != -1 &&
boottime.tv_sec != 0) {
time(&now);
buf->uptime = now - boottime.tv_sec;
buf->flags = _glibtop_sysdeps_uptime;
}
glibtop_get_cpu_s (server, &cpu);
/* Make sure all required fields are present. */
if ((cpu.flags & _required_cpu_flags) != _required_cpu_flags)
return;
/* Calculate values. */
buf->idletime = (double) cpu.idle / (double) cpu.frequency;
buf->idletime /= (double) (server->ncpu + 1);
buf->flags |= _glibtop_sysdeps_idletime;
}