summaryrefslogtreecommitdiff
path: root/sysdeps
diff options
context:
space:
mode:
Diffstat (limited to 'sysdeps')
-rw-r--r--sysdeps/aix/ChangeLog3
-rw-r--r--sysdeps/aix/Makefile.am23
-rw-r--r--sysdeps/aix/close.c30
-rw-r--r--sysdeps/aix/cpu.c125
-rw-r--r--sysdeps/aix/glibtop_machine.h53
-rw-r--r--sysdeps/aix/glibtop_server.h52
-rw-r--r--sysdeps/aix/glibtop_suid.h52
-rw-r--r--sysdeps/aix/loadavg.c78
-rw-r--r--sysdeps/aix/mem.c76
-rw-r--r--sysdeps/aix/msg_limits.c81
-rw-r--r--sysdeps/aix/netload.c207
-rw-r--r--sysdeps/aix/nosuid.c46
-rw-r--r--sysdeps/aix/open.c82
-rw-r--r--sysdeps/aix/ppp.c44
-rw-r--r--sysdeps/aix/procargs.c132
-rw-r--r--sysdeps/aix/prockernel.c98
-rw-r--r--sysdeps/aix/proclist.c247
-rw-r--r--sysdeps/aix/procmap.c50
-rw-r--r--sysdeps/aix/procmem.c73
-rw-r--r--sysdeps/aix/procsegment.c74
-rw-r--r--sysdeps/aix/procsignal.c89
-rw-r--r--sysdeps/aix/procstate.c127
-rw-r--r--sysdeps/aix/proctime.c72
-rw-r--r--sysdeps/aix/procuid.c101
-rw-r--r--sysdeps/aix/sem_limits.c86
-rw-r--r--sysdeps/aix/shm_limits.c79
-rw-r--r--sysdeps/aix/siglist.c72
-rw-r--r--sysdeps/aix/swap.c128
-rw-r--r--sysdeps/aix/sysinfo.c194
-rw-r--r--sysdeps/aix/uptime.c73
-rw-r--r--sysdeps/aix/utils.c141
-rw-r--r--sysdeps/aix/utils.h45
-rw-r--r--sysdeps/common/error.c88
-rw-r--r--sysdeps/common/gnuslib.c375
-rw-r--r--sysdeps/common/inodedb.c117
-rw-r--r--sysdeps/common/xmalloc.c72
-rw-r--r--sysdeps/freebsd/.cvsignore6
-rw-r--r--sysdeps/freebsd/AUTHORS2
-rw-r--r--sysdeps/freebsd/ChangeLog188
-rw-r--r--sysdeps/freebsd/Makefile.am23
-rw-r--r--sysdeps/freebsd/NOTES10
-rw-r--r--sysdeps/freebsd/close.c31
-rw-r--r--sysdeps/freebsd/cpu.c117
-rw-r--r--sysdeps/freebsd/glibtop_machine.h59
-rw-r--r--sysdeps/freebsd/glibtop_server.h52
-rw-r--r--sysdeps/freebsd/glibtop_suid.h58
-rw-r--r--sysdeps/freebsd/init.c45
-rw-r--r--sysdeps/freebsd/loadavg.c60
-rw-r--r--sysdeps/freebsd/mem.c222
-rw-r--r--sysdeps/freebsd/msg_limits.c115
-rw-r--r--sysdeps/freebsd/netload.c219
-rw-r--r--sysdeps/freebsd/nosuid.c37
-rw-r--r--sysdeps/freebsd/open.c95
-rw-r--r--sysdeps/freebsd/ppp.c144
-rw-r--r--sysdeps/freebsd/procargs.c111
-rw-r--r--sysdeps/freebsd/procdata.c180
-rw-r--r--sysdeps/freebsd/prockernel.c184
-rw-r--r--sysdeps/freebsd/proclist.c103
-rw-r--r--sysdeps/freebsd/procmap.c266
-rw-r--r--sysdeps/freebsd/procmem.c259
-rw-r--r--sysdeps/freebsd/procsegment.c82
-rw-r--r--sysdeps/freebsd/procsignal.c107
-rw-r--r--sysdeps/freebsd/procstate.c137
-rw-r--r--sysdeps/freebsd/proctime.c229
-rw-r--r--sysdeps/freebsd/procuid.c128
-rw-r--r--sysdeps/freebsd/sem_limits.c120
-rw-r--r--sysdeps/freebsd/shm_limits.c115
-rw-r--r--sysdeps/freebsd/siglist.c28
-rw-r--r--sysdeps/freebsd/swap.c426
-rw-r--r--sysdeps/freebsd/uptime.c73
-rw-r--r--sysdeps/guile/.cvsignore9
-rw-r--r--sysdeps/guile/ChangeLog50
-rw-r--r--sysdeps/guile/Makefile.am27
-rw-r--r--sysdeps/guile/guile.pl274
-rw-r--r--sysdeps/guile/names/.cvsignore10
-rw-r--r--sysdeps/guile/names/Makefile.am25
-rw-r--r--sysdeps/guile/names/guile-names.pl197
-rw-r--r--sysdeps/kernel/.cvsignore28
-rw-r--r--sysdeps/kernel/ChangeLog27
-rw-r--r--sysdeps/kernel/Makefile.am25
-rw-r--r--sysdeps/kernel/close.c30
-rw-r--r--sysdeps/kernel/cpu.c65
-rw-r--r--sysdeps/kernel/glibtop_private.h89
-rw-r--r--sysdeps/kernel/glibtop_server.h52
-rw-r--r--sysdeps/kernel/kernel.h40
-rw-r--r--sysdeps/kernel/kernel.s42
-rw-r--r--sysdeps/kernel/loadavg.c65
-rw-r--r--sysdeps/kernel/mem.c68
-rw-r--r--sysdeps/kernel/msg_limits.c65
-rw-r--r--sysdeps/kernel/netload.c45
-rw-r--r--sysdeps/kernel/open.c63
-rw-r--r--sysdeps/kernel/ppp.c44
-rw-r--r--sysdeps/kernel/procargs.c47
-rw-r--r--sysdeps/kernel/procdata.c180
-rw-r--r--sysdeps/kernel/prockernel.c68
-rw-r--r--sysdeps/kernel/proclist.c86
-rw-r--r--sysdeps/kernel/procmap.c49
-rw-r--r--sysdeps/kernel/procmem.c70
-rw-r--r--sysdeps/kernel/procsegment.c77
-rw-r--r--sysdeps/kernel/procsignal.c63
-rw-r--r--sysdeps/kernel/procstate.c75
-rw-r--r--sysdeps/kernel/proctime.c73
-rw-r--r--sysdeps/kernel/procuid.c105
-rw-r--r--sysdeps/kernel/sem_limits.c86
-rw-r--r--sysdeps/kernel/shm_limits.c62
-rw-r--r--sysdeps/kernel/siglist.c60
-rw-r--r--sysdeps/kernel/swap.c65
-rw-r--r--sysdeps/kernel/sysinfo.c94
-rw-r--r--sysdeps/kernel/uptime.c64
-rw-r--r--sysdeps/linux/.cvsignore6
-rw-r--r--sysdeps/linux/ChangeLog140
-rw-r--r--sysdeps/linux/Makefile.am18
-rw-r--r--sysdeps/linux/close.c30
-rw-r--r--sysdeps/linux/cpu.c111
-rw-r--r--sysdeps/linux/glibtop_machine.h58
-rw-r--r--sysdeps/linux/glibtop_server.h135
-rw-r--r--sysdeps/linux/loadavg.c94
-rw-r--r--sysdeps/linux/mem.c81
-rw-r--r--sysdeps/linux/msg_limits.c65
-rw-r--r--sysdeps/linux/netload.c354
-rw-r--r--sysdeps/linux/open.c109
-rw-r--r--sysdeps/linux/ppp.c201
-rw-r--r--sysdeps/linux/procargs.c101
-rw-r--r--sysdeps/linux/prockernel.c77
-rw-r--r--sysdeps/linux/proclist.c233
-rw-r--r--sysdeps/linux/procmap.c138
-rw-r--r--sysdeps/linux/procmem.c104
-rw-r--r--sysdeps/linux/procsegment.c115
-rw-r--r--sysdeps/linux/procsignal.c65
-rw-r--r--sysdeps/linux/procstate.c93
-rw-r--r--sysdeps/linux/proctime.c103
-rw-r--r--sysdeps/linux/procuid.c126
-rw-r--r--sysdeps/linux/sem_limits.c86
-rw-r--r--sysdeps/linux/shm_limits.c62
-rw-r--r--sysdeps/linux/siglist.c60
-rw-r--r--sysdeps/linux/swap.c104
-rw-r--r--sysdeps/linux/sysinfo.c94
-rw-r--r--sysdeps/linux/uptime.c69
-rw-r--r--sysdeps/osf1/.cvsignore21
-rw-r--r--sysdeps/osf1/ChangeLog20
-rw-r--r--sysdeps/osf1/Makefile.am23
-rw-r--r--sysdeps/osf1/close.c30
-rw-r--r--sysdeps/osf1/close_suid.c30
-rw-r--r--sysdeps/osf1/cpu.c69
-rw-r--r--sysdeps/osf1/glibtop_machine.h50
-rw-r--r--sysdeps/osf1/glibtop_server.h52
-rw-r--r--sysdeps/osf1/glibtop_suid.h50
-rw-r--r--sysdeps/osf1/loadavg.c73
-rw-r--r--sysdeps/osf1/mem.c69
-rw-r--r--sysdeps/osf1/msg_limits.c87
-rw-r--r--sysdeps/osf1/netload.c45
-rw-r--r--sysdeps/osf1/open.c35
-rw-r--r--sysdeps/osf1/open_suid.c91
-rw-r--r--sysdeps/osf1/ppp.c44
-rw-r--r--sysdeps/osf1/procargs.c47
-rw-r--r--sysdeps/osf1/procdata.c150
-rw-r--r--sysdeps/osf1/prockernel.c49
-rw-r--r--sysdeps/osf1/proclist.c172
-rw-r--r--sysdeps/osf1/procmap.c46
-rw-r--r--sysdeps/osf1/procmem.c103
-rw-r--r--sysdeps/osf1/procsegment.c80
-rw-r--r--sysdeps/osf1/procsignal.c74
-rw-r--r--sysdeps/osf1/procstate.c155
-rw-r--r--sysdeps/osf1/proctime.c79
-rw-r--r--sysdeps/osf1/procuid.c132
-rw-r--r--sysdeps/osf1/sem_limits.c110
-rw-r--r--sysdeps/osf1/shm_limits.c89
-rw-r--r--sysdeps/osf1/siglist.c60
-rw-r--r--sysdeps/osf1/swap.c64
-rw-r--r--sysdeps/osf1/uptime.c61
-rw-r--r--sysdeps/solaris/.cvsignore7
-rw-r--r--sysdeps/solaris/AUTHORS2
-rw-r--r--sysdeps/solaris/ChangeLog284
-rw-r--r--sysdeps/solaris/Makefile.am28
-rw-r--r--sysdeps/solaris/close.c30
-rw-r--r--sysdeps/solaris/close_suid.c30
-rw-r--r--sysdeps/solaris/cpu.c113
-rw-r--r--sysdeps/solaris/glibtop_machine.h78
-rw-r--r--sysdeps/solaris/glibtop_private.h68
-rw-r--r--sysdeps/solaris/glibtop_server.h52
-rw-r--r--sysdeps/solaris/glibtop_suid.h48
-rw-r--r--sysdeps/solaris/loadavg.c87
-rw-r--r--sysdeps/solaris/mem.c127
-rw-r--r--sysdeps/solaris/msg_limits.c80
-rw-r--r--sysdeps/solaris/netload.c45
-rw-r--r--sysdeps/solaris/open.c234
-rw-r--r--sysdeps/solaris/open_suid.c92
-rw-r--r--sysdeps/solaris/ppp.c44
-rw-r--r--sysdeps/solaris/procargs.c83
-rw-r--r--sysdeps/solaris/procdata.c268
-rw-r--r--sysdeps/solaris/prockernel.c44
-rw-r--r--sysdeps/solaris/proclist.c251
-rw-r--r--sysdeps/solaris/procmap.c207
-rw-r--r--sysdeps/solaris/procmem.c64
-rw-r--r--sysdeps/solaris/procsegment.c44
-rw-r--r--sysdeps/solaris/procsignal.c74
-rw-r--r--sysdeps/solaris/procstate.c122
-rw-r--r--sysdeps/solaris/proctime.c69
-rw-r--r--sysdeps/solaris/procuid.c127
-rw-r--r--sysdeps/solaris/safeio.c84
-rw-r--r--sysdeps/solaris/safeio.h48
-rw-r--r--sysdeps/solaris/sem_limits.c85
-rw-r--r--sysdeps/solaris/shm_limits.c68
-rw-r--r--sysdeps/solaris/siglist.c74
-rw-r--r--sysdeps/solaris/swap.c89
-rw-r--r--sysdeps/solaris/uptime.c58
-rw-r--r--sysdeps/stub/.cvsignore27
-rw-r--r--sysdeps/stub/ChangeLog22
-rw-r--r--sysdeps/stub/Makefile.am17
-rw-r--r--sysdeps/stub/close.c30
-rw-r--r--sysdeps/stub/cpu.c43
-rw-r--r--sysdeps/stub/glibtop_server.h52
-rw-r--r--sysdeps/stub/loadavg.c43
-rw-r--r--sysdeps/stub/mem.c43
-rw-r--r--sysdeps/stub/msg_limits.c43
-rw-r--r--sysdeps/stub/netload.c45
-rw-r--r--sysdeps/stub/open.c33
-rw-r--r--sysdeps/stub/ppp.c44
-rw-r--r--sysdeps/stub/procargs.c47
-rw-r--r--sysdeps/stub/prockernel.c44
-rw-r--r--sysdeps/stub/proclist.c52
-rw-r--r--sysdeps/stub/procmap.c50
-rw-r--r--sysdeps/stub/procmem.c44
-rw-r--r--sysdeps/stub/procsegment.c44
-rw-r--r--sysdeps/stub/procsignal.c44
-rw-r--r--sysdeps/stub/procstate.c44
-rw-r--r--sysdeps/stub/proctime.c44
-rw-r--r--sysdeps/stub/procuid.c44
-rw-r--r--sysdeps/stub/sem_limits.c43
-rw-r--r--sysdeps/stub/shm_limits.c43
-rw-r--r--sysdeps/stub/siglist.c28
-rw-r--r--sysdeps/stub/swap.c43
-rw-r--r--sysdeps/stub/uptime.c43
-rw-r--r--sysdeps/stub_suid/.cvsignore28
-rw-r--r--sysdeps/stub_suid/ChangeLog18
-rw-r--r--sysdeps/stub_suid/Makefile.am23
-rw-r--r--sysdeps/stub_suid/close.c30
-rw-r--r--sysdeps/stub_suid/cpu.c48
-rw-r--r--sysdeps/stub_suid/glibtop_machine.h39
-rw-r--r--sysdeps/stub_suid/glibtop_server.h52
-rw-r--r--sysdeps/stub_suid/glibtop_suid.h48
-rw-r--r--sysdeps/stub_suid/init.c45
-rw-r--r--sysdeps/stub_suid/loadavg.c48
-rw-r--r--sysdeps/stub_suid/mem.c48
-rw-r--r--sysdeps/stub_suid/msg_limits.c48
-rw-r--r--sysdeps/stub_suid/netload.c45
-rw-r--r--sysdeps/stub_suid/nosuid.c34
-rw-r--r--sysdeps/stub_suid/open.c77
-rw-r--r--sysdeps/stub_suid/ppp.c44
-rw-r--r--sysdeps/stub_suid/procargs.c47
-rw-r--r--sysdeps/stub_suid/procdata.c180
-rw-r--r--sysdeps/stub_suid/prockernel.c49
-rw-r--r--sysdeps/stub_suid/proclist.c49
-rw-r--r--sysdeps/stub_suid/procmap.c46
-rw-r--r--sysdeps/stub_suid/procmem.c49
-rw-r--r--sysdeps/stub_suid/procsegment.c49
-rw-r--r--sysdeps/stub_suid/procsignal.c49
-rw-r--r--sysdeps/stub_suid/procstate.c49
-rw-r--r--sysdeps/stub_suid/proctime.c49
-rw-r--r--sysdeps/stub_suid/procuid.c49
-rw-r--r--sysdeps/stub_suid/sem_limits.c48
-rw-r--r--sysdeps/stub_suid/shm_limits.c48
-rw-r--r--sysdeps/stub_suid/siglist.c28
-rw-r--r--sysdeps/stub_suid/swap.c48
-rw-r--r--sysdeps/stub_suid/uptime.c48
-rw-r--r--sysdeps/sun4/.cvsignore17
-rw-r--r--sysdeps/sun4/ChangeLog17
-rw-r--r--sysdeps/sun4/Makefile.am22
-rw-r--r--sysdeps/sun4/close.c30
-rw-r--r--sysdeps/sun4/cpu.c107
-rw-r--r--sysdeps/sun4/glibtop_machine.h117
-rw-r--r--sysdeps/sun4/glibtop_server.h49
-rw-r--r--sysdeps/sun4/glibtop_suid.h48
-rw-r--r--sysdeps/sun4/loadavg.c67
-rw-r--r--sysdeps/sun4/loadavg.h57
-rw-r--r--sysdeps/sun4/mem.c91
-rw-r--r--sysdeps/sun4/msg_limits.c75
-rw-r--r--sysdeps/sun4/nosuid.c35
-rw-r--r--sysdeps/sun4/open.c308
-rw-r--r--sysdeps/sun4/ppp.c44
-rw-r--r--sysdeps/sun4/procdata.c33
-rw-r--r--sysdeps/sun4/prockernel.c60
-rw-r--r--sysdeps/sun4/proclist.c97
-rw-r--r--sysdeps/sun4/procmem.c63
-rw-r--r--sysdeps/sun4/procsegment.c61
-rw-r--r--sysdeps/sun4/procsignal.c63
-rw-r--r--sysdeps/sun4/procstate.c60
-rw-r--r--sysdeps/sun4/proctime.c60
-rw-r--r--sysdeps/sun4/procuid.c71
-rw-r--r--sysdeps/sun4/sem_limits.c81
-rw-r--r--sysdeps/sun4/shm_limits.c74
-rw-r--r--sysdeps/sun4/siglist.c60
-rw-r--r--sysdeps/sun4/swap.c37
-rw-r--r--sysdeps/sun4/uptime.c61
294 files changed, 23404 insertions, 0 deletions
diff --git a/sysdeps/aix/ChangeLog b/sysdeps/aix/ChangeLog
new file mode 100644
index 00000000..0b61ebd3
--- /dev/null
+++ b/sysdeps/aix/ChangeLog
@@ -0,0 +1,3 @@
+2002-09-24 Laurent Vivier <Laurent.Vivier@bull.net>
+
+ * Create sysdeps/aix (from stub)
diff --git a/sysdeps/aix/Makefile.am b/sysdeps/aix/Makefile.am
new file mode 100644
index 00000000..e0c6c2f6
--- /dev/null
+++ b/sysdeps/aix/Makefile.am
@@ -0,0 +1,23 @@
+LINK = $(LIBTOOL) --mode=link $(CC) $(CFLAGS) $(LDFLAGS) -o $@
+
+INCLUDES = @INCLUDES@
+
+lib_LTLIBRARIES = libgtop_sysdeps-2.0.la libgtop_sysdeps_suid-2.0.la
+
+libgtop_sysdeps_2_0_la_SOURCES = siglist.c nosuid.c
+
+libgtop_sysdeps_2_0_la_LDFLAGS = $(LT_VERSION_INFO)
+
+libgtop_sysdeps_suid_2_0_la_SOURCES = open.c close.c cpu.c mem.c swap.c \
+ uptime.c loadavg.c shm_limits.c msg_limits.c \
+ sem_limits.c proclist.c procstate.c procuid.c \
+ proctime.c procmem.c procsignal.c prockernel.c \
+ procsegment.c procargs.c procmap.c netload.c \
+ ppp.c utils.c utils.h sysinfo.c
+
+libgtop_sysdeps_suid_2_0_la_LDFLAGS = $(LT_VERSION_INFO)
+libgtop_sysdeps_suid_2_0_la_LIBADD = $(top_builddir)/sysdeps/common/libgtop_suid_common-2.0.la $(GLIB_LIBS)
+
+libgtopinclude_HEADERS = glibtop_server.h glibtop_machine.h glibtop_suid.h
+
+libgtopincludedir = $(includedir)/libgtop-2.0
diff --git a/sysdeps/aix/close.c b/sysdeps/aix/close.c
new file mode 100644
index 00000000..4262d2f0
--- /dev/null
+++ b/sysdeps/aix/close.c
@@ -0,0 +1,30 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <glibtop/close.h>
+
+/* Closes pipe to gtop server. */
+
+void
+glibtop_close_s (glibtop *server)
+{ }
diff --git a/sysdeps/aix/cpu.c b/sysdeps/aix/cpu.c
new file mode 100644
index 00000000..81fb5c04
--- /dev/null
+++ b/sysdeps/aix/cpu.c
@@ -0,0 +1,125 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <stdlib.h>
+#include <sys/systemcfg.h>
+#include <sys/sysinfo.h>
+
+#include <glibtop.h>
+#include <glibtop/error.h>
+#include <glibtop/cpu.h>
+
+#include <utils.h>
+
+static const unsigned long _glibtop_sysdeps_cpu =
+(1L << GLIBTOP_CPU_TOTAL) + (1L << GLIBTOP_CPU_USER) +
+(1L << GLIBTOP_CPU_SYS) + (1L << GLIBTOP_CPU_IDLE) +
+(1L << GLIBTOP_CPU_NICE) + (1 << GLIBTOP_CPU_FREQUENCY) +
+(1L << GLIBTOP_XCPU_TOTAL) + (1L << GLIBTOP_XCPU_USER) +
+(1L << GLIBTOP_XCPU_SYS) + (1L << GLIBTOP_XCPU_IDLE) +
+(1L << GLIBTOP_XCPU_NICE);
+
+/* Init function. */
+
+void
+glibtop_init_cpu_p (glibtop *server)
+{
+ off_t result;
+
+ server->ncpu = _system_configuration.ncpus;
+ if (server->ncpu == 1)
+ {
+ server->ncpu = 0; /* means single-processor, see glibtop.h */
+ }
+
+ result = _glibtop_get_kmem_offset(server, "cpuinfo");
+ if (result == -1)
+ {
+ server->sysdeps.cpu = 0;
+
+ return;
+ }
+ server->machine.cpuinfo_offset = result;
+
+ server->machine.cpuinfo = (struct cpuinfo*)calloc(_system_configuration.ncpus, sizeof(struct cpuinfo));
+
+ server->sysdeps.cpu = _glibtop_sysdeps_cpu;
+}
+
+/* Provides information about cpu usage. */
+
+void
+glibtop_get_cpu_p (glibtop *server, glibtop_cpu *buf)
+{
+ int result;
+ int cpu;
+
+ glibtop_init_p (server, (1L << GLIBTOP_SYSDEPS_CPU), 0);
+
+ memset (buf, 0, sizeof (glibtop_cpu));
+
+ result = _glibtop_get_kmem_info(server, server->machine.cpuinfo_offset,
+ server->machine.cpuinfo,
+ _system_configuration.ncpus
+ * sizeof(struct cpuinfo));
+
+ if (result <= 0)
+ {
+ glibtop_error_io_r (server, "Cannot read cpuinfo");
+ return;
+ }
+
+ buf->idle = 0;
+ buf->user = 0;
+ buf->sys = 0;
+ buf->nice = 0;
+ for (cpu = 0; cpu < _system_configuration.ncpus; cpu++)
+ {
+ if (cpu < GLIBTOP_NCPU)
+ {
+ buf->xcpu_idle[cpu] =
+ server->machine.cpuinfo[cpu].cpu[CPU_IDLE];
+ buf->xcpu_user[cpu] =
+ server->machine.cpuinfo[cpu].cpu[CPU_USER];
+ buf->xcpu_sys[cpu] =
+ server->machine.cpuinfo[cpu].cpu[CPU_KERNEL];
+ buf->xcpu_nice[cpu] =
+ server->machine.cpuinfo[cpu].cpu[CPU_WAIT];
+
+ buf->xcpu_total[cpu] = buf->xcpu_idle[cpu] +
+ buf->xcpu_user[cpu] +
+ buf->xcpu_sys[cpu] +
+ buf->xcpu_nice[cpu];
+ }
+
+ buf->idle += server->machine.cpuinfo[cpu].cpu[CPU_IDLE];
+ buf->user += server->machine.cpuinfo[cpu].cpu[CPU_USER];
+ buf->sys += server->machine.cpuinfo[cpu].cpu[CPU_KERNEL];
+ buf->nice += server->machine.cpuinfo[cpu].cpu[CPU_WAIT];
+
+ buf->total = buf->idle + buf->user + buf->sys + buf->nice ;
+ }
+
+ buf->frequency = sysconf(_SC_CLK_TCK);
+ buf->flags = _glibtop_sysdeps_cpu;
+}
diff --git a/sysdeps/aix/glibtop_machine.h b/sysdeps/aix/glibtop_machine.h
new file mode 100644
index 00000000..508d6c21
--- /dev/null
+++ b/sysdeps/aix/glibtop_machine.h
@@ -0,0 +1,53 @@
+/* $Id$ */
+
+/*
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, March 1999.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#ifndef __GLIBTOP_MACHINE_H__
+#define __GLIBTOP_MACHINE_H__
+
+#include <procinfo.h>
+
+BEGIN_LIBGTOP_DECLS
+
+typedef struct _glibtop_machine glibtop_machine;
+
+struct _glibtop_machine
+{
+ uid_t uid, euid;
+ gid_t gid, egid;
+
+ int kmem_fd;
+
+ off_t cpuinfo_offset;
+ off_t ifnet_offset;
+ off_t loadavg_offset;
+ off_t shminfo_offset;
+ off_t seminfo_offset;
+ off_t msginfo_offset;
+
+ struct cpuinfo *cpuinfo;
+ struct procsinfo last_pinfo;
+};
+
+END_LIBGTOP_DECLS
+
+#endif /* __GLIBTOP_MACHINE_H__ */
diff --git a/sysdeps/aix/glibtop_server.h b/sysdeps/aix/glibtop_server.h
new file mode 100644
index 00000000..ca57af36
--- /dev/null
+++ b/sysdeps/aix/glibtop_server.h
@@ -0,0 +1,52 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#ifndef __GLIBTOP_SERVER_H__
+#define __GLIBTOP_SERVER_H__
+
+BEGIN_LIBGTOP_DECLS
+
+#define GLIBTOP_SUID_CPU (1 << GLIBTOP_SYSDEPS_CPU)
+#define GLIBTOP_SUID_MEM 0
+#define GLIBTOP_SUID_SWAP 0
+#define GLIBTOP_SUID_UPTIME (1 << GLIBTOP_SYSDEPS_UPTIME)
+#define GLIBTOP_SUID_LOADAVG (1 << GLIBTOP_SYSDEPS_LOADAVG)
+#define GLIBTOP_SUID_SHM_LIMITS (1 << GLIBTOP_SYSDEPS_SHM_LIMITS)
+#define GLIBTOP_SUID_MSG_LIMITS (1 << GLIBTOP_SYSDEPS_MSG_LIMITS)
+#define GLIBTOP_SUID_SEM_LIMITS (1 << GLIBTOP_SYSDEPS_SEM_LIMITS)
+#define GLIBTOP_SUID_PROCLIST 0
+#define GLIBTOP_SUID_PROC_STATE 0
+#define GLIBTOP_SUID_PROC_UID 0
+#define GLIBTOP_SUID_PROC_MEM 0
+#define GLIBTOP_SUID_PROC_TIME 0
+#define GLIBTOP_SUID_PROC_SIGNAL 0
+#define GLIBTOP_SUID_PROC_KERNEL 0
+#define GLIBTOP_SUID_PROC_SEGMENT 0
+#define GLIBTOP_SUID_PROC_ARGS 0
+#define GLIBTOP_SUID_PROC_MAP 0
+#define GLIBTOP_SUID_NETLOAD (1 << GLIBTOP_SYSDEPS_NETLOAD)
+#define GLIBTOP_SUID_PPP 0
+
+END_LIBGTOP_DECLS
+
+#endif
diff --git a/sysdeps/aix/glibtop_suid.h b/sysdeps/aix/glibtop_suid.h
new file mode 100644
index 00000000..0d971143
--- /dev/null
+++ b/sysdeps/aix/glibtop_suid.h
@@ -0,0 +1,52 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#ifndef __GLIBTOP_SUID_H__
+#define __GLIBTOP_SUID_H__
+
+BEGIN_LIBGTOP_DECLS
+
+#if _IN_LIBGTOP
+#include <sys/param.h>
+#endif
+
+static inline void glibtop_suid_enter (glibtop *server) {
+ setegid (server->machine.egid);
+}
+
+static inline void glibtop_suid_leave (glibtop *server) {
+ if (setegid (server->machine.gid))
+ _exit (1);
+}
+
+void
+glibtop_init_p (glibtop *server, const unsigned long features,
+ const unsigned flags);
+void
+glibtop_open_p (glibtop *server, const char *program_name,
+ const unsigned long features,
+ const unsigned flags);
+
+END_LIBGTOP_DECLS
+
+#endif
diff --git a/sysdeps/aix/loadavg.c b/sysdeps/aix/loadavg.c
new file mode 100644
index 00000000..67913413
--- /dev/null
+++ b/sysdeps/aix/loadavg.c
@@ -0,0 +1,78 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <nlist.h>
+#include <glibtop.h>
+#include <glibtop/loadavg.h>
+#include <glibtop/error.h>
+
+#include <glibtop_suid.h>
+
+static const unsigned long _glibtop_sysdeps_loadavg =
+(1 << GLIBTOP_LOADAVG_LOADAVG);
+
+/* Init function. */
+
+void
+glibtop_init_loadavg_p (glibtop *server)
+{
+ int result;
+
+ result = _glibtop_get_kmem_offset(server, "avenrun");
+ if (result == -1)
+ {
+ server->sysdeps.loadavg = 0;
+ return;
+ }
+
+ server->machine.loadavg_offset = result;
+
+ server->sysdeps.loadavg = _glibtop_sysdeps_loadavg;
+}
+
+/* Provides load averange. */
+
+void
+glibtop_get_loadavg_p (glibtop *server, glibtop_loadavg *buf)
+{
+ int result;
+ int loadavg[3];
+
+ glibtop_init_p (server, (1L << GLIBTOP_SYSDEPS_LOADAVG), 0);
+
+ memset (buf, 0, sizeof (glibtop_loadavg));
+
+ result = _glibtop_get_kmem_info(server, server->machine.loadavg_offset,
+ loadavg, sizeof(loadavg));
+ if (result <= 0)
+ {
+ glibtop_error_io_r (server, "Cannot read loadavg");
+ return;
+ }
+
+ buf->loadavg[0] = loadavg[0] / 65536.0;
+ buf->loadavg[1] = loadavg[1] / 65536.0;
+ buf->loadavg[2] = loadavg[2] / 65536.0;
+
+ buf->flags = _glibtop_sysdeps_loadavg;
+}
diff --git a/sysdeps/aix/mem.c b/sysdeps/aix/mem.c
new file mode 100644
index 00000000..c2811fd5
--- /dev/null
+++ b/sysdeps/aix/mem.c
@@ -0,0 +1,76 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <unistd.h>
+#include <sys/vminfo.h>
+
+#include <glibtop.h>
+#include <glibtop/error.h>
+#include <glibtop/mem.h>
+
+static const unsigned long _glibtop_sysdeps_mem =
+(1 << GLIBTOP_MEM_TOTAL) + (1 << GLIBTOP_MEM_USED) +
+(1 << GLIBTOP_MEM_FREE) + (1 << GLIBTOP_MEM_LOCKED);
+
+/* Init function. */
+
+void
+glibtop_init_mem_s (glibtop *server)
+{
+ server->sysdeps.mem = _glibtop_sysdeps_mem;
+}
+
+/* Provides information about memory usage. */
+
+void
+glibtop_get_mem_s (glibtop *server, glibtop_mem *buf)
+{
+ struct vminfo vminfo;
+ int pagesize;
+ int result;
+
+ memset (buf, 0, sizeof (glibtop_mem));
+
+ pagesize = sysconf(_SC_PAGESIZE);
+
+#ifdef HAVE_VMGETINFO
+ result = vmgetinfo((void*)&vminfo, VMINFO, sizeof(vminfo));
+#else
+ result = _glibtop_vmgetinfo((void*)&vminfo, VMINFO, sizeof(vminfo));
+#endif
+ if (result == -1)
+ {
+ glibtop_error_io_r (server, "Cannot read vminfo");
+ return;
+ }
+
+
+ buf->total = vminfo.memsizepgs * pagesize;
+ buf->used = (vminfo.numwseguse + vminfo.numpseguse +
+ vminfo.numclseguse) * pagesize;
+ buf->free = vminfo.numfrb * pagesize;
+ buf->locked = (vminfo.numwsegpin + vminfo.numpsegpin +
+ vminfo.numclsegpin) * pagesize;
+
+ buf->flags = _glibtop_sysdeps_mem;
+}
diff --git a/sysdeps/aix/msg_limits.c b/sysdeps/aix/msg_limits.c
new file mode 100644
index 00000000..94bf4446
--- /dev/null
+++ b/sysdeps/aix/msg_limits.c
@@ -0,0 +1,81 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <sys/msg.h>
+
+#include <glibtop.h>
+#include <glibtop/error.h>
+#include <glibtop/msg_limits.h>
+
+static const unsigned long _glibtop_sysdeps_msg_limits =
+(1 << GLIBTOP_IPC_MSGMAX) + (1 << GLIBTOP_IPC_MSGMNB) +
+(1 << GLIBTOP_IPC_MSGMNI) + (1 << GLIBTOP_IPC_MSGTQL);
+
+/* Init function. */
+
+void
+glibtop_init_msg_limits_p (glibtop *server)
+{
+ off_t result;
+
+ result = _glibtop_get_kmem_offset(server, "msginfo");
+ if (result <= 0)
+ {
+ server->sysdeps.sem_limits = 0;
+ return;
+ }
+
+ server->machine.msginfo_offset = result;
+
+ server->sysdeps.msg_limits = _glibtop_sysdeps_msg_limits;
+}
+
+/* Provides information about sysv ipc limits. */
+
+void
+glibtop_get_msg_limits_p (glibtop *server, glibtop_msg_limits *buf)
+{
+ int result;
+ struct msginfo msginfo;
+
+ glibtop_init_p (server, (1L << GLIBTOP_SYSDEPS_MSG_LIMITS), 0);
+
+ memset (buf, 0, sizeof (glibtop_msg_limits));
+
+ result = _glibtop_get_kmem_info(server, server->machine.msginfo_offset,
+ &msginfo, sizeof(msginfo));
+
+ if (result <= 0)
+ {
+ glibtop_error_io_r (server, "Cannot read seminfo");
+
+ return;
+ }
+
+ buf->msgmax = msginfo.msgmax;
+ buf->msgmnb = msginfo.msgmnb;
+ buf->msgmni = msginfo.msgmni;
+ buf->msgtql = msginfo.msgmnm;
+
+ buf->flags = _glibtop_sysdeps_msg_limits;
+}
diff --git a/sysdeps/aix/netload.c b/sysdeps/aix/netload.c
new file mode 100644
index 00000000..ffad1c66
--- /dev/null
+++ b/sysdeps/aix/netload.c
@@ -0,0 +1,207 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, October 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <sys/socket.h>
+#include <net/if.h>
+#include <netinet/in.h>
+
+#include <glibtop.h>
+#include <glibtop/error.h>
+#include <glibtop/netload.h>
+
+#include "utils.h"
+
+static const unsigned long _glibtop_sysdeps_netload =
+(1 << GLIBTOP_NETLOAD_IF_FLAGS) + (1 << GLIBTOP_NETLOAD_MTU) +
+(1 << GLIBTOP_NETLOAD_SUBNET) + (1 << GLIBTOP_NETLOAD_ADDRESS) +
+(1 << GLIBTOP_NETLOAD_PACKETS_IN) + (1 << GLIBTOP_NETLOAD_PACKETS_OUT) +
+(1 << GLIBTOP_NETLOAD_PACKETS_TOTAL) + (1 << GLIBTOP_NETLOAD_BYTES_IN) +
+(1 << GLIBTOP_NETLOAD_BYTES_OUT) + (1 << GLIBTOP_NETLOAD_BYTES_TOTAL) +
+(1 << GLIBTOP_NETLOAD_ERRORS_IN) + (1 << GLIBTOP_NETLOAD_ERRORS_OUT) +
+(1 << GLIBTOP_NETLOAD_ERRORS_TOTAL) + (1 << GLIBTOP_NETLOAD_COLLISIONS);
+
+static void get_ifaddr(glibtop* server, struct ifaddr* next, long* addr, long* mask)
+{
+ struct ifaddr ifaddr;
+ struct sockaddr_in sockaddr;
+
+ *addr = 0;
+ *mask = 0;
+
+ while (next)
+ {
+ /* get interface ifaddr structure */
+
+ _glibtop_get_kmem_info(server, (off_t)next, &ifaddr, sizeof(ifaddr));
+
+ /* get socket addr information */
+
+ _glibtop_get_kmem_info( server, (off_t)ifaddr.ifa_addr
+ , &sockaddr, sizeof(sockaddr));
+
+ /* if valid family : UDP, TCP, ...*/
+
+ if (sockaddr.sin_family == AF_INET)
+ {
+ *addr = sockaddr.sin_addr.s_addr;
+
+ _glibtop_get_kmem_info( server, (off_t)ifaddr.ifa_netmask
+ , &sockaddr, sizeof(sockaddr));
+
+ *mask = sockaddr.sin_addr.s_addr;
+
+ /* address found */
+
+ return;
+ }
+
+ next = ifaddr.ifa_next;
+ }
+}
+
+/* Init function. */
+
+void
+glibtop_init_netload_p (glibtop *server)
+{
+ off_t result;
+ off_t addr;
+
+ result = _glibtop_get_kmem_offset(server, "ifnet");
+ if (result <= 0)
+ {
+ server->sysdeps.netload = 0;
+ return;
+ }
+
+ result = _glibtop_get_kmem_info(server, result, &addr, sizeof(addr));
+ if (result <= 0)
+ {
+ server->sysdeps.netload = 0;
+ return;
+ }
+
+ server->machine.ifnet_offset = addr;
+
+ server->sysdeps.netload = _glibtop_sysdeps_netload;
+}
+
+/* Provides network statistics. */
+
+void
+glibtop_get_netload_p (glibtop *server, glibtop_netload *buf,
+ const char *interface)
+{
+ int result;
+ off_t offset;
+ struct ifnet ifnet;
+ long addr;
+ long mask;
+ char name[16];
+
+ memset (buf, 0, sizeof (glibtop_netload));
+
+ for ( offset = server->machine.ifnet_offset;
+ offset != 0;
+ offset = (off_t)ifnet.if_next
+ )
+ {
+ result = _glibtop_get_kmem_info(server, offset,
+ &ifnet, sizeof(ifnet));
+ if (result <= 0)
+ {
+ glibtop_error_io_r (server, "Cannot read ifnet");
+
+ return;
+ }
+
+ result = _glibtop_get_kmem_info(server, (off_t)ifnet.if_name,
+ name, sizeof(name));
+ if (result <= 0)
+ {
+ glibtop_error_io_r (server, "Cannot read if_name");
+
+ return;
+ }
+
+ sprintf(name+strlen(name), "%d", ifnet.if_unit);
+ if (strcmp(name, interface) != 0)
+ {
+ continue;
+ }
+
+ if (ifnet.if_flags & IFF_UP)
+ buf->if_flags |= (1 << GLIBTOP_IF_FLAGS_UP);
+ if (ifnet.if_flags & IFF_BROADCAST)
+ buf->if_flags |= (1 << GLIBTOP_IF_FLAGS_BROADCAST);
+ if (ifnet.if_flags & IFF_LOOPBACK)
+ buf->if_flags |= (1 << GLIBTOP_IF_FLAGS_LOOPBACK);
+ if (ifnet.if_flags & IFF_POINTOPOINT)
+ buf->if_flags |= (1 << GLIBTOP_IF_FLAGS_POINTOPOINT);
+ if (ifnet.if_flags & IFF_RUNNING)
+ buf->if_flags |= (1 << GLIBTOP_IF_FLAGS_RUNNING);
+ if (ifnet.if_flags & IFF_NOARP)
+ buf->if_flags |= (1 << GLIBTOP_IF_FLAGS_NOARP);
+ if (ifnet.if_flags & IFF_PROMISC)
+ buf->if_flags |= (1 << GLIBTOP_IF_FLAGS_PROMISC);
+ if (ifnet.if_flags & IFF_ALLMULTI)
+ buf->if_flags |= (1 << GLIBTOP_IF_FLAGS_ALLMULTI);
+ if (ifnet.if_flags & IFF_OACTIVE)
+ buf->if_flags |= (1 << GLIBTOP_IF_FLAGS_OACTIVE);
+ if (ifnet.if_flags & IFF_SIMPLEX)
+ buf->if_flags |= (1 << GLIBTOP_IF_FLAGS_SIMPLEX);
+ if (ifnet.if_flags & IFF_LINK0)
+ buf->if_flags |= (1 << GLIBTOP_IF_FLAGS_LINK0);
+ if (ifnet.if_flags & IFF_LINK1)
+ buf->if_flags |= (1 << GLIBTOP_IF_FLAGS_LINK1);
+ if (ifnet.if_flags & IFF_LINK2)
+ buf->if_flags |= (1 << GLIBTOP_IF_FLAGS_LINK2);
+ if (ifnet.if_flags & IFF_LINK2)
+ buf->if_flags |= (1 << GLIBTOP_IF_FLAGS_LINK2);
+ if (ifnet.if_flags & 0x80000)
+ buf->if_flags |= (1 << GLIBTOP_IF_FLAGS_MULTICAST);
+
+ buf->mtu = ifnet.if_mtu;
+
+ get_ifaddr(server, ifnet.if_addrlist, &addr, &mask);
+
+ buf->subnet = addr & mask;
+ buf->address = addr;
+
+ buf->packets_in = ifnet.if_ipackets;
+ buf->packets_out = ifnet.if_opackets;
+ buf->packets_total = buf->packets_in + buf->packets_out;
+
+ buf->bytes_in = ifnet.if_ibytes;
+ buf->bytes_out = ifnet.if_obytes;
+ buf->bytes_total = buf->bytes_in + buf->bytes_out;
+
+ buf->errors_in = ifnet.if_ierrors;
+ buf->errors_out = ifnet.if_oerrors;
+ buf->errors_total = ifnet.if_ierrors + ifnet.if_oerrors;
+
+ buf->collisions = ifnet.if_collisions;
+ }
+
+ buf->flags = _glibtop_sysdeps_netload;
+}
diff --git a/sysdeps/aix/nosuid.c b/sysdeps/aix/nosuid.c
new file mode 100644
index 00000000..c904a3a5
--- /dev/null
+++ b/sysdeps/aix/nosuid.c
@@ -0,0 +1,46 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <sys/systemcfg.h>
+
+#include <glibtop.h>
+#include <glibtop/open.h>
+#include <glibtop/close.h>
+
+void
+glibtop_open_s (glibtop *server,
+ const char *program_name,
+ const unsigned long features,
+ const unsigned flags)
+{
+ server->ncpu = _system_configuration.ncpus;
+
+ if (server->ncpu == 1)
+ {
+ server->ncpu = 0; /* means single-processor, see glibtop.h */
+ }
+}
+
+void
+glibtop_close_s (glibtop *server)
+{ }
diff --git a/sysdeps/aix/open.c b/sysdeps/aix/open.c
new file mode 100644
index 00000000..8a0757fa
--- /dev/null
+++ b/sysdeps/aix/open.c
@@ -0,0 +1,82 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <fcntl.h>
+#include <unistd.h>
+#include <glibtop.h>
+#include <glibtop/error.h>
+#include <glibtop/open.h>
+
+#include "glibtop_suid.h"
+
+/* !!! THIS FUNCTION RUNS SUID ROOT - CHANGE WITH CAUTION !!! */
+
+void
+glibtop_init_p (glibtop *server, const unsigned long features,
+ const unsigned flags)
+{
+ glibtop_init_func_t *init_fkt;
+
+ if (server == NULL)
+ glibtop_error_r (NULL, "glibtop_init_p (server == NULL)");
+
+ 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;
+ }
+}
+
+/* Opens pipe to gtop server. Returns 0 on success and -1 on error. */
+
+void
+glibtop_open_p (glibtop *server, const char *program_name,
+ const unsigned long features, const unsigned flags)
+{
+ /* !!! WE ARE ROOT HERE - CHANGE WITH CAUTION !!! */
+
+ server->machine.uid = getuid ();
+ server->machine.euid = geteuid ();
+ server->machine.gid = getgid ();
+ server->machine.egid = getegid ();
+
+ /* open kmem */
+
+ server->machine.kmem_fd = open("/dev/kmem", O_RDONLY);
+ if (server->machine.kmem_fd == -1)
+ glibtop_error_io_r (server, "Cannot open /dev/kmem");
+
+ /* Drop priviledges. */
+
+ if (seteuid (server->machine.uid))
+ _exit (1);
+
+ if (setegid (server->machine.gid))
+ _exit (1);
+
+ /* !!! END OF SUID ROOT PART !!! */
+
+ server->name = program_name;
+}
diff --git a/sysdeps/aix/ppp.c b/sysdeps/aix/ppp.c
new file mode 100644
index 00000000..6d0905d5
--- /dev/null
+++ b/sysdeps/aix/ppp.c
@@ -0,0 +1,44 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, October 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <glibtop.h>
+#include <glibtop/error.h>
+#include <glibtop/ppp.h>
+
+static const unsigned long _glibtop_sysdeps_ppp = 0;
+
+/* Init function. */
+
+void
+glibtop_init_ppp_s (glibtop *server)
+{
+ server->sysdeps.ppp = _glibtop_sysdeps_ppp;
+}
+
+/* Provides PPP/ISDN information. */
+
+void
+glibtop_get_ppp_s (glibtop *server, glibtop_ppp *buf, unsigned short device)
+{
+ memset (buf, 0, sizeof (glibtop_ppp));
+}
diff --git a/sysdeps/aix/procargs.c b/sysdeps/aix/procargs.c
new file mode 100644
index 00000000..97bf0b34
--- /dev/null
+++ b/sysdeps/aix/procargs.c
@@ -0,0 +1,132 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <procinfo.h>
+
+#include <glibtop.h>
+#include <glibtop/error.h>
+#include <glibtop/xmalloc.h>
+#include <glibtop/procargs.h>
+
+#include "utils.h"
+
+static const unsigned long _glibtop_sysdeps_proc_args =
+ (1 << GLIBTOP_PROC_ARGS_SIZE);
+
+/* Init function. */
+
+void
+glibtop_init_proc_args_s (glibtop *server)
+{
+ server->sysdeps.proc_args = _glibtop_sysdeps_proc_args;
+}
+
+/* Provides detailed information about a process. */
+
+static void _glibtop_remove_non_ascii(char* string)
+{
+ for (;*string != 0;string++)
+ {
+ if (!isascii(*string))
+ *string = '?';
+ }
+}
+
+char *
+glibtop_get_proc_args_s (glibtop *server, glibtop_proc_args *buf,
+ pid_t pid, unsigned max_len)
+{
+ struct procsinfo *pinfo;
+ char *args_buffer;
+ char* args = NULL;
+ int size;
+ int result;
+ int len;
+
+ memset (buf, 0, sizeof (glibtop_proc_args));
+
+ pinfo = _glibtop_get_procinfo(server, pid);
+ if (pinfo == NULL)
+ {
+ glibtop_error_io_r (server, "Cannot read procsinfo");
+
+ return NULL;
+ }
+
+ size = max_len != 0 ? max_len : 4096;
+ args_buffer = glibtop_malloc_r (server, size);
+ if (args_buffer == NULL)
+ {
+ glibtop_error_io_r (server, "Cannot malloc procsinfo");
+
+ return NULL;
+
+ }
+
+ result = getargs(pinfo, sizeof(struct procsinfo), args_buffer, size);
+ if (result == -1)
+ {
+ glibtop_error_io_r (server, "Cannot malloc getargs");
+
+ glibtop_free_r(server, args_buffer);
+
+ return NULL;
+ }
+
+ /* look if empty string */
+
+ if (args_buffer[0] == 0)
+ {
+ glibtop_free_r(server, args_buffer);
+
+ return NULL;
+ }
+
+ /* compute length of args and realloc */
+
+ len = 0;
+ while ((args_buffer[len] != 0) && (len < size))
+ {
+ _glibtop_remove_non_ascii(args_buffer + len);
+
+ len += strlen(args_buffer + len) + 1;
+ }
+
+ args = glibtop_malloc_r (server, len);
+ if (args == NULL)
+ {
+ glibtop_error_io_r (server, "Cannot malloc procsinfo");
+
+ glibtop_free_r(server, args_buffer);
+
+ return NULL;
+ }
+ memcpy(args, args_buffer, len);
+ glibtop_free_r(server, args_buffer);
+
+ buf->size = len - 1;
+
+ buf->flags = _glibtop_sysdeps_proc_args;
+
+ return args;
+}
diff --git a/sysdeps/aix/prockernel.c b/sysdeps/aix/prockernel.c
new file mode 100644
index 00000000..e8885994
--- /dev/null
+++ b/sysdeps/aix/prockernel.c
@@ -0,0 +1,98 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <procinfo.h>
+#include <sys/proc.h>
+
+#include <glibtop.h>
+#include <glibtop/prockernel.h>
+#include <glibtop/error.h>
+
+#include "utils.h"
+
+static const unsigned long _glibtop_sysdeps_proc_kernel =
+(1 <<GLIBTOP_PROC_KERNEL_MIN_FLT) + (1 <<GLIBTOP_PROC_KERNEL_MAJ_FLT) +
+(1 <<GLIBTOP_PROC_KERNEL_CMIN_FLT) + (1 <<GLIBTOP_PROC_KERNEL_CMAJ_FLT) +
+(1 <<GLIBTOP_PROC_KERNEL_KSTK_ESP) + (1 <<GLIBTOP_PROC_KERNEL_KSTK_EIP) +
+(1 <<GLIBTOP_PROC_KERNEL_NWCHAN);
+
+
+
+/* Init function. */
+
+void
+glibtop_init_proc_kernel_s (glibtop *server)
+{
+ server->sysdeps.proc_kernel = _glibtop_sysdeps_proc_kernel;
+}
+
+/* Provides detailed information about a process. */
+
+void
+glibtop_get_proc_kernel_s (glibtop *server, glibtop_proc_kernel *buf,
+ pid_t pid)
+{
+ struct thrdsinfo thinfo;
+ struct procsinfo *pinfo;
+ tid_t thid;
+ int result;
+
+ memset (buf, 0, sizeof (glibtop_proc_kernel));
+
+ pinfo = _glibtop_get_procinfo(server, pid);
+ if (pinfo == NULL)
+ {
+ glibtop_error_io_r(server, "Cannot read procsinfo");
+
+ return;
+ }
+
+ if (!(pinfo->pi_flags | SKPROC))
+ {
+ /* not a kernel process */
+
+ return;
+ }
+
+ buf->min_flt = pinfo->pi_ru.ru_minflt;
+ buf->maj_flt = pinfo->pi_ru.ru_majflt;
+
+ buf->cmin_flt = pinfo->pi_cru.ru_minflt;
+ buf->cmaj_flt = pinfo->pi_cru.ru_majflt;
+
+ thid = 0;
+ result = getthrds(pid, &thinfo, sizeof(thinfo), &thid, 1);
+ if (result != 1)
+ {
+ glibtop_error_io_r(server, "Cannot read thrdsinfo");
+
+ return;
+ }
+
+ buf->kstk_esp = thinfo.ti_ustk;
+ buf->kstk_eip = thinfo.ti_code;
+
+ buf->nwchan = thinfo.ti_wchan;
+
+ buf->flags = _glibtop_sysdeps_proc_kernel;
+}
diff --git a/sysdeps/aix/proclist.c b/sysdeps/aix/proclist.c
new file mode 100644
index 00000000..b92c5669
--- /dev/null
+++ b/sysdeps/aix/proclist.c
@@ -0,0 +1,247 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <procinfo.h>
+
+#include <glibtop.h>
+#include <glibtop/xmalloc.h>
+#include <glibtop/proclist.h>
+
+static const unsigned long _glibtop_sysdeps_proclist =
+(1 << GLIBTOP_PROCLIST_NUMBER) + (1 << GLIBTOP_PROCLIST_TOTAL) +
+(1 << GLIBTOP_PROCLIST_SIZE);
+
+#define BLOCK_COUNT 256
+#define BLOCK_SIZE (BLOCK_COUNT * sizeof (unsigned int))
+
+/* Init function. */
+
+void
+glibtop_init_proclist_s (glibtop *server)
+{
+ server->sysdeps.proclist = _glibtop_sysdeps_proclist;
+}
+
+/* Fetch list of currently running processes.
+ *
+ * IMPORTANT NOTE:
+ * On error, this function MUST return NULL and set buf->flags to zero !
+ * On success, it returnes a pointer to a list of buf->number elements
+ * each buf->size big. The total size is stored in buf->total. */
+
+unsigned *
+glibtop_get_proclist_s (glibtop *server, glibtop_proclist *buf,
+ int64_t which, int64_t arg)
+{
+ struct procsinfo pinfo;
+ int count, total;
+ unsigned pids [BLOCK_COUNT], *pids_chain = NULL;
+ int pids_size = 0, pids_offset = 0, new_size;
+ pid_t current;
+ int result;
+
+ memset (buf, 0, sizeof (glibtop_proclist));
+
+ for( count = total = 0, current = 0
+ , result = getprocs(&pinfo, sizeof(pinfo), NULL, 0, &current, 1);
+ result == 1;
+ result = getprocs(&pinfo, sizeof(pinfo), NULL, 0, &current, 1))
+ {
+ if (which & GLIBTOP_EXCLUDE_IDLE)
+ {
+ if (pinfo.pi_state & SIDL)
+ {
+ /* exclude idle processes */
+
+ continue;
+ }
+ }
+
+ if (which & GLIBTOP_EXCLUDE_SYSTEM)
+ {
+ if (pinfo.pi_flags & SKPROC)
+ {
+ /* exclude Kernel processes */
+
+ continue;
+ }
+ }
+
+ if (which & GLIBTOP_EXCLUDE_NOTTY)
+ {
+ if (!pinfo.pi_ttyp)
+ {
+ /* exclude processes without tty */
+
+ continue;
+ }
+ }
+
+ switch(which & GLIBTOP_KERN_PROC_MASK)
+ {
+ case GLIBTOP_KERN_PROC_ALL:
+
+ /* return information about all processes
+ * so, let's go ahead
+ */
+
+ break;
+
+ case GLIBTOP_KERN_PROC_PID:
+
+ /* return information about all processes with
+ * pid passed in arg
+ */
+
+ if (pinfo.pi_pid != arg)
+ {
+ continue;
+ }
+
+ break;
+
+ case GLIBTOP_KERN_PROC_PGRP:
+
+ /* return information about all processes in
+ * process group passed in arg
+ */
+
+ if (pinfo.pi_pgrp != arg)
+ {
+ continue;
+ }
+
+ break;
+
+ case GLIBTOP_KERN_PROC_SESSION:
+
+ /* return information about all processes in
+ * session passed in arg
+ */
+
+ if (pinfo.pi_sid != arg)
+ {
+ continue;
+ }
+
+ break;
+
+ case GLIBTOP_KERN_PROC_TTY:
+
+ /* return information about all processes with
+ * tty device number passed in arg
+ */
+
+ if (pinfo.pi_ttyd != arg)
+ {
+ continue;
+ }
+
+ break;
+
+ case GLIBTOP_KERN_PROC_UID:
+
+ /* return information about all processes with
+ * effective uid passed in arg
+ */
+
+ if (pinfo.pi_cred.cr_uid != arg)
+ {
+ continue;
+ }
+
+ break;
+
+ case GLIBTOP_KERN_PROC_RUID:
+
+ /* return information about all processes with
+ * real uid passed in arg
+ */
+
+ if (pinfo.pi_cred.cr_ruid != arg)
+ {
+ continue;
+ }
+
+ break;
+ }
+
+ if (count >= BLOCK_COUNT)
+ {
+ /* The following call to glibtop_realloc will be
+ * equivalent to glibtop_malloc () if `pids_chain' is
+ * NULL. We just calculate the new size and copy `pids'
+ * to the beginning of the newly allocated block. */
+
+ new_size = pids_size + BLOCK_SIZE;
+
+ pids_chain = glibtop_realloc_r
+ (server, pids_chain, new_size);
+ memcpy (pids_chain + pids_offset, pids, BLOCK_SIZE);
+
+ pids_size = new_size;
+ pids_offset += BLOCK_COUNT;
+ count = 0;
+ }
+
+ /* pids is now big enough to hold at least one single pid. */
+
+ pids[count++] = pinfo.pi_pid;
+
+ total++;
+ }
+
+ if (result == -1)
+ {
+ glibtop_error_io_r(server, "Cannot read procsinfo");
+ }
+
+ /* count is only zero if an error occured (one a running Linux system,
+ * we have at least one single process). */
+
+ if (!count) return NULL;
+
+ /* The following call to glibtop_realloc will be equivalent to
+ * glibtop_malloc if pids_chain is NULL. We just calculate the
+ * new size and copy pids to the beginning of the newly allocated
+ * block. */
+
+ new_size = pids_size + count * sizeof (unsigned);
+
+ pids_chain = glibtop_realloc_r (server, pids_chain, new_size);
+
+ memcpy (pids_chain + pids_offset, pids, count * sizeof (unsigned));
+
+ pids_size = new_size;
+
+ /* Since everything is ok now, we can set buf->flags, fill in the
+ * remaining fields and return the `pids_chain'. */
+
+ buf->size = sizeof(unsigned int);
+ buf->number = total;
+ buf->total = total * buf->size;
+
+ buf->flags = _glibtop_sysdeps_proclist;
+
+ return pids_chain;
+}
diff --git a/sysdeps/aix/procmap.c b/sysdeps/aix/procmap.c
new file mode 100644
index 00000000..2ed372aa
--- /dev/null
+++ b/sysdeps/aix/procmap.c
@@ -0,0 +1,50 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+
+#include <glibtop.h>
+#include <glibtop/error.h>
+#include <glibtop/xmalloc.h>
+#include <glibtop/procmap.h>
+
+static const unsigned long _glibtop_sysdeps_proc_map = 0;
+
+/* Init function. */
+
+void
+glibtop_init_proc_map_s (glibtop *server)
+{
+ server->sysdeps.proc_map = _glibtop_sysdeps_proc_map;
+}
+
+/* Provides detailed information about a process. */
+
+glibtop_map_entry *
+glibtop_get_proc_map_s (glibtop *server, glibtop_proc_map *buf, pid_t pid)
+{
+ glibtop_init_p (&server, GLIBTOP_SYSDEPS_PROC_MAP, 0);
+
+ memset (buf, 0, sizeof (glibtop_proc_map));
+
+ return NULL;
+}
diff --git a/sysdeps/aix/procmem.c b/sysdeps/aix/procmem.c
new file mode 100644
index 00000000..2e7738d3
--- /dev/null
+++ b/sysdeps/aix/procmem.c
@@ -0,0 +1,73 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <unistd.h>
+#include <sys/vminfo.h>
+#include <sys/resource.h>
+
+#include <glibtop.h>
+#include <glibtop/error.h>
+#include <glibtop/procmem.h>
+
+#include "utils.h"
+
+static const unsigned long _glibtop_sysdeps_proc_mem =
+(1 << GLIBTOP_PROC_MEM_SIZE) + (1 << GLIBTOP_PROC_MEM_VSIZE) +
+(1 << GLIBTOP_PROC_MEM_RESIDENT) + (1 << GLIBTOP_PROC_MEM_RSS) +
+(1 << GLIBTOP_PROC_MEM_RSS_RLIM);
+
+/* Init function. */
+
+void
+glibtop_init_proc_mem_s (glibtop *server)
+{
+ server->sysdeps.proc_mem = _glibtop_sysdeps_proc_mem;
+}
+
+/* Provides detailed information about a process. */
+
+void
+glibtop_get_proc_mem_s (glibtop *server, glibtop_proc_mem *buf,
+ pid_t pid)
+{
+ struct procsinfo *pinfo;
+ int pagesize;
+
+ memset (buf, 0, sizeof (glibtop_proc_mem));
+
+ pinfo = _glibtop_get_procinfo(server, pid);
+ if (pinfo == NULL)
+ {
+ glibtop_error_io_r (server, "Cannot read procsinfo");
+
+ return;
+ }
+
+ pagesize = sysconf(_SC_PAGESIZE);
+
+ buf->vsize = buf->size = pinfo->pi_size * pagesize;
+ buf->resident = buf->rss = (pinfo->pi_drss + pinfo->pi_trss) * pagesize;
+ buf->rss_rlim = pinfo->pi_rlimit[RLIMIT_RSS].rlim_cur;
+
+ buf->flags = _glibtop_sysdeps_proc_mem;
+}
diff --git a/sysdeps/aix/procsegment.c b/sysdeps/aix/procsegment.c
new file mode 100644
index 00000000..b1cf02a1
--- /dev/null
+++ b/sysdeps/aix/procsegment.c
@@ -0,0 +1,74 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <unistd.h>
+#include <sys/vminfo.h>
+#include <sys/resource.h>
+
+#include <glibtop.h>
+#include <glibtop/procsegment.h>
+#include <glibtop/error.h>
+
+#include "utils.h"
+
+static const unsigned long _glibtop_sysdeps_proc_segment =
+(1 << GLIBTOP_PROC_SEGMENT_TEXT_RSS) + (1 << GLIBTOP_PROC_SEGMENT_SHLIB_RSS) +
+(1 << GLIBTOP_PROC_SEGMENT_DATA_RSS) + (1 << GLIBTOP_PROC_SEGMENT_STACK_RSS);
+
+
+/* Init function. */
+
+void
+glibtop_init_proc_segment_s (glibtop *server)
+{
+ server->sysdeps.proc_segment = _glibtop_sysdeps_proc_segment;
+}
+
+/* Provides detailed information about a process. */
+
+void
+glibtop_get_proc_segment_s (glibtop *server, glibtop_proc_segment *buf,
+ pid_t pid)
+{
+ struct procsinfo *pinfo;
+ int pagesize;
+
+ memset (buf, 0, sizeof (glibtop_proc_segment));
+
+ pinfo = _glibtop_get_procinfo(server, pid);
+ if (pinfo == NULL)
+ {
+ glibtop_error_io_r (server, "Cannot read procsinfo");
+
+ return;
+ }
+
+ pagesize = sysconf(_SC_PAGESIZE);
+
+ buf->text_rss = pinfo->pi_trss * pagesize;
+ buf->data_rss = pinfo->pi_drss * pagesize;
+ buf->shlib_rss = pinfo->pi_ru.ru_ixrss * pagesize;
+ buf->stack_rss = pinfo->pi_ru.ru_isrss * pagesize;
+
+ buf->flags = _glibtop_sysdeps_proc_segment;
+}
diff --git a/sysdeps/aix/procsignal.c b/sysdeps/aix/procsignal.c
new file mode 100644
index 00000000..dbcb7829
--- /dev/null
+++ b/sysdeps/aix/procsignal.c
@@ -0,0 +1,89 @@
+/* $Id$ */
+
+/* Copyright (C)) +998-99 Martin Baulig
+ This file is part of LibGTop) +.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April) +998.
+
+ 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) + of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite) +30,
+ Boston, MA) +2111-1307, USA.
+*/
+
+#include <unistd.h>
+#include <sys/vminfo.h>
+#include <sys/resource.h>
+#include <sys/signal.h>
+
+#include <glibtop.h>
+#include <glibtop/procsignal.h>
+#include <glibtop/error.h>
+
+#include "utils.h"
+
+static const unsigned long _glibtop_sysdeps_proc_signal =
+(1 <<GLIBTOP_PROC_SIGNAL_SIGNAL) + (1 <<GLIBTOP_PROC_SIGNAL_BLOCKED) +
+(1 <<GLIBTOP_PROC_SIGNAL_SIGIGNORE) + (1 <<GLIBTOP_PROC_SIGNAL_SIGCATCH);
+
+/* Init function. */
+
+void
+glibtop_init_proc_signal_s (glibtop *server)
+{
+ server->sysdeps.proc_signal = _glibtop_sysdeps_proc_signal;
+}
+
+/* Provides detailed information about a process. */
+
+void
+glibtop_get_proc_signal_s (glibtop *server, glibtop_proc_signal *buf,
+ pid_t pid)
+{
+ struct procsinfo *pinfo;
+ int i;
+ long bit;
+
+ memset (buf, 0, sizeof (glibtop_proc_signal));
+
+ pinfo = _glibtop_get_procinfo(server, pid);
+ if (pinfo == NULL)
+ {
+ glibtop_error_io_r (server, "Cannot read procsinfo");
+
+ return;
+ }
+
+ /* pending signals */
+
+#define NB_BITS (8 * sizeof(u_int64_t))
+
+ for (i = 0; (i < NSIG) && (i < 2 * NB_BITS); i++)
+ {
+ bit = 1 << (NB_BITS - 1 - (i % NB_BITS));
+
+ if (sigismember(&pinfo->pi_sig, i))
+ buf->signal[i / NB_BITS] |= bit;
+
+ if (pinfo->pi_signal[i] == (long)SIG_HOLD)
+ buf->blocked[i / NB_BITS] |= bit;
+
+ if (pinfo->pi_signal[i] == (long)SIG_IGN)
+ buf->sigignore[i / NB_BITS] |= bit;
+
+ if (pinfo->pi_signal[i] == (long)SIG_CATCH)
+ buf->sigcatch[i / NB_BITS] |= bit;
+ }
+
+ buf->flags = _glibtop_sysdeps_proc_signal;
+}
diff --git a/sysdeps/aix/procstate.c b/sysdeps/aix/procstate.c
new file mode 100644
index 00000000..b0a9c814
--- /dev/null
+++ b/sysdeps/aix/procstate.c
@@ -0,0 +1,127 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <procinfo.h>
+#include <sys/thread.h>
+
+#include <glibtop.h>
+#include <glibtop/procstate.h>
+#include <glibtop/error.h>
+
+#include "utils.h"
+
+static const unsigned long _glibtop_sysdeps_proc_state =
+(1 << GLIBTOP_PROC_STATE_CMD) + (1 << GLIBTOP_PROC_STATE_STATE) +
+(1 << GLIBTOP_PROC_STATE_UID) + (1 << GLIBTOP_PROC_STATE_GID);
+
+/* Init function. */
+
+void
+glibtop_init_proc_state_s (glibtop *server)
+{
+ server->sysdeps.proc_state = _glibtop_sysdeps_proc_state;
+}
+
+/* Provides detailed information about a process. */
+
+void
+glibtop_get_proc_state_s (glibtop *server, glibtop_proc_state *buf,
+ pid_t pid)
+{
+ struct procsinfo *pinfo;
+ struct thrdsinfo thinfo;
+ tid_t thid;
+ int result;
+
+ memset (buf, 0, sizeof (glibtop_proc_state));
+
+ pinfo = _glibtop_get_procinfo(server, pid);
+ if (pinfo == NULL)
+ {
+ glibtop_error_io_r(server, "Cannot read procsinfo");
+
+ return;
+ }
+
+ if (pinfo->pi_pid == 0)
+ {
+ strcpy(buf->cmd, "swapper");
+ }
+
+ if (pinfo->pi_comm[0] == 0)
+ {
+ strcpy(buf->cmd, "<unknown>");
+ }
+ else
+ {
+ strncpy(buf->cmd, pinfo->pi_comm, 39);
+ }
+
+ buf->uid = pinfo->pi_uid;
+ buf->gid = pinfo->pi_cred.cr_gid;
+
+ if (pinfo->pi_state == SZOMB)
+ {
+ buf->state = 'Z';
+ strcpy(buf->cmd, "<defunct>");
+ }
+ else
+ {
+ /* get state of first thread */
+
+ thid = 0;
+ result = getthrds(pid, &thinfo, sizeof(thinfo), &thid, 1);
+ if (result != 1)
+ {
+ glibtop_error_io_r(server, "Cannot read threadinfo");
+ }
+
+ switch (thinfo.ti_state)
+ {
+ case TSIDL:
+ buf->state = 'D';
+ break;
+ case TSRUN:
+ buf->state = 'R';
+ break;
+ case TSSLEEP:
+ buf->state = 'S';
+ break;
+ case TSZOMB:
+ buf->state = 'Z';
+ strcpy(buf->cmd, "<defunct>");
+ break;
+ case TSSTOP:
+ buf->state = 'T';
+ break;
+ case TSSWAP:
+ buf->state = 'W';
+ break;
+ default:
+ buf->state = 0;
+ break;
+ }
+ }
+
+ buf->flags = _glibtop_sysdeps_proc_state;
+}
diff --git a/sysdeps/aix/proctime.c b/sysdeps/aix/proctime.c
new file mode 100644
index 00000000..4526a889
--- /dev/null
+++ b/sysdeps/aix/proctime.c
@@ -0,0 +1,72 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <unistd.h>
+
+#include <glibtop.h>
+#include <glibtop/proctime.h>
+#include <glibtop/error.h>
+
+#include "utils.h"
+
+static const unsigned long _glibtop_sysdeps_proc_time =
+(1 << GLIBTOP_PROC_TIME_START_TIME) + (1 << GLIBTOP_PROC_TIME_RTIME) +
+(1 << GLIBTOP_PROC_TIME_UTIME) + (1 << GLIBTOP_PROC_TIME_STIME) +
+(1 << GLIBTOP_PROC_TIME_CUTIME) + (1 << GLIBTOP_PROC_TIME_CSTIME) +
+(1 << GLIBTOP_PROC_TIME_FREQUENCY);
+
+/* Init function. */
+
+void
+glibtop_init_proc_time_s (glibtop *server)
+{
+ server->sysdeps.proc_time = _glibtop_sysdeps_proc_time;
+}
+
+/* Provides detailed information about a process. */
+
+void
+glibtop_get_proc_time_s (glibtop *server, glibtop_proc_time *buf,
+ pid_t pid)
+{
+ struct procsinfo *pinfo;
+
+ memset (buf, 0, sizeof (glibtop_proc_time));
+
+ pinfo = _glibtop_get_procinfo(server, pid);
+ if (pinfo == NULL)
+ {
+ glibtop_error_io_r (server, "Cannot read procsinfo");
+ return;
+ }
+
+ buf->start_time = pinfo->pi_start;
+ buf->utime = pinfo->pi_ru.ru_utime.tv_sec + (double)pinfo->pi_ru.ru_utime.tv_usec/1000000.0;
+ buf->stime = pinfo->pi_ru.ru_stime.tv_sec + (double)pinfo->pi_ru.ru_stime.tv_usec/1000000.0;
+ buf->rtime = buf->utime + buf->stime;
+ buf->cutime = pinfo->pi_cru.ru_utime.tv_sec + (double)pinfo->pi_cru.ru_utime.tv_usec/1000000.0;
+ buf->cstime = pinfo->pi_cru.ru_stime.tv_sec + (double)pinfo->pi_cru.ru_stime.tv_usec/1000000.0;
+ buf->frequency = sysconf(_SC_CLK_TCK);
+
+ buf->flags = _glibtop_sysdeps_proc_time;
+}
diff --git a/sysdeps/aix/procuid.c b/sysdeps/aix/procuid.c
new file mode 100644
index 00000000..c5fe476f
--- /dev/null
+++ b/sysdeps/aix/procuid.c
@@ -0,0 +1,101 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <unistd.h>
+#include <sys/vminfo.h>
+#include <sys/resource.h>
+
+#include <glibtop.h>
+#include <glibtop/procuid.h>
+#include <glibtop/error.h>
+
+#include "utils.h"
+
+static const unsigned long _glibtop_sysdeps_proc_uid =
+(1 << GLIBTOP_PROC_UID_UID) + (1 << GLIBTOP_PROC_UID_EUID) +
+(1 << GLIBTOP_PROC_UID_GID) + (1 << GLIBTOP_PROC_UID_EGID) +
+(1 << GLIBTOP_PROC_UID_PID) + (1 << GLIBTOP_PROC_UID_PPID) +
+(1 << GLIBTOP_PROC_UID_PGRP) + (1 << GLIBTOP_PROC_UID_SESSION) +
+(1 << GLIBTOP_PROC_UID_TTY) + (1 << GLIBTOP_PROC_UID_PRIORITY) +
+(1 << GLIBTOP_PROC_UID_NICE);
+
+
+/* Init function. */
+
+void
+glibtop_init_proc_uid_s (glibtop *server)
+{
+ server->sysdeps.proc_uid = _glibtop_sysdeps_proc_uid;
+}
+
+/* Provides detailed information about a process. */
+
+void
+glibtop_get_proc_uid_s (glibtop *server, glibtop_proc_uid *buf,
+ pid_t pid)
+{
+ struct procsinfo *pinfo;
+ struct thrdsinfo thinfo;
+ tid_t thid;
+ int result;
+
+ memset (buf, 0, sizeof (glibtop_proc_uid));
+
+ pinfo = _glibtop_get_procinfo(server, pid);
+ if (pinfo == NULL)
+ {
+ glibtop_error_io_r (server, "Cannot read procsinfo");
+
+ return;
+ }
+
+ buf->uid = pinfo->pi_cred.cr_ruid;
+ buf->euid = pinfo->pi_cred.cr_uid;
+ buf->gid = pinfo->pi_cred.cr_rgid;
+ buf->egid = pinfo->pi_cred.cr_gid;
+
+ buf->pid = pinfo->pi_pid;
+ buf->ppid = pinfo->pi_ppid;
+
+ buf->pgrp = pinfo->pi_pgrp;
+ buf->session = pinfo->pi_sid;
+
+ buf->tty = pinfo->pi_ttyd;
+
+ buf->nice = pinfo->pi_nice;
+
+ buf->flags = _glibtop_sysdeps_proc_uid;
+
+ thid = 0;
+ result = getthrds(pid, &thinfo, sizeof(thinfo), &thid, 1);
+ if (result != 1)
+ {
+ buf->flags &= ~(1 << GLIBTOP_PROC_UID_PRIORITY);
+
+ glibtop_error_io_r(server, "Cannot read thrdsinfo");
+ }
+
+ /* priority of first thread */
+
+ buf->priority = thinfo.ti_pri;
+}
diff --git a/sysdeps/aix/sem_limits.c b/sysdeps/aix/sem_limits.c
new file mode 100644
index 00000000..f3fce8d5
--- /dev/null
+++ b/sysdeps/aix/sem_limits.c
@@ -0,0 +1,86 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <glibtop.h>
+#include <glibtop/sem_limits.h>
+#include <glibtop/error.h>
+
+#include "utils.h"
+
+static const unsigned long _glibtop_sysdeps_sem_limits =
+(1 << GLIBTOP_IPC_SEMMNI) + (1 << GLIBTOP_IPC_SEMMSL) +
+(1 << GLIBTOP_IPC_SEMOPM) + (1 << GLIBTOP_IPC_SEMUME) +
+(1 << GLIBTOP_IPC_SEMUSZ) + (1 << GLIBTOP_IPC_SEMVMX) +
+(1 << GLIBTOP_IPC_SEMAEM);
+
+/* Init function. */
+
+void
+glibtop_init_sem_limits_p (glibtop *server)
+{
+ off_t result;
+
+ result = _glibtop_get_kmem_offset(server, "seminfo");
+ if (result <= 0)
+ {
+ server->sysdeps.sem_limits = 0;
+ return;
+ }
+
+ server->machine.seminfo_offset = result;
+
+ server->sysdeps.sem_limits = _glibtop_sysdeps_sem_limits;
+}
+
+/* Provides information about sysv sem limits. */
+
+void
+glibtop_get_sem_limits_p (glibtop *server, glibtop_sem_limits *buf)
+{
+ int result;
+ struct seminfo seminfo;
+
+ glibtop_init_p (server, (1L << GLIBTOP_SYSDEPS_SEM_LIMITS), 0);
+
+ memset (buf, 0, sizeof (glibtop_sem_limits));
+
+ result = _glibtop_get_kmem_info(server, server->machine.seminfo_offset,
+ &seminfo, sizeof(seminfo));
+
+ if (result <= 0)
+ {
+ glibtop_error_io_r (server, "Cannot read seminfo");
+
+ return;
+ }
+
+ buf->semmni = seminfo.semmni;
+ buf->semmsl = seminfo.semmsl;
+ buf->semopm = seminfo.semopm;
+ buf->semume = seminfo.semume;
+ buf->semusz = seminfo.semusz;
+ buf->semvmx = seminfo.semvmx;
+ buf->semaem = seminfo.semaem;
+
+ buf->flags = _glibtop_sysdeps_sem_limits;
+}
diff --git a/sysdeps/aix/shm_limits.c b/sysdeps/aix/shm_limits.c
new file mode 100644
index 00000000..67d20517
--- /dev/null
+++ b/sysdeps/aix/shm_limits.c
@@ -0,0 +1,79 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <sys/shm.h>
+
+#include <glibtop.h>
+#include <glibtop/error.h>
+#include <glibtop/shm_limits.h>
+
+static const unsigned long _glibtop_sysdeps_shm_limits =
+(1L << GLIBTOP_IPC_SHMMAX) + (1L << GLIBTOP_IPC_SHMMIN) +
+(1L << GLIBTOP_IPC_SHMMNI);
+
+/* Init function. */
+
+void
+glibtop_init_shm_limits_p (glibtop *server)
+{
+ int result;
+
+ result = _glibtop_get_kmem_offset(server, "shminfo");
+ if (result == -1)
+ {
+ server->sysdeps.shm_limits = 0;
+ return;
+ }
+
+ server->machine.shminfo_offset = result;
+
+ server->sysdeps.shm_limits = _glibtop_sysdeps_shm_limits;
+}
+
+/* Provides information about sysv ipc limits. */
+
+void
+glibtop_get_shm_limits_p (glibtop *server, glibtop_shm_limits *buf)
+{
+ int result;
+ struct shminfo shminfo;
+ int s;
+
+ glibtop_init_p (server, (1L << GLIBTOP_SYSDEPS_SHM_LIMITS), 0);
+
+ memset (buf, 0, sizeof (glibtop_shm_limits));
+
+ result = _glibtop_get_kmem_info(server, server->machine.shminfo_offset,
+ &shminfo, sizeof(struct shminfo));
+ if (result <= 0)
+ {
+ glibtop_error_io_r (server, "Cannot read shminfo");
+ return;
+ }
+
+ buf->shmmax = shminfo.shmmax;
+ buf->shmmin = shminfo.shmmin;
+ buf->shmmni = shminfo.shmmni;
+
+ buf->flags = _glibtop_sysdeps_shm_limits;
+}
diff --git a/sysdeps/aix/siglist.c b/sysdeps/aix/siglist.c
new file mode 100644
index 00000000..9778c0f8
--- /dev/null
+++ b/sysdeps/aix/siglist.c
@@ -0,0 +1,72 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <glibtop.h>
+#include <glibtop/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 Socket Condition" },
+ { 17, "SIGSTOP", "Stop (signal)" },
+ { 18, "SIGSTP", "Stop (user)" },
+ { 19, "SIGCONT", "Continue" },
+ { 20, "SIGCHLD", "Child Status Changed" },
+ { 21, "SIGTTIN", "Stopped (tty input)" },
+ { 22, "SIGTTOU", "Stopped (tty output)" },
+ { 23, "SIGIO", "I/O completed" },
+ { 24, "SIGXCPU", "Cpu Limit Exceeded" },
+ { 25, "SIGXFSZ", "File Size Limit Exceeded" },
+ { 27, "SIGMSG", "Message" },
+ { 28, "SIGWINCH","Window Size Change" },
+ { 29, "SIGPWR", "Power-Fail/Restart" },
+ { 30, "SIGUSR1", "User Signal 1" },
+ { 31, "SIGUSR2", "User Signal 2" },
+ { 32, "SIGPROF", "Profiling Timer Expired" },
+ { 33, "SIGDANGER","System Crash Imminent" },
+ { 34, "SIGVTALRM","Virtual Timer Expired" },
+ { 35, "SIGMIGRATE","Migrate Process" },
+ { 36, "SIGPRE", "Programming Exception" },
+ { 37, "SIGVIRT", "AIX Virtual Time Alarm" },
+ { 38, "SIGALRM1", "m:n Condition Variables" },
+ { 39, "SIGWAITING","Scheduling" },
+ { 59, "SIGCPUFAIL","Predictive De-configuration of Processors" },
+ { 60, "SIGKAP", "Keep Alive" },
+ { 61, "SIGRETRACT","Monitor Mode Relinguish" },
+ { 62, "SIGSOUND", "Sound Control Completed" },
+ { 63, "SIGSAK", "Secure Attention Key" },
+ { 0, NULL, NULL }
+};
diff --git a/sysdeps/aix/swap.c b/sysdeps/aix/swap.c
new file mode 100644
index 00000000..7e4db97c
--- /dev/null
+++ b/sysdeps/aix/swap.c
@@ -0,0 +1,128 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <sys/vminfo.h>
+
+#include <glibtop.h>
+#include <glibtop/error.h>
+#include <glibtop/swap.h>
+
+static const unsigned long _glibtop_sysdeps_swap =
+(1 << GLIBTOP_SWAP_TOTAL) + (1 << GLIBTOP_SWAP_USED) +
+(1 << GLIBTOP_SWAP_FREE) + (1 << GLIBTOP_SWAP_PAGEIN) +
+(1 << GLIBTOP_SWAP_PAGEOUT);
+
+#define FILENAME "/etc/swapspaces"
+
+/* Init function. */
+
+void
+glibtop_init_swap_s (glibtop *server)
+{
+ server->sysdeps.swap = _glibtop_sysdeps_swap;
+}
+
+/* Provides information about swap usage. */
+
+void
+glibtop_get_swap_s (glibtop *server, glibtop_swap *buf)
+{
+ struct vminfo vminfo;
+ struct pginfo pginfo;
+ int pagesize;
+ int result;
+ FILE* fd;
+ char device_name[128];
+ int c;
+ int comment = 0;
+ int pos = 0;
+
+ memset (buf, 0, sizeof (glibtop_swap));
+
+ pagesize = sysconf(_SC_PAGESIZE);
+
+ fd = fopen(FILENAME, "r");
+ if (fd == NULL)
+ {
+ glibtop_error_io_r (server, "open (%s)", FILENAME);
+ }
+
+ buf->total = 0;
+ buf->free = 0;
+ while((c = getc(fd)) != EOF)
+ {
+ if (comment)
+ {
+ /* skip comments */
+ if (c == '\n') comment = 0;
+ continue;
+ }
+ switch(c)
+ {
+ case '*':
+ comment = 1;
+ break;
+ case '\n':
+ device_name[pos] = 0;
+ pos = 0;
+
+ if (strncmp("dev=", device_name, 4) == 0)
+ {
+ result = swapqry(device_name+4, &pginfo);
+ if (result == -1)
+ {
+ glibtop_error_io_r (server, "Cannot read pginfo");
+ break;
+ }
+
+ buf->total += pginfo.size * pagesize;
+ buf->free += pginfo.free * pagesize;;
+ }
+ break;
+ case ' ':
+ case '\t':
+ break;
+ default:
+ device_name[pos++] = c;
+ break;
+ }
+ }
+
+ buf->used = buf->total - buf->free;
+ fclose(fd);
+#ifdef HAVE_VMGETINFO
+ result = vmgetinfo((void*)&vminfo, VMINFO, sizeof(vminfo));
+#else
+ result = _glibtop_vmgetinfo((void*)&vminfo, VMINFO, sizeof(vminfo));
+#endif
+ if (result == -1)
+ {
+ glibtop_error_io_r (server, "Cannot read vminfo");
+ return;
+ }
+
+ buf->pagein = vminfo.pageins;
+ buf->pageout = vminfo.pageouts;
+
+ buf->flags = _glibtop_sysdeps_swap;
+}
diff --git a/sysdeps/aix/sysinfo.c b/sysdeps/aix/sysinfo.c
new file mode 100644
index 00000000..8185c6cc
--- /dev/null
+++ b/sysdeps/aix/sysinfo.c
@@ -0,0 +1,194 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <sys/systemcfg.h>
+
+#include <config.h>
+#include <glibtop/sysinfo.h>
+
+static const unsigned long _glibtop_sysdeps_sysinfo =
+(1L << GLIBTOP_SYSINFO_CPUINFO);
+
+static glibtop_sysinfo sysinfo;
+
+static void add_info(glibtop_entry* entry, char* label, char* value)
+{
+ g_ptr_array_add(entry->labels, g_strdup(label));
+ g_hash_table_insert(entry->values, label, g_strdup(value));
+}
+
+static void init_sysinfo(void)
+{
+ int cpu;
+ char buf[64];
+
+ memset (&sysinfo, 0, sizeof (glibtop_sysinfo));
+
+ sysinfo.ncpu = MIN(_system_configuration.ncpus, GLIBTOP_NCPU);
+
+ for (cpu = 0; cpu < sysinfo.ncpu ; cpu++)
+ {
+ /* init cpu data structure */
+
+ sysinfo.cpuinfo[cpu].labels = g_ptr_array_new();
+ sysinfo.cpuinfo[cpu].values = g_hash_table_new (NULL, NULL);
+
+ /* add properties */
+
+ switch(_system_configuration.architecture)
+ {
+ case POWER_RS:
+ add_info( &sysinfo.cpuinfo[cpu]
+ , "architecture"
+ , "Power Classic architecture");
+ break;
+ case POWER_PC:
+ add_info( &sysinfo.cpuinfo[cpu]
+ , "architecture"
+ , "Power PC architecture");
+ break;
+ case IA64:
+ add_info( &sysinfo.cpuinfo[cpu]
+ , "architecture"
+ , "Intel IA64 architecture");
+ break;
+ default:
+ add_info( &sysinfo.cpuinfo[cpu]
+ , "architecture"
+ , "Unknown architecture");
+ break;
+ }
+
+ if ( (_system_configuration.architecture == POWER_RS) ||
+ (_system_configuration.architecture == POWER_PC) )
+ {
+ switch(_system_configuration.implementation)
+ {
+ case POWER_RS1:
+ add_info( &sysinfo.cpuinfo[cpu]
+ , "implementation"
+ , "RS1");
+ break;
+ case POWER_RSC:
+ add_info( &sysinfo.cpuinfo[cpu]
+ , "implementation"
+ , "RSC");
+ break;
+ case POWER_RS2:
+ add_info( &sysinfo.cpuinfo[cpu]
+ , "implementation"
+ , "RS2");
+ break;
+ case POWER_601:
+ add_info( &sysinfo.cpuinfo[cpu]
+ , "implementation"
+ , "601");
+ break;
+ case POWER_603:
+ add_info( &sysinfo.cpuinfo[cpu]
+ , "implementation"
+ , "603");
+ break;
+ case POWER_604:
+ add_info( &sysinfo.cpuinfo[cpu]
+ , "implementation"
+ , "604");
+ break;
+ case POWER_620:
+ add_info( &sysinfo.cpuinfo[cpu]
+ , "implementation"
+ , "620");
+ break;
+ case POWER_630:
+ add_info( &sysinfo.cpuinfo[cpu]
+ , "implementation"
+ , "630");
+ break;
+ case POWER_A35:
+ add_info( &sysinfo.cpuinfo[cpu]
+ , "implementation"
+ , "A35");
+ break;
+ case POWER_RS64II:
+ add_info( &sysinfo.cpuinfo[cpu]
+ , "implementation"
+ , "RS64II");
+ break;
+ case POWER_RS64III:
+ add_info( &sysinfo.cpuinfo[cpu]
+ , "implementation"
+ , "RS64III");
+ break;
+ }
+ }
+ else if (_system_configuration.architecture == IA64)
+ {
+ switch(_system_configuration.implementation)
+ {
+ case IA64_M1:
+ add_info( &sysinfo.cpuinfo[cpu]
+ , "implementation"
+ , "IA64 M1");
+ break;
+ case IA64_M2:
+ add_info( &sysinfo.cpuinfo[cpu]
+ , "implementation"
+ , "IA64 M2");
+ break;
+ }
+ }
+
+ sprintf(buf,"%d", _system_configuration.width);
+ add_info( &sysinfo.cpuinfo[cpu], "width", buf);
+
+ if (_system_configuration.cache_attrib & (1 << 31))
+ {
+ /* L1 cache is present */
+
+ sprintf(buf,"%d", _system_configuration.icache_size);
+ add_info( &sysinfo.cpuinfo[cpu], "L1 instruction cache size", buf);
+
+ sprintf(buf,"%d", _system_configuration.dcache_size);
+ add_info( &sysinfo.cpuinfo[cpu], "L1 data cache size", buf);
+ }
+
+ sprintf(buf,"%d", _system_configuration.L2_cache_size);
+ add_info( &sysinfo.cpuinfo[cpu], "L2 cache size", buf);
+ }
+
+ sysinfo.flags = _glibtop_sysdeps_sysinfo;
+}
+
+glibtop_sysinfo *
+glibtop_get_sysinfo_s (glibtop *server)
+{
+ static int first_time = 1;
+
+ if (first_time)
+ {
+ init_sysinfo();
+ first_time = 0;
+ }
+
+ return &sysinfo;
+}
diff --git a/sysdeps/aix/uptime.c b/sysdeps/aix/uptime.c
new file mode 100644
index 00000000..250a72d1
--- /dev/null
+++ b/sysdeps/aix/uptime.c
@@ -0,0 +1,73 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <glibtop.h>
+#include <glibtop/error.h>
+#include <glibtop/uptime.h>
+
+#include <glibtop/cpu.h>
+
+#include <glibtop_suid.h>
+
+static const unsigned long _glibtop_sysdeps_uptime =
+(1L << GLIBTOP_UPTIME_UPTIME) + (1L << GLIBTOP_UPTIME_IDLETIME);
+
+static const unsigned long _required_cpu_flags =
+(1L << GLIBTOP_CPU_TOTAL) + (1L << GLIBTOP_CPU_IDLE) +
+(1L << GLIBTOP_CPU_FREQUENCY);
+
+/* Init function. */
+
+void
+glibtop_init_uptime_p (glibtop *server)
+{
+ server->sysdeps.uptime = _glibtop_sysdeps_uptime;
+}
+
+/* Provides uptime and idle time. */
+
+void
+glibtop_get_uptime_p (glibtop *server, glibtop_uptime *buf)
+{
+ glibtop_cpu cpu;
+
+ glibtop_init_p (server, (1L << GLIBTOP_SYSDEPS_UPTIME), 0);
+
+ memset (buf, 0, sizeof (glibtop_uptime));
+
+ /* We simply calculate it from the CPU usage. */
+
+ glibtop_get_cpu_p (server, &cpu);
+
+ /* Make sure all required fields are present. */
+
+ if ((cpu.flags & _required_cpu_flags) != _required_cpu_flags)
+ return;
+
+ /* Calculate values. */
+
+ buf->uptime = (double) cpu.total / (double) cpu.frequency;
+ buf->idletime = (double) cpu.idle / (double) cpu.frequency;
+
+ buf->flags = _glibtop_sysdeps_uptime;
+}
diff --git a/sysdeps/aix/utils.c b/sysdeps/aix/utils.c
new file mode 100644
index 00000000..e230eb77
--- /dev/null
+++ b/sysdeps/aix/utils.c
@@ -0,0 +1,141 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <nlist.h>
+
+#include <procinfo.h>
+#include <sys/proc.h>
+#include <sys/vminfo.h>
+
+#include <glibtop.h>
+#include <glibtop/error.h>
+#include <glibtop/xmalloc.h>
+#include "glibtop_suid.h"
+#include "utils.h"
+
+#ifndef HAVE_VMGETINFO
+#include <dlfcn.h>
+typedef int (*vmgetinfo_proto)(void *out, int command, int arg);
+#endif
+
+off_t
+_glibtop_get_kmem_offset(glibtop* server, char* kname)
+{
+ int result;
+ struct nlist kernelnames[] =
+ { {NULL, 0, 0, 0, 0, 0},
+ {NULL, 0, 0, 0, 0, 0},
+ };
+
+ kernelnames[0]._n._n_name = kname;
+
+ glibtop_suid_enter(server);
+
+ result = knlist(kernelnames, 1, sizeof(struct nlist));
+
+ glibtop_suid_leave(server);
+
+ if (result == -1)
+ {
+ return -1;
+ }
+
+ return kernelnames[0].n_value;
+}
+
+int
+_glibtop_get_kmem_info(glibtop* server, off_t offset, void* buf, size_t len)
+{
+ int result;
+
+ glibtop_suid_enter(server);
+
+ lseek(server->machine.kmem_fd, offset, SEEK_SET);
+
+ result = read(server->machine.kmem_fd, buf, len);
+
+ glibtop_suid_leave(server);
+
+ return result;
+}
+
+struct procsinfo*
+_glibtop_get_procinfo (glibtop *server, pid_t pid)
+{
+ int result;
+ pid_t current;
+ static int first_time = 1;
+
+ /* test if procsinfo already found */
+
+ if ((server->machine.last_pinfo.pi_pid == pid) && (!first_time))
+ {
+ return &server->machine.last_pinfo;
+ }
+
+ /* seek procsinfo if given pid */
+
+ first_time = 0;
+ current = 0;
+ while ((result = getprocs( &server->machine.last_pinfo
+ , sizeof(struct procsinfo)
+ , NULL, 0, &current, 1)) == 1)
+ {
+
+ if (pid == server->machine.last_pinfo.pi_pid)
+ {
+ return &server->machine.last_pinfo;
+ }
+ }
+ return NULL;
+}
+
+#ifndef HAVE_VMGETINFO
+int
+_glibtop_vmgetinfo (void *out, int command, int arg)
+{
+ void* handle;
+
+ static vmgetinfo_proto kern_vmgetinfo = NULL;
+
+ if (kern_vmgetinfo == NULL)
+ {
+ handle = dlopen("/unix", RTLD_NOW | RTLD_GLOBAL);
+ if (handle == NULL)
+ {
+ return -1;
+ }
+
+ kern_vmgetinfo = dlsym( handle, "vmgetinfo");
+
+ dlclose(handle);
+
+ if (kern_vmgetinfo == NULL)
+ {
+ return -1;
+ }
+ }
+
+ return kern_vmgetinfo(out, command, arg);
+}
+#endif
diff --git a/sysdeps/aix/utils.h b/sysdeps/aix/utils.h
new file mode 100644
index 00000000..f845f61a
--- /dev/null
+++ b/sysdeps/aix/utils.h
@@ -0,0 +1,45 @@
+/* $Id$ */
+
+/*
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, March 1999.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#ifndef __UTILS_H__
+#define __UTILS_H__
+
+BEGIN_LIBGTOP_DECLS
+
+extern off_t
+_glibtop_get_kmem_offset(glibtop* server, char* kname);
+
+extern int
+_glibtop_get_kmem_info(glibtop* server, off_t offset, void* buf, size_t len);
+
+extern struct procsinfo*
+_glibtop_get_procinfo (glibtop *server, pid_t pid);
+
+#ifndef HAVE_VMGETINFO
+extern int
+_glibtop_vmgetinfo (void *out, int command, int arg);
+#endif
+
+END_LIBGTOP_DECLS
+
+#endif /* __UTILS_H__ */
diff --git a/sysdeps/common/error.c b/sysdeps/common/error.c
new file mode 100644
index 00000000..f334ec50
--- /dev/null
+++ b/sysdeps/common/error.c
@@ -0,0 +1,88 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <glibtop/error.h>
+
+#define DEFAULT_NAME "LibGTop-Server"
+
+/* Prints error message and exits. */
+
+static void
+print_server_name (glibtop *server)
+{
+ fprintf (stderr, "%s: ", server ?
+ (server->name ? server->name : DEFAULT_NAME)
+ : DEFAULT_NAME);
+}
+
+void
+glibtop_error_vr (glibtop *server, char *format, va_list args)
+{
+ print_server_name (server);
+ vfprintf (stderr, format, args);
+ fprintf (stderr, "\n");
+
+#ifdef LIBGTOP_ENABLE_DEBUG
+ abort ();
+#else
+ exit (1);
+#endif
+}
+
+void
+glibtop_error_io_vr (glibtop *server, char *format, int error, va_list args)
+{
+ print_server_name (server);
+ vfprintf (stderr, format, args);
+ fprintf (stderr, ": %s\n", strerror (error));
+
+#ifdef LIBGTOP_ENABLE_DEBUG
+ abort ();
+#else
+ exit (1);
+#endif
+}
+
+void
+glibtop_warn_vr (glibtop *server, char *format, va_list args)
+{
+ print_server_name (server);
+ vfprintf (stderr, format, args);
+ fprintf (stderr, "\n");
+
+#ifdef LIBGTOP_FATAL_WARNINGS
+ abort ();
+#endif
+}
+
+void
+glibtop_warn_io_vr (glibtop *server, char *format, int error, va_list args)
+{
+ print_server_name (server);
+ vfprintf (stderr, format, args);
+ fprintf (stderr, ": %s\n", strerror (error));
+
+#ifdef LIBGTOP_FATAL_WARNINGS
+ abort ();
+#endif
+}
diff --git a/sysdeps/common/gnuslib.c b/sysdeps/common/gnuslib.c
new file mode 100644
index 00000000..67abf508
--- /dev/null
+++ b/sysdeps/common/gnuslib.c
@@ -0,0 +1,375 @@
+/* -*-C-*-
+ * Common library code for the GNU Emacs server and client.
+ *
+ * This file is part of GNU Emacs.
+ *
+ * Copying is permitted under those conditions described by the GNU
+ * General Public License.
+ *
+ * Copyright (C) 1989 Free Software Foundation, Inc.
+ *
+ * Author: Andy Norman (ange@hplb.hpl.hp.com), based on
+ * 'etc/server.c' and 'etc/emacsclient.c' from the 18.52 GNU
+ * Emacs distribution.
+ *
+ * Please mail bugs and suggestions to the author at the above address.
+ */
+
+/* HISTORY
+ * 11-Nov-1990 bristor@simba
+ * Added EOT stuff.
+ */
+
+/*
+ * This file incorporates new features added by Bob Weiner <weiner@mot.com>,
+ * Darrell Kindred <dkindred@cmu.edu> and Arup Mukherjee <arup@cmu.edu>.
+ * Please see the note at the end of the README file for details.
+ *
+ * (If gnuserv came bundled with your emacs, the README file is probably
+ * ../etc/gnuserv.README relative to the directory containing this file)
+ */
+
+#include <glibtop.h>
+#include <glibtop/gnuserv.h>
+
+#include <fcntl.h>
+
+#ifdef UNIX_DOMAIN_SOCKETS
+static int connect_to_unix_server (void);
+#endif
+
+#ifdef INTERNET_DOMAIN_SOCKETS
+static int connect_to_internet_server (const char *serverhost, u_short port);
+#endif
+
+/* On some systems, e.g. DGUX, inet_addr returns a 'struct in_addr'. */
+#ifdef HAVE_BROKEN_INET_ADDR
+#define IN_ADDR struct in_addr
+#define NUMERIC_ADDR_ERROR (numeric_addr.s_addr == 0xffffffff)
+#else
+#if (LONGBITS > 32)
+#define IN_ADDR unsigned int
+#else
+#define IN_ADDR unsigned long
+#endif
+#define NUMERIC_ADDR_ERROR (numeric_addr == (IN_ADDR) 0xffffffff)
+#endif
+
+#include <arpa/inet.h>
+
+int
+glibtop_make_connection (hostarg, portarg, s)
+ const char *hostarg;
+ int portarg;
+ int *s;
+{
+#ifdef INTERNET_DOMAIN_SOCKETS
+ char *ptr;
+
+ if (hostarg == NULL)
+ hostarg = getenv ("LIBGTOP_HOST");
+ if (portarg == 0 && (ptr = getenv ("LIBGTOP_PORT")) != NULL)
+ portarg = atoi (ptr);
+#endif
+
+ if (hostarg != NULL) {
+ /* hostname was given explicitly, via cmd line arg or
+ * LIBGTOP_HOST, * so obey it. */
+#ifdef UNIX_DOMAIN_SOCKETS
+ if (!strcmp (hostarg, "unix")) {
+ *s = connect_to_unix_server ();
+ return (int) CONN_UNIX;
+ }
+#endif /* UNIX_DOMAIN_SOCKETS */
+#ifdef INTERNET_DOMAIN_SOCKETS
+ *s = connect_to_internet_server (hostarg, portarg);
+ return (int) CONN_INTERNET;
+#endif
+ } else {
+ /* no hostname given. Use unix-domain/sysv-ipc, or *
+ * internet-domain connection to local host if they're not
+ * available. */
+#if defined(UNIX_DOMAIN_SOCKETS)
+ *s = connect_to_unix_server ();
+ return (int) CONN_UNIX;
+#elif defined(INTERNET_DOMAIN_SOCKETS)
+ {
+ char localhost[HOSTNAMSZ];
+
+ gethostname (localhost, HOSTNAMSZ); /* use this
+ * host by
+ * default */
+ *s = connect_to_internet_server (localhost, portarg);
+ return (int) CONN_INTERNET;
+ }
+#endif /* IPC type */
+ }
+}
+
+#if defined(INTERNET_DOMAIN_SOCKETS) || defined(UNIX_DOMAIN_SOCKETS)
+/*
+ * send_string -- send string to socket.
+ */
+#if 0
+static void
+send_string (s, msg)
+ int s;
+ const char *msg;
+{
+#if 0
+ if (send (s, msg, strlen (msg), 0) < 0) {
+ perror (progname);
+ fprintf (stderr, "%s: unable to send\n", progname);
+ exit (1);
+ }; /* if */
+#else
+ int len, left = strlen (msg);
+
+ while (left > 0) {
+ if ((len = write (s, msg, min2 (left, GSERV_BUFSZ))) < 0) {
+ /* XEmacs addition: robertl@arnet.com */
+ if (errno == EPIPE) {
+ return;
+ }
+ perror (progname);
+ fprintf (stderr, "%s: unable to send\n", progname);
+ exit (1);
+ }; /* if */
+ left -= len;
+ msg += len;
+ }; /* while */
+#endif
+} /* send_string */
+
+/*
+ * read_line -- read a \n terminated line from a socket
+ */
+static int
+read_line (int s, char *dest)
+{
+ int length;
+ int offset = 0;
+ char buffer[GSERV_BUFSZ + 1];
+
+ while ((length = read (s, buffer + offset, 1) > 0) && buffer[offset] != '\n'
+ && buffer[offset] != EOT_CHR) {
+ offset += length;
+ if (offset >= GSERV_BUFSZ)
+ break;
+ }
+ buffer[offset] = '\0';
+ strcpy (dest, buffer);
+ return 1;
+} /* read_line */
+#endif
+#endif /* INTERNET_DOMAIN_SOCKETS || UNIX_DOMAIN_SOCKETS */
+
+
+#ifdef UNIX_DOMAIN_SOCKETS
+/*
+ * connect_to_unix_server -- establish connection with server process via a unix-
+ * domain socket. Returns socket descriptor for server
+ * if successful.
+ */
+static int
+connect_to_unix_server (void)
+{
+ int s; /* connected socket descriptor */
+ struct sockaddr_un server; /* for unix connections */
+
+ if ((s = socket (AF_UNIX, SOCK_STREAM, 0)) < 0)
+ glibtop_error_io ("unable to create socket");
+
+ server.sun_family = AF_UNIX;
+#ifdef HIDE_UNIX_SOCKET
+ sprintf (server.sun_path, "/tmp/lgtddir%d/lgtd", (int) geteuid ());
+#else /* HIDE_UNIX_SOCKET */
+ sprintf (server.sun_path, "/tmp/lgtd%d", (int) geteuid ());
+#endif /* HIDE_UNIX_SOCKET */
+ if (connect (s, (struct sockaddr *) &server, strlen (server.sun_path) + 2) < 0)
+ glibtop_error_io ("unable to connect to local");
+
+ return (s);
+
+} /* connect_to_unix_server */
+#endif /* UNIX_DOMAIN_SOCKETS */
+
+
+#ifdef INTERNET_DOMAIN_SOCKETS
+/*
+ * internet_addr -- return the internet addr of the hostname or
+ * internet address passed. Return -1 on error.
+ */
+long
+glibtop_internet_addr (host)
+ const char *host;
+{
+ struct hostent *hp; /* pointer to host info for remote host */
+ IN_ADDR numeric_addr; /* host address */
+
+ numeric_addr = inet_addr (host);
+ if (!NUMERIC_ADDR_ERROR)
+ return numeric_addr;
+ else if ((hp = gethostbyname (host)) != NULL)
+ return ((struct in_addr *) (hp->h_addr))->s_addr;
+ else {
+ glibtop_warn_io ("gethostbyname (%s)", host);
+ return -1;
+ }
+
+} /* glibtop_internet_addr */
+
+#ifdef AUTH_MAGIC_COOKIE
+#include <X11/X.h>
+#include <X11/Xauth.h>
+
+static Xauth *server_xauth = NULL;
+
+#endif
+
+/*
+ * connect_to_internet_server -- establish connection with server process via
+ * an internet domain socket. Returns socket
+ * descriptor for server if successful.
+ */
+static int
+connect_to_internet_server (const char *serverhost, u_short port)
+{
+ int s; /* connected socket descriptor */
+ struct servent *sp; /* pointer to service information */
+ struct sockaddr_in peeraddr_in; /* for peer socket address */
+ char buf[512]; /* temporary buffer */
+
+ /* clear out address structures */
+ memset ((char *) &peeraddr_in, 0, sizeof (struct sockaddr_in));
+
+ /* Set up the peer address to which we will connect. */
+ peeraddr_in.sin_family = AF_INET;
+
+ /* look up the server host's internet address */
+ peeraddr_in.sin_addr.s_addr = glibtop_internet_addr (serverhost);
+ if ((long) peeraddr_in.sin_addr.s_addr == -1)
+ glibtop_error ("unable to find %s in /etc/hosts or from YP", serverhost);
+
+ if (port == 0) {
+ if ((sp = getservbyname ("gtopd", "tcp")) == NULL)
+ peeraddr_in.sin_port = htons (DEFAULT_PORT + getuid ());
+ else
+ peeraddr_in.sin_port = sp->s_port;
+ }
+ /* if */
+ else
+ peeraddr_in.sin_port = htons (port);
+
+ /* Create the socket. */
+ if ((s = socket (AF_INET, SOCK_STREAM, 0)) == -1)
+ glibtop_error_io ("unable to create socket");
+
+ /* Try to connect to the remote server at the address * which was
+ * just built into peeraddr. */
+ if (connect (s, (struct sockaddr *) &peeraddr_in,
+ sizeof (struct sockaddr_in)) == -1)
+ glibtop_error_io ("unable to connect to remote");
+
+#ifdef AUTH_MAGIC_COOKIE
+
+ /* send credentials using MIT-MAGIC-COOKIE-1 protocol */
+
+ sprintf (buf, "%d", port);
+
+ server_xauth =
+ XauGetAuthByAddr (FamilyInternet,
+ sizeof (peeraddr_in.sin_addr.s_addr),
+ (char *) &peeraddr_in.sin_addr.s_addr,
+ strlen (buf), buf,
+ strlen (MCOOKIE_X_NAME), MCOOKIE_X_NAME);
+
+ if (server_xauth && server_xauth->data) {
+ sprintf (buf, "%s\n%d\n", MCOOKIE_NAME, server_xauth->data_length);
+ write (s, buf, strlen (buf));
+ write (s, server_xauth->data, server_xauth->data_length);
+
+ return (s);
+ }
+#endif /* AUTH_MAGIC_COOKIE */
+
+ sprintf (buf, "%s\n", DEFAUTH_NAME);
+ write (s, buf, strlen (buf));
+
+ return (s);
+
+} /* connect_to_internet_server */
+#endif /* INTERNET_DOMAIN_SOCKETS */
+
+
+#if defined(INTERNET_DOMAIN_SOCKETS) || defined(UNIX_DOMAIN_SOCKETS)
+/*
+ * disconnect_from_server -- inform the server that sending has finished, and wait for
+ * its reply.
+ */
+#if 0
+static void
+disconnect_from_server (s, echo)
+ int s;
+ int echo;
+{
+#if 0
+ char buffer[REPLYSIZ + 1];
+
+#else
+ char buffer[GSERV_BUFSZ + 1];
+
+#endif
+ int add_newline = 1;
+ int length;
+
+ send_string (s, EOT_STR); /* make sure server gets string */
+
+#if !defined (linux) && !defined (_SCO_DS)
+ /*
+ * shutdown is completely hozed under linux. If s is a unix domain socket,
+ * you'll get EOPNOTSUPP back from it. If s is an internet socket, you get
+ * a broken pipe when you try to read a bit later. The latter
+ * problem is fixed for linux versions >= 1.1.46, but the problem
+ * with unix sockets persists. Sigh.
+ */
+
+ if (shutdown (s, 1) == -1) {
+ perror (progname);
+ fprintf (stderr, "%s: unable to shutdown socket\n", progname);
+ exit (1);
+ }; /* if */
+#endif
+
+#if 0
+ while ((length = recv (s, buffer, REPLYSIZ, 0)) > 0) {
+ buffer[length] = '\0';
+ if (echo)
+ fputs (buffer, stdout);
+ add_newline = (buffer[length - 1] != '\n');
+ }; /* while */
+#else
+ while ((length = read (s, buffer, GSERV_BUFSZ)) > 0 ||
+ (length == -1 && errno == EINTR)) {
+ if (length) {
+ buffer[length] = '\0';
+ if (echo) {
+ fputs (buffer, stdout);
+ add_newline = (buffer[length - 1] != '\n');
+ }; /* if */
+ }; /* if */
+ }; /* while */
+#endif
+
+ if (echo && add_newline)
+ putchar ('\n');
+
+ if (length < 0) {
+ perror (progname);
+ fprintf (stderr, "%s: unable to read the reply from the server\n", progname);
+ exit (1);
+ }; /* if */
+
+} /* disconnect_from_server */
+#endif
+#endif /* INTERNET_DOMAIN_SOCKETS || UNIX_DOMAIN_SOCKETS */
diff --git a/sysdeps/common/inodedb.c b/sysdeps/common/inodedb.c
new file mode 100644
index 00000000..d78d3905
--- /dev/null
+++ b/sysdeps/common/inodedb.c
@@ -0,0 +1,117 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <glibtop.h>
+#include <glibtop/error.h>
+#include <glibtop/xmalloc.h>
+#include <glibtop/inodedb.h>
+
+#include <pwd.h>
+#include <gdbm.h>
+
+#ifndef SYSTEM_INODEDB
+#define SYSTEM_INODEDB "/usr/var/libgtop/inodedb.db"
+#endif
+
+glibtop_inodedb *
+glibtop_inodedb_open_s (glibtop *server, unsigned databases,
+ unsigned long cachesize)
+{
+ glibtop_inodedb *inodedb;
+ char filename [BUFSIZ];
+ struct passwd *pwd;
+ struct stat statb;
+
+ if (!databases)
+ databases = GLIBTOP_INODEDB_ALL;
+
+ inodedb = glibtop_calloc_r (server, 1, sizeof (glibtop_inodedb));
+
+ if (stat (SYSTEM_INODEDB, &statb))
+ databases &= ~GLIBTOP_INODEDB_SYSTEM;
+
+ if (databases & GLIBTOP_INODEDB_SYSTEM) {
+ inodedb->system_dbf = gdbm_open
+ (SYSTEM_INODEDB, 0, GDBM_READER, 0, 0);
+ if (!inodedb->system_dbf)
+ glibtop_error_io_r
+ (server, "gdbm_open (%s)", SYSTEM_INODEDB);
+ }
+
+ pwd = getpwuid (getuid ());
+ if (!pwd) glibtop_error_io_r (server, "getpwuid");
+
+ sprintf (filename, "%s/var/libgtop/inodedb.db", pwd->pw_dir);
+
+ if (stat (filename, &statb))
+ databases &= ~GLIBTOP_INODEDB_USER;
+
+ if (databases & GLIBTOP_INODEDB_USER) {
+ inodedb->user_dbf = gdbm_open
+ (filename, 0, GDBM_READER, 0, 0);
+ if (!inodedb->user_dbf)
+ glibtop_error_io_r
+ (server, "gdbm_open (%s)", filename);
+ }
+
+ return inodedb;
+}
+
+const char *
+glibtop_inodedb_lookup_s (glibtop *server,
+ glibtop_inodedb *inodedb,
+ u_int64_t device, u_int64_t inode)
+{
+ glibtop_inodedb_key key;
+ datum d_key, d_content;
+
+ d_key.dptr = (void *) &key;
+ d_key.dsize = sizeof (key);
+
+ key.device = device;
+ key.inode = inode;
+
+ if (inodedb->system_dbf) {
+ d_content = gdbm_fetch (inodedb->system_dbf, d_key);
+ if (d_content.dptr) return d_content.dptr;
+ }
+
+ if (inodedb->user_dbf) {
+ d_content = gdbm_fetch (inodedb->user_dbf, d_key);
+ if (d_content.dptr) return d_content.dptr;
+ }
+
+ return NULL;
+}
+
+void
+glibtop_inodedb_close_s (glibtop *server, glibtop_inodedb *inodedb)
+{
+ if (inodedb->system_dbf)
+ gdbm_close (inodedb->system_dbf);
+
+ if (inodedb->user_dbf)
+ gdbm_close (inodedb->user_dbf);
+
+ glibtop_free_r (server, inodedb);
+}
diff --git a/sysdeps/common/xmalloc.c b/sysdeps/common/xmalloc.c
new file mode 100644
index 00000000..d8d0080f
--- /dev/null
+++ b/sysdeps/common/xmalloc.c
@@ -0,0 +1,72 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <glibtop/xmalloc.h>
+
+/* Wrappers to malloc, calloc, realloc ... */
+
+void *
+glibtop_malloc_r (glibtop *server, size_t size)
+{
+ void *buf = malloc (size);
+
+ if (!buf)
+ glibtop_error_io_r (server, "malloc %d bytes", size);
+
+ return buf;
+}
+
+void *
+glibtop_calloc_r (glibtop *server, size_t nmemb, size_t size)
+{
+ void *buf = calloc (nmemb, size);
+
+ if (!buf)
+ glibtop_error_io_r (server, "calloc %d blocks (%d bytes each)",
+ nmemb, size);
+
+ return buf;
+}
+
+void *
+glibtop_realloc_r (glibtop *server, void *ptr, size_t size)
+{
+ void *buf = realloc (ptr, size);
+
+ if (!buf)
+ glibtop_error_io_r (server, "realloc %d bytes", size);
+
+ return buf;
+}
+
+char *
+glibtop_strdup_r (glibtop *server, const char *string)
+{
+ return strcpy (glibtop_malloc_r (server, strlen (string) + 1), string);
+}
+
+void
+glibtop_free_r (glibtop *server, const void *ptr)
+{
+ if (ptr) free ((void *) ptr);
+}
diff --git a/sysdeps/freebsd/.cvsignore b/sysdeps/freebsd/.cvsignore
new file mode 100644
index 00000000..09980ae6
--- /dev/null
+++ b/sysdeps/freebsd/.cvsignore
@@ -0,0 +1,6 @@
+.deps
+.libs
+Makefile
+Makefile.in
+*.lo
+*.la
diff --git a/sysdeps/freebsd/AUTHORS b/sysdeps/freebsd/AUTHORS
new file mode 100644
index 00000000..9da8aceb
--- /dev/null
+++ b/sysdeps/freebsd/AUTHORS
@@ -0,0 +1,2 @@
+Martin Baulig (martin@home-of-linux.org)
+Josh Sled (jsled@scam.XCF.Berkeley.EDU)
diff --git a/sysdeps/freebsd/ChangeLog b/sysdeps/freebsd/ChangeLog
new file mode 100644
index 00000000..72a89fa7
--- /dev/null
+++ b/sysdeps/freebsd/ChangeLog
@@ -0,0 +1,188 @@
+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.
diff --git a/sysdeps/freebsd/Makefile.am b/sysdeps/freebsd/Makefile.am
new file mode 100644
index 00000000..b955e6ff
--- /dev/null
+++ b/sysdeps/freebsd/Makefile.am
@@ -0,0 +1,23 @@
+LINK = $(LIBTOOL) --mode=link $(CC) $(CFLAGS) $(LDFLAGS) -o $@
+
+INCLUDES = @INCLUDES@
+
+lib_LTLIBRARIES = libgtop_sysdeps-2.0.la libgtop_sysdeps_suid-2.0.la
+
+libgtop_sysdeps_2_0_la_SOURCES = nosuid.c siglist.c
+
+libgtop_sysdeps_2_0_la_LDFLAGS = $(LT_VERSION_INFO)
+
+libgtop_sysdeps_suid_2_0_la_SOURCES = open.c close.c siglist.c cpu.c mem.c swap.c \
+ uptime.c loadavg.c shm_limits.c msg_limits.c \
+ sem_limits.c proclist.c procstate.c procuid.c \
+ proctime.c procmem.c procsignal.c prockernel.c \
+ procsegment.c procargs.c procmap.c netload.c \
+ 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
diff --git a/sysdeps/freebsd/NOTES b/sysdeps/freebsd/NOTES
new file mode 100644
index 00000000..82bbbc4b
--- /dev/null
+++ b/sysdeps/freebsd/NOTES
@@ -0,0 +1,10 @@
+sysctl (3)
+/usr/include/sys/vmmeter.h : VM stats
+kvm (3)
+
+CPU stats: /usr/include/sys/dkstat.h
+cp_time_offset = kvm_nlist(...)["_cp_time"].n_value;
+
+"systemwide main memory usage structure"
+sysctl(...)
+
diff --git a/sysdeps/freebsd/close.c b/sysdeps/freebsd/close.c
new file mode 100644
index 00000000..b887a914
--- /dev/null
+++ b/sysdeps/freebsd/close.c
@@ -0,0 +1,31 @@
+/* $Id$ */
+
+/* Copyright (C) 1998 Joshua Sled
+ This file is part of LibGTop 1.0.
+
+ Contributed by Joshua Sled <jsled@xcf.berkeley.edu>, July 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <glibtop.h>
+#include <glibtop/close.h>
+
+/* Closes pipe to gtop server. */
+
+void
+glibtop_close_p (glibtop *server)
+{ }
diff --git a/sysdeps/freebsd/cpu.c b/sysdeps/freebsd/cpu.c
new file mode 100644
index 00000000..5fdce7ad
--- /dev/null
+++ b/sysdeps/freebsd/cpu.c
@@ -0,0 +1,117 @@
+/* $Id$ */
+
+/* Copyright (C) 1998 Joshua Sled
+ This file is part of LibGTop 1.0.
+
+ Contributed by Joshua Sled <jsled@xcf.berkeley.edu>, July 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <glibtop.h>
+#include <glibtop/error.h>
+#include <glibtop/cpu.h>
+
+#include <glibtop_suid.h>
+
+static const unsigned long _glibtop_sysdeps_cpu =
+(1L << GLIBTOP_CPU_TOTAL) + (1L << GLIBTOP_CPU_USER) +
+(1L << GLIBTOP_CPU_NICE) + (1L << GLIBTOP_CPU_SYS) +
+(1L << GLIBTOP_CPU_IDLE) + (1L << GLIBTOP_CPU_FREQUENCY);
+
+/* nlist structure for kernel access */
+static struct nlist nlst [] = {
+#ifdef __bsdi__
+ { "_cpustats" },
+#else
+ { "_cp_time" },
+#endif
+ { 0 }
+};
+
+/* MIB array for sysctl */
+static int mib_length=2;
+static int mib [] = { CTL_KERN, KERN_CLOCKRATE };
+
+/* Init function. */
+
+void
+glibtop_init_cpu_p (glibtop *server)
+{
+ if (kvm_nlist (server->machine.kd, nlst) < 0) {
+ glibtop_warn_io_r (server, "kvm_nlist (cpu)");
+ return;
+ }
+
+ /* Set this only if kvm_nlist () succeeded. */
+ server->sysdeps.cpu = _glibtop_sysdeps_cpu;
+}
+
+/* Provides information about cpu usage. */
+
+void
+glibtop_get_cpu_p (glibtop *server, glibtop_cpu *buf)
+{
+ long cpts [CPUSTATES];
+ /* sysctl vars*/
+ struct clockinfo ci;
+ size_t length;
+
+ glibtop_init_p (server, (1L << GLIBTOP_SYSDEPS_CPU), 0);
+
+ memset (buf, 0, sizeof (glibtop_cpu));
+
+ /* If this fails, the nlist may not be valid. */
+ if (server->sysdeps.cpu == 0)
+ return;
+
+ if (kvm_read (server->machine.kd, nlst [0].n_value,
+ &cpts, sizeof (cpts)) != sizeof (cpts)) {
+ glibtop_warn_io_r (server, "kvm_read (cp_time)");
+ return;
+ }
+
+ /* Get the clockrate data */
+ length = sizeof (struct clockinfo);
+ if (sysctl (mib, mib_length, &ci, &length, NULL, 0)) {
+ glibtop_warn_io_r (server, "sysctl");
+ return;
+ }
+
+ /* set user time */
+ buf->user = cpts [CP_USER];
+ /* set nice time */
+ buf->nice = cpts [CP_NICE];
+ /* set sys time */
+ buf->sys = cpts [CP_SYS];
+ /* set idle time */
+ buf->idle = cpts [CP_IDLE];
+
+ /* set frequency */
+ /*
+ FIXME -- is hz, tick, profhz or stathz wanted?
+ buf->frequency = sysctl("kern.clockrate", ...);
+
+ struct clockinfo
+ */
+ buf->frequency = ci.hz;
+ /* set total */
+ buf->total = cpts [CP_USER] + cpts [CP_NICE]
+ + cpts [CP_SYS] + cpts [CP_IDLE];
+
+ /* Set the flags last. */
+ buf->flags = _glibtop_sysdeps_cpu;
+}
diff --git a/sysdeps/freebsd/glibtop_machine.h b/sysdeps/freebsd/glibtop_machine.h
new file mode 100644
index 00000000..192c3b7f
--- /dev/null
+++ b/sysdeps/freebsd/glibtop_machine.h
@@ -0,0 +1,59 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#ifndef __GLIBTOP_MACHINE_H__
+#define __GLIBTOP_MACHINE_H__
+
+#include <sys/param.h>
+#include <nlist.h>
+#include <kvm.h>
+#include <sys/dkstat.h>
+#include <time.h>
+#include <sys/user.h>
+#include <sys/types.h>
+#include <sys/sysctl.h>
+
+#include <fcntl.h>
+
+#ifdef __FreeBSD__
+#include <osreldate.h>
+#endif
+
+BEGIN_LIBGTOP_DECLS
+
+typedef struct _glibtop_machine glibtop_machine;
+
+struct _glibtop_machine
+{
+ uid_t uid, euid;
+ gid_t gid, egid;
+
+ /* The kernel descriptor, used by kvm_* calls. We keep and re-use
+ * it rather than re-getting it for almost all function
+ * invocations. */
+ kvm_t *kd;
+};
+
+END_LIBGTOP_DECLS
+
+#endif /* __GLIBTOP_MACHINE_H__ */
diff --git a/sysdeps/freebsd/glibtop_server.h b/sysdeps/freebsd/glibtop_server.h
new file mode 100644
index 00000000..ccf3d29d
--- /dev/null
+++ b/sysdeps/freebsd/glibtop_server.h
@@ -0,0 +1,52 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#ifndef __GLIBTOP_SERVER_H__
+#define __GLIBTOP_SERVER_H__
+
+BEGIN_LIBGTOP_DECLS
+
+#define GLIBTOP_SUID_CPU (1 << GLIBTOP_SYSDEPS_CPU)
+#define GLIBTOP_SUID_MEM (1 << GLIBTOP_SYSDEPS_MEM)
+#define GLIBTOP_SUID_SWAP (1 << GLIBTOP_SYSDEPS_SWAP)
+#define GLIBTOP_SUID_UPTIME (1 << GLIBTOP_SYSDEPS_UPTIME)
+#define GLIBTOP_SUID_LOADAVG (1 << GLIBTOP_SYSDEPS_LOADAVG)
+#define GLIBTOP_SUID_SHM_LIMITS (1 << GLIBTOP_SYSDEPS_SHM_LIMITS)
+#define GLIBTOP_SUID_MSG_LIMITS (1 << GLIBTOP_SYSDEPS_MSG_LIMITS)
+#define GLIBTOP_SUID_SEM_LIMITS (1 << GLIBTOP_SYSDEPS_SEM_LIMITS)
+#define GLIBTOP_SUID_PROCLIST (1 << GLIBTOP_SYSDEPS_PROCLIST)
+#define GLIBTOP_SUID_PROC_STATE (1 << GLIBTOP_SYSDEPS_PROC_STATE)
+#define GLIBTOP_SUID_PROC_UID (1 << GLIBTOP_SYSDEPS_PROC_UID)
+#define GLIBTOP_SUID_PROC_MEM (1 << GLIBTOP_SYSDEPS_PROC_MEM)
+#define GLIBTOP_SUID_PROC_TIME (1 << GLIBTOP_SYSDEPS_PROC_TIME)
+#define GLIBTOP_SUID_PROC_SIGNAL (1 << GLIBTOP_SYSDEPS_PROC_SIGNAL)
+#define GLIBTOP_SUID_PROC_KERNEL (1 << GLIBTOP_SYSDEPS_PROC_KERNEL)
+#define GLIBTOP_SUID_PROC_SEGMENT (1 << GLIBTOP_SYSDEPS_PROC_SEGMENT)
+#define GLIBTOP_SUID_PROC_ARGS (1 << GLIBTOP_SYSDEPS_PROC_ARGS)
+#define GLIBTOP_SUID_PROC_MAP (1 << GLIBTOP_SYSDEPS_PROC_MAP)
+#define GLIBTOP_SUID_NETLOAD (1 << GLIBTOP_SYSDEPS_NETLOAD)
+#define GLIBTOP_SUID_PPP (1 << GLIBTOP_SYSDEPS_PPP)
+
+END_LIBGTOP_DECLS
+
+#endif
diff --git a/sysdeps/freebsd/glibtop_suid.h b/sysdeps/freebsd/glibtop_suid.h
new file mode 100644
index 00000000..18ad4b76
--- /dev/null
+++ b/sysdeps/freebsd/glibtop_suid.h
@@ -0,0 +1,58 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#ifndef __GLIBTOP_SUID_H__
+#define __GLIBTOP_SUID_H__
+
+BEGIN_LIBGTOP_DECLS
+
+#if _IN_LIBGTOP
+#include <sys/param.h>
+#endif
+
+#define KI_PROC(ki) (&(ki))->kp_proc)
+#define KI_EPROC(ki) (&(ki))->kp_eproc)
+
+#define FORCEUREAD 1
+#define UREADOK(ki) (FORCEUREAD || (KI_PROC(ki)->p_flag & P_INMEM))
+
+static inline void glibtop_suid_enter (glibtop *server) {
+ setregid (server->machine.gid, server->machine.egid);
+};
+
+static inline void glibtop_suid_leave (glibtop *server) {
+ if (setregid (server->machine.egid, server->machine.gid))
+ _exit (1);
+};
+
+void
+glibtop_init_p (glibtop *server, const unsigned long features,
+ const unsigned flags);
+void
+glibtop_open_p (glibtop *server, const char *program_name,
+ const unsigned long features,
+ const unsigned flags);
+
+END_LIBGTOP_DECLS
+
+#endif
diff --git a/sysdeps/freebsd/init.c b/sysdeps/freebsd/init.c
new file mode 100644
index 00000000..11d89342
--- /dev/null
+++ b/sysdeps/freebsd/init.c
@@ -0,0 +1,45 @@
+/* $Id$ */
+
+/* Copyright (C) 1998 Joshua Sled
+ This file is part of LibGTop 1.0.
+
+ Contributed by Joshua Sled <jsled@xcf.berkeley.edu>, July 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <glibtop.h>
+#include <glibtop/open.h>
+
+static glibtop _glibtop_global_server;
+glibtop *glibtop_global_server = NULL;
+
+glibtop *
+glibtop_init_r (glibtop **server,
+ const unsigned long features,
+ const unsigned flags)
+{
+ if (*server != NULL)
+ return *server;
+
+ if (glibtop_global_server == NULL) {
+ glibtop_global_server = &_glibtop_global_server;
+ glibtop_open (glibtop_global_server, "glibtop",
+ features, flags);
+ }
+
+ return *server = glibtop_global_server;
+}
diff --git a/sysdeps/freebsd/loadavg.c b/sysdeps/freebsd/loadavg.c
new file mode 100644
index 00000000..b0530e8a
--- /dev/null
+++ b/sysdeps/freebsd/loadavg.c
@@ -0,0 +1,60 @@
+/* $Id$ */
+
+/* Copyright (C) 1998 Joshua Sled
+ This file is part of LibGTop 1.0.
+
+ Contributed by Joshua Sled <jsled@xcf.berkeley.edu>, July 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <glibtop.h>
+#include <glibtop/error.h>
+#include <glibtop/loadavg.h>
+
+#include <glibtop_suid.h>
+
+static const unsigned long _glibtop_sysdeps_loadavg =
+(1L << GLIBTOP_LOADAVG_LOADAVG);
+
+/* Init function. */
+
+void
+glibtop_init_loadavg_p (glibtop *server)
+{
+ server->sysdeps.loadavg = _glibtop_sysdeps_loadavg;
+}
+
+/* Provides load averange. */
+
+void
+glibtop_get_loadavg_p (glibtop *server, glibtop_loadavg *buf)
+{
+ double ldavg[3];
+ int i;
+
+ glibtop_init_p (server, (1L << GLIBTOP_SYSDEPS_LOADAVG), 0);
+
+ memset (buf, 0, sizeof (glibtop_loadavg));
+
+ getloadavg (ldavg, 3);
+
+ /* fill in the struct */
+ buf->flags = _glibtop_sysdeps_loadavg;
+ for (i = 0; i < 3; i++) {
+ buf->loadavg [i] = ldavg [i];
+ } /* end for */
+}
diff --git a/sysdeps/freebsd/mem.c b/sysdeps/freebsd/mem.c
new file mode 100644
index 00000000..1b96fe7f
--- /dev/null
+++ b/sysdeps/freebsd/mem.c
@@ -0,0 +1,222 @@
+/* $Id$ */
+
+/* Copyright (C) 1998 Joshua Sled
+ This file is part of LibGTop 1.0.
+
+ Contributed by Joshua Sled <jsled@xcf.berkeley.edu>, July 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <glibtop.h>
+#include <glibtop/error.h>
+#include <glibtop/mem.h>
+
+#include <glibtop_suid.h>
+
+#include <sys/sysctl.h>
+#include <sys/vmmeter.h>
+#include <vm/vm_param.h>
+
+#if defined(__NetBSD__) && (__NetBSD_Version__ >= 104000000)
+#include <uvm/uvm_extern.h>
+#endif
+
+static const unsigned long _glibtop_sysdeps_mem =
+(1L << GLIBTOP_MEM_TOTAL) + (1L << GLIBTOP_MEM_USED) +
+(1L << GLIBTOP_MEM_FREE) +
+(1L << GLIBTOP_MEM_SHARED) +
+(1L << GLIBTOP_MEM_BUFFER) +
+#ifdef __FreeBSD__
+(1L << GLIBTOP_MEM_CACHED) +
+#endif
+(1L << GLIBTOP_MEM_USER) + (1L << GLIBTOP_MEM_LOCKED);
+
+#ifndef LOG1024
+#define LOG1024 10
+#endif
+
+/* these are for getting the memory statistics */
+static int pageshift; /* log base 2 of the pagesize */
+
+/* define pagetok in terms of pageshift */
+#define pagetok(size) ((size) << pageshift)
+
+/* nlist structure for kernel access */
+static struct nlist nlst [] = {
+#if defined(__NetBSD__) && (__NetBSD_Version__ >= 104000000)
+ { "_bufpages" },
+ { 0 }
+#else
+#if defined(__bsdi__)
+ { "_bufcachemem" },
+#elif defined(__FreeBSD__)
+ { "_bufspace" },
+#else
+ { "_bufpages" },
+#endif
+ { "_cnt" },
+ { 0 }
+#endif
+};
+
+/* MIB array for sysctl */
+static int mib_length=2;
+#ifdef __bsdi__
+static int mib [] = { CTL_VM, VM_TOTAL };
+#else
+static int mib [] = { CTL_VM, VM_METER };
+#endif
+
+#if defined(__NetBSD__) && (__NetBSD_Version__ >= 104000000)
+static int mib_uvmexp [] = { CTL_VM, VM_UVMEXP };
+#endif
+
+/* Init function. */
+
+void
+glibtop_init_mem_p (glibtop *server)
+{
+ register int pagesize;
+
+ if (kvm_nlist (server->machine.kd, nlst) < 0) {
+ glibtop_warn_io_r (server, "kvm_nlist (mem)");
+ return;
+ }
+
+ /* get the page size with "getpagesize" and calculate pageshift
+ * from it */
+ pagesize = getpagesize ();
+ pageshift = 0;
+ while (pagesize > 1) {
+ pageshift++;
+ pagesize >>= 1;
+ }
+
+ /* we only need the amount of log(2)1024 for our conversion */
+ pageshift -= LOG1024;
+
+ server->sysdeps.mem = _glibtop_sysdeps_mem;
+}
+
+void
+glibtop_get_mem_p (glibtop *server, glibtop_mem *buf)
+{
+ struct vmtotal vmt;
+ size_t length_vmt;
+#if defined(__NetBSD__) && (__NetBSD_Version__ >= 104000000)
+ struct uvmexp uvmexp;
+ size_t length_uvmexp;
+#else
+ struct vmmeter vmm;
+#endif
+ u_int v_used_count;
+ u_int v_total_count;
+ u_int v_free_count;
+ int bufspace;
+
+ glibtop_init_p (server, (1L << GLIBTOP_SYSDEPS_MEM), 0);
+
+ memset (buf, 0, sizeof (glibtop_mem));
+
+ if (server->sysdeps.mem == 0)
+ return;
+
+ /* [FIXME: On FreeBSD 2.2.6, sysctl () returns an incorrect
+ * value for `vmt.vm'. We use some code from Unix top
+ * here.] */
+
+ /* Get the data from sysctl */
+ length_vmt = sizeof (vmt);
+ if (sysctl (mib, 2, &vmt, &length_vmt, NULL, 0)) {
+ glibtop_warn_io_r (server, "sysctl (vmt)");
+ return;
+ }
+
+#if defined(__NetBSD__) && (__NetBSD_Version__ >= 104000000)
+ length_uvmexp = sizeof (uvmexp);
+ if (sysctl (mib_uvmexp, 2, &uvmexp, &length_uvmexp, NULL, 0)) {
+ glibtop_warn_io_r (server, "sysctl (uvmexp)");
+ return;
+ }
+#else
+ /* Get the data from kvm_* */
+ if (kvm_read (server->machine.kd, nlst[1].n_value,
+ &vmm, sizeof (vmm)) != sizeof (vmm)) {
+ glibtop_warn_io_r (server, "kvm_read (cnt)");
+ return;
+ }
+#endif
+
+ if (kvm_read (server->machine.kd, nlst[0].n_value,
+ &bufspace, sizeof (bufspace)) != sizeof (bufspace)) {
+ glibtop_warn_io_r (server, "kvm_read (bufspace)");
+ return;
+ }
+
+ /* convert memory stats to Kbytes */
+
+#if defined(__FreeBSD__)
+ v_total_count = vmm.v_page_count;
+#else
+#if defined(__NetBSD__) && (__NetBSD_Version__ >= 104000000)
+ v_total_count = uvmexp.reserve_kernel +
+ uvmexp.reserve_pagedaemon +
+ uvmexp.free + uvmexp.wired + uvmexp.active +
+ uvmexp.inactive;
+#else
+ v_total_count = vmm.v_kernel_pages +
+ vmm.v_free_count + vmm.v_wire_count +
+ vmm.v_active_count + vmm.v_inactive_count;
+#endif
+#endif
+
+#if defined(__NetBSD__) && (__NetBSD_Version__ >= 104000000)
+ v_used_count = uvmexp.active + uvmexp.inactive;
+ v_free_count = uvmexp.free;
+#else
+ v_used_count = vmm.v_active_count + vmm.v_inactive_count;
+ v_free_count = vmm.v_free_count;
+#endif
+
+ buf->total = (u_int64_t) pagetok (v_total_count) << LOG1024;
+ buf->used = (u_int64_t) pagetok (v_used_count) << LOG1024;
+ buf->free = (u_int64_t) pagetok (v_free_count) << LOG1024;
+
+#ifdef __FreeBSD__
+ buf->cached = (u_int64_t) pagetok (vmm.v_cache_count) << LOG1024;
+#endif
+
+#if defined(__NetBSD__) && (__NetBSD_Version__ >= 104000000)
+ buf->locked = (u_int64_t) pagetok (uvmexp.wired) << LOG1024;
+#else
+ buf->locked = (u_int64_t) pagetok (vmm.v_wire_count) << LOG1024;
+#endif
+
+ buf->shared = (u_int64_t) pagetok (vmt.t_rmshr) << LOG1024;
+
+#if __FreeBSD__
+ buf->buffer = (u_int64_t) bufspace;
+#else
+ buf->buffer = (u_int64_t) pagetok (bufspace) << LOG1024;
+#endif
+
+ /* user */
+ buf->user = buf->total - buf->free - buf->shared - buf->buffer;
+
+ /* Set the values to return */
+ buf->flags = _glibtop_sysdeps_mem;
+}
diff --git a/sysdeps/freebsd/msg_limits.c b/sysdeps/freebsd/msg_limits.c
new file mode 100644
index 00000000..e4752bf3
--- /dev/null
+++ b/sysdeps/freebsd/msg_limits.c
@@ -0,0 +1,115 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, August 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <glibtop.h>
+#include <glibtop/error.h>
+#include <glibtop/msg_limits.h>
+
+#include <glibtop_suid.h>
+
+#if (defined __bsdi__) && (_BSDI_VERSION < 199700)
+/* Older versions of BSDI don't seem to have this. */
+
+void
+glibtop_init_msg_limits_p (glibtop *server)
+{ }
+
+void
+glibtop_get_msg_limits_p (glibtop *server, glibtop_msg_limits *buf)
+{
+ glibtop_init_p (server, (1L << GLIBTOP_SYSDEPS_MSG_LIMITS), 0);
+
+ memset (buf, 0, sizeof (glibtop_msg_limits));
+}
+
+#else
+
+/* #define KERNEL to get declaration of `struct msginfo'. */
+
+#if (defined(__FreeBSD__) && (__FreeBSD_version < 410000)) || (defined __bsdi__)
+#define KERNEL 1
+#else
+#define _KERNEL 1
+#endif
+
+#include <sys/ipc.h>
+#include <sys/msg.h>
+
+static const unsigned long _glibtop_sysdeps_msg_limits =
+(1L << GLIBTOP_IPC_MSGMAX) + (1L << GLIBTOP_IPC_MSGMNI) +
+(1L << GLIBTOP_IPC_MSGMNB) + (1L << GLIBTOP_IPC_MSGTQL) +
+(1L << GLIBTOP_IPC_MSGSSZ);
+
+/* The values in this structure never change at runtime, so we only
+ * read it once during initialization. We have to use the name `_msginfo'
+ * since `msginfo' is already declared external in <sys/msg.h>. */
+static struct msginfo _msginfo;
+
+/* nlist structure for kernel access */
+static struct nlist nlst [] = {
+ { "_msginfo" },
+ { 0 }
+};
+
+/* Init function. */
+
+void
+glibtop_init_msg_limits_p (glibtop *server)
+{
+ if (kvm_nlist (server->machine.kd, nlst) < 0) {
+ glibtop_warn_io_r (server, "kvm_nlist (msg_limits)");
+ return;
+ }
+
+ if (kvm_read (server->machine.kd, nlst [0].n_value,
+ &_msginfo, sizeof (_msginfo)) != sizeof (_msginfo)) {
+ glibtop_warn_io_r (server, "kvm_read (msginfo)");
+ return;
+ }
+
+ server->sysdeps.msg_limits = _glibtop_sysdeps_msg_limits;
+}
+
+/* Provides information about sysv ipc limits. */
+
+void
+glibtop_get_msg_limits_p (glibtop *server, glibtop_msg_limits *buf)
+{
+ glibtop_init_p (server, (1L << GLIBTOP_SYSDEPS_MSG_LIMITS), 0);
+
+ memset (buf, 0, sizeof (glibtop_msg_limits));
+
+ if (server->sysdeps.msg_limits == 0)
+ return;
+
+ buf->msgmax = _msginfo.msgmax;
+ buf->msgmni = _msginfo.msgmni;
+ buf->msgmnb = _msginfo.msgmnb;
+ buf->msgtql = _msginfo.msgtql;
+ buf->msgssz = _msginfo.msgtql;
+
+ buf->flags = _glibtop_sysdeps_msg_limits;
+}
+
+#endif /* either a newer BSDI or no BSDI at all. */
+
diff --git a/sysdeps/freebsd/netload.c b/sysdeps/freebsd/netload.c
new file mode 100644
index 00000000..4062dfe2
--- /dev/null
+++ b/sysdeps/freebsd/netload.c
@@ -0,0 +1,219 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, October 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <glibtop.h>
+#include <glibtop/error.h>
+#include <glibtop/netload.h>
+
+#include <glibtop_suid.h>
+
+#include <net/if.h>
+#include <net/if_dl.h>
+#include <net/if_types.h>
+
+#ifdef HAVE_NET_IF_VAR_H
+#include <net/if_var.h>
+#endif
+
+#include <netinet/in.h>
+#include <netinet/in_var.h>
+
+static const unsigned long _glibtop_sysdeps_netload =
+(1L << GLIBTOP_NETLOAD_IF_FLAGS) +
+(1L << GLIBTOP_NETLOAD_MTU) +
+#if !defined(__bsdi__)
+(1L << GLIBTOP_NETLOAD_SUBNET) +
+#endif
+(1L << GLIBTOP_NETLOAD_ADDRESS) +
+(1L << GLIBTOP_NETLOAD_PACKETS_IN) +
+(1L << GLIBTOP_NETLOAD_PACKETS_OUT) +
+(1L << GLIBTOP_NETLOAD_PACKETS_TOTAL) +
+(1L << GLIBTOP_NETLOAD_BYTES_IN) +
+(1L << GLIBTOP_NETLOAD_BYTES_OUT) +
+(1L << GLIBTOP_NETLOAD_BYTES_TOTAL) +
+(1L << GLIBTOP_NETLOAD_ERRORS_IN) +
+(1L << GLIBTOP_NETLOAD_ERRORS_OUT) +
+(1L << GLIBTOP_NETLOAD_ERRORS_TOTAL) +
+(1L << GLIBTOP_NETLOAD_COLLISIONS);
+
+/* nlist structure for kernel access */
+static struct nlist nlst [] = {
+ { "_ifnet" },
+ { 0 }
+};
+
+/* Init function. */
+
+void
+glibtop_init_netload_p (glibtop *server)
+{
+ server->sysdeps.netload = _glibtop_sysdeps_netload;
+
+ if (kvm_nlist (server->machine.kd, nlst) < 0)
+ glibtop_error_io_r (server, "kvm_nlist");
+}
+
+/* Provides Network statistics. */
+
+void
+glibtop_get_netload_p (glibtop *server, glibtop_netload *buf,
+ const char *interface)
+{
+ struct ifnet ifnet;
+ u_long ifnetaddr, ifnetfound, ifaddraddr;
+ struct sockaddr *sa;
+ char tname [16];
+
+ union {
+ struct ifaddr ifa;
+ struct in_ifaddr in;
+ } ifaddr;
+
+ glibtop_init_p (server, (1L << GLIBTOP_SYSDEPS_NETLOAD), 0);
+
+ memset (buf, 0, sizeof (glibtop_netload));
+
+ if (kvm_read (server->machine.kd, nlst [0].n_value,
+ &ifnetaddr, sizeof (ifnetaddr)) != sizeof (ifnetaddr))
+ glibtop_error_io_r (server, "kvm_read (ifnet)");
+
+ ifaddraddr = 0;
+ while (ifnetaddr || ifaddraddr) {
+ struct sockaddr_in *sin;
+ register char *cp;
+
+ if (ifaddraddr == 0) {
+ ifnetfound = ifnetaddr;
+
+ if (kvm_read (server->machine.kd, ifnetaddr, &ifnet,
+ sizeof (ifnet)) != sizeof (ifnet))
+ glibtop_error_io_r (server, "kvm_read (ifnetaddr)");
+
+#if defined(__FreeBSD__) || defined(__bsdi__)
+ if (kvm_read (server->machine.kd, (u_long) ifnet.if_name,
+ tname, 16) != 16)
+ glibtop_error_io_r (server, "kvm_read (if_name)");
+#else
+ strncpy (tname, ifnet.if_xname, 16);
+ tname [15] = 0;
+#endif
+
+#if defined(__FreeBSD__) && (__FreeBSD_version >= 300000)
+ ifaddraddr = (u_long) ifnet.if_addrhead.tqh_first;
+#elif defined(__FreeBSD__) || defined(__bsdi__)
+ ifaddraddr = (u_long) ifnet.if_addrlist;
+#else
+ ifaddraddr = (u_long) ifnet.if_addrlist.tqh_first;
+#endif
+ }
+
+ if (ifaddraddr) {
+ if ((kvm_read (server->machine.kd, ifaddraddr, &ifaddr,
+ sizeof (ifaddr)) != sizeof (ifaddr)))
+ glibtop_error_io_r (server, "kvm_read (ifaddraddr)");
+
+#define CP(x) ((char *)(x))
+ cp = (CP(ifaddr.ifa.ifa_addr) - CP(ifaddraddr)) +
+ CP(&ifaddr); sa = (struct sockaddr *)cp;
+
+ if (!strcmp (interface, tname) && (sa->sa_family == AF_INET)) {
+ sin = (struct sockaddr_in *)sa;
+
+ if (ifnet.if_flags & IFF_UP)
+ buf->if_flags |= GLIBTOP_IF_FLAGS_UP;
+ if (ifnet.if_flags & IFF_BROADCAST)
+ buf->if_flags |= GLIBTOP_IF_FLAGS_BROADCAST;
+ if (ifnet.if_flags & IFF_DEBUG)
+ buf->if_flags |= GLIBTOP_IF_FLAGS_DEBUG;
+ if (ifnet.if_flags & IFF_LOOPBACK)
+ buf->if_flags |= GLIBTOP_IF_FLAGS_LOOPBACK;
+ if (ifnet.if_flags & IFF_POINTOPOINT)
+ buf->if_flags |= GLIBTOP_IF_FLAGS_POINTOPOINT;
+ if (ifnet.if_flags & IFF_RUNNING)
+ buf->if_flags |= GLIBTOP_IF_FLAGS_RUNNING;
+ if (ifnet.if_flags & IFF_NOARP)
+ buf->if_flags |= GLIBTOP_IF_FLAGS_NOARP;
+ if (ifnet.if_flags & IFF_PROMISC)
+ buf->if_flags |= GLIBTOP_IF_FLAGS_PROMISC;
+ if (ifnet.if_flags & IFF_ALLMULTI)
+ buf->if_flags |= GLIBTOP_IF_FLAGS_ALLMULTI;
+ if (ifnet.if_flags & IFF_OACTIVE)
+ buf->if_flags |= GLIBTOP_IF_FLAGS_OACTIVE;
+ if (ifnet.if_flags & IFF_SIMPLEX)
+ buf->if_flags |= GLIBTOP_IF_FLAGS_SIMPLEX;
+ if (ifnet.if_flags & IFF_LINK0)
+ buf->if_flags |= GLIBTOP_IF_FLAGS_LINK0;
+ if (ifnet.if_flags & IFF_LINK1)
+ buf->if_flags |= GLIBTOP_IF_FLAGS_LINK1;
+ if (ifnet.if_flags & IFF_LINK2)
+ buf->if_flags |= GLIBTOP_IF_FLAGS_LINK2;
+#ifdef __FreeBSD__
+ if (ifnet.if_flags & IFF_ALTPHYS)
+ buf->if_flags |= GLIBTOP_IF_FLAGS_ALTPHYS;
+#endif
+ if (ifnet.if_flags & IFF_MULTICAST)
+ buf->if_flags |= GLIBTOP_IF_FLAGS_MULTICAST;
+
+#if !defined(__bsdi__)
+ /* Commenting out to "fix" #13345. */
+ buf->subnet = htonl (ifaddr.in.ia_subnet);
+#endif
+ buf->address = sin->sin_addr.s_addr;
+
+ buf->mtu = ifnet.if_mtu;
+
+ buf->packets_in = ifnet.if_ipackets;
+ buf->packets_out = ifnet.if_opackets;
+ buf->packets_total = buf->packets_in + buf->packets_out;
+
+ buf->bytes_in = ifnet.if_ibytes;
+ buf->bytes_out = ifnet.if_obytes;
+ buf->bytes_total = buf->bytes_in + buf->bytes_out;
+
+ buf->errors_in = ifnet.if_ierrors;
+ buf->errors_out = ifnet.if_oerrors;
+ buf->errors_total = buf->errors_in + buf->errors_out;
+
+ buf->collisions = ifnet.if_collisions;
+ buf->flags = _glibtop_sysdeps_netload;
+ return;
+ }
+
+#if defined(__FreeBSD__) && (__FreeBSD_version >= 300000)
+ ifaddraddr = (u_long)ifaddr.ifa.ifa_link.tqe_next;
+#elif defined(__FreeBSD__) || defined(__bsdi__)
+ ifaddraddr = (u_long)ifaddr.ifa.ifa_next;
+#else
+ ifaddraddr = (u_long)ifaddr.ifa.ifa_list.tqe_next;
+#endif
+ }
+
+#if defined(__FreeBSD__) && (__FreeBSD_version >= 300000)
+ ifnetaddr = (u_long) ifnet.if_link.tqe_next;
+#elif defined(__FreeBSD__) || defined(__bsdi__)
+ ifnetaddr = (u_long) ifnet.if_next;
+#else
+ ifnetaddr = (u_long) ifnet.if_list.tqe_next;
+#endif
+ }
+}
diff --git a/sysdeps/freebsd/nosuid.c b/sysdeps/freebsd/nosuid.c
new file mode 100644
index 00000000..15edf79a
--- /dev/null
+++ b/sysdeps/freebsd/nosuid.c
@@ -0,0 +1,37 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <glibtop.h>
+#include <glibtop/open.h>
+#include <glibtop/close.h>
+
+void
+glibtop_open_s (glibtop *server,
+ const char *program_name,
+ const unsigned long features,
+ const unsigned flags)
+{ }
+
+void
+glibtop_close_s (glibtop *server)
+{ }
diff --git a/sysdeps/freebsd/open.c b/sysdeps/freebsd/open.c
new file mode 100644
index 00000000..ea95d16f
--- /dev/null
+++ b/sysdeps/freebsd/open.c
@@ -0,0 +1,95 @@
+/* $Id$ */
+
+/* Copyright (C) 1998 Joshua Sled
+ This file is part of LibGTop 1.0.
+
+ Contributed by Joshua Sled <jsled@xcf.berkeley.edu>, July 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <glibtop.h>
+#include <glibtop/open.h>
+#include <glibtop/xmalloc.h>
+
+/* !!! THIS FUNCTION RUNS SUID ROOT - CHANGE WITH CAUTION !!! */
+
+void
+glibtop_init_p (glibtop *server, const unsigned long features,
+ const unsigned flags)
+{
+ glibtop_init_func_t *init_fkt;
+
+ if (server == NULL)
+ glibtop_error_r (NULL, "glibtop_init_p (server == NULL)");
+
+ /* Do the initialization, but only if not already initialized. */
+
+ if ((server->flags & _GLIBTOP_INIT_STATE_SYSDEPS) == 0) {
+ glibtop_open_p (server, "glibtop", features, flags);
+
+ for (init_fkt = _glibtop_init_hook_p; *init_fkt; init_fkt++)
+ (*init_fkt) (server);
+
+ server->flags |= _GLIBTOP_INIT_STATE_SYSDEPS;
+ }
+}
+
+void
+glibtop_open_p (glibtop *server, const char *program_name,
+ const unsigned long features,
+ const unsigned flags)
+{
+#ifdef DEBUG
+ fprintf (stderr, "DEBUG (%d): glibtop_open_p ()\n", getpid ());
+#endif
+
+ /* !!! WE ARE ROOT HERE - CHANGE WITH CAUTION !!! */
+
+ server->machine.uid = getuid ();
+ server->machine.euid = geteuid ();
+ server->machine.gid = getgid ();
+ server->machine.egid = getegid ();
+
+#ifdef __FreeBSD__
+ server->os_version_code = __FreeBSD_version;
+#endif
+
+ /* Setup machine-specific data */
+ server->machine.kd = kvm_open (NULL, NULL, NULL, O_RDONLY, "kvm_open");
+
+ if (server->machine.kd == NULL)
+ glibtop_error_io_r (server, "kvm_open");
+
+ /* Drop priviledges. */
+
+ if (setreuid (server->machine.euid, server->machine.uid))
+ _exit (1);
+
+ if (setregid (server->machine.egid, server->machine.gid))
+ _exit (1);
+
+ /* !!! END OF SUID ROOT PART !!! */
+
+ /* Our effective uid is now those of the user invoking the server,
+ * so we do no longer have any priviledges. */
+
+ /* NOTE: On FreeBSD, we do not need to be suid root, we just need to
+ * be sgid kmem.
+ *
+ * The server will only use setegid() to get back it's priviledges,
+ * so it will fail if it is suid root and not sgid kmem. */
+}
diff --git a/sysdeps/freebsd/ppp.c b/sysdeps/freebsd/ppp.c
new file mode 100644
index 00000000..41ab1b36
--- /dev/null
+++ b/sysdeps/freebsd/ppp.c
@@ -0,0 +1,144 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, October 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <glibtop.h>
+#include <glibtop/error.h>
+#include <glibtop/ppp.h>
+
+#include <glibtop_suid.h>
+
+#ifdef HAVE_I4B
+
+#include <net/if.h>
+#include <net/if_types.h>
+
+#ifdef HAVE_NET_IF_VAR_H
+#include <net/if_var.h>
+#endif
+
+#include <net/netisr.h>
+#include <net/route.h>
+
+#if defined(__FreeBSD__) || defined(__NetBSD__)
+#include <net/if_sppp.h>
+#else
+#include <i4b/sppp/if_sppp.h>
+#endif
+
+/* Read `misc/i4b_acct.txt' for details ... */
+#ifdef HAVE_I4B_ACCT
+#include <machine/i4b_acct.h>
+#endif
+
+static const unsigned long _glibtop_sysdeps_ppp =
+(1L << GLIBTOP_PPP_STATE);
+
+#ifdef HAVE_I4B_ACCT
+static const unsigned long _glibtop_sysdeps_ppp_acct =
+(1L << GLIBTOP_PPP_BYTES_IN) + (1L << GLIBTOP_PPP_BYTES_OUT);
+#endif
+
+#endif /* HAVE_I4B */
+
+/* nlist structure for kernel access */
+static struct nlist nlst [] = {
+#ifdef HAVE_I4B
+ { "_i4bisppp_softc" },
+#endif
+ { 0 }
+};
+
+/* Init function. */
+
+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_error_io_r (server, "kvm_nlist");
+}
+
+/* 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;
+
+ glibtop_init_p (server, (1L << GLIBTOP_SYSDEPS_PPP), 0);
+
+ memset (buf, 0, sizeof (glibtop_ppp));
+
+ if (kvm_read (server->machine.kd, nlst [0].n_value,
+ &data, sizeof (data)) != sizeof (data))
+ glibtop_error_io_r (server, "kvm_read (i4bisppp_softc)");
+
+#ifdef HAVE_I4B_ACCT
+ phase = data.sc_if_un.scu_sp.pp_phase;
+#else
+ /* FIXME: Which FreeBSD version have this field and
+ * which not. */
+#if 0
+ phase = data.pp_phase;
+#endif
+#endif
+
+ switch (phase) {
+#ifdef HAVE_I4B_ACCT
+ case PHASE_DEAD:
+ case PHASE_TERMINATE:
+ buf->state = GLIBTOP_PPP_STATE_HANGUP;
+ break;
+ case PHASE_ESTABLISH:
+ case PHASE_NETWORK:
+ buf->state = GLIBTOP_PPP_STATE_ONLINE;
+ break;
+#endif
+ default:
+ buf->state = GLIBTOP_PPP_STATE_UNKNOWN;
+ break;
+ }
+
+ buf->flags = _glibtop_sysdeps_ppp;
+
+#ifdef HAVE_I4B_ACCT
+ buf->bytes_in = data.sc_inb;
+ buf->bytes_out = data.sc_outb;
+ buf->flags |= _glibtop_sysdeps_ppp_acct;
+#endif
+#endif /* HAVE_I4B */
+}
diff --git a/sysdeps/freebsd/procargs.c b/sysdeps/freebsd/procargs.c
new file mode 100644
index 00000000..83b6a78b
--- /dev/null
+++ b/sysdeps/freebsd/procargs.c
@@ -0,0 +1,111 @@
+/* $Id$ */
+
+/* Copyright (C) 1998 Joshua Sled
+ This file is part of LibGTop 1.0.
+
+ Contributed by Joshua Sled <jsled@xcf.berkeley.edu>, July 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <glibtop.h>
+#include <glibtop/error.h>
+#include <glibtop/xmalloc.h>
+#include <glibtop/procargs.h>
+
+#include <glibtop_suid.h>
+
+#include <kvm.h>
+#include <sys/param.h>
+#include <sys/proc.h>
+
+static const unsigned long _glibtop_sysdeps_proc_args =
+(1L << GLIBTOP_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;
+ unsigned size = 0, pos = 0;
+ int count;
+
+#ifndef __bsdi__
+ char filename [BUFSIZ];
+ struct stat statb;
+#endif
+
+ glibtop_init_p (server, (1L << GLIBTOP_SYSDEPS_PROC_ARGS), 0);
+
+ memset (buf, 0, sizeof (glibtop_proc_args));
+
+ /* swapper, init, pagedaemon, vmdaemon, update - this doen't work. */
+ if (pid < 5) return NULL;
+
+#ifndef __bsdi__
+ sprintf (filename, "/proc/%d/mem", pid);
+ if (stat (filename, &statb)) return NULL;
+#endif
+
+ glibtop_suid_enter (server);
+
+ /* Get the process data */
+ pinfo = kvm_getprocs (server->machine.kd, KERN_PROC_PID, pid, &count);
+ if ((pinfo == NULL) || (count < 1)) {
+ glibtop_suid_leave (server);
+ glibtop_warn_io_r (server, "kvm_getprocs (%d)", pid);
+ return NULL;
+ }
+
+ args = kvm_getargv (server->machine.kd, pinfo, max_len);
+ if (args == NULL) {
+ glibtop_suid_leave (server);
+ glibtop_warn_io_r (server, "kvm_getargv (%d)", pid);
+ return NULL;
+ }
+
+ glibtop_suid_leave (server);
+
+ for (ptr = args; *ptr; ptr++)
+ size += strlen (*ptr)+1;
+
+ size += 2;
+ retval = glibtop_malloc_r (server, size);
+ memset (retval, 0, size);
+
+ for (ptr = args; *ptr; ptr++) {
+ int 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;
+}
diff --git a/sysdeps/freebsd/procdata.c b/sysdeps/freebsd/procdata.c
new file mode 100644
index 00000000..65ec6822
--- /dev/null
+++ b/sysdeps/freebsd/procdata.c
@@ -0,0 +1,180 @@
+/* $Id$ */
+
+/* Copyright (C) 1998 Joshua Sled
+ This file is part of LibGTop 1.0.
+
+ Contributed by Joshua Sled <jsled@xcf.berkeley.edu>, July 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <config.h>
+#include <glibtop/procdata.h>
+
+#include <sys/stat.h>
+
+#define LINUX_VERSION(x,y,z) (0x10000*(x) + 0x100*(y) + z)
+
+#define BIT_SHIFT(x) (1L << (x % 64))
+
+static const unsigned long _glibtop_sysdeps_procdata_0 =
+BIT_SHIFT(GLIBTOP_PROCDATA_CMD) +
+BIT_SHIFT(GLIBTOP_PROCDATA_STATE) +
+BIT_SHIFT(GLIBTOP_PROCDATA_UID) +
+BIT_SHIFT(GLIBTOP_PROCDATA_PID) +
+BIT_SHIFT(GLIBTOP_PROCDATA_PPID) +
+BIT_SHIFT(GLIBTOP_PROCDATA_PGRP) +
+BIT_SHIFT(GLIBTOP_PROCDATA_SESSION) +
+BIT_SHIFT(GLIBTOP_PROCDATA_TTY) +
+BIT_SHIFT(GLIBTOP_PROCDATA_TPGID) +
+BIT_SHIFT(GLIBTOP_PROCDATA_PRIORITY) +
+BIT_SHIFT(GLIBTOP_PROCDATA_NICE) +
+BIT_SHIFT(GLIBTOP_PROCDATA_SIGNAL) +
+BIT_SHIFT(GLIBTOP_PROCDATA_BLOCKED) +
+BIT_SHIFT(GLIBTOP_PROCDATA_SIGIGNORE) +
+BIT_SHIFT(GLIBTOP_PROCDATA_SIGCATCH) +
+BIT_SHIFT(GLIBTOP_PROCDATA_START_TIME) +
+BIT_SHIFT(GLIBTOP_PROCDATA_UTIME) +
+BIT_SHIFT(GLIBTOP_PROCDATA_STIME) +
+BIT_SHIFT(GLIBTOP_PROCDATA_CUTIME) +
+BIT_SHIFT(GLIBTOP_PROCDATA_CSTIME) +
+BIT_SHIFT(GLIBTOP_PROCDATA_SIZE) +
+BIT_SHIFT(GLIBTOP_PROCDATA_RESIDENT) +
+BIT_SHIFT(GLIBTOP_PROCDATA_SHARE) +
+BIT_SHIFT(GLIBTOP_PROCDATA_TRS) +
+BIT_SHIFT(GLIBTOP_PROCDATA_LRS) +
+BIT_SHIFT(GLIBTOP_PROCDATA_DRS) +
+BIT_SHIFT(GLIBTOP_PROCDATA_DT) +
+BIT_SHIFT(GLIBTOP_PROCDATA_VSIZE) +
+BIT_SHIFT(GLIBTOP_PROCDATA_RSS) +
+BIT_SHIFT(GLIBTOP_PROCDATA_RSS_RLIM) +
+BIT_SHIFT(GLIBTOP_PROCDATA_TIMEOUT) +
+BIT_SHIFT(GLIBTOP_PROCDATA_IT_REAL_VALUE);
+
+static const unsigned long _glibtop_sysdeps_procdata_1 =
+BIT_SHIFT(GLIBTOP_PROCDATA_K_FLAGS) +
+BIT_SHIFT(GLIBTOP_PROCDATA_MIN_FLT) +
+BIT_SHIFT(GLIBTOP_PROCDATA_MAJ_FLT) +
+BIT_SHIFT(GLIBTOP_PROCDATA_CMIN_FLT) +
+BIT_SHIFT(GLIBTOP_PROCDATA_CMAJ_FLT) +
+BIT_SHIFT(GLIBTOP_PROCDATA_START_CODE) +
+BIT_SHIFT(GLIBTOP_PROCDATA_END_CODE) +
+BIT_SHIFT(GLIBTOP_PROCDATA_START_STACK) +
+BIT_SHIFT(GLIBTOP_PROCDATA_KSTK_ESP) +
+BIT_SHIFT(GLIBTOP_PROCDATA_KSTK_EIP) +
+BIT_SHIFT(GLIBTOP_PROCDATA_WCHAN);
+
+/* Provides detailed information about a process. */
+
+void
+glibtop_get_procdata_s (glibtop *server, glibtop_procdata *buf, pid_t pid)
+{
+ char input [BUFSIZ], *tmp;
+ struct stat statb;
+ int nread;
+ FILE *f;
+
+ glibtop_init_r (&server, 0, 0);
+
+ memset (buf, 0, sizeof (glibtop_procdata));
+
+ if (pid == 0) {
+ /* Client is only interested in the flags. */
+ buf->flags [0] = _glibtop_sysdeps_procdata_0;
+ buf->flags [1] = _glibtop_sysdeps_procdata_1;
+ return;
+ }
+
+
+ sprintf (input, "/proc/%d/stat", pid);
+
+ if (stat (input, &statb)) return;
+
+ buf->uid = statb.st_uid;
+
+ f = fopen (input, "r");
+ if (!f) return;
+
+ nread = fread (input, 1, BUFSIZ, f);
+
+ if (nread < 0) {
+ fclose (f);
+ return;
+ }
+
+ input [nread] = 0;
+
+ /* This is from guile-utils/gtop/proc/readproc.c */
+
+ /* split into "PID (cmd" and "<rest>" */
+ tmp = strrchr (input, ')');
+ *tmp = '\0'; /* replace trailing ')' with NUL */
+ /* parse these two strings separately, skipping the leading "(". */
+ memset (buf->cmd, 0, sizeof (buf->cmd));
+ sscanf (input, "%d (%39c", &buf->pid, buf->cmd);
+ sscanf(tmp + 2, /* skip space after ')' too */
+ "%c %d %d %d %d %d %lu %lu %lu %lu %lu "
+ "%ld %ld %ld %ld %d %d %lu %lu %ld %lu "
+ "%lu %lu %lu %lu %lu %lu %lu %d %d %d %d %lu",
+ &buf->state, &buf->ppid, &buf->pgrp, &buf->session,
+ &buf->tty, &buf->tpgid, &buf->k_flags, &buf->min_flt,
+ &buf->cmin_flt, &buf->maj_flt, &buf->cmaj_flt,
+ &buf->utime, &buf->stime, &buf->cutime, &buf->cstime,
+ &buf->priority, &buf->nice, &buf->timeout,
+ &buf->it_real_value, &buf->start_time, &buf->vsize,
+ &buf->rss, &buf->rss_rlim, &buf->start_code,
+ &buf->end_code, &buf->start_stack, &buf->kstk_esp,
+ &buf->kstk_eip, &buf->signal, &buf->blocked,
+ &buf->sigignore, &buf->sigcatch, &buf->wchan);
+
+ if (buf->tty == 0)
+ /* the old notty val, update elsewhere bef. moving to 0 */
+ buf->tty = -1;
+
+ if (server->os_version_code < LINUX_VERSION(1,3,39)) {
+ /* map old meanings to new */
+ buf->priority = 2*15 - buf->priority;
+ buf->nice = 15 - buf->nice;
+ }
+ if (server->os_version_code < LINUX_VERSION(1,1,30) && buf->tty != -1)
+ /* when tty wasn't full devno */
+ buf->tty = 4*0x100 + buf->tty;
+
+ fclose (f);
+
+ sprintf (input, "/proc/%d/statm", pid);
+
+ f = fopen (input, "r");
+ if (!f) return;
+
+ nread = fread (input, 1, BUFSIZ, f);
+
+ if (nread < 0) {
+ fclose (f);
+ return;
+ }
+
+ input [nread] = 0;
+
+ sscanf (input, "%ld %ld %ld %ld %ld %ld %ld",
+ &buf->size, &buf->resident, &buf->share,
+ &buf->trs, &buf->lrs, &buf->drs, &buf->dt);
+
+ fclose (f);
+
+ buf->flags [0] = _glibtop_sysdeps_procdata_0;
+ buf->flags [1] = _glibtop_sysdeps_procdata_1;
+}
diff --git a/sysdeps/freebsd/prockernel.c b/sysdeps/freebsd/prockernel.c
new file mode 100644
index 00000000..0dd97ab4
--- /dev/null
+++ b/sysdeps/freebsd/prockernel.c
@@ -0,0 +1,184 @@
+/* $Id$ */
+
+/* Copyright (C) 1998 Joshua Sled
+ This file is part of LibGTop 1.0.
+
+ Contributed by Joshua Sled <jsled@xcf.berkeley.edu>, July 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <glibtop.h>
+#include <glibtop/error.h>
+#include <glibtop/prockernel.h>
+
+#include <glibtop_suid.h>
+
+#include <kvm.h>
+#include <sys/param.h>
+#include <sys/sysctl.h>
+#include <sys/proc.h>
+#if (!defined __OpenBSD__) && (!defined __bsdi__)
+#include <sys/user.h>
+#endif
+#if !defined(__bsdi__) && !(defined(__FreeBSD__) && defined(__alpha__))
+#include <machine/pcb.h>
+#endif
+#if defined(__FreeBSD__) && !defined(__alpha__)
+#include <machine/tss.h>
+#endif
+
+#include <unistd.h>
+#include <fcntl.h>
+
+#ifdef __FreeBSD__
+#include <osreldate.h>
+#endif
+
+static const unsigned long _glibtop_sysdeps_proc_kernel_pstats =
+(1L << GLIBTOP_PROC_KERNEL_MIN_FLT) +
+(1L << GLIBTOP_PROC_KERNEL_MAJ_FLT) +
+(1L << GLIBTOP_PROC_KERNEL_CMIN_FLT) +
+(1L << GLIBTOP_PROC_KERNEL_CMAJ_FLT);
+
+static const unsigned long _glibtop_sysdeps_proc_kernel_pcb =
+(1L << GLIBTOP_PROC_KERNEL_KSTK_EIP) +
+(1L << GLIBTOP_PROC_KERNEL_KSTK_ESP);
+
+static const unsigned long _glibtop_sysdeps_proc_kernel_wchan =
+(1L << GLIBTOP_PROC_KERNEL_NWCHAN) +
+(1L << GLIBTOP_PROC_KERNEL_WCHAN);
+
+/* Init function. */
+
+void
+glibtop_init_proc_kernel_p (glibtop *server)
+{
+ server->sysdeps.proc_kernel = _glibtop_sysdeps_proc_kernel_pstats |
+ _glibtop_sysdeps_proc_kernel_pcb |
+ _glibtop_sysdeps_proc_kernel_wchan;
+}
+
+void
+glibtop_get_proc_kernel_p (glibtop *server,
+ glibtop_proc_kernel *buf,
+ pid_t pid)
+{
+ struct kinfo_proc *pinfo;
+ struct user *u_addr = (struct user *)USRSTACK;
+ struct pstats pstats;
+ struct pcb pcb;
+ int count;
+
+ char filename [BUFSIZ];
+ struct stat statb;
+
+ glibtop_init_p (server, (1L << GLIBTOP_SYSDEPS_PROC_KERNEL), 0);
+
+ memset (buf, 0, sizeof (glibtop_proc_kernel));
+
+ if (server->sysdeps.proc_time == 0)
+ return;
+
+ /* 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_error_io_r (server, "kvm_getprocs (%d)", pid);
+
+ buf->nwchan = (unsigned long) pinfo [0].kp_proc.p_wchan &~ KERNBASE;
+ buf->flags |= (1L << GLIBTOP_PROC_KERNEL_NWCHAN);
+
+ if (pinfo [0].kp_proc.p_wchan && pinfo [0].kp_proc.p_wmesg) {
+ strncpy (buf->wchan, pinfo [0].kp_eproc.e_wmesg,
+ sizeof (buf->wchan) - 1);
+ buf->wchan [sizeof (buf->wchan) - 1] = 0;
+ buf->flags |= (1L << GLIBTOP_PROC_KERNEL_WCHAN);
+ } else {
+ buf->wchan [0] = 0;
+ }
+
+ /* Taken from `saveuser ()' in `/usr/src/bin/ps/ps.c'. */
+
+ /* [FIXME]: /usr/include/sys/user.h tells me that the user area
+ * may or may not be at the same kernel address in all
+ * processes, but I don't see any way to get that address.
+ * Since `ps' simply uses its own address, I think it's
+ * safe to do this here, too. */
+
+ /* NOTE: You need to mount the /proc filesystem to make
+ * `kvm_uread' work. */
+
+ sprintf (filename, "/proc/%d/mem", (int) pid);
+ if (stat (filename, &statb)) return;
+
+ glibtop_suid_enter (server);
+
+ if ((pinfo [0].kp_proc.p_flag & P_INMEM) &&
+ kvm_uread (server->machine.kd, &(pinfo [0]).kp_proc,
+ (unsigned long) &u_addr->u_stats,
+ (char *) &pstats, sizeof (pstats)) == sizeof (pstats))
+ {
+ /*
+ * The u-area might be swapped out, and we can't get
+ * at it because we have a crashdump and no swap.
+ * If it's here fill in these fields, otherwise, just
+ * leave them 0.
+ */
+
+ buf->min_flt = (u_int64_t) pstats.p_ru.ru_minflt;
+ buf->maj_flt = (u_int64_t) pstats.p_ru.ru_majflt;
+ buf->cmin_flt = (u_int64_t) pstats.p_cru.ru_minflt;
+ buf->cmaj_flt = (u_int64_t) pstats.p_cru.ru_majflt;
+
+ buf->flags |= _glibtop_sysdeps_proc_kernel_pstats;
+ }
+
+ if ((pinfo [0].kp_proc.p_flag & P_INMEM) &&
+ kvm_uread (server->machine.kd, &(pinfo [0]).kp_proc,
+ (unsigned long) &u_addr->u_pcb,
+ (char *) &pcb, sizeof (pcb)) == sizeof (pcb))
+ {
+#ifdef __FreeBSD__
+#ifndef __alpha__
+#if (__FreeBSD_version >= 300003)
+ buf->kstk_esp = (u_int64_t) pcb.pcb_esp;
+ buf->kstk_eip = (u_int64_t) pcb.pcb_eip;
+#else
+ buf->kstk_esp = (u_int64_t) pcb.pcb_ksp;
+ buf->kstk_eip = (u_int64_t) pcb.pcb_pc;
+#endif
+#else
+ /*xxx FreeBSD/Alpha? */
+#endif
+#else
+ buf->kstk_esp = (u_int64_t) pcb.pcb_tss.tss_esp0;
+#ifdef __bsdi__
+ buf->kstk_eip = (u_int64_t) pcb.pcb_tss.tss_eip;
+#else
+ buf->kstk_eip = (u_int64_t) pcb.pcb_tss.__tss_eip;
+#endif
+
+ buf->flags |= _glibtop_sysdeps_proc_kernel_pcb;
+#endif
+ }
+
+ /* Taken from `wchan ()' in `/usr/src/bin/ps/print.c'. */
+
+ glibtop_suid_leave (server);
+}
diff --git a/sysdeps/freebsd/proclist.c b/sysdeps/freebsd/proclist.c
new file mode 100644
index 00000000..20353ec5
--- /dev/null
+++ b/sysdeps/freebsd/proclist.c
@@ -0,0 +1,103 @@
+/* $Id$ */
+
+/* Copyright (C) 1998 Joshua Sled
+ This file is part of LibGTop 1.0.
+
+ Contributed by Joshua Sled <jsled@xcf.berkeley.edu>, July 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <glibtop.h>
+#include <glibtop/error.h>
+#include <glibtop/xmalloc.h>
+#include <glibtop/proclist.h>
+
+#include <glibtop_suid.h>
+
+static const unsigned long _glibtop_sysdeps_proclist =
+(1L << GLIBTOP_PROCLIST_TOTAL) + (1L << GLIBTOP_PROCLIST_NUMBER) +
+(1L << GLIBTOP_PROCLIST_SIZE);
+
+/* Fetch list of currently running processes.
+ * The interface of this function is a little bit different from the others:
+ * buf->flags is only set if the call succeeded, in this case pids_chain,
+ * a list of the pids of all currently running processes is returned,
+ * buf->number is the number of elements of this list and buf->size is
+ * the size of one single element (sizeof (unsigned)). The total size is
+ * stored in buf->total.
+ *
+ * The calling function has to free the memory to which a pointer is returned.
+ *
+ * IMPORTANT NOTE:
+ * On error, this function MUST return NULL and set buf->flags to zero !
+ * On success, it returnes a pointer to a list of buf->number elements
+ * each buf->size big. The total size is stored in buf->total.
+ * The calling function has to free the memory to which a pointer is returned.
+ *
+ * On error, NULL is returned and buf->flags is zero. */
+
+/* Init function. */
+
+void
+glibtop_init_proclist_p (glibtop *server)
+{
+ server->sysdeps.proclist = _glibtop_sysdeps_proclist;
+}
+
+unsigned *
+glibtop_get_proclist_p (glibtop *server, glibtop_proclist *buf,
+ int64_t real_which, int64_t arg)
+{
+ struct kinfo_proc *pinfo;
+ unsigned *pids = NULL;
+ int which, count;
+ int i,j;
+
+ glibtop_init_p (server, (1L << GLIBTOP_SYSDEPS_PROCLIST), 0);
+
+ memset (buf, 0, sizeof (glibtop_proclist));
+
+ which = (int)(real_which & GLIBTOP_KERN_PROC_MASK);
+
+ /* Get the process data */
+ pinfo = kvm_getprocs (server->machine.kd, which, arg, &count);
+ if ((pinfo == NULL) || (count < 1)) {
+ glibtop_warn_io_r (server, "kvm_getprocs (proclist)");
+ return NULL;
+ }
+ count--;
+
+ /* Allocate count objects in the pids_chain array
+ * Same as malloc is pids is NULL, which it is. */
+ pids = glibtop_realloc_r (server, pids, count * sizeof (unsigned));
+ /* Copy the pids over to this chain */
+ for (i=j=0; i < count; i++) {
+ if ((real_which & GLIBTOP_EXCLUDE_IDLE) &&
+ (pinfo[i].kp_proc.p_stat != SRUN))
+ continue;
+ else if ((real_which & GLIBTOP_EXCLUDE_SYSTEM) &&
+ (pinfo[i].kp_eproc.e_pcred.p_ruid == 0))
+ continue;
+ pids [j++] = (unsigned) pinfo[i].kp_proc.p_pid;
+ } /* end for */
+ /* Set the fields in buf */
+ buf->number = j;
+ buf->size = sizeof (unsigned);
+ buf->total = j * sizeof (unsigned);
+ buf->flags = _glibtop_sysdeps_proclist;
+ return pids;
+}
diff --git a/sysdeps/freebsd/procmap.c b/sysdeps/freebsd/procmap.c
new file mode 100644
index 00000000..f29445b5
--- /dev/null
+++ b/sysdeps/freebsd/procmap.c
@@ -0,0 +1,266 @@
+/* $Id$ */
+
+/* Copyright (C) 1998 Joshua Sled
+ This file is part of LibGTop 1.0.
+
+ Contributed by Joshua Sled <jsled@xcf.berkeley.edu>, July 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <glibtop.h>
+#include <glibtop/error.h>
+#include <glibtop/xmalloc.h>
+#include <glibtop/procmap.h>
+
+#include <glibtop_suid.h>
+
+#include <kvm.h>
+#include <sys/param.h>
+#include <sys/proc.h>
+#include <sys/resource.h>
+#include <vm/vm_object.h>
+#include <vm/vm_prot.h>
+#include <vm/vm_map.h>
+
+#include <sys/vnode.h>
+#include <sys/mount.h>
+#include <ufs/ufs/quota.h>
+#include <ufs/ufs/inode.h>
+
+#include <sys/ucred.h>
+#if (!defined __OpenBSD__) && (!defined __bsdi__)
+#include <sys/user.h>
+#endif
+#include <sys/sysctl.h>
+#include <vm/vm.h>
+
+#if defined(__NetBSD__) && (__NetBSD_Version__ >= 104000000)
+/* Fixme ... */
+#undef _KERNEL
+#define _UVM_UVM_AMAP_I_H_ 1
+#define _UVM_UVM_MAP_I_H_ 1
+#include <uvm/uvm.h>
+#endif
+
+static const unsigned long _glibtop_sysdeps_proc_map =
+(1L << GLIBTOP_PROC_MAP_TOTAL) + (1L << GLIBTOP_PROC_MAP_NUMBER) +
+(1L << GLIBTOP_PROC_MAP_SIZE);
+
+static const unsigned long _glibtop_sysdeps_map_entry =
+(1L << GLIBTOP_MAP_ENTRY_START) + (1L << GLIBTOP_MAP_ENTRY_END) +
+(1L << GLIBTOP_MAP_ENTRY_OFFSET) + (1L << GLIBTOP_MAP_ENTRY_PERM) +
+(1L << GLIBTOP_MAP_ENTRY_INODE) + (1L << GLIBTOP_MAP_ENTRY_DEVICE);
+
+/* Init function. */
+
+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;
+#if defined(__NetBSD__) && (__NetBSD_Version__ >= 104000000)
+ struct vnode vnode;
+ struct inode inode;
+#else
+ struct vm_object object;
+#endif
+ glibtop_map_entry *maps;
+#if defined __FreeBSD__
+ struct vnode vnode;
+ struct inode inode;
+ struct mount mount;
+#endif
+ int count, i = 0;
+ int update = 0;
+
+ glibtop_init_p (server, (1L << GLIBTOP_SYSDEPS_PROC_MAP), 0);
+
+ memset (buf, 0, sizeof (glibtop_proc_map));
+
+ /* It does not work for the swapper task. */
+ if (pid == 0) return NULL;
+
+ glibtop_suid_enter (server);
+
+ /* Get the process data */
+ pinfo = kvm_getprocs (server->machine.kd, KERN_PROC_PID, pid, &count);
+ if ((pinfo == NULL) || (count < 1))
+ glibtop_error_io_r (server, "kvm_getprocs (%d)", pid);
+
+ /* Now we get the memory maps. */
+
+ if (kvm_read (server->machine.kd,
+ (unsigned long) pinfo [0].kp_proc.p_vmspace,
+ (char *) &vmspace, sizeof (vmspace)) != sizeof (vmspace))
+ glibtop_error_io_r (server, "kvm_read (vmspace)");
+
+ first = vmspace.vm_map.header.next;
+
+ if (kvm_read (server->machine.kd,
+ (unsigned long) vmspace.vm_map.header.next,
+ (char *) &entry, sizeof (entry)) != sizeof (entry))
+ glibtop_error_io_r (server, "kvm_read (entry)");
+
+ /* Allocate space. */
+
+ buf->number = vmspace.vm_map.nentries;
+ buf->size = sizeof (glibtop_map_entry);
+
+ buf->total = buf->number * buf->size;
+
+ maps = glibtop_malloc_r (server, buf->total);
+
+ memset (maps, 0, buf->total);
+
+ buf->flags = _glibtop_sysdeps_proc_map;
+
+ /* Walk through the `vm_map_entry' list ... */
+
+ /* I tested this a few times with `mmap'; as soon as you write
+ * to the mmap'ed area, the object type changes from OBJT_VNODE
+ * to OBJT_DEFAULT so if seems this really works. */
+
+ do {
+ if (update) {
+ if (kvm_read (server->machine.kd,
+ (unsigned long) entry.next,
+ &entry, sizeof (entry)) != sizeof (entry))
+ glibtop_error_io_r (server, "kvm_read (entry)");
+ } else {
+ update = 1;
+ }
+
+#ifdef __FreeBSD__
+#if __FreeBSD__ >= 4
+ if (entry.eflags & (MAP_ENTRY_IS_SUB_MAP))
+ continue;
+#else
+ if (entry.eflags & (MAP_ENTRY_IS_A_MAP|MAP_ENTRY_IS_SUB_MAP))
+ continue;
+#endif
+#else
+#if defined(__NetBSD__) && (__NetBSD_Version__ >= 104000000)
+ if (UVM_ET_ISSUBMAP (&entry))
+ continue;
+#else
+ if (entry.is_a_map || entry.is_sub_map)
+ continue;
+#endif
+#endif
+
+ maps [i].flags = _glibtop_sysdeps_map_entry;
+
+ maps [i].start = entry.start;
+ maps [i].end = entry.end;
+ maps [i].offset = entry.offset;
+
+ maps [i].perm = 0;
+
+ if (entry.protection & VM_PROT_READ)
+ maps [i].perm |= GLIBTOP_MAP_PERM_READ;
+ if (entry.protection & VM_PROT_WRITE)
+ maps [i].perm |= GLIBTOP_MAP_PERM_WRITE;
+ if (entry.protection & VM_PROT_EXECUTE)
+ maps [i].perm |= GLIBTOP_MAP_PERM_EXECUTE;
+
+ i++;
+
+#if defined(__NetBSD__) && (__NetBSD_Version__ >= 104000000)
+ if (!entry.object.uvm_obj)
+ continue;
+
+ /* We're only interested in vnodes */
+
+ if (kvm_read (server->machine.kd,
+ (unsigned long) entry.object.uvm_obj,
+ &vnode, sizeof (vnode)) != sizeof (vnode)) {
+ glibtop_warn_io_r (server, "kvm_read (vnode)");
+ return NULL;
+ }
+#else
+ if (!entry.object.vm_object)
+ continue;
+
+ /* We're only interested in `vm_object's */
+
+ if (kvm_read (server->machine.kd,
+ (unsigned long) entry.object.vm_object,
+ &object, sizeof (object)) != sizeof (object))
+ glibtop_error_io_r (server, "kvm_read (object)");
+#endif
+
+#if defined(__NetBSD__) && (__NetBSD_Version__ >= 104000000)
+ if (!vnode.v_uvm.u_flags & UVM_VNODE_VALID)
+ continue;
+
+ if ((vnode.v_type != VREG) || (vnode.v_tag != VT_UFS) ||
+ !vnode.v_data) continue;
+
+ if (kvm_read (server->machine.kd,
+ (unsigned long) vnode.v_data,
+ &inode, sizeof (inode)) != sizeof (inode))
+ glibtop_error_io_r (server, "kvm_read (inode)");
+
+ maps [i-1].inode = inode.i_number;
+ maps [i-1].device = inode.i_dev;
+#endif
+
+
+#ifdef __FreeBSD__
+ /* If the object is of type vnode, add its size */
+
+ if (object.type != OBJT_VNODE)
+ continue;
+
+ if (!object.handle)
+ continue;
+
+ if (kvm_read (server->machine.kd,
+ (unsigned long) object.handle,
+ &vnode, sizeof (vnode)) != sizeof (vnode))
+ glibtop_error_io_r (server, "kvm_read (vnode)");
+
+ if ((vnode.v_type != VREG) || (vnode.v_tag != VT_UFS) ||
+ !vnode.v_data) continue;
+
+ if (kvm_read (server->machine.kd,
+ (unsigned long) vnode.v_data,
+ &inode, sizeof (inode)) != sizeof (inode))
+ glibtop_error_io_r (server, "kvm_read (inode)");
+
+ if (kvm_read (server->machine.kd,
+ (unsigned long) vnode.v_mount,
+ &mount, sizeof (mount)) != sizeof (mount))
+ glibtop_error_io_r (server, "kvm_read (mount)");
+
+ maps [i-1].inode = inode.i_number;
+ maps [i-1].device = inode.i_dev;
+#endif
+ } while (entry.next != first);
+
+ return maps;
+}
diff --git a/sysdeps/freebsd/procmem.c b/sysdeps/freebsd/procmem.c
new file mode 100644
index 00000000..05f66001
--- /dev/null
+++ b/sysdeps/freebsd/procmem.c
@@ -0,0 +1,259 @@
+/* $Id$ */
+
+/* Copyright (C) 1998 Joshua Sled
+ This file is part of LibGTop 1.0.
+
+ Contributed by Joshua Sled <jsled@xcf.berkeley.edu>, July 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <glibtop.h>
+#include <glibtop/error.h>
+#include <glibtop/procmem.h>
+
+#include <glibtop_suid.h>
+
+#include <kvm.h>
+#include <sys/param.h>
+#include <sys/proc.h>
+#include <sys/resource.h>
+#include <vm/vm_object.h>
+#include <vm/vm_map.h>
+
+#include <sys/vnode.h>
+#include <ufs/ufs/quota.h>
+#include <ufs/ufs/inode.h>
+
+#include <sys/ucred.h>
+#if (!defined __OpenBSD__) && (!defined __bsdi__)
+#include <sys/user.h>
+#endif
+#include <sys/sysctl.h>
+#include <vm/vm.h>
+
+#if defined(__NetBSD__) && (__NetBSD_Version__ >= 104000000)
+/* Fixme ... */
+#undef _KERNEL
+#define _UVM_UVM_AMAP_I_H_ 1
+#define _UVM_UVM_MAP_I_H_ 1
+#include <uvm/uvm.h>
+#endif
+
+static const unsigned long _glibtop_sysdeps_proc_mem =
+(1L << GLIBTOP_PROC_MEM_SIZE) +
+(1L << GLIBTOP_PROC_MEM_VSIZE) +
+(1L << GLIBTOP_PROC_MEM_RESIDENT) +
+(1L << GLIBTOP_PROC_MEM_RSS) +
+(1L << GLIBTOP_PROC_MEM_RSS_RLIM);
+
+static const unsigned long _glibtop_sysdeps_proc_mem_share =
+#if defined(__NetBSD__) && (__NetBSD_Version__ >= 104000000)
+(1L << GLIBTOP_PROC_MEM_SHARE);
+#elif defined(__FreeBSD__)
+(1L << GLIBTOP_PROC_MEM_SHARE);
+#else
+0;
+#endif
+
+#ifndef LOG1024
+#define LOG1024 10
+#endif
+
+/* these are for getting the memory statistics */
+static int pageshift; /* log base 2 of the pagesize */
+
+/* define pagetok in terms of pageshift */
+#define pagetok(size) ((size) << pageshift)
+
+/* Init function. */
+
+void
+glibtop_init_proc_mem_p (glibtop *server)
+{
+ register int pagesize;
+
+ /* get the page size with "getpagesize" and calculate pageshift
+ * from it */
+ pagesize = getpagesize ();
+ pageshift = 0;
+ while (pagesize > 1) {
+ pageshift++;
+ pagesize >>= 1;
+ }
+
+ /* we only need the amount of log(2)1024 for our conversion */
+ pageshift -= LOG1024;
+
+ server->sysdeps.proc_mem = _glibtop_sysdeps_proc_mem |
+ _glibtop_sysdeps_proc_mem_share;
+}
+
+/* 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 *vms, vmspace;
+#if defined(__NetBSD__) && (__NetBSD_Version__ >= 104000000)
+ struct vnode vnode;
+ struct inode inode;
+#else
+ struct vm_object object;
+#endif
+ struct plimit plimit;
+ int count;
+
+ glibtop_init_p (server, (1L << GLIBTOP_SYSDEPS_PROC_MEM), 0);
+
+ memset (buf, 0, sizeof (glibtop_proc_mem));
+
+ if (server->sysdeps.proc_mem == 0)
+ return;
+
+ /* 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;
+ }
+
+ if (kvm_read (server->machine.kd,
+ (unsigned long) pinfo [0].kp_proc.p_limit,
+ (char *) &plimit, sizeof (plimit)) != sizeof (plimit)) {
+ glibtop_warn_io_r (server, "kvm_read (plimit)");
+ return;
+ }
+
+ buf->rss_rlim = (u_int64_t)
+ (plimit.pl_rlimit [RLIMIT_RSS].rlim_cur);
+
+ vms = &pinfo [0].kp_eproc.e_vm;
+
+ buf->vsize = buf->size = (u_int64_t) pagetok
+ (vms->vm_tsize + vms->vm_dsize + vms->vm_ssize) << LOG1024;
+
+ buf->resident = buf->rss = (u_int64_t) pagetok
+ (vms->vm_rssize) << LOG1024;
+
+ /* Now we get the shared memory. */
+
+ if (kvm_read (server->machine.kd,
+ (unsigned long) pinfo [0].kp_proc.p_vmspace,
+ (char *) &vmspace, sizeof (vmspace)) != sizeof (vmspace)) {
+ glibtop_warn_io_r (server, "kvm_read (vmspace)");
+ return;
+ }
+
+ 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,
+ &entry, sizeof (entry)) != sizeof (entry)) {
+ glibtop_warn_io_r (server, "kvm_read (entry)");
+ return;
+ }
+
+#ifdef __FreeBSD__
+#if __FreeBSD__ >= 4
+ if (entry.eflags & (MAP_ENTRY_IS_SUB_MAP))
+ continue;
+#else
+ if (entry.eflags & (MAP_ENTRY_IS_A_MAP|MAP_ENTRY_IS_SUB_MAP))
+ continue;
+#endif
+#else
+#if defined(__NetBSD__) && (__NetBSD_Version__ >= 104000000)
+ if (UVM_ET_ISSUBMAP (&entry))
+ continue;
+#else
+ if (entry.is_a_map || entry.is_sub_map)
+ continue;
+#endif
+#endif
+
+#if defined(__NetBSD__) && (__NetBSD_Version__ >= 104000000)
+ if (!entry.object.uvm_obj)
+ continue;
+
+ /* We're only interested in vnodes */
+
+ if (kvm_read (server->machine.kd,
+ (unsigned long) entry.object.uvm_obj,
+ &vnode, sizeof (vnode)) != sizeof (vnode)) {
+ glibtop_warn_io_r (server, "kvm_read (vnode)");
+ return;
+ }
+#else
+ 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,
+ &object, sizeof (object)) != sizeof (object)) {
+ glibtop_warn_io_r (server, "kvm_read (object)");
+ return;
+ }
+#endif
+ /* If the object is of type vnode, add its size */
+
+#if defined(__NetBSD__) && (__NetBSD_Version__ >= 104000000)
+ if (!vnode.v_uvm.u_flags & UVM_VNODE_VALID)
+ continue;
+
+ if ((vnode.v_type != VREG) || (vnode.v_tag != VT_UFS) ||
+ !vnode.v_data) continue;
+
+ /* Reference count must be at least two. */
+ if (vnode.v_uvm.u_obj.uo_refs <= 1)
+ continue;
+
+ buf->share += pagetok (vnode.v_uvm.u_obj.uo_npages) << LOG1024;
+#endif
+
+#ifdef __FreeBSD__
+ if (object.type != OBJT_VNODE)
+ continue;
+
+ buf->share += object.un_pager.vnp.vnp_size;
+#endif
+ }
+
+ buf->flags = _glibtop_sysdeps_proc_mem |
+ _glibtop_sysdeps_proc_mem_share;
+}
diff --git a/sysdeps/freebsd/procsegment.c b/sysdeps/freebsd/procsegment.c
new file mode 100644
index 00000000..915472ef
--- /dev/null
+++ b/sysdeps/freebsd/procsegment.c
@@ -0,0 +1,82 @@
+/* $Id$ */
+
+/* Copyright (C) 1998 Joshua Sled
+ This file is part of LibGTop 1.0.
+
+ Contributed by Joshua Sled <jsled@xcf.berkeley.edu>, July 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <glibtop.h>
+#include <glibtop/error.h>
+#include <glibtop/procsegment.h>
+
+#include <glibtop_suid.h>
+
+#include <kvm.h>
+#include <sys/param.h>
+#include <sys/sysctl.h>
+
+static const unsigned long _glibtop_sysdeps_proc_segment = 0;
+
+/* Init function. */
+
+void
+glibtop_init_proc_segment_p (glibtop *server)
+{
+ 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)
+{
+ glibtop_init_p (server, (1L << GLIBTOP_SYSDEPS_PROC_SEGMENT), 0);
+
+ memset (buf, 0, sizeof (glibtop_proc_segment));
+
+#if 0
+ /* Get the process info from the kernel */
+ kvm_getprocs (server->machine.kd, KERN_PROC_PID, pid, count);
+ if (*count != 1) {
+ return; /* the zeroed-out buffer indicating no data */
+ }
+
+ /* trs: text resident set size
+ pinfo[0]->kp_eproc.e_xrssize;
+ */
+ /* buf->trs = pinfo[0]->kp_eproc.e_xrssize; */
+ /* lrs: shared-lib resident set size
+ ? */
+ /* drs: data resident set size
+ pinfo[0]->kp_eproc.e_vm.vm_map.vm_dsize;
+ */
+ /* dt: dirty pages
+ */
+ /* start_code: address of beginning of code segment
+
+ */
+ /* end_code: address of end of code segment
+ */
+ /* start_stack: address of the bottom of stack segment
+ */
+#endif
+}
+
diff --git a/sysdeps/freebsd/procsignal.c b/sysdeps/freebsd/procsignal.c
new file mode 100644
index 00000000..6ee36cab
--- /dev/null
+++ b/sysdeps/freebsd/procsignal.c
@@ -0,0 +1,107 @@
+/* $Id$ */
+
+/* Copyright (C) 1998 Joshua Sled
+ This file is part of LibGTop 1.0.
+
+ Contributed by Joshua Sled <jsled@xcf.berkeley.edu>, July 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <glibtop.h>
+#include <glibtop/error.h>
+#include <glibtop/procsignal.h>
+
+#include <glibtop_suid.h>
+
+#ifdef __FreeBSD__
+#include <osreldate.h>
+#endif
+
+static const unsigned long _glibtop_sysdeps_proc_signal =
+(1L << GLIBTOP_PROC_SIGNAL_SIGNAL) +
+(1L << GLIBTOP_PROC_SIGNAL_BLOCKED) +
+(1L << GLIBTOP_PROC_SIGNAL_SIGIGNORE) +
+(1L << GLIBTOP_PROC_SIGNAL_SIGCATCH);
+
+/* Init function. */
+
+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;
+
+ glibtop_init_p (server, (1L << GLIBTOP_SYSDEPS_PROC_SIGNAL), 0);
+
+ memset (buf, 0, sizeof (glibtop_proc_signal));
+
+ /* It does not work for the swapper task. */
+ if (pid == 0) return;
+
+ /* 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;
+ }
+
+ /* signal: mask of pending signals.
+ * pinfo [0].kp_proc.p_siglist
+ */
+#if (defined(__NetBSD__) && (NSIG > 32)) || (__FreeBSD_version >= 400011)
+ buf->signal [0] = pinfo [0].kp_proc.p_siglist.__bits[0];
+#else
+ buf->signal [0] = pinfo [0].kp_proc.p_siglist;
+#endif
+
+ /* blocked: mask of blocked signals.
+ * pinfo [0].kp_proc.p_sigmask
+ */
+#if (defined(__NetBSD__) && (NSIG > 32)) || (__FreeBSD_version >= 400011)
+ buf->blocked [0] = pinfo [0].kp_proc.p_sigmask.__bits[0];
+#else
+ buf->blocked [0] = pinfo [0].kp_proc.p_sigmask;
+#endif
+
+ /* sigignore: mask of ignored signals.
+ * pinfo [0].kp_proc.p_sigignore
+ */
+#if (defined(__NetBSD__) && (NSIG > 32)) || (__FreeBSD_version >= 400011)
+ buf->sigignore [0] = pinfo [0].kp_proc.p_sigignore.__bits[0];
+#else
+ buf->sigignore [0] = pinfo [0].kp_proc.p_sigignore;
+#endif
+
+ /* sigcatch: mask of caught signals.
+ * pinfo [0].kp_proc.p_sigcatch
+ */
+#if (defined(__NetBSD__) && (NSIG > 32)) || (__FreeBSD_version >= 400011)
+ buf->sigcatch [0] = pinfo [0].kp_proc.p_sigcatch.__bits[0];
+#else
+ buf->sigcatch [0] = pinfo [0].kp_proc.p_sigcatch;
+#endif
+
+ buf->flags = _glibtop_sysdeps_proc_signal;
+}
diff --git a/sysdeps/freebsd/procstate.c b/sysdeps/freebsd/procstate.c
new file mode 100644
index 00000000..2357b393
--- /dev/null
+++ b/sysdeps/freebsd/procstate.c
@@ -0,0 +1,137 @@
+/* $Id$ */
+
+/* Copyright (C) 1998 Joshua Sled
+ This file is part of LibGTop 1.0.
+
+ Contributed by Joshua Sled <jsled@xcf.berkeley.edu>, July 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <glibtop.h>
+#include <glibtop/error.h>
+#include <glibtop/procstate.h>
+
+#include <glibtop_suid.h>
+
+#if !defined(__OpenBSD__)
+//&& (!defined __bsdi__)
+#include <sys/user.h>
+#endif
+
+static const unsigned long _glibtop_sysdeps_proc_state =
+(1L << GLIBTOP_PROC_STATE_CMD) + (1L << GLIBTOP_PROC_STATE_UID) +
+(1L << GLIBTOP_PROC_STATE_GID);
+
+static const unsigned long _glibtop_sysdeps_proc_state_new =
+#if LIBGTOP_VERSION_CODE >= 1001000
+(1L << GLIBTOP_PROC_STATE_RUID) + (1L << GLIBTOP_PROC_STATE_RGID);
+#else
+0;
+#endif
+
+/* Init function. */
+
+void
+glibtop_init_proc_state_p (glibtop *server)
+{
+ server->sysdeps.proc_state = _glibtop_sysdeps_proc_state |
+ _glibtop_sysdeps_proc_state_new;
+}
+
+/* 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;
+
+ glibtop_init_p (server, (1L << GLIBTOP_SYSDEPS_PROC_STATE), 0);
+
+ memset (buf, 0, sizeof (glibtop_proc_state));
+
+ /* It does not work for the swapper task. */
+ if (pid == 0) return;
+
+ /* 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;
+ }
+
+ strncpy (buf->cmd, pinfo [0].kp_proc.p_comm, sizeof (buf->cmd)-1);
+ buf->cmd [sizeof (buf->cmd)-1] = 0;
+
+ buf->uid = pinfo [0].kp_eproc.e_pcred.p_svuid;
+ buf->gid = pinfo [0].kp_eproc.e_pcred.p_svgid;
+
+#if LIBGTOP_VERSION_CODE >= 1001000
+ buf->ruid = pinfo [0].kp_eproc.e_pcred.p_ruid;
+ buf->rgid = pinfo [0].kp_eproc.e_pcred.p_rgid;
+#endif
+
+ /* Set the flags for the data we're about to return*/
+ buf->flags = _glibtop_sysdeps_proc_state |
+ _glibtop_sysdeps_proc_state_new;
+
+#if LIBGTOP_VERSION_CODE >= 1001000
+ switch (pinfo [0].kp_proc.p_stat) {
+ case SIDL:
+ buf->state = 0;
+ break;
+ case SRUN:
+ buf->state = GLIBTOP_PROCESS_RUNNING;
+ break;
+ case SSLEEP:
+ buf->state = GLIBTOP_PROCESS_INTERRUPTIBLE;
+ break;
+ case SSTOP:
+ buf->state = GLIBTOP_PROCESS_STOPPED;
+ break;
+ case SZOMB:
+ buf->state = GLIBTOP_PROCESS_ZOMBIE;
+ break;
+ default:
+ return;
+ }
+#else
+ switch (pinfo [0].kp_proc.p_stat) {
+ case SIDL:
+ buf->state = 'S';
+ break;
+ case SRUN:
+ buf->state = 'R';
+ break;
+ case SSLEEP:
+ buf->state = 'S';
+ break;
+ case SSTOP:
+ buf->state = 'T';
+ break;
+ case SZOMB:
+ buf->state = 'Z';
+ break;
+ default:
+ return;
+ }
+#endif
+
+ buf->flags |= (1L << GLIBTOP_PROC_STATE_STATE);
+}
diff --git a/sysdeps/freebsd/proctime.c b/sysdeps/freebsd/proctime.c
new file mode 100644
index 00000000..0c71c593
--- /dev/null
+++ b/sysdeps/freebsd/proctime.c
@@ -0,0 +1,229 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <glibtop.h>
+#include <glibtop/error.h>
+#include <glibtop/proctime.h>
+
+#include <glibtop_suid.h>
+
+#ifdef __FreeBSD__
+#include <osreldate.h>
+#endif
+
+static const unsigned long _glibtop_sysdeps_proc_time =
+(1L << GLIBTOP_PROC_TIME_RTIME) + (1L << GLIBTOP_PROC_TIME_FREQUENCY);
+
+static const unsigned long _glibtop_sysdeps_proc_time_user =
+(1L << GLIBTOP_PROC_TIME_UTIME) + (1L << GLIBTOP_PROC_TIME_STIME) +
+(1L << GLIBTOP_PROC_TIME_CUTIME) + (1L << GLIBTOP_PROC_TIME_CSTIME) +
+(1L << GLIBTOP_PROC_TIME_START_TIME);
+
+#define tv2sec(tv) (((u_int64_t) tv.tv_sec * 1000000) + (u_int64_t) tv.tv_usec)
+
+/* Init function. */
+
+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 */
+
+/*
+ * Transform the running time and tick information in proc p into user,
+ * system, and interrupt time usage.
+ */
+
+static void
+calcru(p, up, sp, ip)
+ struct proc *p;
+ struct timeval *up;
+ struct timeval *sp;
+ struct timeval *ip;
+{
+ quad_t totusec;
+ u_quad_t u, st, ut, it, tot;
+#if (__FreeBSD_version < 300003)
+ long sec, usec;
+#endif
+ struct timeval tv;
+
+ st = p->p_sticks;
+ ut = p->p_uticks;
+ it = p->p_iticks;
+
+ tot = st + ut + it;
+ if (tot == 0) {
+ st = 1;
+ tot = 1;
+ }
+
+#if (defined __FreeBSD__) && (__FreeBSD_version >= 300003)
+
+ /* This was changed from a `struct timeval' into a `u_int64_t'
+ * on FreeBSD 3.0 and renamed p_rtime -> p_runtime.
+ */
+
+ totusec = (u_quad_t) p->p_runtime;
+#else
+ sec = p->p_rtime.tv_sec;
+ usec = p->p_rtime.tv_usec;
+
+ totusec = (quad_t)sec * 1000000 + usec;
+#endif
+
+ if (totusec < 0) {
+ /* XXX no %qd in kernel. Truncate. */
+ fprintf (stderr, "calcru: negative time: %ld usec\n",
+ (long)totusec);
+ totusec = 0;
+ }
+
+
+ u = totusec;
+ st = (u * st) / tot;
+ sp->tv_sec = st / 1000000;
+ sp->tv_usec = st % 1000000;
+ ut = (u * ut) / tot;
+ up->tv_sec = ut / 1000000;
+ up->tv_usec = ut % 1000000;
+ if (ip != NULL) {
+ it = (u * it) / tot;
+ ip->tv_sec = it / 1000000;
+ ip->tv_usec = it % 1000000;
+ }
+}
+
+/* Provides detailed information about a process. */
+
+void
+glibtop_get_proc_time_p (glibtop *server, glibtop_proc_time *buf,
+ pid_t pid)
+{
+ struct kinfo_proc *pinfo;
+#if (defined(__NetBSD__) && (__NetBSD_Version__ >= 104000000)) || (defined(OpenBSD) && (OpenBSD >= 199912))
+ register struct rusage *rup;
+#else
+ struct user *u_addr = (struct user *)USRSTACK;
+#endif
+ struct pstats pstats;
+ int count;
+
+ char filename [BUFSIZ];
+ struct stat statb;
+
+ glibtop_init_p (server, (1L << GLIBTOP_SYSDEPS_PROC_TIME), 0);
+
+ memset (buf, 0, sizeof (glibtop_proc_time));
+
+ /* It does not work for the swapper task. */
+ if (pid == 0) return;
+
+#if !(defined(__NetBSD__) && (__NetBSD_Version__ >= 104000000))
+ if (server->sysdeps.proc_time == 0)
+ return;
+
+#ifndef __bsdi__
+ sprintf (filename, "/proc/%d/mem", (int) pid);
+ if (stat (filename, &statb)) return;
+#endif
+#endif
+
+ /* Get the process information */
+ pinfo = kvm_getprocs (server->machine.kd, KERN_PROC_PID, pid, &count);
+ if ((pinfo == NULL) || (count != 1))
+ glibtop_error_io_r (server, "kvm_getprocs (%d)", pid);
+
+#if (defined __FreeBSD__) && (__FreeBSD_version >= 300003)
+ buf->rtime = pinfo [0].kp_proc.p_runtime;
+#else
+ buf->rtime = tv2sec (pinfo [0].kp_proc.p_rtime);
+#endif
+
+ buf->frequency = 1000000;
+ buf->flags = _glibtop_sysdeps_proc_time;
+
+#if (defined(__NetBSD__) && (__NetBSD_Version__ >= 104000000)) || (defined(OpenBSD) && (OpenBSD >= 199912))
+ glibtop_suid_enter (server);
+
+ if (kvm_read (server->machine.kd,
+ (unsigned long) pinfo [0].kp_proc.p_stats,
+ &pstats, sizeof (pstats)) != sizeof (pstats)) {
+ glibtop_warn_io_r (server, "kvm_read (pstats)");
+ return;
+ }
+
+ glibtop_suid_leave (server);
+
+ rup = &pstats.p_ru;
+ calcru(&(pinfo [0]).kp_proc,
+ &rup->ru_utime, &rup->ru_stime, NULL);
+
+ buf->utime = tv2sec (pstats.p_ru.ru_utime);
+ buf->stime = tv2sec (pstats.p_ru.ru_stime);
+
+ buf->cutime = tv2sec (pstats.p_cru.ru_utime);
+ buf->cstime = tv2sec (pstats.p_cru.ru_stime);
+
+ buf->start_time = (u_int64_t) pstats.p_start.tv_sec;
+
+ buf->flags |= _glibtop_sysdeps_proc_time_user;
+#else
+ glibtop_suid_enter (server);
+
+ if ((pinfo [0].kp_proc.p_flag & P_INMEM) &&
+ kvm_uread (server->machine.kd, &(pinfo [0]).kp_proc,
+ (unsigned long) &u_addr->u_stats,
+ (char *) &pstats, sizeof (pstats)) == sizeof (pstats))
+ {
+ /* This is taken form the kernel source code of
+ * FreeBSD 2.2.6. */
+
+ /* Well, we just do the same getrusage () does ... */
+
+ register struct rusage *rup;
+
+ glibtop_suid_leave (server);
+
+ rup = &pstats.p_ru;
+ calcru(&(pinfo [0]).kp_proc,
+ &rup->ru_utime, &rup->ru_stime, NULL);
+
+ buf->utime = tv2sec (pstats.p_ru.ru_utime);
+ buf->stime = tv2sec (pstats.p_ru.ru_stime);
+
+ buf->cutime = tv2sec (pstats.p_cru.ru_utime);
+ buf->cstime = tv2sec (pstats.p_cru.ru_stime);
+
+ buf->start_time = tv2sec (pstats.p_start);
+
+ buf->flags = _glibtop_sysdeps_proc_time_user;
+ }
+
+ glibtop_suid_leave (server);
+#endif
+}
+
diff --git a/sysdeps/freebsd/procuid.c b/sysdeps/freebsd/procuid.c
new file mode 100644
index 00000000..03c4598a
--- /dev/null
+++ b/sysdeps/freebsd/procuid.c
@@ -0,0 +1,128 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <glibtop.h>
+#include <glibtop/error.h>
+#include <glibtop/procuid.h>
+
+#include <glibtop_suid.h>
+
+static const unsigned long _glibtop_sysdeps_proc_uid =
+(1L << GLIBTOP_PROC_UID_UID) + (1L << GLIBTOP_PROC_UID_EUID) +
+(1L << GLIBTOP_PROC_UID_EGID) + (1L << GLIBTOP_PROC_UID_PID) +
+(1L << GLIBTOP_PROC_UID_PPID) + (1L << GLIBTOP_PROC_UID_PGRP) +
+(1L << GLIBTOP_PROC_UID_TPGID) + (1L << GLIBTOP_PROC_UID_PRIORITY) +
+(1L << GLIBTOP_PROC_UID_NICE);
+
+static const unsigned long _glibtop_sysdeps_proc_uid_groups =
+#if LIBGTOP_VERSION_CODE >= 1001000
+#if defined(__NetBSD__) && (__NetBSD_Version__ >= 104000000)
+(1L << GLIBTOP_PROC_UID_NGROUPS) + (1L << GLIBTOP_PROC_UID_GROUPS);
+#else
+0L;
+#endif
+#else /* LIBGTOP_VERSION_CODE < 1001000 */
+0L;
+#endif
+
+/* Init function. */
+
+void
+glibtop_init_proc_uid_p (glibtop *server)
+{
+ server->sysdeps.proc_uid = _glibtop_sysdeps_proc_uid |
+ _glibtop_sysdeps_proc_uid_groups;
+}
+
+/* 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;
+
+#if LIBGTOP_VERSION_CODE >= 1001000
+#if defined(__NetBSD__) && (__NetBSD_Version__ >= 104000000)
+ struct ucred ucred;
+ void *ucred_ptr;
+#endif
+#endif
+
+ glibtop_init_p (server, (1L << GLIBTOP_SYSDEPS_PROC_UID), 0);
+
+ memset (buf, 0, sizeof (glibtop_proc_uid));
+
+ /* It does not work for the swapper task. */
+ if (pid == 0) return;
+
+ /* 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].kp_eproc.e_pcred.p_ruid;
+ buf->euid = pinfo [0].kp_eproc.e_pcred.p_svuid;
+ buf->gid = pinfo [0].kp_eproc.e_pcred.p_rgid;
+ buf->egid = pinfo [0].kp_eproc.e_pcred.p_svgid;
+
+ buf->ppid = pinfo [0].kp_eproc.e_ppid;
+ buf->pgrp = pinfo [0].kp_eproc.e_pgid;
+ buf->tpgid = pinfo [0].kp_eproc.e_tpgid;
+
+ buf->nice = pinfo [0].kp_proc.p_nice;
+ buf->priority = pinfo [0].kp_proc.p_priority;
+
+ /* Set the flags for the data we're about to return*/
+ buf->flags = _glibtop_sysdeps_proc_uid;
+
+ /* Use LibGTop conditionals here so we can more easily merge this
+ * code into the LIBGTOP_STABLE_1_0 branch. */
+#if LIBGTOP_VERSION_CODE >= 1001000
+ /* This probably also works with other versions, but not yet
+ * tested. Please remove the conditional if this is true. */
+#if defined(__NetBSD__) && (__NetBSD_Version__ >= 104000000)
+ ucred_ptr = (void *) pinfo [0].kp_eproc.e_pcred.pc_ucred;
+
+ if (ucred_ptr) {
+ if (kvm_read (server->machine.kd, (unsigned long) ucred_ptr,
+ &ucred, sizeof (ucred)) != sizeof (ucred)) {
+ glibtop_warn_io_r (server, "kvm_read (ucred)");
+ } else {
+ int count = (ucred.cr_ngroups < GLIBTOP_MAX_GROUPS) ?
+ ucred.cr_ngroups : GLIBTOP_MAX_GROUPS;
+ int i;
+
+ for (i = 0; i < count; i++)
+ buf->groups [i] = ucred.cr_groups [i];
+ buf->ngroups = count;
+
+ buf->flags |= _glibtop_sysdeps_proc_uid_groups;
+ }
+ }
+#endif
+#endif
+}
diff --git a/sysdeps/freebsd/sem_limits.c b/sysdeps/freebsd/sem_limits.c
new file mode 100644
index 00000000..c9a177de
--- /dev/null
+++ b/sysdeps/freebsd/sem_limits.c
@@ -0,0 +1,120 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, August 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <glibtop.h>
+#include <glibtop/error.h>
+#include <glibtop/sem_limits.h>
+
+#include <glibtop_suid.h>
+
+#if defined(__bsdi__) && (_BSDI_VERSION < 199700)
+/* Older versions of BSDI don't seem to have this. */
+
+void
+glibtop_init_sem_limits_p (glibtop *server)
+{ }
+
+void
+glibtop_get_sem_limits_p (glibtop *server, glibtop_sem_limits *buf)
+{
+ glibtop_init_p (server, (1L << GLIBTOP_SYSDEPS_SEM_LIMITS), 0);
+
+ memset (buf, 0, sizeof (glibtop_sem_limits));
+}
+
+#else
+
+/* #define KERNEL to get declaration of `struct seminfo'. */
+
+#if (defined(__FreeBSD__) && (__FreeBSD_version < 410000)) || defined(__bsdi__)
+#define KERNEL 1
+#else
+#define _KERNEL 1
+#endif
+
+#include <sys/ipc.h>
+#include <sys/sem.h>
+
+static unsigned long _glibtop_sysdeps_sem_limits =
+(1L << GLIBTOP_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);
+
+/* The values in this structure never change at runtime, so we only
+ * read it once during initialization. We have to use the name `_seminfo'
+ * since `seminfo' is already declared external in <sys/sem.h>. */
+static struct seminfo _seminfo;
+
+/* nlist structure for kernel access */
+static struct nlist nlst [] = {
+ { "_seminfo" },
+ { 0 }
+};
+
+/* Init function. */
+
+void
+glibtop_init_sem_limits_p (glibtop *server)
+{
+ if (kvm_nlist (server->machine.kd, nlst) < 0) {
+ glibtop_warn_io_r (server, "kvm_nlist (sem_limits)");
+ return;
+ }
+
+ if (kvm_read (server->machine.kd, nlst [0].n_value,
+ &_seminfo, sizeof (_seminfo)) != sizeof (_seminfo)) {
+ glibtop_warn_io_r (server, "kvm_read (seminfo)");
+ return;
+ }
+
+ server->sysdeps.sem_limits = _glibtop_sysdeps_sem_limits;
+}
+
+/* Provides information about sysv sem limits. */
+
+void
+glibtop_get_sem_limits_p (glibtop *server, glibtop_sem_limits *buf)
+{
+ glibtop_init_p (server, (1L << GLIBTOP_SYSDEPS_SEM_LIMITS), 0);
+
+ memset (buf, 0, sizeof (glibtop_sem_limits));
+
+ if (server->sysdeps.sem_limits == 0)
+ return;
+
+ buf->semmap = _seminfo.semmap;
+ buf->semmni = _seminfo.semmni;
+ buf->semmns = _seminfo.semmns;
+ buf->semmnu = _seminfo.semmnu;
+ buf->semmsl = _seminfo.semmsl;
+ buf->semopm = _seminfo.semopm;
+ buf->semvmx = _seminfo.semvmx;
+ buf->semaem = _seminfo.semaem;
+
+ buf->flags = _glibtop_sysdeps_sem_limits;
+}
+
+#endif /* either a newer BSDI or no BSDI at all. */
+
diff --git a/sysdeps/freebsd/shm_limits.c b/sysdeps/freebsd/shm_limits.c
new file mode 100644
index 00000000..5abe88e8
--- /dev/null
+++ b/sysdeps/freebsd/shm_limits.c
@@ -0,0 +1,115 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, August 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <glibtop.h>
+#include <glibtop/error.h>
+#include <glibtop/shm_limits.h>
+
+#include <glibtop_suid.h>
+
+#if defined(__bsdi__) && (_BSDI_VERSION < 199700)
+/* Older versions of BSDI don't seem to have this. */
+
+void
+glibtop_init_shm_limits_p (glibtop *server)
+{ }
+
+void
+glibtop_get_shm_limits_p (glibtop *server, glibtop_shm_limits *buf)
+{
+ glibtop_init_p (server, (1L << GLIBTOP_SYSDEPS_SHM_LIMITS), 0);
+
+ memset (buf, 0, sizeof (glibtop_shm_limits));
+}
+
+#else
+
+/* #define KERNEL to get declaration of `struct shminfo'. */
+
+#if (defined(__FreeBSD__) && (__FreeBSD_version < 410000)) || defined(__bsdi__)
+#define KERNEL 1
+#else
+#define _KERNEL 1
+#endif
+
+#include <sys/ipc.h>
+#include <sys/shm.h>
+
+static unsigned long _glibtop_sysdeps_shm_limits =
+(1L << GLIBTOP_IPC_SHMMAX) + (1L << GLIBTOP_IPC_SHMMIN) +
+(1L << GLIBTOP_IPC_SHMMNI) + (1L << GLIBTOP_IPC_SHMSEG) +
+(1L << GLIBTOP_IPC_SHMALL);
+
+/* The values in this structure never change at runtime, so we only
+ * read it once during initialization. We have to use the name `_shminfo'
+ * since `shminfo' is already declared external in <sys/shm.h>. */
+static struct shminfo _shminfo;
+
+/* nlist structure for kernel access */
+static struct nlist nlst [] = {
+ { "_shminfo" },
+ { 0 }
+};
+
+/* Init function. */
+
+void
+glibtop_init_shm_limits_p (glibtop *server)
+{
+ if (kvm_nlist (server->machine.kd, nlst) < 0) {
+ glibtop_warn_io_r (server, "kvm_nlist (shm_limits)");
+ return;
+ }
+
+ if (kvm_read (server->machine.kd, nlst [0].n_value,
+ &_shminfo, sizeof (_shminfo)) != sizeof (_shminfo)) {
+ glibtop_warn_io_r (server, "kvm_read (shminfo)");
+ return;
+ }
+
+ server->sysdeps.shm_limits = _glibtop_sysdeps_shm_limits;
+}
+
+/* Provides information about sysv ipc limits. */
+
+void
+glibtop_get_shm_limits_p (glibtop *server, glibtop_shm_limits *buf)
+{
+ glibtop_init_p (server, (1L << GLIBTOP_SYSDEPS_SHM_LIMITS), 0);
+
+ memset (buf, 0, sizeof (glibtop_shm_limits));
+
+ if (server->sysdeps.shm_limits == 0)
+ return;
+
+ buf->shmmax = _shminfo.shmmax;
+ buf->shmmin = _shminfo.shmmin;
+ buf->shmmni = _shminfo.shmmni;
+ buf->shmseg = _shminfo.shmseg;
+ buf->shmall = _shminfo.shmall;
+
+ buf->flags = _glibtop_sysdeps_shm_limits;
+}
+
+#endif /* either a newer BSDI or no BSDI at all. */
+
diff --git a/sysdeps/freebsd/siglist.c b/sysdeps/freebsd/siglist.c
new file mode 100644
index 00000000..94abfdc6
--- /dev/null
+++ b/sysdeps/freebsd/siglist.c
@@ -0,0 +1,28 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <glibtop.h>
+#include <glibtop/signal.h>
+
+const glibtop_signame glibtop_sys_siglist [] =
+{ { 0, NULL, NULL } };
diff --git a/sysdeps/freebsd/swap.c b/sysdeps/freebsd/swap.c
new file mode 100644
index 00000000..d9669fa6
--- /dev/null
+++ b/sysdeps/freebsd/swap.c
@@ -0,0 +1,426 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <glibtop.h>
+#include <glibtop/error.h>
+#include <glibtop/swap.h>
+
+#include <glibtop/xmalloc.h>
+
+#include <glibtop_suid.h>
+
+static const unsigned long _glibtop_sysdeps_swap =
+(1L << GLIBTOP_SWAP_TOTAL) + (1L << GLIBTOP_SWAP_USED) +
+(1L << GLIBTOP_SWAP_FREE) + (1L << GLIBTOP_SWAP_PAGEIN) +
+(1L << GLIBTOP_SWAP_PAGEOUT);
+
+#if defined(__FreeBSD__) || defined(__bsdi__)
+
+#include <sys/conf.h>
+#ifdef __bsdi__
+#include <vm/swap_pager.h>
+#else
+#if __FreeBSD_version < 400005
+#include <sys/rlist.h>
+#endif
+#endif
+#include <sys/vmmeter.h>
+
+/* nlist structure for kernel access */
+
+#if defined(__bsdi__)
+static struct nlist nlst [] = {
+ { "_swapstats" }, /* general swap info */
+ { 0 }
+};
+#elif __FreeBSD__ < 4
+static struct nlist nlst [] = {
+#define VM_SWAPLIST 0
+ { "_swaplist" },/* list of free swap areas */
+#define VM_SWDEVT 1
+ { "_swdevt" }, /* list of swap devices and sizes */
+#define VM_NSWAP 2
+ { "_nswap" }, /* size of largest swap device */
+#define VM_NSWDEV 3
+ { "_nswdev" }, /* number of swap devices */
+#define VM_DMMAX 4
+ { "_dmmax" }, /* maximum size of a swap block */
+ { 0 }
+};
+#endif
+
+#elif defined(__NetBSD__)
+
+#if (__NetBSD_Version__ >= 104000000)
+#include <uvm/uvm_extern.h>
+#include <sys/swap.h>
+#else
+#include <vm/vm_swap.h>
+#endif
+
+#endif
+
+#if defined(__NetBSD__) && (__NetBSD_Version__ >= 104000000)
+static int mib_uvmexp [] = { CTL_VM, VM_UVMEXP };
+#else
+/* nlist structure for kernel access */
+static struct nlist nlst2 [] = {
+ { "_cnt" },
+ { 0 }
+};
+#endif
+
+/* Init function. */
+
+void
+glibtop_init_swap_p (glibtop *server)
+{
+#if defined(__FreeBSD__) || defined(__bsdi__)
+#if __FreeBSD__ < 4 || defined(__bsdi__)
+ if (kvm_nlist (server->machine.kd, nlst) < 0) {
+ glibtop_warn_io_r (server, "kvm_nlist (swap)");
+ return;
+ }
+#else
+ struct kvm_swap dummy;
+
+ if (kvm_getswapinfo (server->machine.kd, &dummy, 1, 0) != 0) {
+ glibtop_warn_io_r (server, "kvm_swap (swap)");
+ return;
+ }
+#endif
+#endif
+
+#if !(defined(__NetBSD__) && (__NetBSD_Version__ >= 104000000))
+ if (kvm_nlist (server->machine.kd, nlst2) < 0) {
+ glibtop_warn_io_r (server, "kvm_nlist (cnt)");
+ return;
+ }
+#endif
+
+ server->sysdeps.swap = _glibtop_sysdeps_swap;
+}
+
+/* Provides information about swap usage. */
+
+/*
+ * This function is based on a program called swapinfo written
+ * by Kevin Lahey <kml@rokkaku.atl.ga.us>.
+ */
+
+void
+glibtop_get_swap_p (glibtop *server, glibtop_swap *buf)
+{
+#if defined(__FreeBSD__)
+
+# if __FreeBSD__ < 4
+ char *header;
+ int hlen, nswdev, dmmax;
+ int div, nfree, npfree;
+ struct swdevt *sw;
+ long blocksize, *perdev;
+ struct rlist head;
+ struct rlisthdr swaplist;
+ struct rlist *swapptr;
+ size_t sw_size;
+ u_long ptr;
+# else
+ int nswdev;
+ struct kvm_swap kvmsw[16];
+# endif
+
+#elif defined(__bsdi__)
+ struct swapstats swap;
+#elif defined(__NetBSD__)
+ struct swapent *swaplist;
+#endif
+
+ int nswap, i;
+ int avail = 0, inuse = 0;
+
+#if defined(__NetBSD__) && (__NetBSD_Version__ >= 104000000)
+ struct uvmexp uvmexp;
+ size_t length_uvmexp;
+#else
+ /* To get `pagein' and `pageout'. */
+ struct vmmeter vmm;
+#endif
+ static int swappgsin = -1;
+ static int swappgsout = -1;
+
+ glibtop_init_p (server, (1L << GLIBTOP_SYSDEPS_SWAP), 0);
+
+ memset (buf, 0, sizeof (glibtop_swap));
+
+ if (server->sysdeps.swap == 0)
+ return;
+
+#if defined(__NetBSD__) && (__NetBSD_Version__ >= 104000000)
+ length_uvmexp = sizeof (uvmexp);
+ if (sysctl (mib_uvmexp, 2, &uvmexp, &length_uvmexp, NULL, 0)) {
+ glibtop_warn_io_r (server, "sysctl (uvmexp)");
+ return;
+ }
+#else
+ /* This is used to get the `pagein' and `pageout' members. */
+
+ if (kvm_read (server->machine.kd, nlst2[0].n_value,
+ &vmm, sizeof (vmm)) != sizeof (vmm)) {
+ glibtop_warn_io_r (server, "kvm_read (cnt)");
+ return;
+ }
+#endif
+
+ if (swappgsin < 0) {
+ buf->pagein = 0;
+ buf->pageout = 0;
+ } else {
+#ifdef __FreeBSD__
+ buf->pagein = vmm.v_swappgsin - swappgsin;
+ buf->pageout = vmm.v_swappgsout - swappgsout;
+#else
+#if defined(__NetBSD__) && (__NetBSD_Version__ >= 104000000)
+ buf->pagein = uvmexp.swapins - swappgsin;
+ buf->pageout = uvmexp.swapouts - swappgsout;
+#else
+ buf->pagein = vmm.v_swpin - swappgsin;
+ buf->pageout = vmm.v_swpout - swappgsout;
+#endif
+#endif
+ }
+
+#ifdef __FreeBSD__
+ swappgsin = vmm.v_swappgsin;
+ swappgsout = vmm.v_swappgsout;
+#else
+#if defined(__NetBSD__) && (__NetBSD_Version__ >= 104000000)
+ swappgsin = uvmexp.swapins;
+ swappgsout = uvmexp.swapouts;
+#else
+ swappgsin = vmm.v_swpin;
+ swappgsout = vmm.v_swpout;
+#endif
+#endif
+
+#if defined(__FreeBSD__)
+
+#if __FreeBSD__ < 4
+
+ /* Size of largest swap device. */
+
+ if (kvm_read (server->machine.kd, nlst[VM_NSWAP].n_value,
+ &nswap, sizeof (nswap)) != sizeof (nswap)) {
+ glibtop_warn_io_r (server, "kvm_read (nswap)");
+ return;
+ }
+
+ /* Number of swap devices. */
+
+ if (kvm_read (server->machine.kd, nlst[VM_NSWDEV].n_value,
+ &nswdev, sizeof (nswdev)) != sizeof (nswdev)) {
+ glibtop_warn_io_r (server, "kvm_read (nswdev)");
+ return;
+ }
+
+ /* Maximum size of a swap block. */
+
+ if (kvm_read (server->machine.kd, nlst[VM_DMMAX].n_value,
+ &dmmax, sizeof (dmmax)) != sizeof (dmmax)) {
+ glibtop_warn_io_r (server, "kvm_read (dmmax)");
+ return;
+ }
+
+ /* List of free swap areas. */
+
+ if (kvm_read (server->machine.kd, nlst[VM_SWAPLIST].n_value,
+ &swaplist, sizeof (swaplist)) != sizeof (swaplist)) {
+ glibtop_warn_io_r (server, "kvm_read (swaplist)");
+ return;
+ }
+
+ /* Kernel offset of list of swap devices and sizes. */
+
+ if (kvm_read (server->machine.kd, nlst[VM_SWDEVT].n_value,
+ &ptr, sizeof (ptr)) != sizeof (ptr)) {
+ glibtop_warn_io_r (server, "kvm_read (swdevt)");
+ return;
+ }
+
+ /* List of swap devices and sizes. */
+
+ sw_size = nswdev * sizeof (*sw);
+ sw = glibtop_malloc_r (server, sw_size);
+
+ if (kvm_read (server->machine.kd, ptr, sw, sw_size) != (ssize_t)sw_size) {
+ glibtop_warn_io_r (server, "kvm_read (*swdevt)");
+ return;
+ }
+
+ perdev = glibtop_malloc (nswdev * sizeof (*perdev));
+
+ /* Count up swap space. */
+
+ nfree = 0;
+ memset (perdev, 0, nswdev * sizeof(*perdev));
+
+ swapptr = swaplist.rlh_list;
+
+ while (swapptr) {
+ int top, bottom, next_block;
+
+ if (kvm_read (server->machine.kd, (int) swapptr, &head,
+ sizeof (struct rlist)) != sizeof (struct rlist)) {
+ glibtop_warn_io_r (server, "kvm_read (swapptr)");
+ return;
+ }
+
+ top = head.rl_end;
+ bottom = head.rl_start;
+
+ nfree += top - bottom + 1;
+
+ /*
+ * Swap space is split up among the configured disks.
+ *
+ * For interleaved swap devices, the first dmmax blocks
+ * of swap space some from the first disk, the next dmmax
+ * blocks from the next, and so on up to nswap blocks.
+ *
+ * The list of free space joins adjacent free blocks,
+ * ignoring device boundries. If we want to keep track
+ * of this information per device, we'll just have to
+ * extract it ourselves.
+ */
+ while (top / dmmax != bottom / dmmax) {
+ next_block = ((bottom + dmmax) / dmmax);
+ perdev[(bottom / dmmax) % nswdev] +=
+ next_block * dmmax - bottom;
+ bottom = next_block * dmmax;
+ }
+ perdev[(bottom / dmmax) % nswdev] +=
+ top - bottom + 1;
+
+ swapptr = head.rl_next;
+ }
+
+ header = getbsize (&hlen, &blocksize);
+
+ div = blocksize / 512;
+ avail = npfree = 0;
+ for (i = 0; i < nswdev; i++) {
+ int xsize, xfree;
+
+ /*
+ * Don't report statistics for partitions which have not
+ * yet been activated via swapon(8).
+ */
+ if (!(sw[i].sw_flags & SW_FREED))
+ continue;
+
+ /* The first dmmax is never allocated to avoid trashing of
+ * disklabels
+ */
+ xsize = sw[i].sw_nblks - dmmax;
+ xfree = perdev[i];
+ inuse = xsize - xfree;
+ npfree++;
+ avail += xsize;
+ }
+
+ /*
+ * If only one partition has been set up via swapon(8), we don't
+ * need to bother with totals.
+ */
+ inuse = avail - nfree;
+
+ glibtop_free_r (server, sw);
+ glibtop_free_r (server, perdev);
+
+ buf->flags = _glibtop_sysdeps_swap;
+
+ buf->used = inuse;
+ buf->free = avail;
+
+ buf->total = inuse + avail;
+
+#else
+
+ nswdev = kvm_getswapinfo(server->machine.kd, kvmsw, 16, 0);
+
+ buf->flags = _glibtop_sysdeps_swap;
+
+ buf->used = kvmsw[nswdev].ksw_used;
+ buf->total = kvmsw[nswdev].ksw_total;
+
+ buf->free = buf->total - buf->used;
+
+#endif
+
+#elif defined(__bsdi__)
+
+ /* General info about swap devices. */
+
+ if (kvm_read (server->machine.kd, nlst[0].n_value,
+ &swap, sizeof (swap)) != sizeof (swap)) {
+ glibtop_warn_io_r (server, "kvm_read (swap)");
+ return;
+ }
+
+ buf->flags = _glibtop_sysdeps_swap;
+
+ buf->used = swap.swap_total - swap.swap_free;
+ buf->free = swap.swap_free;
+
+ buf->total = swap.swap_total;
+
+#elif defined(__NetBSD__)
+
+ nswap = swapctl (SWAP_NSWAP, NULL, 0);
+ if (nswap < 0) {
+ glibtop_warn_io_r (server, "swapctl (SWAP_NSWAP)");
+ return;
+ }
+
+ swaplist = glibtop_calloc_r (server, nswap, sizeof (struct swapent));
+
+ if (swapctl (SWAP_STATS, swaplist, nswap) != nswap) {
+ glibtop_warn_io_r (server, "swapctl (SWAP_STATS)");
+ glibtop_free_r (server, swaplist);
+ return;
+ }
+
+ for (i = 0; i < nswap; i++) {
+ avail += swaplist[i].se_nblks;
+ inuse += swaplist[i].se_inuse;
+ }
+
+ glibtop_free_r (server, swaplist);
+
+ buf->flags = _glibtop_sysdeps_swap;
+
+ buf->used = inuse;
+ buf->free = avail;
+
+ buf->total = inuse + avail;
+#endif
+}
diff --git a/sysdeps/freebsd/uptime.c b/sysdeps/freebsd/uptime.c
new file mode 100644
index 00000000..250a72d1
--- /dev/null
+++ b/sysdeps/freebsd/uptime.c
@@ -0,0 +1,73 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <glibtop.h>
+#include <glibtop/error.h>
+#include <glibtop/uptime.h>
+
+#include <glibtop/cpu.h>
+
+#include <glibtop_suid.h>
+
+static const unsigned long _glibtop_sysdeps_uptime =
+(1L << GLIBTOP_UPTIME_UPTIME) + (1L << GLIBTOP_UPTIME_IDLETIME);
+
+static const unsigned long _required_cpu_flags =
+(1L << GLIBTOP_CPU_TOTAL) + (1L << GLIBTOP_CPU_IDLE) +
+(1L << GLIBTOP_CPU_FREQUENCY);
+
+/* Init function. */
+
+void
+glibtop_init_uptime_p (glibtop *server)
+{
+ server->sysdeps.uptime = _glibtop_sysdeps_uptime;
+}
+
+/* Provides uptime and idle time. */
+
+void
+glibtop_get_uptime_p (glibtop *server, glibtop_uptime *buf)
+{
+ glibtop_cpu cpu;
+
+ glibtop_init_p (server, (1L << GLIBTOP_SYSDEPS_UPTIME), 0);
+
+ memset (buf, 0, sizeof (glibtop_uptime));
+
+ /* We simply calculate it from the CPU usage. */
+
+ glibtop_get_cpu_p (server, &cpu);
+
+ /* Make sure all required fields are present. */
+
+ if ((cpu.flags & _required_cpu_flags) != _required_cpu_flags)
+ return;
+
+ /* Calculate values. */
+
+ buf->uptime = (double) cpu.total / (double) cpu.frequency;
+ buf->idletime = (double) cpu.idle / (double) cpu.frequency;
+
+ buf->flags = _glibtop_sysdeps_uptime;
+}
diff --git a/sysdeps/guile/.cvsignore b/sysdeps/guile/.cvsignore
new file mode 100644
index 00000000..db2bb60f
--- /dev/null
+++ b/sysdeps/guile/.cvsignore
@@ -0,0 +1,9 @@
+.deps
+.libs
+Makefile
+Makefile.in
+guile.c
+so_locations
+libgtop_guile.la
+*.lo
+*.x
diff --git a/sysdeps/guile/ChangeLog b/sysdeps/guile/ChangeLog
new file mode 100644
index 00000000..7e59c460
--- /dev/null
+++ b/sysdeps/guile/ChangeLog
@@ -0,0 +1,50 @@
+1999-02-04 Martin Baulig <martin@home-of-linux.org>
+
+ * names/guile-names.awk: Use `_' instead of `gettext'.
+
+1999-01-22 Martin Baulig <martin@home-of-linux.org>
+
+ * names/guile-names.awk: Use a `(TYPE . DIMENSION)' pair for
+ array types in `glibtop-types-*'.
+
+1998-12-09 Martin Baulig <martin@home-of-linux.org>
+
+ * guile.awk: For arrays, make a gh_list out of it and add this list
+ to the returned list instead of adding all array fields there.
+
+1998-12-08 Martin Baulig <martin@home-of-linux.org>
+
+ * guile.awk (glibtop-get-sysdeps): New guile function.
+
+ * guile.awk (glibtop_get_proc_map): Make a gh_list for each map
+ entry and append all of them to the returned list.
+ (glibtop_get_mountlist): Likewise.
+
+1998-10-20 Martin Baulig <martin@home-of-linux.org>
+
+ * guile.awk: If the features.def contains something like
+ `fieldname[number]' we interpret this as an array and add all
+ members of this array.
+
+1998-10-12 Martin Baulig <martin@home-of-linux.org>
+
+ * Makefile.am: Let the `Makefile' depend upon $(BUILT_SOURCES).
+ This is required to get dependencies correctly.
+ * names/Makefile.am: Likewise.
+
+1998-10-11 Martin Baulig <martin@home-of-linux.org>
+
+ * names/Makefile.am (BUILT_SOURCES, CLEANFILES): Added
+ `guile-names.x' here and a rule to make it from `guile-names.c'
+ using guile-snarf.
+
+ * names/guile-names.awk: Use the SCM_GLOBAL_VCELL macros and
+ guile-snarf here; declared all `glibtop_guile_*' functions static.
+
+ * guile.awk: Declared all `glibtop_guile_get_*' functions static.
+
+ * Makefile.am (BUILT_SOURCES, CLEANFILES): Added `guile.x'.
+ Added rule to make `guile.x' from `guile.c' using guile-snarf.
+
+ * guile.awk: Use the SCM_PROC macros and guile-snarf here.
+
diff --git a/sysdeps/guile/Makefile.am b/sysdeps/guile/Makefile.am
new file mode 100644
index 00000000..518180e9
--- /dev/null
+++ b/sysdeps/guile/Makefile.am
@@ -0,0 +1,27 @@
+SUBDIRS = names
+
+LINK = $(LIBTOOL) --mode=link $(CC) $(CFLAGS) $(LDFLAGS) -o $@
+
+INCLUDES = @INCLUDES@
+
+BUILT_SOURCES = guile.c guile.x
+
+lib_LTLIBRARIES = libgtop_guile-2.0.la
+
+libgtop_guile_2_0_la_SOURCES = $(BUILT_SOURCES)
+
+libgtop_guile_2_0_la_LDFLAGS = $(LT_VERSION_INFO)
+
+Makefile: $(BUILT_SOURCES)
+
+guile.c: guile.pl $(top_builddir)/config.h $(top_srcdir)/features.def
+ $(PERL) $(srcdir)/guile.pl < $(top_srcdir)/features.def > gnc-t
+ mv gnc-t guile.c
+
+guile.x: guile.c
+ guile-snarf $(DEFS) $(INCLUDES) $(CPPFLAGS) $(CFLAGS) $< > $@
+
+EXTRA_DIST = guile.pl
+
+CLEANFILES = guile.c guile.x
+
diff --git a/sysdeps/guile/guile.pl b/sysdeps/guile/guile.pl
new file mode 100644
index 00000000..7a272ebc
--- /dev/null
+++ b/sysdeps/guile/guile.pl
@@ -0,0 +1,274 @@
+#!/usr/bin/perl
+
+$[ = 1; # set array base to 1
+$, = ' '; # set output field separator
+$\ = "\n"; # set output record separator
+
+sub toupper {
+ local($_) = @_;
+ tr/a-z/A-Z/;
+ return $_;
+}
+
+sub tolower {
+ local($_) = @_;
+ tr/A-Z/a-z/;
+ return $_;
+}
+
+print '/* guile.c */';
+print "/* This is a generated file. Please modify `guile.pl' */";
+print '';
+
+print '#include <glibtop.h>';
+print '#include <glibtop/xmalloc.h>';
+print '#include <glibtop/sysdeps.h>';
+print '#include <glibtop/union.h>';
+print '';
+print '#include <guile/gh.h>';
+
+print '';
+
+$convert{'long'} = 'gh_long2scm ';
+$convert{'ulong'} = 'gh_ulong2scm ';
+$convert{'double'} = 'gh_double2scm';
+$convert{'str'} = 'gh_str02scm ';
+$convert{'char'} = 'gh_char2scm ';
+
+$backconv{'int'} = 'gh_scm2long';
+$backconv{'pid_t'} = 'gh_scm2ulong';
+$backconv{'long'} = 'gh_scm2long';
+$backconv{'ulong'} = 'gh_scm2ulong';
+$backconv{'unsigned'} = 'gh_scm2ulong';
+
+$feature_count = 0;
+
+while (<>) {
+ chop; # strip record separator
+
+ if (/^[^#]/) {
+ &make_output($_);
+ }
+}
+
+$sep = '';
+$sysdeps = 'void|sysdeps|ulong(';
+for ($nr = 0; $nr < $feature_count; $nr++) {
+ $sysdeps = $sysdeps . '' . $sep . '' . $feature_field{$nr};
+ $sep = ',';
+}
+$sysdeps = $sysdeps . ')';
+&make_output($sysdeps);
+print 'void';
+print 'glibtop_boot_guile (void)';
+print '{';
+print "#include \"guile.x\"";
+print '}';
+
+sub make_output {
+ local($line) = @_;
+ @line_fields = split(/\|/, $line, 9999);
+ $retval = $line_fields[1];
+ $element_def = $line_fields[3];
+ $feature = $line_fields[2];
+ $param_def = $line_fields[4];
+
+ $feature =~ s/^@//;
+ $features{$feature} = $feature;
+
+ $feature_field{$feature_count} = $feature;
+ $feature_count = $feature_count + 1;
+
+ $total_nr_params = 0;
+
+ if ($param_def eq 'string') {
+ $call_param = ', gh_scm2newstr( ' . $line_fields[5] . ', NULL)';
+ $param_decl = 'SCM ' . $line_fields[5];
+ $total_nr_params = 1;
+ }
+ else {
+ $call_param = '';
+ $param_decl = '';
+ $nr_params = (@params = split(/:/, $param_def, 9999));
+ for ($param = 1; $param <= $nr_params; $param++) {
+ $list = $params[$param];
+ $type = $params[$param];
+ $type =~ s/\(.*//;
+ $list =~ s/^.*\(//;
+ $list =~ s/\)$//;
+ $count = (@fields = split(/,/, $list, 9999));
+ $total_nr_params = $total_nr_params + $count;
+ for ($field = 1; $field <= $count; $field++) {
+ if ($param_decl ne '') {
+ $param_decl = $param_decl . ', ';
+ }
+ $param_decl = $param_decl . 'SCM ' . $fields[$field];
+ $call_param = $call_param . ', ' . $backconv{$type} . ' (' .
+
+ $fields[$field] . ')';
+ }
+ }
+ if ($param_decl eq '') {
+ $param_decl = 'void';
+ }
+ }
+
+ $nr_params_field{$feature} = $total_nr_params;
+
+ $feature_name = $feature;
+ $feature_name =~ s/_/-/;
+ $output = 'SCM_PROC (s_' . $feature . ", \"glibtop-get-" . $feature_name .
+
+ "\",";
+ $output = $output . ' ' . $nr_params_field{$feature} . ', 0, 0, ';
+ $output = $output . 'glibtop_guile_get_' . $feature . ");\n\n";
+
+ $output = $output . "static SCM\nglibtop_guile_get_" . $feature . ' (' .
+
+ $param_decl . ")\n{\n";
+
+ $output = $output . "\tglibtop_" . $feature . ' ' . $feature . ";\n";
+ if ($retval ne 'void') {
+ $output = $output . "\t" . $retval . " retval;\n";
+ }
+ if ($feature =~ /^(proc(list|_map|_args))|mountlist$/) {
+ $output = $output . "\tunsigned i;\n";
+ }
+ if ($feature =~ /^proc_args$/) {
+ $output = $output . "\tSCM list, scm_args, args_list;\n";
+ $output = $output . "\tchar *start;\n\n";
+ }
+ else {
+ $output = $output . "\tSCM list;\n\n";
+ }
+ if ($retval ne 'void') {
+ $prefix = 'retval = ';
+ }
+ else {
+ $prefix = '';
+ }
+ $output = $output . "\t" . $prefix . 'glibtop_get_' . $feature . ' (&' .
+
+ $feature . '' . $call_param . ");\n\n";
+
+ $output = $output . "\tlist = gh_list (gh_ulong2scm (" . $feature .
+
+ ".flags),\n\t\t\t";
+
+ $nr_elements = (@elements = split(/:/, $element_def, 9999));
+ for ($element = 1; $element <= $nr_elements; $element++) {
+ $list = $elements[$element];
+ $type = $elements[$element];
+ $type =~ s/\(.*//;
+ $list =~ s/^.*\(//;
+ $list =~ s/\)$//;
+ $count = (@fields = split(/,/, $list, 9999));
+ for ($field = 1; $field <= $count; $field++) {
+ if ($fields[$field] =~ /^(\w+)\[([0-9]+)\]$/) {
+ @field_parts = split(/\[/, $fields[$field], 9999);
+ $fields[$field] = $field_parts[1];
+ $field_parts[2] =~ s/\]//;
+ $number = $field_parts[2];
+ $output = $output . "gh_list\n\t\t\t(";
+ for ($nr = 0; $nr < $number; $nr++) {
+ $output = $output . '' . $convert{$type} . ' (' . $feature
+
+ . '.' . $fields[$field] . ' [' . $nr . "]),\n\t\t\t ";
+ }
+ $output = $output . "SCM_UNDEFINED),\n\t\t\t";
+ }
+ else {
+ $output = $output . '' . $convert{$type} . ' (' . $feature .
+
+ '.' . $fields[$field] . "),\n\t\t\t";
+ }
+ }
+ }
+ $output = $output . "SCM_UNDEFINED);\n";
+
+ print $output;
+
+ if ($feature =~ /^proclist$/) {
+ print "\tif (retval == NULL)";
+ print "\t\treturn list;";
+ print '';
+ print "\tfor (i = 0; i < proclist.number; i++)";
+ print "\t\tlist = scm_append";
+ print "\t\t\t(gh_list (list,";
+ print
+
+ "\t\t\t\t gh_list (gh_ulong2scm ((unsigned long) retval [i])),";
+ print "\t\t\t\t SCM_UNDEFINED));";
+ print '';
+ print "\tglibtop_free (retval);\n";
+ }
+
+ if ($feature =~ /^proc_map$/) {
+ print "\tif (retval == NULL)";
+ print "\t\treturn list;";
+ print '';
+ print "\tfor (i = 0; i < proc_map.number; i++) {";
+ print "\t\tglibtop_map_entry *entry = &(retval [i]);";
+ print "\t\tSCM scm_entry = gh_list";
+ print "\t\t\t(gh_ulong2scm ((unsigned long) entry->flags),";
+ print "\t\t\t gh_ulong2scm ((unsigned long) entry->start),";
+ print "\t\t\t gh_ulong2scm ((unsigned long) entry->end),";
+ print "\t\t\t gh_ulong2scm ((unsigned long) entry->offset),";
+ print "\t\t\t gh_ulong2scm ((unsigned long) entry->perm),";
+ print "\t\t\t gh_ulong2scm ((unsigned long) entry->inode),";
+ print "\t\t\t gh_ulong2scm ((unsigned long) entry->device),";
+ print "\t\t\t gh_str02scm (entry->filename), SCM_UNDEFINED);";
+ print "\t\tSCM entry_list = gh_list (scm_entry, SCM_UNDEFINED);\n";
+
+ print
+
+ "\t\tlist = scm_append (gh_list (list, entry_list, SCM_UNDEFINED));";
+ print "\t};\n";
+ print "\tglibtop_free (retval);\n";
+ }
+
+ if ($feature =~ /^proc_args$/) {
+ print "\tif (retval == NULL)";
+ print "\t\treturn list;";
+ print '';
+ print "\tstart = retval;";
+ print "\tscm_args = gh_list (SCM_UNDEFINED);\n";
+ print "\tfor (i = 0; i <= proc_args.size; i++) {";
+ print "\t\tSCM arg_list;\n";
+ print "\t\tif (retval [i]) continue;\n";
+ print "\t\targ_list = gh_list (gh_str02scm (start), SCM_UNDEFINED);";
+ print "\t\tscm_args = scm_append";
+ print "\t\t\t(gh_list (scm_args, arg_list, SCM_UNDEFINED));\n;";
+ print "\t\tstart = &(retval [i+1]);";
+ print "\t};\n";
+ print "\targs_list = gh_list (scm_args, SCM_UNDEFINED);";
+ print
+
+ "\tlist = scm_append (gh_list (list, args_list, SCM_UNDEFINED));\n";
+ print "\tglibtop_free (retval);\n";
+ }
+
+ if ($feature =~ /^mountlist$/) {
+ print "\tif (retval == NULL)";
+ print "\t\treturn list;";
+ print '';
+ print "\tfor (i = 0; i < mountlist.number; i++) {";
+ print "\t\tglibtop_mountentry *entry = &(retval [i]);";
+ print "\t\tSCM scm_entry = gh_list";
+ print "\t\t\t(gh_ulong2scm ((unsigned long) entry->dev),";
+ print "\t\t\t gh_str02scm (entry->devname),";
+ print "\t\t\t gh_str02scm (entry->mountdir),";
+ print "\t\t\t gh_str02scm (entry->type), SCM_UNDEFINED);";
+ print "\t\tSCM entry_list = gh_list (scm_entry, SCM_UNDEFINED);\n";
+
+ print
+
+ "\t\tlist = scm_append (gh_list (list, entry_list, SCM_UNDEFINED));";
+ print "\t};\n";
+ print "\tglibtop_free (retval);\n";
+ }
+
+ print "\treturn list;";
+ print '}';
+ print '';
+}
diff --git a/sysdeps/guile/names/.cvsignore b/sysdeps/guile/names/.cvsignore
new file mode 100644
index 00000000..f2bf91eb
--- /dev/null
+++ b/sysdeps/guile/names/.cvsignore
@@ -0,0 +1,10 @@
+.deps
+so_locations
+.libs
+Makefile
+guile-names.c
+Makefile.in
+libgtop_guile.la
+libgtop_guile_names.la
+*.lo
+*.x
diff --git a/sysdeps/guile/names/Makefile.am b/sysdeps/guile/names/Makefile.am
new file mode 100644
index 00000000..a5dcf077
--- /dev/null
+++ b/sysdeps/guile/names/Makefile.am
@@ -0,0 +1,25 @@
+LINK = $(LIBTOOL) --mode=link $(CC) $(CFLAGS) $(LDFLAGS) -o $@
+
+INCLUDES = @INCLUDES@
+
+lib_LTLIBRARIES = libgtop_guile_names-2.0.la
+
+BUILT_SOURCES = guile-names.c guile-names.x
+
+libgtop_guile_names_2_0_la_SOURCES = $(BUILT_SOURCES)
+
+libgtop_guile_names_2_0_la_LDFLAGS = $(LT_VERSION_INFO)
+
+Makefile: $(BUILT_SOURCES)
+
+guile-names.c: guile-names.pl $(top_builddir)/config.h $(top_srcdir)/features.def
+ $(PERL) $(srcdir)/guile-names.pl < $(top_srcdir)/features.def > gnc-t
+ mv gnc-t guile-names.c
+
+guile-names.x: guile-names.c
+ guile-snarf $(DEFS) $(INCLUDES) $(CPPFLAGS) $(CFLAGS) $< > $@
+
+EXTRA_DIST = guile-names.pl
+
+CLEANFILES = guile-names.c guile-names.x
+
diff --git a/sysdeps/guile/names/guile-names.pl b/sysdeps/guile/names/guile-names.pl
new file mode 100644
index 00000000..bdfb2941
--- /dev/null
+++ b/sysdeps/guile/names/guile-names.pl
@@ -0,0 +1,197 @@
+#!/usr/bin/perl
+
+$[ = 1; # set array base to 1
+$, = ' '; # set output field separator
+$\ = "\n"; # set output record separator
+
+sub toupper {
+ local($_) = @_;
+ tr/a-z/A-Z/;
+ return $_;
+}
+
+sub tolower {
+ local($_) = @_;
+ tr/A-Z/a-z/;
+ return $_;
+}
+
+print '/* guile_names.c */';
+print "/* This is a generated file. Please modify `guile-names.pl' */";
+print '';
+
+print '#include <glibtop.h>';
+print '#include <glibtop/sysdeps.h>';
+print '#include <glibtop/union.h>';
+print '';
+print '#include <guile/gh.h>';
+
+print '';
+
+while (<>) {
+ chop; # strip record separator
+
+ if (/^[^#]/) {
+ $line = $_;
+ @line_fields = split(/\|/, $line, 9999);
+ $feature = $line_fields[2];
+ $element_def = $line_fields[3];
+ $feature =~ s/^@//;
+
+ $features{$feature} = $feature;
+ $element_defs{$feature} = $element_def;
+ }
+}
+
+$features{'sysdeps'} = 'sysdeps';
+
+foreach $feature (keys %features) {
+ &output($feature);
+}
+
+foreach $feature (keys %features) {
+ $feature_name = $feature;
+ $feature_name =~ s/_/-/;
+ print 'SCM_GLOBAL_VCELL (s_names_' . $feature . ", \"glibtop-names-" .
+
+ $feature_name . "\");";
+ print 'SCM_GLOBAL_VCELL (s_labels_' . $feature . ", \"glibtop-labels-" .
+
+ $feature_name . "\");";
+ print 'SCM_GLOBAL_VCELL (s_types_' . $feature . ", \"glibtop-types-" .
+
+ $feature_name . "\");";
+ print 'SCM_GLOBAL_VCELL (s_descriptions_' . $feature .
+
+ ", \"glibtop-descriptions-" . $feature_name . "\");";
+}
+print '';
+
+print 'void';
+print 'glibtop_boot_guile_names (void)';
+print '{';
+print "#include \"guile-names.x\"";
+foreach $feature (keys %features) {
+ print 'SCM_SETCDR (s_names_' . $feature . ', glibtop_guile_names_' .
+
+ $feature . ' ());';
+ print 'SCM_SETCDR (s_labels_' . $feature . ', glibtop_guile_labels_' .
+
+ $feature . ' ());';
+ print 'SCM_SETCDR (s_types_' . $feature . ', glibtop_guile_types_' .
+
+ $feature . ' ());';
+ print 'SCM_SETCDR (s_descriptions_' . $feature .
+
+ ', glibtop_guile_descriptions_' . $feature . ' ());';
+}
+print '}';
+
+sub output {
+ local($feature) = @_;
+ print 'static SCM';
+ print 'glibtop_guile_names_' . $feature . ' (void)';
+ print '{';
+ print "\tint i;";
+ print "\tSCM list;";
+ print '';
+ print "\tlist = gh_list (SCM_UNDEFINED);";
+ print '';
+ print "\tfor (i = 0; i < GLIBTOP_MAX_" . &toupper($feature) . '; i++)';
+ print "\t\tlist = scm_append";
+ print "\t\t\t(gh_list (list,";
+ print "\t\t\t\t gh_list (gh_str02scm ((char *) glibtop_names_" . $feature
+
+ . ' [i])),';
+ print "\t\t\t\t SCM_UNDEFINED));";
+ print '';
+ print "\treturn list;";
+ print '}';
+
+ print '';
+
+ print 'static SCM';
+ print 'glibtop_guile_types_' . $feature . ' (void)';
+ print '{';
+ print "\tSCM list;";
+ print '';
+
+ $out = "\tlist = gh_list (";
+
+ $nr_elements = (@elements = split(/:/, $element_defs{$feature}, 9999));
+ for ($element = 1; $element <= $nr_elements; $element++) {
+ $list = $elements[$element];
+ $type = $elements[$element];
+ $type =~ s/\(.*//;
+ $list =~ s/^.*\(//;
+ $list =~ s/\)$//;
+ $count = (@fields = split(/,/, $list, 9999));
+ for ($field = 1; $field <= $count; $field++) {
+ if ($fields[$field] =~ /^(\w+)\[([0-9]+)\]$/) {
+ @field_parts = split(/\[/, $fields[$field], 9999);
+ $fields[$field] = $field_parts[1];
+ $field_parts[2] =~ s/\]//;
+ $number = $field_parts[2];
+ $out = $out . "gh_cons\n\t\t\t";
+ $out = $out . '(gh_ulong2scm (glibtop_types_' . $feature .
+
+ ' [' . ($field - 1) . "]),\n\t\t\t";
+ $out = $out . ' gh_ulong2scm (' . $number . ")),\n\t\t\t";
+ }
+ else {
+ $out = $out . 'gh_ulong2scm (glibtop_types_' . $feature . ' ['
+
+ . ($field - 1) . "]),\n\t\t\t";
+ }
+ }
+ }
+
+ print $out . 'SCM_UNDEFINED);';
+ print '';
+ print "\treturn list;";
+ print '}';
+
+ print '';
+
+ print 'static SCM';
+ print 'glibtop_guile_labels_' . $feature . ' (void)';
+ print '{';
+ print "\tint i;";
+ print "\tSCM list;";
+ print '';
+ print "\tlist = gh_list (SCM_UNDEFINED);";
+ print '';
+ print "\tfor (i = 0; i < GLIBTOP_MAX_" . &toupper($feature) . '; i++)';
+ print "\t\tlist = scm_append";
+ print "\t\t\t(gh_list (list,";
+ print "\t\t\t\t gh_list (gh_str02scm (_(glibtop_labels_" . $feature .
+
+ ' [i]))),';
+ print "\t\t\t\t SCM_UNDEFINED));";
+ print '';
+ print "\treturn list;";
+ print '}';
+
+ print '';
+
+ print 'static SCM';
+ print 'glibtop_guile_descriptions_' . $feature . ' (void)';
+ print '{';
+ print "\tint i;";
+ print "\tSCM list;";
+ print '';
+ print "\tlist = gh_list (SCM_UNDEFINED);";
+ print '';
+ print "\tfor (i = 0; i < GLIBTOP_MAX_" . &toupper($feature) . '; i++)';
+ print "\t\tlist = scm_append";
+ print "\t\t\t(gh_list (list,";
+ print "\t\t\t\t gh_list (gh_str02scm (_(glibtop_descriptions_" . $feature
+
+ . ' [i]))),';
+ print "\t\t\t\t SCM_UNDEFINED));";
+ print '';
+ print "\treturn list;";
+ print '}';
+
+ print '';
+}
diff --git a/sysdeps/kernel/.cvsignore b/sysdeps/kernel/.cvsignore
new file mode 100644
index 00000000..b851d091
--- /dev/null
+++ b/sysdeps/kernel/.cvsignore
@@ -0,0 +1,28 @@
+.deps
+.libs
+Makefile
+Makefile.in
+close.lo
+cpu.lo
+init.lo
+ipc_limits.lo
+libgtop_sysdeps.la
+loadavg.lo
+mem.lo
+msg_limits.lo
+open.lo
+procdata.lo
+prockernel.lo
+proclist.lo
+procmem.lo
+procsegment.lo
+procsignal.lo
+procstate.lo
+proctime.lo
+procuid.lo
+sem_limits.lo
+shm_limits.lo
+swap.lo
+sysdeps.lo
+sysinfo.lo
+uptime.lo
diff --git a/sysdeps/kernel/ChangeLog b/sysdeps/kernel/ChangeLog
new file mode 100644
index 00000000..e833f0aa
--- /dev/null
+++ b/sysdeps/kernel/ChangeLog
@@ -0,0 +1,27 @@
+2001-10-17 Abel Cheung <maddog@linux.org.hk>
+
+ * Makefile.am: move header to $(includedir)/libgtop-1.0/glibtop.
+
+1998-10-26 Martin Baulig <martin@home-of-linux.org>
+
+ * netload.c: New file. Currently empty.
+
+1998-10-26 Martin Baulig <martin@home-of-linux.org>
+
+ * procargs.c: New file. Currently empty.
+
+1998-10-25 Martin Baulig <martin@home-of-linux.org>
+
+ * ppp.c: New file. Currently empty.
+
+1998-06-14 Martin Baulig <martin@home-of-linux.org>
+
+ * kernel.s: New file - declaration of the table () function
+ via _syscall3 (); due to a bug in egcs, we cannot put this
+ into a C file.
+
+1998-06-13 Martin Baulig <martin@home-of-linux.org>
+
+ The code in this directory fetches all information
+ directly from the kernel. It uses the new table ()
+ system call from the `kernel' directory.
diff --git a/sysdeps/kernel/Makefile.am b/sysdeps/kernel/Makefile.am
new file mode 100644
index 00000000..d632d1d0
--- /dev/null
+++ b/sysdeps/kernel/Makefile.am
@@ -0,0 +1,25 @@
+LINK = $(LIBTOOL) --mode=link $(CC) $(CFLAGS) $(LDFLAGS) -o $@
+
+INCLUDES = @INCLUDES@
+
+lib_LTLIBRARIES = libgtop_sysdeps-2.0.la
+
+libgtop_sysdeps_2_0_la_SOURCES = open.c close.c kernel.s cpu.c mem.c swap.c \
+ uptime.c loadavg.c shm_limits.c msg_limits.c \
+ sem_limits.c proclist.c procstate.c procuid.c \
+ proctime.c procmem.c procsignal.c prockernel.c \
+ procsegment.c siglist.c procargs.c procmap.c \
+ netload.c ppp.c
+
+libgtop_sysdeps_2_0_la_LDFLAGS = $(LT_VERSION_INFO)
+
+libgtopinclude_HEADERS = glibtop_server.h
+libgtopincludedir = $(includedir)/libgtop-2.0
+
+noinst_HEADERS = kernel.h
+
+kernel.o kernel.lo: $(srcdir)/kernel.s
+ rm -f kernel.o kernel.lo
+ $(AS) -o kernel.o $(srcdir)/kernel.s
+ cp kernel.o kernel.lo
+
diff --git a/sysdeps/kernel/close.c b/sysdeps/kernel/close.c
new file mode 100644
index 00000000..4262d2f0
--- /dev/null
+++ b/sysdeps/kernel/close.c
@@ -0,0 +1,30 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <glibtop/close.h>
+
+/* Closes pipe to gtop server. */
+
+void
+glibtop_close_s (glibtop *server)
+{ }
diff --git a/sysdeps/kernel/cpu.c b/sysdeps/kernel/cpu.c
new file mode 100644
index 00000000..1a7127ba
--- /dev/null
+++ b/sysdeps/kernel/cpu.c
@@ -0,0 +1,65 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <config.h>
+#include <glibtop/error.h>
+#include <glibtop/cpu.h>
+
+#include "kernel.h"
+
+static const unsigned long _glibtop_sysdeps_cpu =
+(1 << GLIBTOP_CPU_TOTAL) + (1 << GLIBTOP_CPU_USER) +
+(1 << GLIBTOP_CPU_NICE) + (1 << GLIBTOP_CPU_SYS) +
+(1 << GLIBTOP_CPU_IDLE) + (1 << GLIBTOP_CPU_FREQUENCY);
+
+/* Init function. */
+
+void
+glibtop_init_cpu_s (glibtop *server)
+{
+ server->sysdeps.cpu = _glibtop_sysdeps_cpu;
+}
+
+/* Provides information about cpu usage. */
+
+void
+glibtop_get_cpu_s (glibtop *server, glibtop_cpu *buf)
+{
+ union table tbl;
+
+ glibtop_init_s (&server, GLIBTOP_SYSDEPS_CPU, 0);
+
+ memset (buf, 0, sizeof (glibtop_cpu));
+
+ if (table (TABLE_CPU, &tbl, NULL))
+ glibtop_error_io_r (server, "table(TABLE_CPU)");
+
+ buf->flags = _glibtop_sysdeps_cpu;
+
+ buf->total = tbl.cpu.total;
+ buf->user = tbl.cpu.user;
+ buf->nice = tbl.cpu.nice;
+ buf->sys = tbl.cpu.sys;
+ buf->idle = tbl.cpu.idle;
+ buf->frequency = tbl.cpu.frequency;
+}
diff --git a/sysdeps/kernel/glibtop_private.h b/sysdeps/kernel/glibtop_private.h
new file mode 100644
index 00000000..dd8f47ea
--- /dev/null
+++ b/sysdeps/kernel/glibtop_private.h
@@ -0,0 +1,89 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, March 1999.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#ifndef __GLIBTOP_PRIVATE_H__
+#define __GLIBTOP_PRIVATE_H__
+
+#include <glibtop.h>
+#include <glibtop/error.h>
+
+#include <sys/param.h>
+#include <sys/sysctl.h>
+#include <sys/user.h>
+
+#undef LIBGTOP_VERSION
+#include <linux/libgtop.h>
+
+BEGIN_LIBGTOP_DECLS
+
+int
+glibtop_get_proc_data_stat_s (glibtop *server, libgtop_stat_t *stat);
+
+int
+glibtop_get_proc_data_mem_s (glibtop *server, libgtop_mem_t *mem);
+
+int
+glibtop_get_proc_data_swap_s (glibtop *server, libgtop_swap_t *swap);
+
+int
+glibtop_get_proc_data_proclist_s (glibtop *server,
+ libgtop_proclist_t *proclist,
+ u_int64_t which, u_int64_t arg);
+
+int
+glibtop_get_proc_data_proc_state_s (glibtop *server,
+ libgtop_proc_state_t *proc_state,
+ pid_t pid);
+
+int
+glibtop_get_proc_data_proc_mem_s (glibtop *server,
+ libgtop_proc_mem_t *proc_mem,
+ pid_t pid);
+
+int
+glibtop_get_proc_data_proc_signal_s (glibtop *server,
+ libgtop_proc_signal_t *proc_signal,
+ pid_t pid);
+
+int
+glibtop_get_proc_data_proc_kernel_s (glibtop *server,
+ libgtop_proc_kernel_t *proc_kernel,
+ pid_t pid);
+
+int
+glibtop_get_proc_data_proc_args_s (glibtop *server, pid_t pid,
+ char *result, size_t max_len);
+
+int
+glibtop_get_proc_data_proc_maps_s (glibtop *server, pid_t pid,
+ libgtop_proc_maps_t *result,
+ size_t max_len);
+
+int
+glibtop_get_proc_data_netload_s (glibtop *server,
+ libgtop_netload_t *netload,
+ const char *device);
+
+END_LIBGTOP_DECLS
+
+#endif /* __GLIBTOP_PRIVATE_H__ */
diff --git a/sysdeps/kernel/glibtop_server.h b/sysdeps/kernel/glibtop_server.h
new file mode 100644
index 00000000..b3822d47
--- /dev/null
+++ b/sysdeps/kernel/glibtop_server.h
@@ -0,0 +1,52 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#ifndef __GLIBTOP_SERVER_H__
+#define __GLIBTOP_SERVER_H__
+
+BEGIN_LIBGTOP_DECLS
+
+#define GLIBTOP_SUID_CPU 0
+#define GLIBTOP_SUID_MEM 0
+#define GLIBTOP_SUID_SWAP 0
+#define GLIBTOP_SUID_UPTIME 0
+#define GLIBTOP_SUID_LOADAVG 0
+#define GLIBTOP_SUID_SHM_LIMITS 0
+#define GLIBTOP_SUID_MSG_LIMITS 0
+#define GLIBTOP_SUID_SEM_LIMITS 0
+#define GLIBTOP_SUID_PROCLIST 0
+#define GLIBTOP_SUID_PROC_STATE 0
+#define GLIBTOP_SUID_PROC_UID 0
+#define GLIBTOP_SUID_PROC_MEM 0
+#define GLIBTOP_SUID_PROC_TIME 0
+#define GLIBTOP_SUID_PROC_SIGNAL 0
+#define GLIBTOP_SUID_PROC_KERNEL 0
+#define GLIBTOP_SUID_PROC_SEGMENT 0
+#define GLIBTOP_SUID_PROC_ARGS 0
+#define GLIBTOP_SUID_PROC_MAP 0
+#define GLIBTOP_SUID_NETLOAD 0
+#define GLIBTOP_SUID_PPP 0
+
+END_LIBGTOP_DECLS
+
+#endif
diff --git a/sysdeps/kernel/kernel.h b/sysdeps/kernel/kernel.h
new file mode 100644
index 00000000..bfa8ac9f
--- /dev/null
+++ b/sysdeps/kernel/kernel.h
@@ -0,0 +1,40 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#ifndef __GLIBTOP_KERNEL_KERNEL_H__
+#define __GLIBTOP_KERNEL_KERNEL_H__
+
+#include <linux/unistd.h>
+#include <linux/table.h>
+
+#include <sys/param.h>
+
+#include <syscall.h>
+
+BEGIN_LIBGTOP_DECLS
+
+extern int table (int, union table *, const void *);
+
+END_LIBGTOP_DECLS
+
+#endif
diff --git a/sysdeps/kernel/kernel.s b/sysdeps/kernel/kernel.s
new file mode 100644
index 00000000..d6b368c1
--- /dev/null
+++ b/sysdeps/kernel/kernel.s
@@ -0,0 +1,42 @@
+ .file "test.c"
+ .version "01.01"
+/ GNU C version egcs-2.90.29 980515 (egcs-1.0.3 release) (i686-pc-linux-gnu) compiled by GNU C version egcs-2.90.29 980515 (egcs-1.0.3 release).
+/ options passed: -O2 -Wall -W
+/ options enabled: -fdefer-pop -fcse-follow-jumps -fcse-skip-blocks
+/ -fexpensive-optimizations -fthread-jumps -fstrength-reduce -fpeephole
+/ -fforce-mem -ffunction-cse -finline -fkeep-static-consts -fcaller-saves
+/ -fpcc-struct-return -frerun-cse-after-loop -frerun-loop-opt
+/ -fschedule-insns2 -fcommon -fverbose-asm -fgnu-linker -fregmove
+/ -falias-check -fargument-alias -m80387 -mhard-float -mno-soft-float
+/ -mieee-fp -mfp-ret-in-387 -mschedule-prologue -mcpu=pentiumpro
+/ -march=pentium
+
+gcc2_compiled.:
+.text
+ .align 4
+.globl table
+ .type table,@function
+table:
+ pushl %ebp
+ movl %esp,%ebp
+ movl $190,%eax
+ pushl %ebx
+ movl 8(%ebp),%ebx
+ movl 12(%ebp),%ecx
+ movl 16(%ebp),%edx
+#APP
+ int $0x80
+#NO_APP
+ testl %eax,%eax
+ jge .L3
+ negl %eax
+ movl %eax,errno
+ movl $-1,%eax
+.L3:
+ movl -4(%ebp),%ebx
+ movl %ebp,%esp
+ popl %ebp
+ ret
+.Lfe1:
+ .size table,.Lfe1-table
+ .ident "GCC: (GNU) egcs-2.90.29 980515 (egcs-1.0.3 release)"
diff --git a/sysdeps/kernel/loadavg.c b/sysdeps/kernel/loadavg.c
new file mode 100644
index 00000000..a31712d9
--- /dev/null
+++ b/sysdeps/kernel/loadavg.c
@@ -0,0 +1,65 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <config.h>
+#include <glibtop/error.h>
+#include <glibtop/loadavg.h>
+
+#include "kernel.h"
+
+static const unsigned long _glibtop_sysdeps_loadavg =
+(1 << GLIBTOP_LOADAVG_LOADAVG) + (1 << GLIBTOP_LOADAVG_NR_RUNNING) +
+(1 << GLIBTOP_LOADAVG_NR_TASKS) + (1 << GLIBTOP_LOADAVG_LAST_PID);
+
+/* Init function. */
+
+void
+glibtop_init_loadavg_s (glibtop *server)
+{
+ server->sysdeps.loadavg = _glibtop_sysdeps_loadavg;
+}
+
+/* Provides load load averange. */
+
+void
+glibtop_get_loadavg_s (glibtop *server, glibtop_loadavg *buf)
+{
+ union table tbl;
+
+ glibtop_init_s (&server, GLIBTOP_SYSDEPS_LOADAVG, 0);
+
+ memset (buf, 0, sizeof (glibtop_loadavg));
+
+ if (table (TABLE_LOADAVG, &tbl, NULL))
+ glibtop_error_io_r (server, "table(TABLE_LOADAVG)");
+
+ buf->flags = _glibtop_sysdeps_loadavg;
+
+ buf->loadavg [0] = tbl.loadavg.loadavg [0];
+ buf->loadavg [1] = tbl.loadavg.loadavg [1];
+ buf->loadavg [2] = tbl.loadavg.loadavg [2];
+
+ buf->nr_running = tbl.loadavg.nr_running;
+ buf->nr_tasks = tbl.loadavg.nr_tasks;
+ buf->last_pid = tbl.loadavg.last_pid;
+}
diff --git a/sysdeps/kernel/mem.c b/sysdeps/kernel/mem.c
new file mode 100644
index 00000000..6e7e74d6
--- /dev/null
+++ b/sysdeps/kernel/mem.c
@@ -0,0 +1,68 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <config.h>
+#include <glibtop/error.h>
+#include <glibtop/mem.h>
+
+#include "kernel.h"
+
+static const unsigned long _glibtop_sysdeps_mem =
+(1 << GLIBTOP_MEM_TOTAL) + (1 << GLIBTOP_MEM_USED) +
+(1 << GLIBTOP_MEM_FREE) + (1 << GLIBTOP_MEM_SHARED) +
+(1 << GLIBTOP_MEM_BUFFER) + (1 << GLIBTOP_MEM_CACHED) +
+(1 << GLIBTOP_MEM_USER);
+
+/* Init function. */
+
+void
+glibtop_init_mem_s (glibtop *server)
+{
+ server->sysdeps.mem = _glibtop_sysdeps_mem;
+}
+
+/* Provides information about memory usage. */
+
+void
+glibtop_get_mem_s (glibtop *server, glibtop_mem *buf)
+{
+ union table tbl;
+
+ glibtop_init_s (&server, GLIBTOP_SYSDEPS_MEM, 0);
+
+ memset (buf, 0, sizeof (glibtop_mem));
+
+ if (table (TABLE_MEM, &tbl, NULL))
+ glibtop_error_io_r (server, "table(TABLE_MEM)");
+
+ buf->flags = _glibtop_sysdeps_mem;
+
+ buf->total = tbl.mem.total;
+ buf->used = tbl.mem.used;
+ buf->free = tbl.mem.free;
+ buf->shared = tbl.mem.shared;
+ buf->buffer = tbl.mem.buffer;
+ buf->cached = tbl.mem.cached;
+
+ buf->user = buf->total - buf->free - buf->shared - buf->buffer;
+}
diff --git a/sysdeps/kernel/msg_limits.c b/sysdeps/kernel/msg_limits.c
new file mode 100644
index 00000000..2ebd1b05
--- /dev/null
+++ b/sysdeps/kernel/msg_limits.c
@@ -0,0 +1,65 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <glibtop/msg_limits.h>
+
+#include <sys/ipc.h>
+#include <sys/msg.h>
+
+static const unsigned long _glibtop_sysdeps_msg_limits =
+(1 << GLIBTOP_IPC_MSGPOOL) + (1 << GLIBTOP_IPC_MSGMAP) +
+(1 << GLIBTOP_IPC_MSGMAX) + (1 << GLIBTOP_IPC_MSGMNB) +
+(1 << GLIBTOP_IPC_MSGMNI) + (1 << GLIBTOP_IPC_MSGSSZ) +
+(1 << GLIBTOP_IPC_MSGTQL);
+
+/* 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)
+{
+ struct msginfo msginfo;
+
+ glibtop_init_s (&server, GLIBTOP_SYSDEPS_MSG_LIMITS, 0);
+
+ memset (buf, 0, sizeof (glibtop_msg_limits));
+
+ buf->flags = _glibtop_sysdeps_msg_limits;
+
+ msgctl (0, IPC_INFO, (struct msqid_ds *) &msginfo);
+
+ buf->msgpool = msginfo.msgpool;
+ buf->msgmap = msginfo.msgmap;
+ buf->msgmax = msginfo.msgmax;
+ buf->msgmnb = msginfo.msgmnb;
+ buf->msgmni = msginfo.msgmni;
+ buf->msgssz = msginfo.msgssz;
+ buf->msgtql = msginfo.msgtql;
+}
diff --git a/sysdeps/kernel/netload.c b/sysdeps/kernel/netload.c
new file mode 100644
index 00000000..beebedba
--- /dev/null
+++ b/sysdeps/kernel/netload.c
@@ -0,0 +1,45 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, October 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <glibtop.h>
+#include <glibtop/error.h>
+#include <glibtop/netload.h>
+
+static const unsigned long _glibtop_sysdeps_netload = 0;
+
+/* Init function. */
+
+void
+glibtop_init_netload_s (glibtop *server)
+{
+ server->sysdeps.netload = _glibtop_sysdeps_netload;
+}
+
+/* Provides network statistics. */
+
+void
+glibtop_get_netload_s (glibtop *server, glibtop_netload *buf,
+ const char *interface)
+{
+ memset (buf, 0, sizeof (glibtop_netload));
+}
diff --git a/sysdeps/kernel/open.c b/sysdeps/kernel/open.c
new file mode 100644
index 00000000..bd4bf34b
--- /dev/null
+++ b/sysdeps/kernel/open.c
@@ -0,0 +1,63 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <glibtop/open.h>
+
+/* =====================================================
+ * Linux kernel version information for procps utilities
+ * Copyright (c) 1996 Charles Blake <cblake@bbn.com>
+ */
+#include <sys/utsname.h>
+
+#define LINUX_VERSION(x,y,z) (0x10000*(x) + 0x100*(y) + z)
+
+static int linux_version_code = 0;
+
+static void set_linux_version(void) {
+ static struct utsname uts;
+ int x = 0, y = 0, z = 0; /* cleared in case sscanf() < 3 */
+
+ if (linux_version_code) return;
+ if (uname(&uts) == -1) /* failure most likely implies impending death */
+ exit(1);
+ if (sscanf(uts.release, "%d.%d.%d", &x, &y, &z) < 3)
+ fprintf(stderr, /* *very* unlikely to happen by accident */
+ "Non-standard uts for running kernel:\n"
+ "release %s=%d.%d.%d gives version code %d\n",
+ uts.release, x, y, z, LINUX_VERSION(x,y,z));
+ linux_version_code = LINUX_VERSION(x, y, z);
+}
+
+/* ======================================================= */
+
+/* Opens pipe to gtop server. Returns 0 on success and -1 on error. */
+
+void
+glibtop_open_s (glibtop *server, const char *program_name,
+ const unsigned long features, const unsigned flags)
+{
+ server->name = program_name;
+
+ set_linux_version ();
+ server->os_version_code = (unsigned long) linux_version_code;
+}
diff --git a/sysdeps/kernel/ppp.c b/sysdeps/kernel/ppp.c
new file mode 100644
index 00000000..6d0905d5
--- /dev/null
+++ b/sysdeps/kernel/ppp.c
@@ -0,0 +1,44 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, October 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <glibtop.h>
+#include <glibtop/error.h>
+#include <glibtop/ppp.h>
+
+static const unsigned long _glibtop_sysdeps_ppp = 0;
+
+/* Init function. */
+
+void
+glibtop_init_ppp_s (glibtop *server)
+{
+ server->sysdeps.ppp = _glibtop_sysdeps_ppp;
+}
+
+/* Provides PPP/ISDN information. */
+
+void
+glibtop_get_ppp_s (glibtop *server, glibtop_ppp *buf, unsigned short device)
+{
+ memset (buf, 0, sizeof (glibtop_ppp));
+}
diff --git a/sysdeps/kernel/procargs.c b/sysdeps/kernel/procargs.c
new file mode 100644
index 00000000..7bf1b682
--- /dev/null
+++ b/sysdeps/kernel/procargs.c
@@ -0,0 +1,47 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <glibtop.h>
+#include <glibtop/error.h>
+#include <glibtop/xmalloc.h>
+#include <glibtop/procargs.h>
+
+static const unsigned long _glibtop_sysdeps_proc_args = 0;
+
+/* Init function. */
+
+void
+glibtop_init_proc_args_s (glibtop *server)
+{
+ server->sysdeps.proc_args = _glibtop_sysdeps_proc_args;
+}
+
+/* Provides detailed information about a process. */
+
+const char *
+glibtop_get_proc_args_s (glibtop *server, glibtop_proc_args *buf,
+ pid_t pid, unsigned max_len)
+{
+ memset (buf, 0, sizeof (glibtop_proc_args));
+ return NULL;
+}
diff --git a/sysdeps/kernel/procdata.c b/sysdeps/kernel/procdata.c
new file mode 100644
index 00000000..64fa1583
--- /dev/null
+++ b/sysdeps/kernel/procdata.c
@@ -0,0 +1,180 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <config.h>
+#include <glibtop/procdata.h>
+
+#include <sys/stat.h>
+
+#define LINUX_VERSION(x,y,z) (0x10000*(x) + 0x100*(y) + z)
+
+#define BIT_SHIFT(x) (1 << (x % 32))
+
+static const unsigned long _glibtop_sysdeps_procdata_0 =
+BIT_SHIFT(GLIBTOP_PROCDATA_CMD) +
+BIT_SHIFT(GLIBTOP_PROCDATA_STATE) +
+BIT_SHIFT(GLIBTOP_PROCDATA_UID) +
+BIT_SHIFT(GLIBTOP_PROCDATA_PID) +
+BIT_SHIFT(GLIBTOP_PROCDATA_PPID) +
+BIT_SHIFT(GLIBTOP_PROCDATA_PGRP) +
+BIT_SHIFT(GLIBTOP_PROCDATA_SESSION) +
+BIT_SHIFT(GLIBTOP_PROCDATA_TTY) +
+BIT_SHIFT(GLIBTOP_PROCDATA_TPGID) +
+BIT_SHIFT(GLIBTOP_PROCDATA_PRIORITY) +
+BIT_SHIFT(GLIBTOP_PROCDATA_NICE) +
+BIT_SHIFT(GLIBTOP_PROCDATA_SIGNAL) +
+BIT_SHIFT(GLIBTOP_PROCDATA_BLOCKED) +
+BIT_SHIFT(GLIBTOP_PROCDATA_SIGIGNORE) +
+BIT_SHIFT(GLIBTOP_PROCDATA_SIGCATCH) +
+BIT_SHIFT(GLIBTOP_PROCDATA_START_TIME) +
+BIT_SHIFT(GLIBTOP_PROCDATA_UTIME) +
+BIT_SHIFT(GLIBTOP_PROCDATA_STIME) +
+BIT_SHIFT(GLIBTOP_PROCDATA_CUTIME) +
+BIT_SHIFT(GLIBTOP_PROCDATA_CSTIME) +
+BIT_SHIFT(GLIBTOP_PROCDATA_SIZE) +
+BIT_SHIFT(GLIBTOP_PROCDATA_RESIDENT) +
+BIT_SHIFT(GLIBTOP_PROCDATA_SHARE) +
+BIT_SHIFT(GLIBTOP_PROCDATA_TRS) +
+BIT_SHIFT(GLIBTOP_PROCDATA_LRS) +
+BIT_SHIFT(GLIBTOP_PROCDATA_DRS) +
+BIT_SHIFT(GLIBTOP_PROCDATA_DT) +
+BIT_SHIFT(GLIBTOP_PROCDATA_VSIZE) +
+BIT_SHIFT(GLIBTOP_PROCDATA_RSS) +
+BIT_SHIFT(GLIBTOP_PROCDATA_RSS_RLIM) +
+BIT_SHIFT(GLIBTOP_PROCDATA_TIMEOUT) +
+BIT_SHIFT(GLIBTOP_PROCDATA_IT_REAL_VALUE);
+
+static const unsigned long _glibtop_sysdeps_procdata_1 =
+BIT_SHIFT(GLIBTOP_PROCDATA_K_FLAGS) +
+BIT_SHIFT(GLIBTOP_PROCDATA_MIN_FLT) +
+BIT_SHIFT(GLIBTOP_PROCDATA_MAJ_FLT) +
+BIT_SHIFT(GLIBTOP_PROCDATA_CMIN_FLT) +
+BIT_SHIFT(GLIBTOP_PROCDATA_CMAJ_FLT) +
+BIT_SHIFT(GLIBTOP_PROCDATA_START_CODE) +
+BIT_SHIFT(GLIBTOP_PROCDATA_END_CODE) +
+BIT_SHIFT(GLIBTOP_PROCDATA_START_STACK) +
+BIT_SHIFT(GLIBTOP_PROCDATA_KSTK_ESP) +
+BIT_SHIFT(GLIBTOP_PROCDATA_KSTK_EIP) +
+BIT_SHIFT(GLIBTOP_PROCDATA_WCHAN);
+
+/* Provides detailed information about a process. */
+
+void
+glibtop_get_procdata_s (glibtop *server, glibtop_procdata *buf, pid_t pid)
+{
+ char input [BUFSIZ], *tmp;
+ struct stat statb;
+ int nread;
+ FILE *f;
+
+ glibtop_init_s (&server, 0, 0);
+
+ memset (buf, 0, sizeof (glibtop_procdata));
+
+ if (pid == 0) {
+ /* Client is only interested in the flags. */
+ buf->flags [0] = _glibtop_sysdeps_procdata_0;
+ buf->flags [1] = _glibtop_sysdeps_procdata_1;
+ return;
+ }
+
+
+ sprintf (input, "/proc/%d/stat", pid);
+
+ if (stat (input, &statb)) return;
+
+ buf->uid = statb.st_uid;
+
+ f = fopen (input, "r");
+ if (!f) return;
+
+ nread = fread (input, 1, BUFSIZ, f);
+
+ if (nread < 0) {
+ fclose (f);
+ return;
+ }
+
+ input [nread] = 0;
+
+ /* This is from guile-utils/gtop/proc/readproc.c */
+
+ /* split into "PID (cmd" and "<rest>" */
+ tmp = strrchr (input, ')');
+ *tmp = '\0'; /* replace trailing ')' with NUL */
+ /* parse these two strings separately, skipping the leading "(". */
+ memset (buf->cmd, 0, sizeof (buf->cmd));
+ sscanf (input, "%d (%39c", &buf->pid, buf->cmd);
+ sscanf(tmp + 2, /* skip space after ')' too */
+ "%c %d %d %d %d %d %lu %lu %lu %lu %lu "
+ "%ld %ld %ld %ld %d %d %lu %lu %ld %lu "
+ "%lu %lu %lu %lu %lu %lu %lu %d %d %d %d %lu",
+ &buf->state, &buf->ppid, &buf->pgrp, &buf->session,
+ &buf->tty, &buf->tpgid, &buf->k_flags, &buf->min_flt,
+ &buf->cmin_flt, &buf->maj_flt, &buf->cmaj_flt,
+ &buf->utime, &buf->stime, &buf->cutime, &buf->cstime,
+ &buf->priority, &buf->nice, &buf->timeout,
+ &buf->it_real_value, &buf->start_time, &buf->vsize,
+ &buf->rss, &buf->rss_rlim, &buf->start_code,
+ &buf->end_code, &buf->start_stack, &buf->kstk_esp,
+ &buf->kstk_eip, &buf->signal, &buf->blocked,
+ &buf->sigignore, &buf->sigcatch, &buf->wchan);
+
+ if (buf->tty == 0)
+ /* the old notty val, update elsewhere bef. moving to 0 */
+ buf->tty = -1;
+
+ if (server->os_version_code < LINUX_VERSION(1,3,39)) {
+ /* map old meanings to new */
+ buf->priority = 2*15 - buf->priority;
+ buf->nice = 15 - buf->nice;
+ }
+ if (server->os_version_code < LINUX_VERSION(1,1,30) && buf->tty != -1)
+ /* when tty wasn't full devno */
+ buf->tty = 4*0x100 + buf->tty;
+
+ fclose (f);
+
+ sprintf (input, "/proc/%d/statm", pid);
+
+ f = fopen (input, "r");
+ if (!f) return;
+
+ nread = fread (input, 1, BUFSIZ, f);
+
+ if (nread < 0) {
+ fclose (f);
+ return;
+ }
+
+ input [nread] = 0;
+
+ sscanf (input, "%ld %ld %ld %ld %ld %ld %ld",
+ &buf->size, &buf->resident, &buf->share,
+ &buf->trs, &buf->lrs, &buf->drs, &buf->dt);
+
+ fclose (f);
+
+ buf->flags [0] = _glibtop_sysdeps_procdata_0;
+ buf->flags [1] = _glibtop_sysdeps_procdata_1;
+}
diff --git a/sysdeps/kernel/prockernel.c b/sysdeps/kernel/prockernel.c
new file mode 100644
index 00000000..4380d681
--- /dev/null
+++ b/sysdeps/kernel/prockernel.c
@@ -0,0 +1,68 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <glibtop.h>
+#include <glibtop/error.h>
+#include <glibtop/prockernel.h>
+
+#include "kernel.h"
+
+static const unsigned long _glibtop_sysdeps_proc_kernel =
+(1 << GLIBTOP_PROC_KERNEL_K_FLAGS) + (1 << GLIBTOP_PROC_KERNEL_MIN_FLT) +
+(1 << GLIBTOP_PROC_KERNEL_MAJ_FLT) + (1 << GLIBTOP_PROC_KERNEL_CMIN_FLT) +
+(1 << GLIBTOP_PROC_KERNEL_CMAJ_FLT) + (1 << GLIBTOP_PROC_KERNEL_KSTK_ESP) +
+(1 << GLIBTOP_PROC_KERNEL_KSTK_EIP) + (1 << GLIBTOP_PROC_KERNEL_NWCHAN);
+
+/* Init function. */
+
+void
+glibtop_init_proc_kernel_s (glibtop *server)
+{
+ server->sysdeps.proc_kernel = _glibtop_sysdeps_proc_kernel;
+}
+
+/* Provides detailed information about a process. */
+
+void
+glibtop_get_proc_kernel_s (glibtop *server, glibtop_proc_kernel *buf,
+ pid_t pid)
+{
+ union table tbl;
+
+ glibtop_init_s (&server, GLIBTOP_SYSDEPS_PROC_KERNEL, 0);
+
+ memset (buf, 0, sizeof (glibtop_proc_kernel));
+
+ if (table (TABLE_PROC_KERNEL, &tbl, &pid))
+ glibtop_error_io_r (server, "table(TABLE_PROC_KERNEL)");
+
+ buf->flags = _glibtop_sysdeps_proc_kernel;
+
+ buf->min_flt = tbl.proc_kernel.min_flt;
+ buf->cmin_flt = tbl.proc_kernel.cmin_flt;
+ buf->maj_flt = tbl.proc_kernel.maj_flt;
+ buf->cmaj_flt = tbl.proc_kernel.cmaj_flt;
+ buf->kstk_esp = tbl.proc_kernel.kesp;
+ buf->kstk_eip = tbl.proc_kernel.keip;
+ buf->nwchan = tbl.proc_kernel.wchan;
+}
diff --git a/sysdeps/kernel/proclist.c b/sysdeps/kernel/proclist.c
new file mode 100644
index 00000000..9b527aaf
--- /dev/null
+++ b/sysdeps/kernel/proclist.c
@@ -0,0 +1,86 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <glibtop.h>
+#include <glibtop/xmalloc.h>
+#include <glibtop/proclist.h>
+
+#include "kernel.h"
+
+static const unsigned long _glibtop_sysdeps_proclist =
+(1 << GLIBTOP_PROCLIST_TOTAL) + (1 << GLIBTOP_PROCLIST_NUMBER) +
+(1 << GLIBTOP_PROCLIST_SIZE);
+
+/* Init function. */
+
+void
+glibtop_init_proclist_s (glibtop *server)
+{
+ server->sysdeps.proclist = _glibtop_sysdeps_proclist;
+}
+
+#define BLOCK_COUNT 256
+#define BLOCK_SIZE (BLOCK_COUNT * sizeof (unsigned))
+
+/* Fetch list of currently running processes.
+ *
+ * The interface of this function is a little bit different from the others:
+ * buf->flags is only set if the call succeeded, in this case pids_chain,
+ * a list of the pids of all currently running processes is returned,
+ * buf->number is the number of elements of this list and buf->size is
+ * the size of one single element (sizeof (unsigned)). The total size is
+ * stored in buf->total.
+ *
+ * The calling function has to free the memory to which a pointer is returned.
+ *
+ * On error, NULL is returned and buf->flags is zero. */
+
+unsigned *
+glibtop_get_proclist_s (glibtop *server, glibtop_proclist *buf,
+ int64_t which, int64_t arg)
+{
+ union table tbl;
+ unsigned *pids_chain;
+ struct proclist_args args;
+
+ glibtop_init_s (&server, GLIBTOP_SYSDEPS_PROCLIST, 0);
+
+ memset (buf, 0, sizeof (glibtop_proclist));
+
+ args.which = which;
+ args.arg = arg;
+
+ if (table (TABLE_PROCLIST, &tbl, &args))
+ glibtop_error_io_r (server, "table(TABLE_PROCLIST)");
+
+ buf->size = sizeof (unsigned);
+ buf->number = tbl.proclist.nr_tasks;
+
+ buf->total = buf->number * sizeof (unsigned);
+
+ pids_chain = glibtop_malloc_r (server, buf->total);
+
+ memcpy (pids_chain, tbl.proclist.pids, buf->total);
+
+ return pids_chain;
+}
diff --git a/sysdeps/kernel/procmap.c b/sysdeps/kernel/procmap.c
new file mode 100644
index 00000000..48a99400
--- /dev/null
+++ b/sysdeps/kernel/procmap.c
@@ -0,0 +1,49 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <glibtop.h>
+#include <glibtop/error.h>
+#include <glibtop/xmalloc.h>
+#include <glibtop/procmap.h>
+
+static const unsigned long _glibtop_sysdeps_proc_map = 0;
+
+/* Init function. */
+
+void
+glibtop_init_proc_map_s (glibtop *server)
+{
+ server->sysdeps.proc_map = _glibtop_sysdeps_proc_map;
+}
+
+/* Provides detailed information about a process. */
+
+glibtop_map_entry *
+glibtop_get_proc_map_s (glibtop *server, glibtop_proc_map *buf, pid_t pid)
+{
+ glibtop_init_s (&server, GLIBTOP_SYSDEPS_PROC_MAP, 0);
+
+ memset (buf, 0, sizeof (glibtop_proc_map));
+
+ return NULL;
+}
diff --git a/sysdeps/kernel/procmem.c b/sysdeps/kernel/procmem.c
new file mode 100644
index 00000000..de65f654
--- /dev/null
+++ b/sysdeps/kernel/procmem.c
@@ -0,0 +1,70 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <glibtop.h>
+#include <glibtop/error.h>
+#include <glibtop/procmem.h>
+
+#include "kernel.h"
+
+static const unsigned long _glibtop_sysdeps_proc_mem =
+(1 << GLIBTOP_PROC_MEM_SIZE) + (1 << GLIBTOP_PROC_MEM_VSIZE) +
+(1 << GLIBTOP_PROC_MEM_RESIDENT) + (1 << GLIBTOP_PROC_MEM_SHARE) +
+(1 << GLIBTOP_PROC_MEM_RSS) + (1 << GLIBTOP_PROC_MEM_RSS_RLIM);
+
+/* Init function. */
+
+void
+glibtop_init_proc_mem_s (glibtop *server)
+{
+ server->sysdeps.proc_mem = _glibtop_sysdeps_proc_mem;
+}
+
+/* Provides detailed information about a process. */
+
+void
+glibtop_get_proc_mem_s (glibtop *server, glibtop_proc_mem *buf,
+ pid_t pid)
+{
+ union table tbl;
+
+ glibtop_init_s (&server, GLIBTOP_SYSDEPS_PROC_MEM, 0);
+
+ memset (buf, 0, sizeof (glibtop_proc_mem));
+
+ if (table (TABLE_PROC_MEM, &tbl, &pid))
+ glibtop_error_io_r (server, "table(TABLE_PROC_MEM)");
+
+ buf->rss = tbl.proc_mem.rss;
+ buf->rss_rlim = tbl.proc_mem.rlim;
+
+ if (table (TABLE_PROC_SEGMENT, &tbl, &pid))
+ glibtop_error_io_r (server, "table(TABLE_PROC_SEGMENT)");
+
+ buf->flags = _glibtop_sysdeps_proc_mem;
+
+ buf->vsize = tbl.proc_segment.vsize;
+ buf->size = tbl.proc_segment.size;
+ buf->resident = tbl.proc_segment.resident;
+ buf->share = tbl.proc_segment.shared;
+}
diff --git a/sysdeps/kernel/procsegment.c b/sysdeps/kernel/procsegment.c
new file mode 100644
index 00000000..2e6d3930
--- /dev/null
+++ b/sysdeps/kernel/procsegment.c
@@ -0,0 +1,77 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <config.h>
+#include <glibtop/error.h>
+#include <glibtop/procsegment.h>
+
+#include "kernel.h"
+
+static const unsigned long _glibtop_sysdeps_proc_segment =
+(1 << GLIBTOP_PROC_SEGMENT_TEXT_RSS) +
+(1 << GLIBTOP_PROC_SEGMENT_SHLIB_RSS) +
+(1 << GLIBTOP_PROC_SEGMENT_DATA_RSS) +
+(1 << GLIBTOP_PROC_SEGMENT_STACK_RSS) +
+(1 << GLIBTOP_PROC_SEGMENT_DIRTY_SIZE) +
+(1 << GLIBTOP_PROC_SEGMENT_START_CODE) +
+(1 << GLIBTOP_PROC_SEGMENT_END_CODE) +
+(1 << GLIBTOP_PROC_SEGMENT_START_STACK);
+
+/* Init function. */
+
+void
+glibtop_init_proc_segment_s (glibtop *server)
+{
+ server->sysdeps.proc_segment = _glibtop_sysdeps_proc_segment;
+}
+
+/* Provides detailed information about a process. */
+
+void
+glibtop_get_proc_segment_s (glibtop *server, glibtop_proc_segment *buf,
+ pid_t pid)
+{
+ union table tbl;
+
+ glibtop_init_s (&server, GLIBTOP_SYSDEPS_PROC_SEGMENT, 0);
+
+ memset (buf, 0, sizeof (glibtop_proc_segment));
+
+ if (table (TABLE_PROC_MEM, &tbl, &pid))
+ glibtop_error_io_r (server, "table(TABLE_PROC_MEM)");
+
+ buf->start_code = tbl.proc_mem.start_code;
+ buf->end_code = tbl.proc_mem.end_code;
+ buf->start_stack = tbl.proc_mem.start_stack;
+
+ if (table (TABLE_PROC_SEGMENT, &tbl, &pid))
+ glibtop_error_io_r (server, "table(TABLE_PROC_SEGMENT)");
+
+ buf->flags = _glibtop_sysdeps_proc_segment;
+
+ buf->text_rss = tbl.proc_segment.trs;
+ buf->shlib_rss = tbl.proc_segment.lrs;
+ buf->data_rss = tbl.proc_segment.drs;
+ buf->stack_rss = tbl.proc_segment.srs;
+ buf->dirty_size = tbl.proc_segment.dt;
+}
diff --git a/sysdeps/kernel/procsignal.c b/sysdeps/kernel/procsignal.c
new file mode 100644
index 00000000..3e3829c2
--- /dev/null
+++ b/sysdeps/kernel/procsignal.c
@@ -0,0 +1,63 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <glibtop.h>
+#include <glibtop/error.h>
+#include <glibtop/procsignal.h>
+
+#include "kernel.h"
+
+static const unsigned long _glibtop_sysdeps_proc_signal =
+(1 << GLIBTOP_PROC_SIGNAL_SIGNAL) + (1 << GLIBTOP_PROC_SIGNAL_BLOCKED) +
+(1 << GLIBTOP_PROC_SIGNAL_SIGIGNORE) + (1 << GLIBTOP_PROC_SIGNAL_SIGCATCH);
+
+/* Init function. */
+
+void
+glibtop_init_proc_signal_s (glibtop *server)
+{
+ server->sysdeps.proc_signal = _glibtop_sysdeps_proc_signal;
+}
+
+/* Provides detailed information about a process. */
+
+void
+glibtop_get_proc_signal_s (glibtop *server, glibtop_proc_signal *buf,
+ pid_t pid)
+{
+ union table tbl;
+
+ glibtop_init_s (&server, GLIBTOP_SYSDEPS_PROC_SIGNAL, 0);
+
+ memset (buf, 0, sizeof (glibtop_proc_signal));
+
+ if (table (TABLE_PROC_SIGNAL, &tbl, &pid))
+ glibtop_error_io_r (server, "table(TABLE_PROC_SIGNAL)");
+
+ buf->flags = _glibtop_sysdeps_proc_signal;
+
+ buf->signal [0] = tbl.proc_signal.signal;
+ buf->blocked [0] = tbl.proc_signal.blocked;
+ buf->sigignore [0] = tbl.proc_signal.ignored;
+ buf->sigcatch [0] = tbl.proc_signal.caught;
+}
diff --git a/sysdeps/kernel/procstate.c b/sysdeps/kernel/procstate.c
new file mode 100644
index 00000000..59217a5e
--- /dev/null
+++ b/sysdeps/kernel/procstate.c
@@ -0,0 +1,75 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <glibtop.h>
+#include <glibtop/error.h>
+#include <glibtop/procstate.h>
+
+#include "kernel.h"
+
+static const unsigned long _glibtop_sysdeps_proc_state =
+(1 << GLIBTOP_PROC_STATE_CMD) + (1 << GLIBTOP_PROC_STATE_STATE) +
+(1 << GLIBTOP_PROC_STATE_UID) + (1 << GLIBTOP_PROC_STATE_GID);
+
+/* Init function. */
+
+void
+glibtop_init_proc_state_s (glibtop *server)
+{
+ server->sysdeps.proc_state = _glibtop_sysdeps_proc_state;
+}
+
+/* Provides detailed information about a process. */
+
+#define NR_STATES 7
+
+void
+glibtop_get_proc_state_s (glibtop *server, glibtop_proc_state *buf,
+ pid_t pid)
+{
+ union table tbl;
+ static const char states [NR_STATES] =
+ { 'R', 'S', 'D', 'Z', 'T', 'W', '.' };
+ unsigned state;
+
+ glibtop_init_s (&server, GLIBTOP_SYSDEPS_PROC_STATE, 0);
+
+ memset (buf, 0, sizeof (glibtop_proc_state));
+
+ if (table (TABLE_PROC_STATE, &tbl, &pid))
+ glibtop_error_io_r (server, "table(TABLE_PROC_STATE)");
+
+ buf->flags = _glibtop_sysdeps_proc_state;
+
+ memcpy (buf->cmd, tbl.proc_state.comm, sizeof (tbl.proc_state.comm));
+
+ buf->uid = tbl.proc_state.uid;
+ buf->gid = tbl.proc_state.state;
+
+ state = (unsigned) tbl.proc_state.state;
+
+ if (state >= NR_STATES)
+ state = NR_STATES;
+
+ buf->state = states [state];
+}
diff --git a/sysdeps/kernel/proctime.c b/sysdeps/kernel/proctime.c
new file mode 100644
index 00000000..5e5f455a
--- /dev/null
+++ b/sysdeps/kernel/proctime.c
@@ -0,0 +1,73 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <glibtop.h>
+#include <glibtop/error.h>
+#include <glibtop/proctime.h>
+
+#include "kernel.h"
+
+static const unsigned long _glibtop_sysdeps_proc_time =
+(1 << GLIBTOP_PROC_TIME_UTIME) + (1 << GLIBTOP_PROC_TIME_CUTIME) +
+(1 << GLIBTOP_PROC_TIME_STIME) + (1 << GLIBTOP_PROC_TIME_CSTIME) +
+(1 << GLIBTOP_PROC_TIME_RTIME) + (1 << GLIBTOP_PROC_TIME_FREQUENCY) +
+(1 << GLIBTOP_PROC_TIME_TIMEOUT) + (1 << GLIBTOP_PROC_TIME_IT_REAL_VALUE) +
+(1 << GLIBTOP_PROC_TIME_START_TIME);
+
+/* Init function. */
+
+void
+glibtop_init_proc_time_s (glibtop *server)
+{
+ server->sysdeps.proc_time = _glibtop_sysdeps_proc_time;
+}
+
+/* Provides detailed information about a process. */
+
+void
+glibtop_get_proc_time_s (glibtop *server, glibtop_proc_time *buf,
+ pid_t pid)
+{
+ union table tbl;
+
+ glibtop_init_s (&server, GLIBTOP_SYSDEPS_PROC_TIME, 0);
+
+ memset (buf, 0, sizeof (glibtop_proc_time));
+
+ if (table (TABLE_PROC_TIME, &tbl, &pid))
+ glibtop_error_io_r (server, "table(TABLE_PROC_TIME)");
+
+ buf->utime = tbl.proc_time.utime;
+ buf->stime = tbl.proc_time.stime;
+
+ buf->rtime = buf->utime + buf->stime;
+
+ buf->cutime = tbl.proc_time.cutime;
+ buf->cstime = tbl.proc_time.cstime;
+
+ buf->frequency = 100;
+
+ buf->timeout = tbl.proc_time.timeout;
+ buf->it_real_value = tbl.proc_time.it_real_value;
+ buf->start_time = tbl.proc_time.start_time;
+}
diff --git a/sysdeps/kernel/procuid.c b/sysdeps/kernel/procuid.c
new file mode 100644
index 00000000..25012916
--- /dev/null
+++ b/sysdeps/kernel/procuid.c
@@ -0,0 +1,105 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <glibtop.h>
+#include <glibtop/error.h>
+#include <glibtop/procuid.h>
+
+#include "kernel.h"
+
+static const unsigned long _glibtop_sysdeps_proc_uid =
+(1 << GLIBTOP_PROC_UID_UID) + (1 << GLIBTOP_PROC_UID_EUID) +
+(1 << GLIBTOP_PROC_UID_GID) + (1 << GLIBTOP_PROC_UID_EGID) +
+(1 << GLIBTOP_PROC_UID_PID) + (1 << GLIBTOP_PROC_UID_PPID) +
+(1 << GLIBTOP_PROC_UID_PGRP) + (1 << GLIBTOP_PROC_UID_SESSION) +
+(1 << GLIBTOP_PROC_UID_TTY) + (1 << GLIBTOP_PROC_UID_TPGID) +
+(1 << GLIBTOP_PROC_UID_PRIORITY) + (1 << GLIBTOP_PROC_UID_NICE);
+
+/* Init function. */
+
+void
+glibtop_init_proc_uid_s (glibtop *server)
+{
+ server->sysdeps.proc_uid = _glibtop_sysdeps_proc_uid;
+}
+
+#define LINUX_VERSION(x,y,z) (0x10000*(x) + 0x100*(y) + z)
+
+/* Provides detailed information about a process. */
+
+void
+glibtop_get_proc_uid_s (glibtop *server, glibtop_proc_uid *buf,
+ pid_t pid)
+{
+ union table tbl;
+ long def_priority, priority, nice;
+
+ glibtop_init_s (&server, GLIBTOP_SYSDEPS_PROC_UID, 0);
+
+ memset (buf, 0, sizeof (glibtop_proc_uid));
+
+ if (table (TABLE_PROC_UID, &tbl, &pid))
+ glibtop_error_io_r (server, "table(TABLE_PROC_UID)");
+
+ buf->flags = _glibtop_sysdeps_proc_uid;
+
+ buf->uid = tbl.proc_uid.uid;
+ buf->euid = tbl.proc_uid.euid;
+ buf->gid = tbl.proc_uid.gid;
+ buf->egid = tbl.proc_uid.egid;
+
+ buf->pid = tbl.proc_uid.pid;
+ buf->ppid = tbl.proc_uid.ppid;
+ buf->pgrp = tbl.proc_uid.pgrp;
+ buf->session = tbl.proc_uid.session;
+ buf->tty = tbl.proc_uid.tty;
+ buf->tpgid = tbl.proc_uid.tpgid;
+
+ /* scale priority and nice values from timeslices to -20..20 */
+ /* to make it look like a "normal" unix priority/nice value */
+
+ def_priority = tbl.proc_uid.def_priority;
+
+ priority = tbl.proc_uid.counter;
+ priority = 20 - (priority * 10 + def_priority / 2) / def_priority;
+ nice = tbl.proc_uid.priority;
+ nice = 20 - (nice * 20 + def_priority / 2) / def_priority;
+
+ buf->priority = (int) priority;
+ buf->nice = (int) nice;
+
+ if (buf->tty == 0)
+ /* the old notty val, update elsewhere bef. moving to 0 */
+ buf->tty = -1;
+
+ if (server->os_version_code < LINUX_VERSION(1,3,39)) {
+ /* map old meanings to new */
+ buf->priority = 2*15 - buf->priority;
+ buf->nice = 15 - buf->nice;
+ }
+ if (server->os_version_code < LINUX_VERSION(1,1,30) && buf->tty != -1)
+ /* when tty wasn't full devno */
+ buf->tty = 4*0x100 + buf->tty;
+
+ buf->flags = _glibtop_sysdeps_proc_uid;
+}
diff --git a/sysdeps/kernel/sem_limits.c b/sysdeps/kernel/sem_limits.c
new file mode 100644
index 00000000..bdb566d4
--- /dev/null
+++ b/sysdeps/kernel/sem_limits.c
@@ -0,0 +1,86 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <glibtop/sem_limits.h>
+
+#include <sys/ipc.h>
+#include <sys/sem.h>
+
+#ifdef _SEM_SEMUN_UNDEFINED
+
+/* glibc 2.1 will no longer defines semun, instead it defines
+ * _SEM_SEMUN_UNDEFINED so users can define semun on their own.
+ * Thanks to Albert K T Hui <avatar@deva.net>. */
+
+union semun
+{
+ int val;
+ struct semid_ds *buf;
+ unsigned short int *array;
+ struct seminfo *__buf;
+};
+#endif
+
+static unsigned long _glibtop_sysdeps_sem_limits =
+(1 << GLIBTOP_IPC_SEMMAP) + (1 << GLIBTOP_IPC_SEMMNI) +
+(1 << GLIBTOP_IPC_SEMMNS) + (1 << GLIBTOP_IPC_SEMMNU) +
+(1 << GLIBTOP_IPC_SEMMSL) + (1 << GLIBTOP_IPC_SEMOPM) +
+(1 << GLIBTOP_IPC_SEMUME) + (1 << GLIBTOP_IPC_SEMUSZ) +
+(1 << GLIBTOP_IPC_SEMVMX) + (1 << 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 ipc limits. */
+
+void
+glibtop_get_sem_limits_s (glibtop *server, glibtop_sem_limits *buf)
+{
+ struct seminfo seminfo;
+ union semun arg;
+
+ glibtop_init_s (&server, GLIBTOP_SYSDEPS_SEM_LIMITS, 0);
+
+ memset (buf, 0, sizeof (glibtop_sem_limits));
+
+ buf->flags = _glibtop_sysdeps_sem_limits;
+
+ arg.array = (ushort *) &seminfo;
+ semctl (0, 0, IPC_INFO, arg);
+
+ buf->semmap = seminfo.semmap;
+ buf->semmni = seminfo.semmni;
+ buf->semmns = seminfo.semmns;
+ buf->semmnu = seminfo.semmnu;
+ buf->semmsl = seminfo.semmsl;
+ buf->semopm = seminfo.semopm;
+ buf->semume = seminfo.semume;
+ buf->semusz = seminfo.semusz;
+ buf->semvmx = seminfo.semvmx;
+ buf->semaem = seminfo.semaem;
+}
diff --git a/sysdeps/kernel/shm_limits.c b/sysdeps/kernel/shm_limits.c
new file mode 100644
index 00000000..da6ec92d
--- /dev/null
+++ b/sysdeps/kernel/shm_limits.c
@@ -0,0 +1,62 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <glibtop/shm_limits.h>
+
+#include <sys/ipc.h>
+#include <sys/shm.h>
+
+static unsigned long _glibtop_sysdeps_shm_limits =
+(1 << GLIBTOP_IPC_SHMMAX) + (1 << GLIBTOP_IPC_SHMMIN) +
+(1 << GLIBTOP_IPC_SHMMNI) + (1 << GLIBTOP_IPC_SHMSEG) +
+(1 << 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)
+{
+ struct shminfo shminfo;
+
+ glibtop_init_s (&server, GLIBTOP_SYSDEPS_SHM_LIMITS, 0);
+
+ memset (buf, 0, sizeof (glibtop_shm_limits));
+
+ buf->flags = _glibtop_sysdeps_shm_limits;
+
+ shmctl (0, IPC_INFO, (struct shmid_ds *) &shminfo);
+
+ buf->shmmax = shminfo.shmmax;
+ buf->shmmin = shminfo.shmmin;
+ buf->shmmni = shminfo.shmmni;
+ buf->shmseg = shminfo.shmseg;
+ buf->shmall = shminfo.shmall;
+}
diff --git a/sysdeps/kernel/siglist.c b/sysdeps/kernel/siglist.c
new file mode 100644
index 00000000..d00223c0
--- /dev/null
+++ b/sysdeps/kernel/siglist.c
@@ -0,0 +1,60 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <glibtop.h>
+#include <glibtop/signal.h>
+
+const glibtop_signame glibtop_sys_siglist [] =
+{ { 1, "SIGHUP", NULL }, /* Hangup (POSIX). */
+ { 2, "SIGINT", NULL }, /* Interrupt (ANSI). */
+ { 3, "SIGQUIT", NULL }, /* Quit (POSIX). */
+ { 4, "SIGILL", NULL }, /* Illegal instruction (ANSI). */
+ { 5, "SIGTRAP", NULL }, /* Trace trap (POSIX). */
+ { 6, "SIGABRT", NULL }, /* Abort (ANSI). */
+ { 7, "SIGBUS", NULL }, /* BUS error (4.2 BSD). */
+ { 8, "SIGFPE", NULL }, /* Floating-point exception (ANSI). */
+ { 9, "SIGKILL", NULL }, /* Kill, unblockable (POSIX). */
+ { 10, "SIGUSR1", NULL }, /* User-defined signal 1 (POSIX). */
+ { 11, "SIGSEGV", NULL }, /* Segmentation violation (ANSI). */
+ { 12, "SIGUSR2", NULL }, /* User-defined signal 2 (POSIX). */
+ { 13, "SIGPIPE", NULL }, /* Broken pipe (POSIX). */
+ { 14, "SIGALRM", NULL }, /* Alarm clock (POSIX). */
+ { 15, "SIGTERM", NULL }, /* Termination (ANSI). */
+ { 16, "SIGSTKFLT", NULL }, /* ??? */
+ { 17, "SIGCHLD", NULL }, /* Child status has changed (POSIX). */
+ { 18, "SIGCONT", NULL }, /* Continue (POSIX). */
+ { 19, "SIGSTOP", NULL }, /* Stop, unblockable (POSIX). */
+ { 20, "SIGTSTP", NULL }, /* Keyboard stop (POSIX). */
+ { 21, "SIGTTIN", NULL }, /* Background read from tty (POSIX). */
+ { 22, "SIGTTOU", NULL }, /* Background write to tty (POSIX). */
+ { 23, "SIGURG", NULL }, /* Urgent condition on socket (4.2 BSD). */
+ { 24, "SIGXCPU", NULL }, /* CPU limit exceeded (4.2 BSD). */
+ { 25, "SIGXFSZ", NULL }, /* File size limit exceeded (4.2 BSD). */
+ { 26, "SIGVTALRM", NULL }, /* Virtual alarm clock (4.2 BSD). */
+ { 27, "SIGPROF", NULL }, /* Profiling alarm clock (4.2 BSD). */
+ { 28, "SIGWINCH", NULL }, /* Window size change (4.3 BSD, Sun). */
+ { 29, "SIGIO", NULL }, /* I/O now possible (4.2 BSD). */
+ { 30, "SIGPWR", NULL }, /* Power failure restart (System V). */
+ { 31, "SIGUNUSED", NULL },
+ { 0, NULL, NULL },
+};
diff --git a/sysdeps/kernel/swap.c b/sysdeps/kernel/swap.c
new file mode 100644
index 00000000..81f13aa0
--- /dev/null
+++ b/sysdeps/kernel/swap.c
@@ -0,0 +1,65 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <config.h>
+#include <glibtop/error.h>
+#include <glibtop/swap.h>
+
+#include "kernel.h"
+
+static unsigned long _glibtop_sysdeps_swap =
+(1 << GLIBTOP_SWAP_TOTAL) + (1 << GLIBTOP_SWAP_USED) +
+(1 << GLIBTOP_SWAP_FREE) + (1 << GLIBTOP_SWAP_PAGEIN) +
+(1 << GLIBTOP_SWAP_PAGEOUT);
+
+/* Init function. */
+
+void
+glibtop_init_swap_s (glibtop *server)
+{
+ server->sysdeps.swap = _glibtop_sysdeps_swap;
+}
+
+/* Provides information about swap usage. */
+
+void
+glibtop_get_swap_s (glibtop *server, glibtop_swap *buf)
+{
+ union table tbl;
+
+ glibtop_init_s (&server, GLIBTOP_SYSDEPS_SWAP, 0);
+
+ memset (buf, 0, sizeof (glibtop_swap));
+
+ if (table (TABLE_SWAP, &tbl, NULL))
+ glibtop_error_io_r (server, "table(TABLE_SWAP)");
+
+ buf->flags = _glibtop_sysdeps_swap;
+
+ buf->total = tbl.swap.total;
+ buf->used = tbl.swap.used;
+ buf->free = tbl.swap.free;
+
+ buf->pagein = tbl.swap.pagein;
+ buf->pageout = tbl.swap.pageout;
+}
diff --git a/sysdeps/kernel/sysinfo.c b/sysdeps/kernel/sysinfo.c
new file mode 100644
index 00000000..49f374c4
--- /dev/null
+++ b/sysdeps/kernel/sysinfo.c
@@ -0,0 +1,94 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <config.h>
+#include <glibtop/cpu.h>
+#include <glibtop/sysinfo.h>
+
+static const unsigned long _glibtop_sysdeps_sysinfo =
+(1 << GLIBTOP_SYSINFO_CPUINFO);
+
+static glibtop_sysinfo sysinfo;
+
+static void
+init_sysinfo (glibtop *server)
+{
+ char buffer [BUFSIZ];
+ static int init = 0;
+ glibtop_entry *cpuinfo = NULL;
+ FILE *f;
+
+ if (init) return;
+
+ init = TRUE;
+
+ glibtop_init_s (&server, GLIBTOP_SYSDEPS_CPU, 0);
+
+ memset (&sysinfo, 0, sizeof (glibtop_sysinfo));
+
+ g_return_if_fail (f = fopen ("/proc/cpuinfo", "r"));
+
+ while (fgets (buffer, BUFSIZ, f)) {
+ char *p, *start, *key, *value;
+
+ if (cpuinfo == NULL) {
+ cpuinfo = &sysinfo.cpuinfo [sysinfo.ncpu++];
+
+ cpuinfo->labels = g_ptr_array_new ();
+
+ cpuinfo->values = g_hash_table_new (NULL, NULL);
+
+ if (sysinfo.ncpu > GLIBTOP_NCPU)
+ sysinfo.ncpu = GLIBTOP_NCPU;
+ }
+
+ p = strchr (buffer, ':');
+ if (!p) continue;
+
+ /* Remove leading spaces from `p'. */
+ *p = '\0'; start = p; p++;
+ while (isspace (*p)) p++;
+
+ /* Remove trailing spaces from `buffer'. */
+ while ((start > buffer) && (*start) && isspace (*start))
+ *start-- = '\0';
+
+ key = g_strdup (buffer);
+ value = g_strdup (p);
+
+ g_ptr_array_add (cpuinfo->labels, key);
+
+ g_hash_table_insert (cpuinfo->values, key, value);
+ }
+
+ fclose (f);
+
+ sysinfo.flags = _glibtop_sysdeps_sysinfo;
+}
+
+glibtop_sysinfo *
+glibtop_get_sysinfo_s (glibtop *server)
+{
+ init_sysinfo (server);
+ return &sysinfo;
+}
diff --git a/sysdeps/kernel/uptime.c b/sysdeps/kernel/uptime.c
new file mode 100644
index 00000000..844dfb5e
--- /dev/null
+++ b/sysdeps/kernel/uptime.c
@@ -0,0 +1,64 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <config.h>
+#include <glibtop/error.h>
+#include <glibtop/uptime.h>
+
+#include "kernel.h"
+
+static unsigned long _glibtop_sysdeps_uptime =
+(1 << GLIBTOP_UPTIME_UPTIME) + (1 << GLIBTOP_UPTIME_IDLETIME);
+
+/* 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)
+{
+ union table tbl;
+
+ glibtop_init_s (&server, GLIBTOP_SYSDEPS_UPTIME, 0);
+
+ memset (buf, 0, sizeof (glibtop_uptime));
+
+ if (table (TABLE_UPTIME, &tbl, NULL))
+ glibtop_error_io_r (server, "table(TABLE_UPTIME)");
+
+ buf->flags = _glibtop_sysdeps_uptime;
+
+#if 0
+ fprintf (stderr, "Table (%u) = %lu, %lu\n",
+ TABLE_UPTIME, tbl.uptime.uptime, tbl.uptime.idle);
+#endif
+
+ buf->uptime = (double) tbl.uptime.uptime / HZ;
+ buf->idletime = (double) tbl.uptime.idle / HZ;
+}
diff --git a/sysdeps/linux/.cvsignore b/sysdeps/linux/.cvsignore
new file mode 100644
index 00000000..635816db
--- /dev/null
+++ b/sysdeps/linux/.cvsignore
@@ -0,0 +1,6 @@
+.deps
+.libs
+Makefile
+Makefile.in
+libgtop_sysdeps.la
+*.lo
diff --git a/sysdeps/linux/ChangeLog b/sysdeps/linux/ChangeLog
new file mode 100644
index 00000000..006529a2
--- /dev/null
+++ b/sysdeps/linux/ChangeLog
@@ -0,0 +1,140 @@
+2001-10-17 Abel Cheung <maddog@linux.org.hk>
+
+ * Makefile.am: move header to $(includedir)/libgtop-1.0/glibtop.
+
+2001-02-13 Martin Baulig <baulig@suse.de>
+
+ Fix bug #14076.
+
+ * open.c (glibtop_open_s): Check whether /proc/1/cpu exists to
+ detect SMP support rather than reading /proc/stat; on Linux 2.4.x,
+ /proc/stat has "cpu" and "cpu0" entries even for non-SMP systems.
+
+2000-01-22 Martin Baulig <martin@home-of-linux.org>
+
+ * procargs.c (glibtop_get_proc_args_s): Set correct `buf->size' and
+ `buf->flags' fields when `max_length' was given. Fixes #5183.
+
+1999-11-28 Martin Baulig <martin@home-of-linux.org>
+
+ * procstate.c (glibtop_get_procstate_s): Stat "/proc/<pid>" instead
+ of "/proc/<pid>/state" to get `uid' and `gid'. Thanks to Jason Becker
+ for pointing out that GTop reported wrong uid's.
+
+1999-10-19 Martin Baulig <martin@home-of-linux.org>
+
+ * uptime.c (glibtop_get_uptime_s): Don't cast uptime and idletime
+ to float as suggested by John Kodis.
+
+1999-07-29 Martin Baulig <martin@home-of-linux.org>
+
+ * proctime.c (glibtop_get_proctime_s): Don't provide `rtime'
+ any longer since we must not use `rtime = utime + stime'.
+
+1999-02-20 Martin Baulig <martin@home-of-linux.org>
+
+ * netload.c: Don't include <linux/ip_fw.h> for libc5 systems
+ since it is no longer required and makes trouble on Slakware.
+
+1999-01-06 Martin Baulig <martin@home-of-linux.org>
+
+ * netload.c (glibtop_get_netload_s): Use `server->os_version_code'
+ instead of GLIBTOP_LINUX_VERSION_CODE.
+
+1999-01-06 Martin Baulig <martin@home-of-linux.org>
+
+ Unconditionally enable SMP support for linux.
+
+ * open.c (_glibtop_open_s): Always determine the number of CPUs
+ we have here, not only when SMP support was enabled.
+
+ * cpu.c, proctime.c: Use `server->ncpu' to determine whether to
+ enable SMP support.
+
+1998-12-28 Martin Baulig <martin@home-of-linux.org>
+
+ * netload.c: When using glibc, don't include <netinet/ip_fw.h>
+ any longer but all headers that were included there; we only
+ needed this file to get those headers.
+
+1998-12-09 Martin Baulig <martin@home-of-linux.org>
+
+ * procargs.c (glibtop_get_proc_args_s): Added implementation
+ for this function.
+
+1998-12-03 Martin Baulig <martin@home-of-linux.org>
+
+ * netload.c: No longer include <linux/version.h>, but use
+ GLIBTOP_LINUX_VERSION_CODE which is set by configure instead.
+ Define _GLIBTOP_IP_FW_ACCTIN and _GLIBTOP_IP_FW_ACCTOUT here
+ and use them instead of IP_FW_F_ACCTIN and IP_FW_F_ACCTOUT.
+
+1998-11-30 Martin Baulig <martin@home-of-linux.org>
+
+ * netload.c: Use correct header files both for libc5 and glibc.
+ With Linux >= 2.1.114 we no longer use IP accounting since it
+ already has byte counts in /proc/net/dev.
+
+1998-11-22 Martin Baulig <baulig@merkur.uni-trier.de>
+
+ * netload.c (glibtop_get_netload_s): Added implementation
+ for this function.
+
+ The code here is smart enough to use /proc/net/ip_acct if
+ IP accounting is enabled in the kernel and activated on the
+ requested device and /proc/net/dev if not.
+
+ To get separate statistics for received and transmitted
+ packets you need to use two accounting rules:
+
+ ipfwadm -A in -a -P all -W eth0
+ ipfwadm -A out -a -P all -W eth0
+
+ But before you activate IP accounting, please have a look
+ at /proc/net/dev - if if already contains byte counters,
+ then don't use IP accounting.
+
+1998-10-28 Martin Baulig <martin@home-of-linux.org>
+
+ * ppp.c: Added code for ISDN here.
+
+1998-10-26 Martin Baulig <martin@home-of-linux.org>
+
+ * netload.c: New file. Currently empty.
+
+1998-10-26 Martin Baulig <martin@home-of-linux.org>
+
+ * procargs.c: New file. Currently empty.
+
+1998-10-25 Martin Baulig <martin@home-of-linux.org>
+
+ * ppp.c: New file. Currently empty.
+
+1998-10-11 Martin Baulig <martin@home-of-linux.org>
+
+ * procdata.c: Removed this obsolete file.
+
+1998-10-02 Martin Baulig <martin@home-of-linux.org>
+
+ * proclist.c (glibtop_init_proclist_s): You can now also use the
+ `GLIBTOP_EXCLUDE_*' flags for the `which' parameter.
+
+1998-10-01 Martin Baulig <baulig@Stud.Informatik.uni-trier.de>
+
+ * proclist.c (glibtop_init_proclist_s): Honor the `which' parameter
+ to select which processes to fetch.
+
+1998-09-12 Martin Baulig <martin@home-of-linux.org>
+
+ * sysinfo.c: New file.
+
+1998-09-09 Martin Baulig <baulig@Stud.Informatik.uni-trier.de>
+
+ * proctime.c (glibtop_get_proc_time_s): Added SMP support.
+
+ * open.c (glibtop_init_s): Initialize `ncpu' on SMP systems.
+
+ * cpu.c (glibtop_get_cpu_s): Added SMP support.
+
+ * ChangeLog: New file.
+
diff --git a/sysdeps/linux/Makefile.am b/sysdeps/linux/Makefile.am
new file mode 100644
index 00000000..8ce5fee7
--- /dev/null
+++ b/sysdeps/linux/Makefile.am
@@ -0,0 +1,18 @@
+LINK = $(LIBTOOL) --mode=link $(CC) $(CFLAGS) $(LDFLAGS) -o $@
+
+INCLUDES = @INCLUDES@
+
+lib_LTLIBRARIES = libgtop_sysdeps-2.0.la
+
+libgtop_sysdeps_2_0_la_SOURCES = open.c close.c cpu.c mem.c swap.c \
+ uptime.c loadavg.c shm_limits.c msg_limits.c \
+ sem_limits.c proclist.c procstate.c procuid.c \
+ proctime.c procmem.c procsignal.c prockernel.c \
+ procsegment.c procargs.c procmap.c siglist.c \
+ sysinfo.c netload.c ppp.c
+libgtop_sysdeps_2_0_la_LIBADD = @GLIB_LIBS@
+
+libgtop_sysdeps_2_0_la_LDFLAGS = $(LT_VERSION_INFO)
+
+libgtopinclude_HEADERS = glibtop_server.h glibtop_machine.h
+libgtopincludedir = $(includedir)/libgtop-2.0
diff --git a/sysdeps/linux/close.c b/sysdeps/linux/close.c
new file mode 100644
index 00000000..4262d2f0
--- /dev/null
+++ b/sysdeps/linux/close.c
@@ -0,0 +1,30 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <glibtop/close.h>
+
+/* Closes pipe to gtop server. */
+
+void
+glibtop_close_s (glibtop *server)
+{ }
diff --git a/sysdeps/linux/cpu.c b/sysdeps/linux/cpu.c
new file mode 100644
index 00000000..012670ad
--- /dev/null
+++ b/sysdeps/linux/cpu.c
@@ -0,0 +1,111 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <config.h>
+#include <glibtop/error.h>
+#include <glibtop/cpu.h>
+
+static const unsigned long _glibtop_sysdeps_cpu =
+(1L << GLIBTOP_CPU_TOTAL) + (1L << GLIBTOP_CPU_USER) +
+(1L << GLIBTOP_CPU_NICE) + (1L << GLIBTOP_CPU_SYS) +
+(1L << GLIBTOP_CPU_IDLE) + (1L << GLIBTOP_CPU_FREQUENCY);
+
+static const unsigned long _glibtop_sysdeps_cpu_smp =
+(1L << GLIBTOP_XCPU_TOTAL) + (1L << GLIBTOP_XCPU_USER) +
+(1L << GLIBTOP_XCPU_NICE) + (1L << GLIBTOP_XCPU_SYS) +
+(1L << GLIBTOP_XCPU_IDLE);
+
+/* 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. */
+
+#define FILENAME "/proc/stat"
+
+void
+glibtop_get_cpu_s (glibtop *server, glibtop_cpu *buf)
+{
+ char buffer [BUFSIZ], *p;
+ int fd, len, i;
+ u_int64_t total;
+
+ glibtop_init_s (&server, GLIBTOP_SYSDEPS_CPU, 0);
+
+ memset (buf, 0, sizeof (glibtop_cpu));
+
+ fd = open (FILENAME, O_RDONLY);
+ if (fd < 0)
+ glibtop_error_io_r (server, "open (%s)", FILENAME);
+
+ len = read (fd, buffer, BUFSIZ-1);
+ if (len < 0)
+ glibtop_error_io_r (server, "read (%s)", FILENAME);
+
+ close (fd);
+
+ buffer [len] = '\0';
+
+ p = skip_token (buffer); /* "cpu" */
+
+ buf->user = strtoul (p, &p, 0);
+ buf->nice = strtoul (p, &p, 0);
+ buf->sys = strtoul (p, &p, 0);
+ buf->idle = strtoul (p, &p, 0);
+
+ total = buf->user;
+ total += buf->nice;
+ total += buf->sys;
+ total += buf->idle;
+ buf->total = total;
+
+ buf->frequency = 100;
+ buf->flags = _glibtop_sysdeps_cpu;
+
+ for (i = 0; i < server->ncpu; i++) {
+ if (strncmp (p+1, "cpu", 3) || !isdigit (p [4]))
+ break;
+
+ p += 6;
+ buf->xcpu_user [i] = strtoul (p, &p, 0);
+ buf->xcpu_nice [i] = strtoul (p, &p, 0);
+ buf->xcpu_sys [i] = strtoul (p, &p, 0);
+ buf->xcpu_idle [i] = strtoul (p, &p, 0);
+
+ total = buf->xcpu_user [i];
+ total += buf->xcpu_nice [i];
+ total += buf->xcpu_sys [i];
+ total += buf->xcpu_idle [i];
+
+ buf->xcpu_total [i] = total;
+ }
+
+ buf->flags |= _glibtop_sysdeps_cpu_smp;
+}
diff --git a/sysdeps/linux/glibtop_machine.h b/sysdeps/linux/glibtop_machine.h
new file mode 100644
index 00000000..9386b1b4
--- /dev/null
+++ b/sysdeps/linux/glibtop_machine.h
@@ -0,0 +1,58 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#ifndef __GLIBTOP_MACHINE_H__
+#define __GLIBTOP_MACHINE_H__
+
+#include <unistd.h>
+#include <fcntl.h>
+#include <ctype.h>
+
+BEGIN_LIBGTOP_DECLS
+
+#if _IN_LIBGTOP
+
+static inline char *
+skip_token(const char *p)
+{
+ while (isspace(*p)) p++;
+ while (*p && !isspace(*p)) p++;
+ return (char *)p;
+}
+
+#endif
+
+typedef struct _glibtop_machine glibtop_machine;
+
+struct _glibtop_machine
+{
+ pid_t last_pid;
+ int no_update;
+ int fd_stat, fd_meminfo, fd_loadavg;
+ char proc_stat [BUFSIZ], proc_statm [BUFSIZ];
+ char proc_status [BUFSIZ];
+};
+
+END_LIBGTOP_DECLS
+
+#endif
diff --git a/sysdeps/linux/glibtop_server.h b/sysdeps/linux/glibtop_server.h
new file mode 100644
index 00000000..e96b1169
--- /dev/null
+++ b/sysdeps/linux/glibtop_server.h
@@ -0,0 +1,135 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#ifndef __GLIBTOP_SERVER_H__
+#define __GLIBTOP_SERVER_H__
+
+#include <fcntl.h>
+#include <ctype.h>
+
+BEGIN_LIBGTOP_DECLS
+
+#ifdef _IN_LIBGTOP
+
+static inline char *
+skip_token (const char *p)
+{
+ while (isspace(*p)) p++;
+ while (*p && !isspace(*p)) p++;
+ return (char *)p;
+}
+
+static inline char *
+skip_multiple_token (const char *p, int count)
+{
+ int i;
+
+ for (i = 0; i < count; i++)
+ p = skip_token (p);
+
+ return (char *)p;
+}
+
+static inline char *
+skip_line (const char *p)
+{
+ while (*p != '\n') p++;
+ return (char *) ++p;
+}
+
+static inline int
+proc_file_to_buffer (char *buffer, const char *fmt, pid_t pid)
+{
+ char filename [BUFSIZ];
+ int fd, len;
+
+ sprintf (filename, fmt, pid);
+
+ fd = open (filename, O_RDONLY);
+ if (fd < 0) return -1;
+
+ len = read (fd, buffer, BUFSIZ-1);
+ close (fd);
+
+ if (len < 0)
+ return -1;
+
+ buffer [len] = '\0';
+
+ return 0;
+}
+
+static inline int
+proc_stat_to_buffer (char *buffer, pid_t pid)
+{
+ return proc_file_to_buffer (buffer, "/proc/%d/stat", pid);
+}
+
+static inline int
+proc_status_to_buffer (char *buffer, pid_t pid)
+{
+ return proc_file_to_buffer (buffer, "/proc/%d/status", pid);
+}
+
+static inline int
+proc_statm_to_buffer (char *buffer, pid_t pid)
+{
+ return proc_file_to_buffer (buffer, "/proc/%d/statm", pid);
+}
+
+static inline char *
+proc_stat_after_cmd (char *p)
+{
+ p = strrchr (p, ')');
+ if (!p) return p;
+
+ *p++ = '\0';
+ return p;
+}
+
+#endif
+
+#define GLIBTOP_SUID_CPU 0
+#define GLIBTOP_SUID_MEM 0
+#define GLIBTOP_SUID_SWAP 0
+#define GLIBTOP_SUID_UPTIME 0
+#define GLIBTOP_SUID_LOADAVG 0
+#define GLIBTOP_SUID_SHM_LIMITS 0
+#define GLIBTOP_SUID_MSG_LIMITS 0
+#define GLIBTOP_SUID_SEM_LIMITS 0
+#define GLIBTOP_SUID_PROCLIST 0
+#define GLIBTOP_SUID_PROC_STATE 0
+#define GLIBTOP_SUID_PROC_UID 0
+#define GLIBTOP_SUID_PROC_MEM 0
+#define GLIBTOP_SUID_PROC_TIME 0
+#define GLIBTOP_SUID_PROC_SIGNAL 0
+#define GLIBTOP_SUID_PROC_KERNEL 0
+#define GLIBTOP_SUID_PROC_SEGMENT 0
+#define GLIBTOP_SUID_PROC_ARGS 0
+#define GLIBTOP_SUID_PROC_MAP 0
+#define GLIBTOP_SUID_NETLOAD 0
+#define GLIBTOP_SUID_PPP 0
+
+END_LIBGTOP_DECLS
+
+#endif
diff --git a/sysdeps/linux/loadavg.c b/sysdeps/linux/loadavg.c
new file mode 100644
index 00000000..aedff8ca
--- /dev/null
+++ b/sysdeps/linux/loadavg.c
@@ -0,0 +1,94 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <config.h>
+#include <glibtop/error.h>
+#include <glibtop/loadavg.h>
+
+static const unsigned long _glibtop_sysdeps_loadavg =
+(1L << GLIBTOP_LOADAVG_LOADAVG);
+
+static const unsigned long _glibtop_sysdeps_loadavg_tasks =
+(1L << GLIBTOP_LOADAVG_NR_RUNNING) +
+(1L << GLIBTOP_LOADAVG_NR_TASKS) +
+(1L << GLIBTOP_LOADAVG_LAST_PID);
+
+/* Init function. */
+
+void
+glibtop_init_loadavg_s (glibtop *server)
+{
+ server->sysdeps.loadavg = _glibtop_sysdeps_loadavg;
+}
+
+/* Provides load load averange. */
+
+#define FILENAME "/proc/loadavg"
+
+void
+glibtop_get_loadavg_s (glibtop *server, glibtop_loadavg *buf)
+{
+ char buffer [BUFSIZ], *p, *old;
+ int fd, len;
+
+ glibtop_init_s (&server, GLIBTOP_SYSDEPS_LOADAVG, 0);
+
+ memset (buf, 0, sizeof (glibtop_loadavg));
+
+ fd = open (FILENAME, O_RDONLY);
+ if (fd < 0)
+ glibtop_error_io_r (server, "open (%s)", FILENAME);
+
+ len = read (fd, buffer, BUFSIZ-1);
+ if (len < 0)
+ glibtop_error_io_r (server, "read (%s)", FILENAME);
+
+ close (fd);
+
+ buffer [len] = '\0';
+
+ buf->loadavg [0] = (float) strtod (buffer, &p);
+ buf->loadavg [1] = (float) strtod (p, &p);
+ buf->loadavg [2] = (float) strtod (p, &p);
+
+ buf->flags = _glibtop_sysdeps_loadavg;
+
+ while (isspace(*p)) p++;
+
+ /* Older Linux versions don't have the nr_running/nr_tasks fields. */
+
+ old = p;
+ while (*p) {
+ if (*p == '/')
+ break;
+ if (!isdigit (*p))
+ return;
+ p++;
+ }
+
+ buf->nr_running = strtoul (old, &p, 0); p++;
+ buf->nr_tasks = strtoul (p, &p, 0);
+ buf->last_pid = strtoul (p, &p, 0);
+
+ buf->flags |= _glibtop_sysdeps_loadavg_tasks;
+}
diff --git a/sysdeps/linux/mem.c b/sysdeps/linux/mem.c
new file mode 100644
index 00000000..53b0f6a8
--- /dev/null
+++ b/sysdeps/linux/mem.c
@@ -0,0 +1,81 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <config.h>
+#include <glibtop/error.h>
+#include <glibtop/mem.h>
+
+static const unsigned long _glibtop_sysdeps_mem =
+(1L << GLIBTOP_MEM_TOTAL) + (1L << GLIBTOP_MEM_USED) +
+(1L << GLIBTOP_MEM_FREE) + (1L << GLIBTOP_MEM_SHARED) +
+(1L << GLIBTOP_MEM_BUFFER) + (1L << GLIBTOP_MEM_CACHED) +
+(1L << GLIBTOP_MEM_USER);
+
+/* Init function. */
+
+void
+glibtop_init_mem_s (glibtop *server)
+{
+ server->sysdeps.mem = _glibtop_sysdeps_mem;
+}
+
+/* Provides information about memory usage. */
+
+#define FILENAME "/proc/meminfo"
+
+void
+glibtop_get_mem_s (glibtop *server, glibtop_mem *buf)
+{
+ char buffer [BUFSIZ], *p;
+ int fd, len;
+
+ glibtop_init_s (&server, GLIBTOP_SYSDEPS_MEM, 0);
+
+ memset (buf, 0, sizeof (glibtop_mem));
+
+ fd = open (FILENAME, O_RDONLY);
+ if (fd < 0)
+ glibtop_error_io_r (server, "open (%s)", FILENAME);
+
+ len = read (fd, buffer, BUFSIZ-1);
+ if (len < 0)
+ glibtop_error_io_r (server, "read (%s)", FILENAME);
+
+ close (fd);
+
+ buffer [len] = '\0';
+
+ p = skip_line (buffer);
+ p = skip_token (p); /* "Mem:" */
+
+ buf->total = strtoul (p, &p, 0);
+ buf->used = strtoul (p, &p, 0);
+ buf->free = strtoul (p, &p, 0);
+ buf->shared = strtoul (p, &p, 0);
+ buf->buffer = strtoul (p, &p, 0);
+ buf->cached = strtoul (p, &p, 0);
+
+ buf->user = buf->total - buf->free - buf->cached - buf->buffer;
+
+ buf->flags = _glibtop_sysdeps_mem;
+}
diff --git a/sysdeps/linux/msg_limits.c b/sysdeps/linux/msg_limits.c
new file mode 100644
index 00000000..81d19c1f
--- /dev/null
+++ b/sysdeps/linux/msg_limits.c
@@ -0,0 +1,65 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <glibtop/msg_limits.h>
+
+#include <sys/ipc.h>
+#include <sys/msg.h>
+
+static const unsigned long _glibtop_sysdeps_msg_limits =
+(1L << GLIBTOP_IPC_MSGPOOL) + (1L << GLIBTOP_IPC_MSGMAP) +
+(1L << GLIBTOP_IPC_MSGMAX) + (1L << GLIBTOP_IPC_MSGMNB) +
+(1L << GLIBTOP_IPC_MSGMNI) + (1L << GLIBTOP_IPC_MSGSSZ) +
+(1L << GLIBTOP_IPC_MSGTQL);
+
+/* 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)
+{
+ struct msginfo msginfo;
+
+ glibtop_init_s (&server, GLIBTOP_SYSDEPS_MSG_LIMITS, 0);
+
+ memset (buf, 0, sizeof (glibtop_msg_limits));
+
+ buf->flags = _glibtop_sysdeps_msg_limits;
+
+ msgctl (0, IPC_INFO, (struct msqid_ds *) &msginfo);
+
+ buf->msgpool = msginfo.msgpool;
+ buf->msgmap = msginfo.msgmap;
+ buf->msgmax = msginfo.msgmax;
+ buf->msgmnb = msginfo.msgmnb;
+ buf->msgmni = msginfo.msgmni;
+ buf->msgssz = msginfo.msgssz;
+ buf->msgtql = msginfo.msgtql;
+}
diff --git a/sysdeps/linux/netload.c b/sysdeps/linux/netload.c
new file mode 100644
index 00000000..75cd1ab6
--- /dev/null
+++ b/sysdeps/linux/netload.c
@@ -0,0 +1,354 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, October 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <glibtop.h>
+#include <glibtop/error.h>
+#include <glibtop/netload.h>
+
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <sys/ioctl.h>
+
+#if !defined (_LIBC) && defined (__GNU_LIBRARY__) && __GNU_LIBRARY__ > 1
+/* GNU LibC */
+#include <net/if.h>
+#include <netinet/ip_icmp.h>
+#include <netinet/in.h>
+#include <netinet/ip.h>
+#include <netinet/tcp.h>
+#include <netinet/udp.h>
+#include <net/if.h>
+#else /* Libc 5 */
+#include <linux/if.h>
+#include <linux/in.h>
+#include <linux/ip.h>
+#include <linux/icmp.h>
+#include <linux/tcp.h>
+#include <linux/udp.h>
+#endif
+
+#define _GLIBTOP_IP_FW_ACCTIN 0x1000 /* Account incoming packets only. */
+#define _GLIBTOP_IP_FW_ACCTOUT 0x2000 /* Account outgoing packets only. */
+
+static const unsigned long _glibtop_sysdeps_netload =
+(1L << GLIBTOP_NETLOAD_ERRORS_IN) +
+(1L << GLIBTOP_NETLOAD_ERRORS_OUT) +
+(1L << GLIBTOP_NETLOAD_COLLISIONS);
+
+static const unsigned long _glibtop_sysdeps_netload_data =
+(1L << GLIBTOP_NETLOAD_ADDRESS) +
+(1L << GLIBTOP_NETLOAD_SUBNET) +
+(1L << GLIBTOP_NETLOAD_MTU);
+
+static const unsigned long _glibtop_sysdeps_netload_bytes =
+(1L << GLIBTOP_NETLOAD_BYTES_IN) +
+(1L << GLIBTOP_NETLOAD_BYTES_OUT) +
+(1L << GLIBTOP_NETLOAD_BYTES_TOTAL);
+
+static const unsigned long _glibtop_sysdeps_netload_packets =
+(1L << GLIBTOP_NETLOAD_PACKETS_IN) +
+(1L << GLIBTOP_NETLOAD_PACKETS_OUT) +
+(1L << GLIBTOP_NETLOAD_PACKETS_TOTAL);
+
+static const unsigned long _glibtop_sysdeps_netload_total =
+(1L << GLIBTOP_NETLOAD_PACKETS_TOTAL) +
+(1L << GLIBTOP_NETLOAD_BYTES_TOTAL);
+
+static const unsigned long _glibtop_sysdeps_netload_in =
+(1L << GLIBTOP_NETLOAD_PACKETS_TOTAL) +
+(1L << GLIBTOP_NETLOAD_BYTES_TOTAL) +
+(1L << GLIBTOP_NETLOAD_PACKETS_IN) +
+(1L << GLIBTOP_NETLOAD_BYTES_IN);
+
+static const unsigned long _glibtop_sysdeps_netload_out =
+(1L << GLIBTOP_NETLOAD_PACKETS_TOTAL) +
+(1L << GLIBTOP_NETLOAD_BYTES_TOTAL) +
+(1L << GLIBTOP_NETLOAD_PACKETS_OUT) +
+(1L << GLIBTOP_NETLOAD_BYTES_OUT);
+
+/* Init function. */
+
+void
+glibtop_init_netload_s (glibtop *server)
+{
+ server->sysdeps.netload = _glibtop_sysdeps_netload |
+ _glibtop_sysdeps_netload_data |
+ _glibtop_sysdeps_netload_bytes |
+ _glibtop_sysdeps_netload_packets;
+}
+
+/* Provides network statistics. */
+
+void
+glibtop_get_netload_s (glibtop *server, glibtop_netload *buf,
+ const char *interface)
+{
+ char buffer [BUFSIZ], *p;
+ int have_bytes, fields, skfd;
+ FILE *f;
+
+ memset (buf, 0, sizeof (glibtop_netload));
+
+ skfd = socket (AF_INET, SOCK_DGRAM, 0);
+ if (skfd) {
+ struct ifreq ifr;
+ unsigned flags;
+
+ strcpy (ifr.ifr_name, interface);
+ if (!ioctl (skfd, SIOCGIFFLAGS, &ifr)) {
+ buf->flags |= (1L << GLIBTOP_NETLOAD_IF_FLAGS);
+ flags = ifr.ifr_flags;
+ } else
+ flags = 0;
+
+ if (flags & IFF_UP)
+ buf->if_flags |= (1L << GLIBTOP_IF_FLAGS_UP);
+
+ if (flags & IFF_BROADCAST)
+ buf->if_flags |= (1L << GLIBTOP_IF_FLAGS_BROADCAST);
+
+ if (flags & IFF_DEBUG)
+ buf->if_flags |= (1L << GLIBTOP_IF_FLAGS_DEBUG);
+
+ if (flags & IFF_LOOPBACK)
+ buf->if_flags |= (1L << GLIBTOP_IF_FLAGS_LOOPBACK);
+
+ if (flags & IFF_POINTOPOINT)
+ buf->if_flags |= (1L << GLIBTOP_IF_FLAGS_POINTOPOINT);
+
+ if (flags & IFF_RUNNING)
+ buf->if_flags |= (1L << GLIBTOP_IF_FLAGS_RUNNING);
+
+ if (flags & IFF_NOARP)
+ buf->if_flags |= (1L << GLIBTOP_IF_FLAGS_NOARP);
+
+ if (flags & IFF_PROMISC)
+ buf->if_flags |= (1L << GLIBTOP_IF_FLAGS_PROMISC);
+
+ if (flags & IFF_ALLMULTI)
+ buf->if_flags |= (1L << GLIBTOP_IF_FLAGS_ALLMULTI);
+
+ if (flags & IFF_MULTICAST)
+ buf->if_flags |= (1L << GLIBTOP_IF_FLAGS_MULTICAST);
+
+ strcpy (ifr.ifr_name, interface);
+ if (!ioctl (skfd, SIOCGIFADDR, &ifr)) {
+ struct sockaddr_in addr =
+ *(struct sockaddr_in *) &ifr.ifr_addr;
+ buf->address = addr.sin_addr.s_addr;
+ buf->flags |= (1L << GLIBTOP_NETLOAD_ADDRESS);
+ }
+
+ strcpy (ifr.ifr_name, interface);
+ if (!ioctl (skfd, SIOCGIFNETMASK, &ifr)) {
+ struct sockaddr_in addr =
+ *(struct sockaddr_in *) &ifr.ifr_addr;
+ buf->subnet = addr.sin_addr.s_addr;
+ buf->flags |= (1L << GLIBTOP_NETLOAD_SUBNET);
+ }
+
+ strcpy (ifr.ifr_name, interface);
+ if (!ioctl (skfd, SIOCGIFMTU, &ifr)) {
+ buf->mtu = ifr.ifr_mtu;
+ buf->flags |= (1L << GLIBTOP_NETLOAD_MTU);
+ }
+
+ close (skfd);
+ }
+
+ /* Linux 2.1.114 - don't know where exactly this was added, but
+ * recent kernels have byte count in /proc/net/dev so we don't
+ * need IP accounting.
+ */
+
+ if (server->os_version_code < 131442) {
+
+ /* If IP accounting is enabled in the kernel and it is
+ * enabled for the requested interface, we use it to
+ * get the data. In this case, we don't use /proc/net/dev
+ * to get errors and collisions.
+ */
+
+ f = fopen ("/proc/net/ip_acct", "r");
+ if (f) {
+ int success = 0;
+
+ /* Skip over the header line. */
+ fgets (buffer, BUFSIZ-1, f);
+
+ while (fgets (buffer, BUFSIZ-1, f)) {
+ unsigned long flags, packets, bytes;
+ char *p, *dev;
+
+ /* Skip over the network thing. */
+ dev = skip_token (buffer) + 1;
+ p = skip_token (dev);
+ *p++ = 0;
+
+ if (strcmp (dev, interface))
+ continue;
+
+ success = 1;
+
+ p = skip_token (p);
+
+ flags = strtoul (p, &p, 16);
+
+ p = skip_multiple_token (p, 2);
+
+ packets = strtoul (p, &p, 0);
+ bytes = strtoul (p, &p, 0);
+
+ if (flags & _GLIBTOP_IP_FW_ACCTIN) {
+ /* Incoming packets only. */
+
+ buf->packets_total += packets;
+ buf->packets_in += packets;
+
+ buf->bytes_total += bytes;
+ buf->bytes_in += bytes;
+
+ buf->flags |= _glibtop_sysdeps_netload_in;
+
+ } else if (flags & _GLIBTOP_IP_FW_ACCTOUT) {
+ /* Outgoing packets only. */
+
+ buf->packets_total += packets;
+ buf->packets_out += packets;
+
+ buf->bytes_total += bytes;
+ buf->bytes_out += bytes;
+
+ buf->flags |= _glibtop_sysdeps_netload_out;
+
+ } else {
+ /* Only have total values. */
+
+ buf->packets_total += packets;
+ buf->bytes_total += bytes;
+
+ buf->flags |= _glibtop_sysdeps_netload_total;
+ }
+ }
+
+ fclose (f);
+
+ if (success) return;
+ }
+ }
+
+ /* Ok, either IP accounting is not enabled in the kernel or
+ * it was not enabled for the requested interface. */
+
+ f = fopen ("/proc/net/dev", "r");
+ if (!f) return;
+
+ /* Skip over the header line. */
+ fgets (buffer, BUFSIZ-1, f);
+ fgets (buffer, BUFSIZ-1, f);
+
+ /* Starting with 2.1.xx (don't know exactly which version)
+ * /proc/net/dev contains both byte and package counters. */
+
+ p = strchr (buffer, '|');
+ if (!p) {
+ fclose (f);
+ return;
+ }
+
+ /* Do we already have byte counters ? */
+ have_bytes = strncmp (++p, "bytes", 5) == 0;
+
+ /* Count remaining 'Receive' fields so we know where
+ * the first 'Transmit' field starts. */
+
+ fields = 0;
+ while (*p != '|') {
+ if (!isspace (*p++)) continue;
+ while (isspace (*p++)) ;
+ fields++;
+ }
+
+ /* Should never happen. */
+ if (fields < 2) {
+ fclose (f);
+ return;
+ }
+ fields--;
+
+ while (fgets (buffer, BUFSIZ-1, f)) {
+ char *p, *dev;
+
+ dev = buffer;
+ while (isspace (*dev)) dev++;
+
+ p = strchr (dev, ':');
+ if (!p) continue;
+ *p++ = 0;
+
+ /* If it's not a digit, then it's most likely an error
+ * message like 'No statistics available'. */
+ while (isspace (*p)) p++;
+ if (!isdigit (*p)) continue;
+
+ if (strcmp (dev, interface))
+ continue;
+
+ /* Only read byte counts if we really have them. */
+
+ if (have_bytes) {
+ buf->bytes_in = strtoul (p, &p, 0);
+ fields--;
+ }
+
+ buf->packets_in = strtoul (p, &p, 0);
+ buf->errors_in = strtoul (p, &p, 0);
+
+ p = skip_multiple_token (p, fields);
+
+ if (have_bytes)
+ buf->bytes_out = strtoul (p, &p, 0);
+
+ buf->packets_out = strtoul (p, &p, 0);
+ buf->errors_out = strtoul (p, &p, 0);
+
+ p = skip_multiple_token (p, 2);
+
+ buf->collisions = strtoul (p, &p, 0);
+
+ /* Compute total valules. */
+
+ buf->bytes_total = buf->bytes_in + buf->bytes_out;
+ buf->packets_total = buf->packets_in + buf->packets_out;
+
+ /* And now the flags. */
+
+ buf->flags |= _glibtop_sysdeps_netload;
+ buf->flags |= _glibtop_sysdeps_netload_packets;
+
+ if (have_bytes)
+ buf->flags |= _glibtop_sysdeps_netload_bytes;
+ }
+
+ fclose (f);
+}
diff --git a/sysdeps/linux/open.c b/sysdeps/linux/open.c
new file mode 100644
index 00000000..08bfa379
--- /dev/null
+++ b/sysdeps/linux/open.c
@@ -0,0 +1,109 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <glibtop.h>
+#include <glibtop/cpu.h>
+#include <glibtop/open.h>
+
+/* =====================================================
+ * Linux kernel version information for procps utilities
+ * Copyright (c) 1996 Charles Blake <cblake@bbn.com>
+ */
+#include <sys/utsname.h>
+
+#define LINUX_VERSION(x,y,z) (0x10000*(x) + 0x100*(y) + z)
+
+static int linux_version_code = 0;
+
+static void set_linux_version(void) {
+ static struct utsname uts;
+ int x = 0, y = 0, z = 0; /* cleared in case sscanf() < 3 */
+
+ if (linux_version_code) return;
+ if (uname(&uts) == -1) /* failure most likely implies impending death */
+ exit(1);
+ if (sscanf(uts.release, "%d.%d.%d", &x, &y, &z) < 3)
+ fprintf(stderr, /* *very* unlikely to happen by accident */
+ "Non-standard uts for running kernel:\n"
+ "release %s=%d.%d.%d gives version code %d\n",
+ uts.release, x, y, z, LINUX_VERSION(x,y,z));
+ linux_version_code = LINUX_VERSION(x, y, z);
+}
+
+/* ======================================================= */
+
+/* Opens pipe to gtop server. Returns 0 on success and -1 on error. */
+
+#define FILENAME "/proc/stat"
+
+void
+glibtop_open_s (glibtop *server, const char *program_name,
+ const unsigned long features,
+ const unsigned flags)
+{
+ char buffer [BUFSIZ], *p;
+ struct stat statb;
+ int fd, len, i;
+
+ server->name = program_name;
+
+ set_linux_version ();
+ server->os_version_code = (unsigned long) linux_version_code;
+
+ server->ncpu = 0;
+
+ /* On Linux 2.4.x, /proc/stat has "cpu" and "cpu0" entries even
+ * for non-SMP systems. Checking whether /proc/<pid>/cpu exists
+ * is a much better way to detect SMP. */
+
+ if (stat ("/proc/1/cpu", &statb))
+ return;
+
+ fd = open (FILENAME, O_RDONLY);
+ if (fd < 0)
+ glibtop_error_io_r (server, "open (%s)", FILENAME);
+
+ len = read (fd, buffer, BUFSIZ-1);
+ if (len < 0)
+ glibtop_error_io_r (server, "read (%s)", FILENAME);
+
+ close (fd);
+
+ buffer [len] = '\0';
+
+ p = skip_multiple_token (buffer, 5) + 1;
+
+ for (i = 0; i < GLIBTOP_NCPU; i++) {
+
+ if (strncmp (p, "cpu", 3) || !isdigit (p [3]))
+ break;
+
+ server->ncpu++;
+
+ p = skip_multiple_token (p, 5) + 1;
+ }
+
+#if DEBUG
+ printf ("\nThis machine has %d CPUs.\n\n", server->ncpu);
+#endif
+}
diff --git a/sysdeps/linux/ppp.c b/sysdeps/linux/ppp.c
new file mode 100644
index 00000000..ca476f8e
--- /dev/null
+++ b/sysdeps/linux/ppp.c
@@ -0,0 +1,201 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, October 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <glibtop.h>
+#include <glibtop/error.h>
+#include <glibtop/xmalloc.h>
+#include <glibtop/ppp.h>
+
+#include <linux/isdn.h>
+#include <sys/ioctl.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+
+#include <ctype.h>
+
+#include <glib.h>
+
+static const unsigned long _glibtop_sysdeps_ppp =
+(1L << GLIBTOP_PPP_STATE) + (1L << GLIBTOP_PPP_BYTES_IN) +
+(1L << GLIBTOP_PPP_BYTES_OUT);
+
+/* Init function. */
+
+void
+glibtop_init_ppp_s (glibtop *server)
+{
+ server->sysdeps.ppp = _glibtop_sysdeps_ppp;
+}
+
+static int
+get_ISDN_stats (glibtop *server, int *in, int *out)
+{
+ unsigned long *isdn_stats, *ptr;
+ int fd, i;
+
+ *in = *out = 0;
+
+ isdn_stats = glibtop_calloc_r (server, ISDN_MAX_CHANNELS * 2,
+ sizeof (unsigned long));
+
+ fd = open ("/dev/isdninfo", O_RDONLY);
+ if (fd < 0) {
+ glibtop_free_r (server, isdn_stats);
+ return FALSE;
+ }
+
+ if ((ioctl (fd, IIOCGETCPS, isdn_stats) < 0) && (errno != 0)) {
+ glibtop_free_r (server, isdn_stats);
+ close (fd);
+
+ return FALSE;
+ }
+
+ for (i = 0, ptr = isdn_stats; i < ISDN_MAX_CHANNELS; i++) {
+ *in += *ptr++; *out += *ptr++;
+ }
+
+ glibtop_free_r (server, isdn_stats);
+ close (fd);
+
+ return TRUE;
+}
+
+static int is_ISDN_on (glibtop *server, int *online)
+{
+ FILE *f = 0;
+ char buffer [BUFSIZ], *p;
+ int i;
+
+ /* Perhaps I should try to explain this code a little bit.
+ *
+ * ------------------------------------------------------------
+ * This is from the manpage of isdninfo(4):
+ *
+ * DESCRIPTION
+ * /dev/isdninfo is a character device with major number 45
+ * and minor number 255. It delivers status information from
+ * the Linux ISDN subsystem to user level.
+ *
+ * DATA FORMAT
+ * When reading from this device, the current status of the
+ * Linux ISDN subsystem is delivered in 6 lines of text. Each
+ * line starts with a tag string followed by a colon and
+ * whitespace. After that the status values are appended sep-
+ * arated by whitespace.
+ *
+ * flags is the tag of line 5. In this line for every driver
+ * slot, it's B-Channel status is shown. If no driver
+ * is registered in a slot, a ? is shown. For every
+ * established B-Channel of the driver, a bit is set
+ * in the shown value. The driver's first channel is
+ * mapped to bit 0, the second channel to bit 1 and so
+ * on.
+ * ------------------------------------------------------------
+ *
+ * So we open /dev/isdninfo, discard the first four lines of text
+ * and then check whether we have something that is not `0' or `?'
+ * in one of the flags fields.
+ *
+ * Sounds complicated, but I don't see any other way to check whether
+ * we are connected. Also, this is the method some other ISDN tools
+ * for Linux use.
+ *
+ * Martin
+ */
+
+ f = fopen ("/dev/isdninfo", "r");
+
+ if (!f) return FALSE;
+
+ for (i = 0; i < 5; i++) {
+ if (fgets (buffer, BUFSIZ, f) == NULL) {
+ fclose (f);
+ return FALSE;
+ }
+ }
+
+ if (strncmp (buffer, "flags:", 6)) {
+ fclose (f);
+ return FALSE;
+ }
+
+ p = buffer+6;
+
+ while (*p) {
+ char *end = p;
+
+ if (isspace (*p)) {
+ p++;
+ continue;
+ }
+
+ for (end = p; *end && !isspace (*end); end++)
+ ;
+
+ if (*end == 0)
+ break;
+ else
+ *end = 0;
+
+ if (!strcmp (p, "?") || !strcmp (p, "0")) {
+ p = end+1;
+ continue;
+ }
+
+ fclose (f);
+
+ *online = TRUE;
+ return TRUE;
+ }
+
+ fclose (f);
+
+ *online = FALSE;
+ return TRUE;
+}
+
+/* Provides PPP/ISDN information. */
+
+void
+glibtop_get_ppp_s (glibtop *server, glibtop_ppp *buf, unsigned short device)
+{
+ int in, out, online;
+
+ glibtop_init_s (&server, GLIBTOP_SYSDEPS_PPP, 0);
+
+ memset (buf, 0, sizeof (glibtop_ppp));
+
+ if (is_ISDN_on (server, &online)) {
+ buf->state = online ? GLIBTOP_PPP_STATE_ONLINE :
+ GLIBTOP_PPP_STATE_HANGUP;
+ buf->flags |= (1L << GLIBTOP_PPP_STATE);
+ }
+
+ if (get_ISDN_stats (server, &in, &out)) {
+ buf->bytes_in = in;
+ buf->bytes_out = out;
+ buf->flags |= (1L << GLIBTOP_PPP_BYTES_IN) |
+ (1L << GLIBTOP_PPP_BYTES_OUT);
+ }
+}
diff --git a/sysdeps/linux/procargs.c b/sysdeps/linux/procargs.c
new file mode 100644
index 00000000..5436bbdb
--- /dev/null
+++ b/sysdeps/linux/procargs.c
@@ -0,0 +1,101 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <glibtop.h>
+#include <glibtop/error.h>
+#include <glibtop/xmalloc.h>
+#include <glibtop/procargs.h>
+
+static const unsigned long _glibtop_sysdeps_proc_args =
+(1L << GLIBTOP_PROC_ARGS_SIZE);
+
+/* Init function. */
+
+void
+glibtop_init_proc_args_s (glibtop *server)
+{
+ server->sysdeps.proc_args = _glibtop_sysdeps_proc_args;
+}
+
+/* Provides detailed information about a process. */
+
+char *
+glibtop_get_proc_args_s (glibtop *server, glibtop_proc_args *buf,
+ pid_t pid, unsigned max_len)
+{
+ char fn [BUFSIZ], buffer [BUFSIZ];
+ int cmdline, len, total = 0;
+ char *retval = NULL;
+
+ glibtop_init_s (&server, GLIBTOP_SYSDEPS_PROC_ARGS, 0);
+
+ memset (buf, 0, sizeof (glibtop_proc_args));
+
+ sprintf (fn, "/proc/%d/cmdline", pid);
+
+ cmdline = open (fn, O_RDONLY);
+ if (cmdline < 0) return NULL;
+
+ if (max_len) {
+ retval = glibtop_malloc_r (server, max_len+1);
+
+ len = read (cmdline, retval, max_len);
+ close (cmdline);
+
+ if (len < 0) {
+ glibtop_free_r (server, retval);
+ return NULL;
+ }
+
+ *(retval+len) = 0;
+
+ buf->size = len;
+ buf->flags = _glibtop_sysdeps_proc_args;
+
+ return retval;
+ }
+
+ while (1) {
+ len = read (cmdline, buffer, BUFSIZ-1);
+ if (len < 0) {
+ close (cmdline);
+ glibtop_free_r (server, retval);
+ return NULL;
+ }
+
+ if (len == 0)
+ break;
+
+ retval = glibtop_realloc_r (server, retval, total+len+1);
+ memcpy (retval+total, buffer, len);
+ *(retval+total+len) = 0;
+ total += len;
+ }
+
+ close (cmdline);
+
+ buf->size = total;
+ buf->flags = _glibtop_sysdeps_proc_args;
+
+ return retval;
+}
diff --git a/sysdeps/linux/prockernel.c b/sysdeps/linux/prockernel.c
new file mode 100644
index 00000000..46a82ec6
--- /dev/null
+++ b/sysdeps/linux/prockernel.c
@@ -0,0 +1,77 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <glibtop.h>
+#include <glibtop/error.h>
+#include <glibtop/prockernel.h>
+
+static const unsigned long _glibtop_sysdeps_proc_kernel =
+(1L << GLIBTOP_PROC_KERNEL_K_FLAGS) + (1L << GLIBTOP_PROC_KERNEL_MIN_FLT) +
+(1L << GLIBTOP_PROC_KERNEL_MAJ_FLT) + (1L << GLIBTOP_PROC_KERNEL_CMIN_FLT) +
+(1L << GLIBTOP_PROC_KERNEL_CMAJ_FLT) + (1L << GLIBTOP_PROC_KERNEL_KSTK_ESP) +
+(1L << GLIBTOP_PROC_KERNEL_KSTK_EIP) + (1L << GLIBTOP_PROC_KERNEL_WCHAN);
+
+/* Init function. */
+
+void
+glibtop_init_proc_kernel_s (glibtop *server)
+{
+ server->sysdeps.proc_kernel = _glibtop_sysdeps_proc_kernel;
+}
+
+/* Provides detailed information about a process. */
+
+void
+glibtop_get_proc_kernel_s (glibtop *server, glibtop_proc_kernel *buf, pid_t pid)
+{
+ char buffer [BUFSIZ], *p;
+
+ glibtop_init_s (&server, GLIBTOP_SYSDEPS_PROC_KERNEL, 0);
+
+ memset (buf, 0, sizeof (glibtop_proc_kernel));
+
+ if (proc_stat_to_buffer (buffer, pid))
+ return;
+
+ p = proc_stat_after_cmd (buffer);
+ if (!p) return;
+
+ p = skip_multiple_token (p, 6);
+
+ buf->k_flags = strtoul (p, &p, 0);
+ buf->min_flt = strtoul (p, &p, 0);
+ buf->cmin_flt = strtoul (p, &p, 0);
+ buf->maj_flt = strtoul (p, &p, 0);
+ buf->cmaj_flt = strtoul (p, &p, 0);
+
+ p = skip_multiple_token (p, 15);
+
+ buf->kstk_esp = strtoul (p, &p, 0);
+ buf->kstk_eip = strtoul (p, &p, 0);
+
+ p = skip_multiple_token (p, 4);
+
+ buf->nwchan = strtoul (p, &p, 0);
+
+ buf->flags = _glibtop_sysdeps_proc_kernel;
+}
diff --git a/sysdeps/linux/proclist.c b/sysdeps/linux/proclist.c
new file mode 100644
index 00000000..cb6a664d
--- /dev/null
+++ b/sysdeps/linux/proclist.c
@@ -0,0 +1,233 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <config.h>
+#include <glibtop/xmalloc.h>
+#include <glibtop/proclist.h>
+
+#include <glibtop/procuid.h>
+#include <glibtop/procstate.h>
+
+#include <sys/stat.h>
+#include <unistd.h>
+#include <dirent.h>
+#include <ctype.h>
+
+static const unsigned long _glibtop_sysdeps_proclist =
+(1L << GLIBTOP_PROCLIST_TOTAL) + (1L << GLIBTOP_PROCLIST_NUMBER) +
+(1L << GLIBTOP_PROCLIST_SIZE);
+
+/* Init function. */
+
+void
+glibtop_init_proclist_s (glibtop *server)
+{
+ server->sysdeps.proclist = _glibtop_sysdeps_proclist;
+}
+
+#define BLOCK_COUNT 256
+#define BLOCK_SIZE (BLOCK_COUNT * sizeof (unsigned))
+
+/* Fetch list of currently running processes.
+ *
+ * The interface of this function is a little bit different from the others:
+ * buf->flags is only set if the call succeeded, in this case pids_chain,
+ * a list of the pids of all currently running processes is returned,
+ * buf->number is the number of elements of this list and buf->size is
+ * the size of one single element (sizeof (unsigned)). The total size is
+ * stored in buf->total.
+ *
+ * The calling function has to free the memory to which a pointer is returned.
+ *
+ * On error, NULL is returned and buf->flags is zero. */
+
+unsigned *
+glibtop_get_proclist_s (glibtop *server, glibtop_proclist *buf,
+ int64_t which, int64_t arg)
+{
+ DIR *proc;
+ struct dirent *entry;
+ char buffer [BUFSIZ];
+ unsigned count, total, pid;
+ unsigned pids [BLOCK_COUNT], *pids_chain = NULL;
+ unsigned pids_size = 0, pids_offset = 0, new_size;
+ struct stat statb;
+ int len, i, ok;
+
+ glibtop_proc_uid procuid;
+ glibtop_proc_state procstate;
+
+ glibtop_init_s (&server, GLIBTOP_SYSDEPS_PROCLIST, 0);
+
+ memset (buf, 0, sizeof (glibtop_proclist));
+
+ proc = opendir ("/proc");
+ if (!proc) return NULL;
+
+ /* read every every entry in /proc */
+
+ for (count = total = 0, entry = readdir (proc);
+ entry; entry = readdir (proc)) {
+ ok = 1; len = strlen (entry->d_name);
+
+ /* does it consist entirely of digits? */
+
+ for (i = 0; i < len; i++)
+ if (!isdigit (entry->d_name [i])) ok = 0;
+ if (!ok) continue;
+
+ /* convert it in a number */
+
+ if (sscanf (entry->d_name, "%u", &pid) != 1) continue;
+
+ /* is it really a directory? */
+
+ sprintf (buffer, "/proc/%d", pid);
+
+ if (stat (buffer, &statb)) continue;
+
+ if (!S_ISDIR (statb.st_mode)) continue;
+
+ switch (which & GLIBTOP_KERN_PROC_MASK) {
+ case GLIBTOP_KERN_PROC_ALL:
+ break;
+ case GLIBTOP_KERN_PROC_PID:
+ if ((unsigned) arg != pid)
+ continue;
+ break;
+ case GLIBTOP_KERN_PROC_UID:
+ if ((uid_t) arg != statb.st_uid)
+ continue;
+ break;
+ case GLIBTOP_KERN_PROC_PGRP:
+ /* Do you really, really need this ? */
+ glibtop_get_proc_uid_s (server, &procuid, pid);
+ if (procuid.flags & (1L << GLIBTOP_PROC_UID_PGRP))
+ if ((int) arg != procuid.pgrp)
+ continue;
+ break;
+ case GLIBTOP_KERN_PROC_SESSION:
+ /* Do you really, really need this ? */
+ glibtop_get_proc_uid_s (server, &procuid, pid);
+ if (procuid.flags & (1L << GLIBTOP_PROC_UID_SESSION))
+ if ((int) arg != procuid.session)
+ continue;
+ break;
+ case GLIBTOP_KERN_PROC_TTY:
+ /* Do you really, really need this ? */
+ glibtop_get_proc_uid_s (server, &procuid, pid);
+ if (procuid.flags & (1L << GLIBTOP_PROC_UID_TTY))
+ if ((int) arg != procuid.tty)
+ continue;
+ break;
+ case GLIBTOP_KERN_PROC_RUID:
+ /* Do you really, really need this ? */
+ glibtop_get_proc_uid_s (server, &procuid, pid);
+ if (procuid.flags & (1L << GLIBTOP_PROC_UID_EUID))
+ if ((int) arg != procuid.euid)
+ continue;
+ break;
+ }
+
+ if (which & GLIBTOP_EXCLUDE_NOTTY) {
+ glibtop_get_proc_uid_s (server, &procuid, pid);
+ if (procuid.flags & (1L << GLIBTOP_PROC_UID_TTY))
+ if (procuid.tty == -1) continue;
+ }
+
+ if (which & GLIBTOP_EXCLUDE_IDLE) {
+ glibtop_get_proc_state_s (server, &procstate, pid);
+ if (procstate.flags & (1L << GLIBTOP_PROC_STATE_STATE))
+ if (procstate.state != 'R') continue;
+ }
+
+ if (which & GLIBTOP_EXCLUDE_SYSTEM) {
+ glibtop_get_proc_uid_s (server, &procuid, pid);
+ if (procuid.flags & (1L << GLIBTOP_PROC_UID_UID))
+ if (procuid.uid == 0) continue;
+ }
+
+ /* Fine. Now we first try to store it in pids. If this buffer is
+ * full, we copy it to the pids_chain. */
+
+ if (count >= BLOCK_COUNT) {
+ /* The following call to glibtop_realloc will be
+ * equivalent to glibtop_malloc () if `pids_chain' is
+ * NULL. We just calculate the new size and copy `pids'
+ * to the beginning of the newly allocated block. */
+
+ new_size = pids_size + BLOCK_SIZE;
+
+ pids_chain = glibtop_realloc_r
+ (server, pids_chain, new_size);
+
+ memcpy (pids_chain + pids_offset, pids, BLOCK_SIZE);
+
+ pids_size = new_size;
+
+ pids_offset += BLOCK_COUNT;
+
+ count = 0;
+ }
+
+ /* pids is now big enough to hold at least one single pid. */
+
+ pids [count++] = pid;
+
+ total++;
+ }
+
+ closedir (proc);
+
+ /* count is only zero if an error occured (one a running Linux system,
+ * we have at least one single process). */
+
+ if (!count) return NULL;
+
+ /* The following call to glibtop_realloc will be equivalent to
+ * glibtop_malloc if pids_chain is NULL. We just calculate the
+ * new size and copy pids to the beginning of the newly allocated
+ * block. */
+
+ new_size = pids_size + count * sizeof (unsigned);
+
+ pids_chain = glibtop_realloc_r (server, pids_chain, new_size);
+
+ memcpy (pids_chain + pids_offset, pids, count * sizeof (unsigned));
+
+ pids_size = new_size;
+
+ pids_offset += BLOCK_COUNT;
+
+ /* Since everything is ok now, we can set buf->flags, fill in the
+ * remaining fields and return the `pids_chain'. */
+
+ buf->flags = _glibtop_sysdeps_proclist;
+
+ buf->size = sizeof (unsigned);
+ buf->number = total;
+
+ buf->total = total * sizeof (unsigned);
+
+ return pids_chain;
+}
diff --git a/sysdeps/linux/procmap.c b/sysdeps/linux/procmap.c
new file mode 100644
index 00000000..9052c84a
--- /dev/null
+++ b/sysdeps/linux/procmap.c
@@ -0,0 +1,138 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <glibtop.h>
+#include <glibtop/error.h>
+#include <glibtop/xmalloc.h>
+#include <glibtop/procmap.h>
+
+static const unsigned long _glibtop_sysdeps_proc_map =
+(1L << GLIBTOP_PROC_MAP_NUMBER) + (1L << GLIBTOP_PROC_MAP_TOTAL) +
+(1L << GLIBTOP_PROC_MAP_SIZE);
+
+static const unsigned long _glibtop_sysdeps_map_entry =
+(1L << GLIBTOP_MAP_ENTRY_START) + (1L << GLIBTOP_MAP_ENTRY_END) +
+(1L << GLIBTOP_MAP_ENTRY_OFFSET) + (1L << GLIBTOP_MAP_ENTRY_PERM) +
+(1L << GLIBTOP_MAP_ENTRY_INODE) + (1L << GLIBTOP_MAP_ENTRY_DEVICE) +
+(1L << GLIBTOP_MAP_ENTRY_FILENAME);
+
+/* Init function. */
+
+void
+glibtop_init_proc_map_s (glibtop *server)
+{
+ server->sysdeps.proc_map = _glibtop_sysdeps_proc_map;
+}
+
+/* Provides detailed information about a process. */
+
+glibtop_map_entry *
+glibtop_get_proc_map_s (glibtop *server, glibtop_proc_map *buf, pid_t pid)
+{
+ char fn [BUFSIZ];
+ glibtop_map_entry *entry_list = NULL;
+ int rv, n = 0;
+ FILE *maps;
+
+ glibtop_init_s (&server, GLIBTOP_SYSDEPS_PROC_MAP, 0);
+
+ memset (buf, 0, sizeof (glibtop_proc_map));
+
+ sprintf (fn, "/proc/%d/maps", pid);
+
+ maps = fopen (fn, "r");
+ if (!maps) return NULL;
+
+ do {
+ short dev_major, dev_minor;
+ unsigned long start, end, offset, inode, perm;
+ char flags [5], *format;
+ size_t size;
+
+ if (sizeof (void*) == 8)
+ format = "%16lx-%16lx %4c\n %16lx %02hx:%02hx %ld";
+ else
+ format = "%08lx-%08lx %4c\n %08lx %02hx:%02hx %ld";
+
+ rv = fscanf (maps, format,
+ &start, &end, flags, &offset,
+ &dev_major, &dev_minor, &inode);
+
+ flags [4] = 0;
+
+ /* Compute access permissions. */
+
+ perm = 0;
+
+ if (flags [0] == 'r')
+ perm |= GLIBTOP_MAP_PERM_READ;
+ if (flags [1] == 'w')
+ perm |= GLIBTOP_MAP_PERM_WRITE;
+ if (flags [2] == 'x')
+ perm |= GLIBTOP_MAP_PERM_EXECUTE;
+ if (flags [3] == 's')
+ perm |= GLIBTOP_MAP_PERM_SHARED;
+ if (flags [3] == 'p')
+ perm |= GLIBTOP_MAP_PERM_PRIVATE;
+
+ /* Read filename. */
+
+ fn [0] = fgetc (maps);
+
+ if (fn [0] != '\n' && fn [0] != EOF) {
+
+ fscanf (maps, "%*[ ]%[^\n]\n", fn);
+
+ } else fn [0] = 0;
+
+ size = (n+1) * sizeof (glibtop_map_entry);
+
+ entry_list = glibtop_realloc_r (server, entry_list, size);
+
+ memset (&(entry_list [n]), 0, sizeof (glibtop_map_entry));
+
+ entry_list [n].flags = _glibtop_sysdeps_map_entry;
+
+ entry_list [n].start = (u_int64_t) start;
+ entry_list [n].end = (u_int64_t) end;
+ entry_list [n].offset = (u_int64_t) offset;
+ entry_list [n].perm = (u_int64_t) perm;
+ entry_list [n].device = (u_int64_t) (dev_major << 8) +
+ (u_int64_t) dev_minor;
+ entry_list [n].inode = (u_int64_t) inode;
+
+ strncpy (entry_list [n].filename, fn, GLIBTOP_MAP_FILENAME_LEN);
+ entry_list [n].filename [GLIBTOP_MAP_FILENAME_LEN] = 0;
+
+ n++;
+
+ } while (rv != EOF && rv && fn [0] != EOF);
+
+ fclose (maps);
+
+ buf->number = n;
+ buf->size = sizeof (glibtop_map_entry);
+ buf->total = n * sizeof (glibtop_map_entry);
+
+ return entry_list;
+}
diff --git a/sysdeps/linux/procmem.c b/sysdeps/linux/procmem.c
new file mode 100644
index 00000000..3e868ee8
--- /dev/null
+++ b/sysdeps/linux/procmem.c
@@ -0,0 +1,104 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <glibtop.h>
+#include <glibtop/error.h>
+#include <glibtop/procmem.h>
+
+static const unsigned long _glibtop_sysdeps_proc_mem =
+(1L << GLIBTOP_PROC_MEM_VSIZE) + (1L << GLIBTOP_PROC_MEM_RSS) +
+(1L << GLIBTOP_PROC_MEM_RSS_RLIM);
+
+static const unsigned long _glibtop_sysdeps_proc_mem_statm =
+(1L << GLIBTOP_PROC_MEM_SIZE) + (1L << GLIBTOP_PROC_MEM_RESIDENT) +
+(1L << GLIBTOP_PROC_MEM_SHARE);
+
+#ifndef LOG1024
+#define LOG1024 10
+#endif
+
+/* these are for getting the memory statistics */
+static int pageshift; /* log base 2 of the pagesize */
+
+/* define pagetok in terms of pageshift */
+#define pagetok(size) ((size) << pageshift)
+
+/* Init function. */
+
+void
+glibtop_init_proc_mem_s (glibtop *server)
+{
+ register int pagesize;
+
+ server->sysdeps.proc_mem = _glibtop_sysdeps_proc_mem |
+ _glibtop_sysdeps_proc_mem_statm;
+
+ /* get the page size with "getpagesize" and calculate pageshift
+ * from it */
+ pagesize = getpagesize ();
+ pageshift = 0;
+ while (pagesize > 1) {
+ pageshift++;
+ pagesize >>= 1;
+ }
+}
+
+/* Provides detailed information about a process. */
+
+void
+glibtop_get_proc_mem_s (glibtop *server, glibtop_proc_mem *buf, pid_t pid)
+{
+ char buffer [BUFSIZ], *p;
+
+ glibtop_init_s (&server, GLIBTOP_SYSDEPS_MEM, 0);
+
+ memset (buf, 0, sizeof (glibtop_proc_mem));
+
+ if (proc_stat_to_buffer (buffer, pid))
+ return;
+
+ p = proc_stat_after_cmd (buffer);
+ if (!p) return;
+
+ p = skip_multiple_token (p, 20);
+
+ buf->vsize = strtoul (p, &p, 0);
+ buf->rss = strtoul (p, &p, 0);
+ buf->rss_rlim = strtoul (p, &p, 0);
+
+ buf->flags = _glibtop_sysdeps_proc_mem;
+
+ if (proc_statm_to_buffer (buffer, pid))
+ return;
+
+ buf->size = strtoul (buffer, &p, 0);
+ buf->resident = strtoul (p, &p, 0);
+ buf->share = strtoul (p, &p, 0);
+
+ buf->size <<= pageshift;
+ buf->resident <<= pageshift;
+ buf->share <<= pageshift;
+ buf->rss <<= pageshift;
+
+ buf->flags |= _glibtop_sysdeps_proc_mem_statm;
+}
diff --git a/sysdeps/linux/procsegment.c b/sysdeps/linux/procsegment.c
new file mode 100644
index 00000000..3179ae40
--- /dev/null
+++ b/sysdeps/linux/procsegment.c
@@ -0,0 +1,115 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <config.h>
+#include <glibtop/error.h>
+#include <glibtop/procsegment.h>
+
+static const unsigned long _glibtop_sysdeps_proc_segment =
+(1L << GLIBTOP_PROC_SEGMENT_START_CODE) +
+(1L << GLIBTOP_PROC_SEGMENT_END_CODE) +
+(1L << GLIBTOP_PROC_SEGMENT_START_STACK);
+
+static const unsigned long _glibtop_sysdeps_proc_segment_statm =
+(1L << GLIBTOP_PROC_SEGMENT_TEXT_RSS) +
+/* Disabled due to bug in the Linux Kernel. */
+/* (1L << GLIBTOP_PROC_SEGMENT_SHLIB_RSS) + */
+(1L << GLIBTOP_PROC_SEGMENT_DATA_RSS) +
+(1L << GLIBTOP_PROC_SEGMENT_DIRTY_SIZE);
+
+#ifndef LOG1024
+#define LOG1024 10
+#endif
+
+/* these are for getting the memory statistics */
+static int pageshift; /* log base 2 of the pagesize */
+
+/* define pagetok in terms of pageshift */
+#define pagetok(size) ((size) << pageshift)
+
+/* Init function. */
+
+void
+glibtop_init_proc_segment_s (glibtop *server)
+{
+ register int pagesize;
+
+ server->sysdeps.proc_segment = _glibtop_sysdeps_proc_segment |
+ _glibtop_sysdeps_proc_segment_statm;
+
+ /* get the page size with "getpagesize" and calculate pageshift
+ * from it */
+ pagesize = getpagesize ();
+ pageshift = 0;
+ while (pagesize > 1) {
+ pageshift++;
+ pagesize >>= 1;
+ }
+}
+
+/* Provides detailed information about a process. */
+
+void
+glibtop_get_proc_segment_s (glibtop *server, glibtop_proc_segment *buf,
+ pid_t pid)
+{
+ char buffer [BUFSIZ], *p;
+
+ glibtop_init_s (&server, GLIBTOP_SYSDEPS_PROC_SEGMENT, 0);
+
+ memset (buf, 0, sizeof (glibtop_proc_segment));
+
+ if (proc_stat_to_buffer (buffer, pid))
+ return;
+
+ p = proc_stat_after_cmd (buffer);
+ if (!p) return;
+
+ p = skip_multiple_token (p, 23);
+
+ buf->start_code = strtoul (p, &p, 0);
+ buf->end_code = strtoul (p, &p, 0);
+ buf->start_stack = strtoul (p, &p, 0);
+
+ buf->flags = _glibtop_sysdeps_proc_segment;
+
+ if (proc_statm_to_buffer (buffer, pid))
+ return;
+
+ p = skip_multiple_token (buffer, 3);
+
+ /* This doesn't work very well due to a bug in the Linux kernel.
+ * I'll submit a patch to the kernel mailing list soon. */
+
+ buf->text_rss = strtoul (p, &p, 0);
+ buf->shlib_rss = strtoul (p, &p, 0);
+ buf->data_rss = strtoul (p, &p, 0);
+ buf->dirty_size = strtoul (p, &p, 0);
+
+ buf->text_rss <<= pageshift;
+ buf->shlib_rss <<= pageshift;
+ buf->data_rss <<= pageshift;
+ buf->dirty_size <<= pageshift;
+
+ buf->flags |= _glibtop_sysdeps_proc_segment_statm;
+}
diff --git a/sysdeps/linux/procsignal.c b/sysdeps/linux/procsignal.c
new file mode 100644
index 00000000..7d8fa56c
--- /dev/null
+++ b/sysdeps/linux/procsignal.c
@@ -0,0 +1,65 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <glibtop.h>
+#include <glibtop/error.h>
+#include <glibtop/procsignal.h>
+
+static const unsigned long _glibtop_sysdeps_proc_signal =
+(1L << GLIBTOP_PROC_SIGNAL_SIGNAL) + (1L << GLIBTOP_PROC_SIGNAL_BLOCKED) +
+(1L << GLIBTOP_PROC_SIGNAL_SIGIGNORE) + (1L << GLIBTOP_PROC_SIGNAL_SIGCATCH);
+
+/* Init function. */
+
+void
+glibtop_init_proc_signal_s (glibtop *server)
+{
+ server->sysdeps.proc_signal = _glibtop_sysdeps_proc_signal;
+}
+
+/* Provides detailed information about a process. */
+
+void
+glibtop_get_proc_signal_s (glibtop *server, glibtop_proc_signal *buf, pid_t pid)
+{
+ char buffer [BUFSIZ], *p;
+
+ glibtop_init_s (&server, GLIBTOP_SYSDEPS_PROC_SIGNAL, 0);
+
+ memset (buf, 0, sizeof (glibtop_proc_signal));
+
+ if (proc_stat_to_buffer (buffer, pid))
+ return;
+
+ p = proc_stat_after_cmd (buffer);
+ if (!p) return;
+
+ p = skip_multiple_token (p, 28);
+
+ buf->signal [0] = strtoul (p, &p, 0);
+ buf->blocked [0] = strtoul (p, &p, 0);
+ buf->sigignore [0] = strtoul (p, &p, 0);
+ buf->sigcatch [0] = strtoul (p, &p, 0);
+
+ buf->flags = _glibtop_sysdeps_proc_signal;
+}
diff --git a/sysdeps/linux/procstate.c b/sysdeps/linux/procstate.c
new file mode 100644
index 00000000..39d93319
--- /dev/null
+++ b/sysdeps/linux/procstate.c
@@ -0,0 +1,93 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <glibtop.h>
+#include <glibtop/error.h>
+#include <glibtop/procstate.h>
+
+#include <sys/stat.h>
+
+static const unsigned long _glibtop_sysdeps_proc_state =
+(1L << GLIBTOP_PROC_STATE_CMD) + (1L << GLIBTOP_PROC_STATE_STATE);
+
+static const unsigned long _glibtop_sysdeps_proc_state_uid =
+(1L << GLIBTOP_PROC_STATE_UID) + (1L << GLIBTOP_PROC_STATE_GID);
+
+/* Init function. */
+
+void
+glibtop_init_proc_state_s (glibtop *server)
+{
+ server->sysdeps.proc_state = _glibtop_sysdeps_proc_state |
+ _glibtop_sysdeps_proc_state_uid;
+}
+
+/* Provides detailed information about a process. */
+
+void
+glibtop_get_proc_state_s (glibtop *server, glibtop_proc_state *buf, pid_t pid)
+{
+ char buffer [BUFSIZ], *p;
+ struct stat statb;
+
+ glibtop_init_s (&server, GLIBTOP_SYSDEPS_PROC_STATE, 0);
+
+ memset (buf, 0, sizeof (glibtop_proc_state));
+
+ /* IMPORTANT NOTICE: For security reasons it is extremely important
+ * that the 'uid' and 'gid' fields have correct
+ * values; NEVER set their flags values if this
+ * is not the case !!! */
+
+ sprintf (buffer, "/proc/%d", pid);
+
+ if (stat (buffer, &statb))
+ return;
+
+ /* For security reasons we use stat () since it is
+ * more failsafe than parsing the file. */
+
+ buf->uid = statb.st_uid;
+ buf->gid = statb.st_gid;
+
+ buf->flags = _glibtop_sysdeps_proc_state_uid;
+
+ sprintf (buffer, "/proc/%d", pid);
+
+ /* Now we read the remaining fields. */
+
+ if (proc_stat_to_buffer (buffer, pid))
+ return;
+
+ p = strrchr (buffer, ')'); *p = '\0';
+ buf->state = p [2];
+
+ p = skip_token (buffer); p++; /* pid */
+ if (*p++ != '(')
+ glibtop_error_r (server, "Bad data in /proc/%d/stat", pid);
+
+ strncpy (buf->cmd, p, sizeof (buf->cmd)-1);
+ buf->cmd [sizeof (buf->cmd)-1] = 0;
+
+ buf->flags |= _glibtop_sysdeps_proc_state;
+}
diff --git a/sysdeps/linux/proctime.c b/sysdeps/linux/proctime.c
new file mode 100644
index 00000000..83ea92b8
--- /dev/null
+++ b/sysdeps/linux/proctime.c
@@ -0,0 +1,103 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <glibtop.h>
+#include <glibtop/error.h>
+#include <glibtop/proctime.h>
+
+static const unsigned long _glibtop_sysdeps_proc_time =
+(1L << GLIBTOP_PROC_TIME_UTIME) + (1L << GLIBTOP_PROC_TIME_CUTIME) +
+(1L << GLIBTOP_PROC_TIME_STIME) + (1L << GLIBTOP_PROC_TIME_CSTIME) +
+(1L << GLIBTOP_PROC_TIME_FREQUENCY) + (1L << GLIBTOP_PROC_TIME_TIMEOUT) +
+(1L << GLIBTOP_PROC_TIME_IT_REAL_VALUE) + (1L << GLIBTOP_PROC_TIME_START_TIME);
+
+static const unsigned long _glibtop_sysdeps_proc_time_smp =
+(1L << GLIBTOP_PROC_TIME_XCPU_UTIME) + (1L << GLIBTOP_PROC_TIME_XCPU_STIME);
+
+/* Init function. */
+
+void
+glibtop_init_proc_time_s (glibtop *server)
+{
+ server->sysdeps.proc_time = _glibtop_sysdeps_proc_time;
+
+ if (server->ncpu)
+ server->sysdeps.proc_time |= _glibtop_sysdeps_proc_time_smp;
+}
+
+/* Provides detailed information about a process. */
+
+void
+glibtop_get_proc_time_s (glibtop *server, glibtop_proc_time *buf, pid_t pid)
+{
+ char buffer [BUFSIZ], *p;
+ int i;
+
+ glibtop_init_s (&server, GLIBTOP_SYSDEPS_PROC_TIME, 0);
+
+ memset (buf, 0, sizeof (glibtop_proc_time));
+
+ if (proc_stat_to_buffer (buffer, pid))
+ return;
+
+ p = proc_stat_after_cmd (buffer);
+ if (!p) return;
+
+ p = skip_multiple_token (p, 11);
+
+ buf->utime = strtoul (p, &p, 0);
+ buf->stime = strtoul (p, &p, 0);
+ buf->cutime = strtoul (p, &p, 0);
+ buf->cstime = strtoul (p, &p, 0);
+
+ p = skip_multiple_token (p, 2);
+
+ buf->timeout = strtoul (p, &p, 0);
+ buf->it_real_value = strtoul (p, &p, 0);
+ buf->start_time = strtoul (p, &p, 0);
+
+ buf->frequency = 100;
+
+ buf->flags = _glibtop_sysdeps_proc_time;
+
+ if (!server->ncpu)
+ return;
+
+ if (proc_file_to_buffer (buffer, "/proc/%d/cpu", pid))
+ return;
+
+ p = skip_token (buffer);
+ buf->utime = strtoul (p, &p, 0);
+ buf->stime = strtoul (p, &p, 0);
+
+ for (i = 0; i < GLIBTOP_NCPU; i++) {
+ if (strncmp (p+1, "cpu", 3) || !isdigit (p [4]))
+ break;
+
+ p += 6;
+ buf->xcpu_utime [i] = strtoul (p, &p, 0);
+ buf->xcpu_stime [i] = strtoul (p, &p, 0);
+ }
+
+ buf->flags |= _glibtop_sysdeps_proc_time_smp;
+}
diff --git a/sysdeps/linux/procuid.c b/sysdeps/linux/procuid.c
new file mode 100644
index 00000000..a7585dcc
--- /dev/null
+++ b/sysdeps/linux/procuid.c
@@ -0,0 +1,126 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <glibtop.h>
+#include <glibtop/error.h>
+#include <glibtop/procuid.h>
+
+static const unsigned long _glibtop_sysdeps_proc_uid =
+(1L << GLIBTOP_PROC_UID_UID) + (1L << GLIBTOP_PROC_UID_EUID) +
+(1L << GLIBTOP_PROC_UID_GID) + (1L << GLIBTOP_PROC_UID_EGID);
+
+static const unsigned long _glibtop_sysdeps_proc_uid_stat =
+(1L << GLIBTOP_PROC_UID_PID) + (1L << GLIBTOP_PROC_UID_PPID) +
+(1L << GLIBTOP_PROC_UID_PGRP) + (1L << GLIBTOP_PROC_UID_SESSION) +
+(1L << GLIBTOP_PROC_UID_TTY) + (1L << GLIBTOP_PROC_UID_TPGID) +
+(1L << GLIBTOP_PROC_UID_PRIORITY) + (1L << GLIBTOP_PROC_UID_NICE);
+
+#define LINUX_VERSION(x,y,z) (0x10000*(x) + 0x100*(y) + z)
+
+/* Init function. */
+
+void
+glibtop_init_proc_uid_s (glibtop *server)
+{
+ server->sysdeps.proc_uid = _glibtop_sysdeps_proc_uid |
+ _glibtop_sysdeps_proc_uid_stat;
+}
+
+/* Provides detailed information about a process. */
+
+void
+glibtop_get_proc_uid_s (glibtop *server, glibtop_proc_uid *buf, pid_t pid)
+{
+ char buffer [BUFSIZ], *p;
+
+ glibtop_init_s (&server, GLIBTOP_SYSDEPS_PROC_UID, 0);
+
+ memset (buf, 0, sizeof (glibtop_proc_uid));
+
+ if (proc_status_to_buffer (buffer, pid))
+ return;
+
+ /* Search substring 'Pid:' */
+
+ p = strstr (buffer, "\nPid:");
+ if (!p) return;
+
+ p = skip_token (p); /* "Pid:" */
+ buf->pid = strtoul (p, &p, 0);
+
+ p = skip_token (p); /* "PPid:" */
+ buf->ppid = strtoul (p, &p, 0);
+
+ /* Maybe future Linux versions place something between
+ * "PPid" and "Uid", so we catch this here. */
+ p = strstr (p, "\nUid:");
+ if (!p) return;
+
+ p = skip_token (p); /* "Uid:" */
+ buf->uid = strtoul (p, &p, 0);
+ buf->euid = strtoul (p, &p, 0);
+
+ /* We don't know how many entries on the "Uid:" line
+ * future Linux version will have, so we catch this here. */
+ p = strstr (p, "\nGid:");
+ if (!p) return;
+
+ p = skip_token (p); /* "Gid:" */
+ buf->gid = strtoul (p, &p, 0);
+ buf->egid = strtoul (p, &p, 0);
+
+ buf->flags = _glibtop_sysdeps_proc_uid;
+
+ if (proc_stat_to_buffer (buffer, pid))
+ return;
+
+ p = proc_stat_after_cmd (buffer);
+ if (!p) return;
+
+ p = skip_multiple_token (p, 2);
+
+ buf->pgrp = strtoul (p, &p, 0);
+ buf->session = strtoul (p, &p, 0);
+ buf->tty = strtoul (p, &p, 0);
+ buf->tpgid = strtoul (p, &p, 0);
+
+ p = skip_multiple_token (p, 9);
+
+ buf->priority = strtoul (p, &p, 0);
+ buf->nice = strtoul (p, &p, 0);
+
+ if (buf->tty == 0)
+ /* the old notty val, update elsewhere bef. moving to 0 */
+ buf->tty = -1;
+
+ if (server->os_version_code < LINUX_VERSION(1,3,39)) {
+ /* map old meanings to new */
+ buf->priority = 2*15 - buf->priority;
+ buf->nice = 15 - buf->nice;
+ }
+ if (server->os_version_code < LINUX_VERSION(1,1,30) && buf->tty != -1)
+ /* when tty wasn't full devno */
+ buf->tty = 4*0x100 + buf->tty;
+
+ buf->flags |= _glibtop_sysdeps_proc_uid_stat;
+}
diff --git a/sysdeps/linux/sem_limits.c b/sysdeps/linux/sem_limits.c
new file mode 100644
index 00000000..531b5f17
--- /dev/null
+++ b/sysdeps/linux/sem_limits.c
@@ -0,0 +1,86 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <glibtop/sem_limits.h>
+
+#include <sys/ipc.h>
+#include <sys/sem.h>
+
+#ifdef _SEM_SEMUN_UNDEFINED
+
+/* glibc 2.1 will no longer defines semun, instead it defines
+ * _SEM_SEMUN_UNDEFINED so users can define semun on their own.
+ * Thanks to Albert K T Hui <avatar@deva.net>. */
+
+union semun
+{
+ int val;
+ struct semid_ds *buf;
+ unsigned short int *array;
+ struct seminfo *__buf;
+};
+#endif
+
+static unsigned long _glibtop_sysdeps_sem_limits =
+(1L << GLIBTOP_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 ipc limits. */
+
+void
+glibtop_get_sem_limits_s (glibtop *server, glibtop_sem_limits *buf)
+{
+ struct seminfo seminfo;
+ union semun arg;
+
+ glibtop_init_s (&server, GLIBTOP_SYSDEPS_SEM_LIMITS, 0);
+
+ memset (buf, 0, sizeof (glibtop_sem_limits));
+
+ buf->flags = _glibtop_sysdeps_sem_limits;
+
+ arg.array = (ushort *) &seminfo;
+ semctl (0, 0, IPC_INFO, arg);
+
+ buf->semmap = seminfo.semmap;
+ buf->semmni = seminfo.semmni;
+ buf->semmns = seminfo.semmns;
+ buf->semmnu = seminfo.semmnu;
+ buf->semmsl = seminfo.semmsl;
+ buf->semopm = seminfo.semopm;
+ buf->semume = seminfo.semume;
+ buf->semusz = seminfo.semusz;
+ buf->semvmx = seminfo.semvmx;
+ buf->semaem = seminfo.semaem;
+}
diff --git a/sysdeps/linux/shm_limits.c b/sysdeps/linux/shm_limits.c
new file mode 100644
index 00000000..859160f1
--- /dev/null
+++ b/sysdeps/linux/shm_limits.c
@@ -0,0 +1,62 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <glibtop/shm_limits.h>
+
+#include <sys/ipc.h>
+#include <sys/shm.h>
+
+static unsigned long _glibtop_sysdeps_shm_limits =
+(1L << GLIBTOP_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)
+{
+ struct shminfo shminfo;
+
+ glibtop_init_s (&server, GLIBTOP_SYSDEPS_SHM_LIMITS, 0);
+
+ memset (buf, 0, sizeof (glibtop_shm_limits));
+
+ buf->flags = _glibtop_sysdeps_shm_limits;
+
+ shmctl (0, IPC_INFO, (struct shmid_ds *) &shminfo);
+
+ buf->shmmax = shminfo.shmmax;
+ buf->shmmin = shminfo.shmmin;
+ buf->shmmni = shminfo.shmmni;
+ buf->shmseg = shminfo.shmseg;
+ buf->shmall = shminfo.shmall;
+}
diff --git a/sysdeps/linux/siglist.c b/sysdeps/linux/siglist.c
new file mode 100644
index 00000000..d00223c0
--- /dev/null
+++ b/sysdeps/linux/siglist.c
@@ -0,0 +1,60 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <glibtop.h>
+#include <glibtop/signal.h>
+
+const glibtop_signame glibtop_sys_siglist [] =
+{ { 1, "SIGHUP", NULL }, /* Hangup (POSIX). */
+ { 2, "SIGINT", NULL }, /* Interrupt (ANSI). */
+ { 3, "SIGQUIT", NULL }, /* Quit (POSIX). */
+ { 4, "SIGILL", NULL }, /* Illegal instruction (ANSI). */
+ { 5, "SIGTRAP", NULL }, /* Trace trap (POSIX). */
+ { 6, "SIGABRT", NULL }, /* Abort (ANSI). */
+ { 7, "SIGBUS", NULL }, /* BUS error (4.2 BSD). */
+ { 8, "SIGFPE", NULL }, /* Floating-point exception (ANSI). */
+ { 9, "SIGKILL", NULL }, /* Kill, unblockable (POSIX). */
+ { 10, "SIGUSR1", NULL }, /* User-defined signal 1 (POSIX). */
+ { 11, "SIGSEGV", NULL }, /* Segmentation violation (ANSI). */
+ { 12, "SIGUSR2", NULL }, /* User-defined signal 2 (POSIX). */
+ { 13, "SIGPIPE", NULL }, /* Broken pipe (POSIX). */
+ { 14, "SIGALRM", NULL }, /* Alarm clock (POSIX). */
+ { 15, "SIGTERM", NULL }, /* Termination (ANSI). */
+ { 16, "SIGSTKFLT", NULL }, /* ??? */
+ { 17, "SIGCHLD", NULL }, /* Child status has changed (POSIX). */
+ { 18, "SIGCONT", NULL }, /* Continue (POSIX). */
+ { 19, "SIGSTOP", NULL }, /* Stop, unblockable (POSIX). */
+ { 20, "SIGTSTP", NULL }, /* Keyboard stop (POSIX). */
+ { 21, "SIGTTIN", NULL }, /* Background read from tty (POSIX). */
+ { 22, "SIGTTOU", NULL }, /* Background write to tty (POSIX). */
+ { 23, "SIGURG", NULL }, /* Urgent condition on socket (4.2 BSD). */
+ { 24, "SIGXCPU", NULL }, /* CPU limit exceeded (4.2 BSD). */
+ { 25, "SIGXFSZ", NULL }, /* File size limit exceeded (4.2 BSD). */
+ { 26, "SIGVTALRM", NULL }, /* Virtual alarm clock (4.2 BSD). */
+ { 27, "SIGPROF", NULL }, /* Profiling alarm clock (4.2 BSD). */
+ { 28, "SIGWINCH", NULL }, /* Window size change (4.3 BSD, Sun). */
+ { 29, "SIGIO", NULL }, /* I/O now possible (4.2 BSD). */
+ { 30, "SIGPWR", NULL }, /* Power failure restart (System V). */
+ { 31, "SIGUNUSED", NULL },
+ { 0, NULL, NULL },
+};
diff --git a/sysdeps/linux/swap.c b/sysdeps/linux/swap.c
new file mode 100644
index 00000000..2a7d639b
--- /dev/null
+++ b/sysdeps/linux/swap.c
@@ -0,0 +1,104 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <config.h>
+#include <glibtop/error.h>
+#include <glibtop/swap.h>
+
+#include <fcntl.h>
+
+static unsigned long _glibtop_sysdeps_swap =
+(1L << GLIBTOP_SWAP_TOTAL) + (1L << GLIBTOP_SWAP_USED) +
+(1L << GLIBTOP_SWAP_FREE);
+
+static unsigned long _glibtop_sysdeps_swap_paging =
+(1L << GLIBTOP_SWAP_PAGEIN) + (1L << GLIBTOP_SWAP_PAGEOUT);
+
+/* Init function. */
+
+void
+glibtop_init_swap_s (glibtop *server)
+{
+ server->sysdeps.swap = _glibtop_sysdeps_swap |
+ _glibtop_sysdeps_swap_paging;
+}
+
+/* Provides information about swap usage. */
+
+#define MEMINFO "/proc/meminfo"
+#define PROC_STAT "/proc/stat"
+
+void
+glibtop_get_swap_s (glibtop *server, glibtop_swap *buf)
+{
+ char buffer [BUFSIZ], *p;
+ int fd, len;
+
+ glibtop_init_s (&server, GLIBTOP_SYSDEPS_SWAP, 0);
+
+ memset (buf, 0, sizeof (glibtop_swap));
+
+ fd = open (MEMINFO, O_RDONLY);
+ if (fd < 0)
+ glibtop_error_io_r (server, "open (%s)", MEMINFO);
+
+ len = read (fd, buffer, BUFSIZ-1);
+ if (len < 0)
+ glibtop_error_io_r (server, "read (%s)", MEMINFO);
+
+ close (fd);
+
+ buffer [len] = '\0';
+
+ p = skip_line (buffer);
+ p = skip_line (p);
+ p = skip_token (p); /* "Swap:" */
+
+ buf->total = strtoul (p, &p, 0);
+ buf->used = strtoul (p, &p, 0);
+ buf->free = strtoul (p, &p, 0);
+
+ buf->flags = _glibtop_sysdeps_swap;
+
+ fd = open (PROC_STAT, O_RDONLY);
+ if (fd < 0)
+ glibtop_error_io_r (server, "open (%s)", PROC_STAT);
+
+ len = read (fd, buffer, BUFSIZ-1);
+ if (len < 0)
+ glibtop_error_io_r (server, "read (%s)", PROC_STAT);
+
+ close (fd);
+
+ buffer [len] = '\0';
+
+ p = strstr (buffer, "\nswap");
+ if (p == NULL) return;
+
+ p = skip_token (p);
+
+ buf->pagein = strtoul (p, &p, 0);
+ buf->pageout = strtoul (p, &p, 0);
+
+ buf->flags |= _glibtop_sysdeps_swap_paging;
+}
diff --git a/sysdeps/linux/sysinfo.c b/sysdeps/linux/sysinfo.c
new file mode 100644
index 00000000..d4a19bf3
--- /dev/null
+++ b/sysdeps/linux/sysinfo.c
@@ -0,0 +1,94 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <config.h>
+#include <glibtop/cpu.h>
+#include <glibtop/sysinfo.h>
+
+static const unsigned long _glibtop_sysdeps_sysinfo =
+(1L << GLIBTOP_SYSINFO_CPUINFO);
+
+static glibtop_sysinfo sysinfo;
+
+static void
+init_sysinfo (glibtop *server)
+{
+ char buffer [BUFSIZ];
+ static int init = 0;
+ glibtop_entry *cpuinfo = NULL;
+ FILE *f;
+
+ if (init) return;
+
+ init = TRUE;
+
+ glibtop_init_s (&server, GLIBTOP_SYSDEPS_CPU, 0);
+
+ memset (&sysinfo, 0, sizeof (glibtop_sysinfo));
+
+ g_return_if_fail (f = fopen ("/proc/cpuinfo", "r"));
+
+ while (fgets (buffer, BUFSIZ, f)) {
+ char *p, *start, *key, *value;
+
+ if (cpuinfo == NULL) {
+ cpuinfo = &sysinfo.cpuinfo [sysinfo.ncpu++];
+
+ cpuinfo->labels = g_ptr_array_new ();
+
+ cpuinfo->values = g_hash_table_new (NULL, NULL);
+
+ if (sysinfo.ncpu > GLIBTOP_NCPU)
+ sysinfo.ncpu = GLIBTOP_NCPU;
+ }
+
+ p = strchr (buffer, ':');
+ if (!p) continue;
+
+ /* Remove leading spaces from `p'. */
+ *p = '\0'; start = p; p++;
+ while (isspace (*p)) p++;
+
+ /* Remove trailing spaces from `buffer'. */
+ while ((start > buffer) && (*start) && isspace (*start))
+ *start-- = '\0';
+
+ key = g_strdup (buffer);
+ value = g_strdup (p);
+
+ g_ptr_array_add (cpuinfo->labels, key);
+
+ g_hash_table_insert (cpuinfo->values, key, value);
+ }
+
+ fclose (f);
+
+ sysinfo.flags = _glibtop_sysdeps_sysinfo;
+}
+
+glibtop_sysinfo *
+glibtop_get_sysinfo_s (glibtop *server)
+{
+ init_sysinfo (server);
+ return &sysinfo;
+}
diff --git a/sysdeps/linux/uptime.c b/sysdeps/linux/uptime.c
new file mode 100644
index 00000000..f54dd1c8
--- /dev/null
+++ b/sysdeps/linux/uptime.c
@@ -0,0 +1,69 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <config.h>
+#include <glibtop/error.h>
+#include <glibtop/uptime.h>
+
+static unsigned long _glibtop_sysdeps_uptime =
+(1L << GLIBTOP_UPTIME_UPTIME) + (1L << GLIBTOP_UPTIME_IDLETIME);
+
+/* Init function. */
+
+void
+glibtop_init_uptime_s (glibtop *server)
+{
+ server->sysdeps.uptime = _glibtop_sysdeps_uptime;
+}
+
+/* Provides uptime and idle time. */
+
+#define FILENAME "/proc/uptime"
+
+void
+glibtop_get_uptime_s (glibtop *server, glibtop_uptime *buf)
+{
+ char buffer [BUFSIZ], *p;
+ int fd, len;
+
+ glibtop_init_s (&server, GLIBTOP_SYSDEPS_UPTIME, 0);
+
+ memset (buf, 0, sizeof (glibtop_uptime));
+
+ fd = open (FILENAME, O_RDONLY);
+ if (fd < 0)
+ glibtop_error_io_r (server, "open (%s)", FILENAME);
+
+ len = read (fd, buffer, BUFSIZ-1);
+ if (len < 0)
+ glibtop_error_io_r (server, "read (%s)", FILENAME);
+
+ close (fd);
+
+ buffer [len] = '\0';
+
+ buf->uptime = strtod (buffer, &p);
+ buf->idletime = strtod (p, &p);
+
+ buf->flags = _glibtop_sysdeps_uptime;
+}
diff --git a/sysdeps/osf1/.cvsignore b/sysdeps/osf1/.cvsignore
new file mode 100644
index 00000000..ee69efbb
--- /dev/null
+++ b/sysdeps/osf1/.cvsignore
@@ -0,0 +1,21 @@
+.deps
+.libs
+Makefile
+Makefile.in
+close.lo
+cpu.lo
+libgtop_sysdeps.la
+libsysdeps.la
+loadavg.lo
+mem.lo
+msg_limits.lo
+open.lo
+proclist.lo
+sem_limits.lo
+shm_limits.lo
+swap.lo
+sysdeps.lo
+uptime.lo
+so_locations
+*.lo
+*.la
diff --git a/sysdeps/osf1/ChangeLog b/sysdeps/osf1/ChangeLog
new file mode 100644
index 00000000..76846805
--- /dev/null
+++ b/sysdeps/osf1/ChangeLog
@@ -0,0 +1,20 @@
+2001-10-17 Abel Cheung <maddog@linux.org.hk>
+
+ * Makefile.am: move header to $(includedir)/libgtop-1.0/glibtop.
+
+1999-05-11 Martin Baulig <martin@home-of-linux.org>
+
+ * procstate.c: Fixed implementation of the `state' field; added
+ `ruid' and `rgid' fields.
+
+1999-02-19 Martin Baulig <martin@home-of-linux.org>
+
+ * procmap.c, procargs.c, netload.c: Copied from stub_suid.
+
+ * proclist.c, procsegment.c: Make them compile again.
+
+1998-10-25 Martin Baulig <martin@home-of-linux.org>
+
+ * ChangeLog: New file.
+ * ppp.c: New file.
+
diff --git a/sysdeps/osf1/Makefile.am b/sysdeps/osf1/Makefile.am
new file mode 100644
index 00000000..2cccd0aa
--- /dev/null
+++ b/sysdeps/osf1/Makefile.am
@@ -0,0 +1,23 @@
+LINK = $(LIBTOOL) --mode=link $(CC) $(CFLAGS) $(LDFLAGS) -o $@
+
+INCLUDES = @INCLUDES@
+
+lib_LTLIBRARIES = libgtop_sysdeps-2.0.la libgtop_sysdeps_suid-2.0.la
+
+libgtop_sysdeps_2_0_la_SOURCES = open.c close.c siglist.c cpu.c mem.c swap.c \
+ uptime.c loadavg.c shm_limits.c msg_limits.c \
+ sem_limits.c ppp.c
+libgtop_sysdeps_2_0_la_LDFLAGS = $(LT_VERSION_INFO)
+libgtop_sysdeps_2_0_la_LIBADD = -lmach
+
+libgtop_sysdeps_suid_2_0_la_SOURCES = open_suid.c close_suid.c proclist.c \
+ procstate.c procuid.c proctime.c procmem.c \
+ procsignal.c prockernel.c procsegment.c \
+ procmap.c procargs.c netload.c
+libgtop_sysdeps_suid_2_0_la_LDFLAGS = $(LT_VERSION_INFO)
+libgtop_sysdeps_suid_2_0_la_LIBADD = -lmach
+
+libgtopinclude_HEADERS = glibtop_server.h glibtop_machine.h
+libgtopincludedir = $(includedir)/libgtop-2.0
+
+noinst_HEADERS = glibtop_suid.h
diff --git a/sysdeps/osf1/close.c b/sysdeps/osf1/close.c
new file mode 100644
index 00000000..4262d2f0
--- /dev/null
+++ b/sysdeps/osf1/close.c
@@ -0,0 +1,30 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <glibtop/close.h>
+
+/* Closes pipe to gtop server. */
+
+void
+glibtop_close_s (glibtop *server)
+{ }
diff --git a/sysdeps/osf1/close_suid.c b/sysdeps/osf1/close_suid.c
new file mode 100644
index 00000000..a8733f0f
--- /dev/null
+++ b/sysdeps/osf1/close_suid.c
@@ -0,0 +1,30 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <glibtop/close.h>
+
+/* Closes pipe to gtop server. */
+
+void
+glibtop_close_p (glibtop *server)
+{ }
diff --git a/sysdeps/osf1/cpu.c b/sysdeps/osf1/cpu.c
new file mode 100644
index 00000000..680c11f8
--- /dev/null
+++ b/sysdeps/osf1/cpu.c
@@ -0,0 +1,69 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <glibtop.h>
+#include <glibtop/error.h>
+#include <glibtop/cpu.h>
+
+static const unsigned long _glibtop_sysdeps_cpu =
+(1L << GLIBTOP_CPU_TOTAL) + (1L << GLIBTOP_CPU_USER) +
+(1L << GLIBTOP_CPU_NICE) + (1L << GLIBTOP_CPU_SYS) +
+(1L << GLIBTOP_CPU_IDLE) + (1L << GLIBTOP_CPU_FREQUENCY);
+
+/* Init function. */
+
+void
+glibtop_init_cpu_s (glibtop *server)
+{
+ server->sysdeps.cpu = _glibtop_sysdeps_cpu;
+}
+
+/* Provides information about cpu usage. */
+
+void
+glibtop_get_cpu_s (glibtop *server, glibtop_cpu *buf)
+{
+ struct tbl_sysinfo sysinfo;
+ int ret;
+
+ glibtop_init_s (&server, GLIBTOP_SYSDEPS_CPU, 0);
+
+ memset (buf, 0, sizeof (glibtop_cpu));
+
+ ret = table (TBL_SYSINFO, 0, (char *) &sysinfo, 1,
+ sizeof (struct tbl_sysinfo));
+
+ if (ret != 1) return;
+
+ buf->flags = _glibtop_sysdeps_cpu;
+
+ buf->user = sysinfo.si_user;
+ buf->nice = sysinfo.si_nice;
+ buf->sys = sysinfo.si_sys;
+ buf->idle = sysinfo.si_idle;
+
+ buf->total = sysinfo.si_user + sysinfo.si_nice +
+ sysinfo.si_sys + sysinfo.si_idle;
+
+ buf->frequency = sysinfo.si_hz;
+}
diff --git a/sysdeps/osf1/glibtop_machine.h b/sysdeps/osf1/glibtop_machine.h
new file mode 100644
index 00000000..a4424818
--- /dev/null
+++ b/sysdeps/osf1/glibtop_machine.h
@@ -0,0 +1,50 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#ifndef __GLIBTOP_MACHINE_H__
+#define __GLIBTOP_MACHINE_H__
+
+#include <sys/table.h>
+
+/* The following are defined in <sys/table.h>. */
+
+#undef sys
+#undef user
+#undef idle
+
+BEGIN_LIBGTOP_DECLS
+
+int table (int id, int index, char *addr, int nel, u_int lel);
+
+typedef struct _glibtop_machine glibtop_machine;
+
+struct _glibtop_machine
+{
+ uid_t uid, euid; /* Real and effective user id */
+ gid_t gid, egid; /* Real and effective group id */
+ unsigned proctable_entries; /* Max entries in the proctable */
+};
+
+END_LIBGTOP_DECLS
+
+#endif
diff --git a/sysdeps/osf1/glibtop_server.h b/sysdeps/osf1/glibtop_server.h
new file mode 100644
index 00000000..47d69199
--- /dev/null
+++ b/sysdeps/osf1/glibtop_server.h
@@ -0,0 +1,52 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#ifndef __GLIBTOP_SERVER_H__
+#define __GLIBTOP_SERVER_H__
+
+BEGIN_LIBGTOP_DECLS
+
+#define GLIBTOP_SUID_CPU 0
+#define GLIBTOP_SUID_MEM 0
+#define GLIBTOP_SUID_SWAP 0
+#define GLIBTOP_SUID_UPTIME 0
+#define GLIBTOP_SUID_LOADAVG 0
+#define GLIBTOP_SUID_SHM_LIMITS 0
+#define GLIBTOP_SUID_MSG_LIMITS 0
+#define GLIBTOP_SUID_SEM_LIMITS 0
+#define GLIBTOP_SUID_PROCLIST (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_MAP (1 << GLIBTOP_SYSDEPS_PROC_MAP)
+#define GLIBTOP_SUID_PROC_ARGS (1 << GLIBTOP_SYSDEPS_PROC_ARGS)
+#define GLIBTOP_SUID_NETLOAD (1 << GLIBTOP_SYSDEPS_NETLOAD)
+#define GLIBTOP_SUID_PPP 0
+
+END_LIBGTOP_DECLS
+
+#endif
diff --git a/sysdeps/osf1/glibtop_suid.h b/sysdeps/osf1/glibtop_suid.h
new file mode 100644
index 00000000..a83fd3cc
--- /dev/null
+++ b/sysdeps/osf1/glibtop_suid.h
@@ -0,0 +1,50 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#ifndef __GLIBTOP_SUID_H__
+#define __GLIBTOP_SUID_H__
+
+#include <sys/table.h>
+
+BEGIN_LIBGTOP_DECLS
+
+static inline void glibtop_suid_enter (glibtop *server) {
+ setreuid (server->machine.uid, server->machine.euid);
+};
+
+static inline void glibtop_suid_leave (glibtop *server) {
+ if (setreuid (server->machine.euid, server->machine.uid))
+ _exit (1);
+};
+
+void
+glibtop_init_p (glibtop *server, const unsigned long features,
+ const unsigned flags);
+void
+glibtop_open_p (glibtop *server, const char *program_name,
+ const unsigned long features,
+ const unsigned flags);
+
+END_LIBGTOP_DECLS
+
+#endif
diff --git a/sysdeps/osf1/loadavg.c b/sysdeps/osf1/loadavg.c
new file mode 100644
index 00000000..abf88ec7
--- /dev/null
+++ b/sysdeps/osf1/loadavg.c
@@ -0,0 +1,73 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <config.h>
+#include <glibtop/error.h>
+#include <glibtop/loadavg.h>
+
+static const unsigned long _glibtop_sysdeps_loadavg =
+(1L << GLIBTOP_LOADAVG_LOADAVG);
+
+/* Init function. */
+
+void
+glibtop_init_loadavg_s (glibtop *server)
+{
+ server->sysdeps.loadavg = _glibtop_sysdeps_loadavg;
+}
+
+/* Provides load averange. */
+
+void
+glibtop_get_loadavg_s (glibtop *server, glibtop_loadavg *buf)
+{
+ struct tbl_loadavg loadavg;
+ int ret;
+
+ glibtop_init_s (&server, GLIBTOP_SYSDEPS_LOADAVG, 0);
+
+ memset (buf, 0, sizeof (glibtop_loadavg));
+
+ ret = table (TBL_LOADAVG, 0, (char *) &loadavg, 1,
+ sizeof (struct tbl_loadavg));
+
+ if (ret != 1) return;
+
+ buf->flags = _glibtop_sysdeps_loadavg;
+
+ if (loadavg.tl_lscale == 0) {
+ buf->loadavg [0] = loadavg.tl_avenrun.d [0];
+ buf->loadavg [1] = loadavg.tl_avenrun.d [1];
+ buf->loadavg [2] = loadavg.tl_avenrun.d [2];
+ } else {
+ buf->loadavg [0] =
+ (double) loadavg.tl_avenrun.l [0] /
+ (double) loadavg.tl_mach_factor [0];
+ buf->loadavg [1] =
+ (double) loadavg.tl_avenrun.l [1]
+ / (double) loadavg.tl_mach_factor [1];
+ buf->loadavg [2] =
+ (double) loadavg.tl_avenrun.l [2] /
+ (double) loadavg.tl_mach_factor [2];
+ }
+}
diff --git a/sysdeps/osf1/mem.c b/sysdeps/osf1/mem.c
new file mode 100644
index 00000000..d76e595c
--- /dev/null
+++ b/sysdeps/osf1/mem.c
@@ -0,0 +1,69 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <glibtop.h>
+#include <glibtop/error.h>
+#include <glibtop/mem.h>
+
+#include <sys/vm.h>
+
+#include <mach.h>
+#include <mach/mach_types.h>
+#include <mach/vm_statistics.h>
+
+static const unsigned long _glibtop_sysdeps_mem =
+(1L << GLIBTOP_MEM_TOTAL) + (1L << GLIBTOP_MEM_USED) +
+(1L << GLIBTOP_MEM_FREE);
+
+/* Init function. */
+
+void
+glibtop_init_mem_s (glibtop *server)
+{
+ server->sysdeps.mem = _glibtop_sysdeps_mem;
+}
+
+/* Provides information about memory usage. */
+
+void
+glibtop_get_mem_s (glibtop *server, glibtop_mem *buf)
+{
+ vm_statistics_data_t vmstats;
+
+ glibtop_init_s (&server, GLIBTOP_SYSDEPS_MEM, 0);
+
+ memset (buf, 0, sizeof (glibtop_mem));
+
+ buf->flags = _glibtop_sysdeps_mem;
+
+ (void) vm_statistics(task_self(), &vmstats);
+
+ buf->free = vmstats.free_count * vmstats.pagesize;
+ buf->used = vmstats.active_count * vmstats.pagesize;
+
+ /* [FIXME]: Is this correct? */
+
+ buf->total = (vmstats.active_count + vmstats.inactive_count +
+ vmstats.free_count + vmstats.wire_count) *
+ vmstats.pagesize;
+}
diff --git a/sysdeps/osf1/msg_limits.c b/sysdeps/osf1/msg_limits.c
new file mode 100644
index 00000000..2b198963
--- /dev/null
+++ b/sysdeps/osf1/msg_limits.c
@@ -0,0 +1,87 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <glibtop.h>
+#include <glibtop/error.h>
+#include <glibtop/msg_limits.h>
+
+static const unsigned long _glibtop_sysdeps_msg_limits =
+(1L << GLIBTOP_IPC_MSGMAP) + (1L << GLIBTOP_IPC_MSGMAX) +
+(1L << GLIBTOP_IPC_MSGMNB) + (1L << GLIBTOP_IPC_MSGMNI) +
+(1L << GLIBTOP_IPC_MSGTQL);
+
+/* 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)
+{
+ int ret, value;
+
+ glibtop_init_s (&server, 0, 0);
+
+ memset (buf, 0, sizeof (glibtop_msg_limits));
+
+ ret = table (TBL_MSGINFO, MSGINFO_MAX, (char *) &value, 1,
+ sizeof (value));
+
+ if (ret != 1) return;
+
+ buf->flags += (1L << GLIBTOP_IPC_MSGMAX);
+
+ buf->msgmax = value;
+
+ ret = table (TBL_MSGINFO, MSGINFO_MNB, (char *) &value, 1,
+ sizeof (value));
+
+ if (ret != 1) return;
+
+ buf->flags += (1L << GLIBTOP_IPC_MSGMNB);
+
+ buf->msgmnb = value;
+
+ ret = table (TBL_MSGINFO, MSGINFO_MNI, (char *) &value, 1,
+ sizeof (value));
+
+ if (ret != 1) return;
+
+ buf->flags += (1L << GLIBTOP_IPC_MSGMNI);
+
+ buf->msgmni = value;
+
+ ret = table (TBL_MSGINFO, MSGINFO_TQL, (char *) &value, 1,
+ sizeof (value));
+
+ if (ret != 1) return;
+
+ buf->flags += (1L << GLIBTOP_IPC_MSGTQL);
+
+ buf->msgtql = value;
+}
diff --git a/sysdeps/osf1/netload.c b/sysdeps/osf1/netload.c
new file mode 100644
index 00000000..bb1226ed
--- /dev/null
+++ b/sysdeps/osf1/netload.c
@@ -0,0 +1,45 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, October 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <glibtop.h>
+#include <glibtop/error.h>
+#include <glibtop/netload.h>
+
+static const unsigned long _glibtop_sysdeps_netload = 0;
+
+/* 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)
+{
+ memset (buf, 0, sizeof (glibtop_netload));
+}
diff --git a/sysdeps/osf1/open.c b/sysdeps/osf1/open.c
new file mode 100644
index 00000000..645e22d8
--- /dev/null
+++ b/sysdeps/osf1/open.c
@@ -0,0 +1,35 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <glibtop.h>
+#include <glibtop/open.h>
+
+#include <unistd.h>
+#include <sys/types.h>
+
+/* Opens pipe to gtop server. Returns 0 on success and -1 on error. */
+
+void
+glibtop_open_s (glibtop *server, const char *program_name,
+ const unsigned long features, const unsigned flags)
+{ }
diff --git a/sysdeps/osf1/open_suid.c b/sysdeps/osf1/open_suid.c
new file mode 100644
index 00000000..d593556a
--- /dev/null
+++ b/sysdeps/osf1/open_suid.c
@@ -0,0 +1,91 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <glibtop.h>
+#include <glibtop/open.h>
+
+#include <glibtop_suid.h>
+
+#include <unistd.h>
+#include <sys/types.h>
+
+/* !!! THIS FUNCTION RUNS SUID ROOT - CHANGE WITH CAUTION !!! */
+
+void
+glibtop_init_p (glibtop *server, const unsigned long features,
+ const unsigned flags)
+{
+ glibtop_init_func_t *init_fkt;
+
+ if (server == NULL)
+ glibtop_error_r (NULL, "glibtop_init_p (server == NULL)");
+
+ /* Do the initialization, but only if not already initialized. */
+
+ if ((server->flags & _GLIBTOP_INIT_STATE_INIT) == 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_INIT;
+ }
+}
+
+/* !!! THIS FUNCTION RUNS SUID ROOT - CHANGE WITH CAUTION !!! */
+
+void
+glibtop_open_p (glibtop *server, const char *program_name,
+ const unsigned long features, const unsigned flags)
+{
+ /* !!! WE ARE ROOT HERE - CHANGE WITH CAUTION !!! */
+
+ server->name = program_name;
+
+ server->machine.uid = getuid ();
+ server->machine.euid = geteuid ();
+ server->machine.gid = getgid ();
+ server->machine.egid = getegid ();
+
+ server->machine.proctable_entries = table
+ (TBL_PROCINFO, 0, NULL, INT_MAX, 0);
+
+ /* Drop priviledges; we only become root when necessary.
+
+ setreuid (ruid, euid) - set real and effective user id;
+ setregid (rgid, egid) - set real and effective group id;
+
+ */
+
+ if (setreuid (server->machine.euid, server->machine.uid))
+ _exit (1);
+
+ if (setregid (server->machine.egid, server->machine.gid))
+ _exit (1);
+
+ /* !!! END OF SUID ROOT PART !!! */
+
+ /* Our effective uid is now those of the user invoking the server,
+ so we do no longer have any priviledges.
+ */
+}
diff --git a/sysdeps/osf1/ppp.c b/sysdeps/osf1/ppp.c
new file mode 100644
index 00000000..6d0905d5
--- /dev/null
+++ b/sysdeps/osf1/ppp.c
@@ -0,0 +1,44 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, October 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <glibtop.h>
+#include <glibtop/error.h>
+#include <glibtop/ppp.h>
+
+static const unsigned long _glibtop_sysdeps_ppp = 0;
+
+/* Init function. */
+
+void
+glibtop_init_ppp_s (glibtop *server)
+{
+ server->sysdeps.ppp = _glibtop_sysdeps_ppp;
+}
+
+/* Provides PPP/ISDN information. */
+
+void
+glibtop_get_ppp_s (glibtop *server, glibtop_ppp *buf, unsigned short device)
+{
+ memset (buf, 0, sizeof (glibtop_ppp));
+}
diff --git a/sysdeps/osf1/procargs.c b/sysdeps/osf1/procargs.c
new file mode 100644
index 00000000..67c183e8
--- /dev/null
+++ b/sysdeps/osf1/procargs.c
@@ -0,0 +1,47 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <glibtop.h>
+#include <glibtop/error.h>
+#include <glibtop/xmalloc.h>
+#include <glibtop/procargs.h>
+
+static const unsigned long _glibtop_sysdeps_proc_args = 0;
+
+/* 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)
+{
+ memset (buf, 0, sizeof (glibtop_proc_args));
+ return NULL;
+}
diff --git a/sysdeps/osf1/procdata.c b/sysdeps/osf1/procdata.c
new file mode 100644
index 00000000..96bb1430
--- /dev/null
+++ b/sysdeps/osf1/procdata.c
@@ -0,0 +1,150 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <config.h>
+#include <glibtop/procdata.h>
+
+#include <sys/user.h>
+#include <sys/time.h>
+#include <sys/resource.h>
+
+#include <mach.h>
+#include <mach/mach_types.h>
+#include <mach/task_info.h>
+
+/* Provides detailed information about a process. */
+
+#define BIT_SHIFT(x) (1L << (x % 64))
+
+static const unsigned long _glibtop_sysdeps_procdata_0 =
+BIT_SHIFT(GLIBTOP_PROCDATA_CMD) +
+BIT_SHIFT(GLIBTOP_PROCDATA_STATE) +
+BIT_SHIFT(GLIBTOP_PROCDATA_UID) +
+BIT_SHIFT(GLIBTOP_PROCDATA_PID) +
+BIT_SHIFT(GLIBTOP_PROCDATA_PPID) +
+BIT_SHIFT(GLIBTOP_PROCDATA_PGRP) +
+BIT_SHIFT(GLIBTOP_PROCDATA_TTY) +
+BIT_SHIFT(GLIBTOP_PROCDATA_K_FLAGS) +
+BIT_SHIFT(GLIBTOP_PROCDATA_SESSION) +
+BIT_SHIFT(GLIBTOP_PROCDATA_TPGID) +
+BIT_SHIFT(GLIBTOP_PROCDATA_SIGIGNORE) +
+BIT_SHIFT(GLIBTOP_PROCDATA_SIGCATCH) +
+BIT_SHIFT(GLIBTOP_PROCDATA_SIGNAL) +
+BIT_SHIFT(GLIBTOP_PROCDATA_NICE);
+
+static const unsigned long _glibtop_sysdeps_procdata_1 = 0;
+
+void
+glibtop_get_procdata_r (glibtop *server, glibtop_procdata *buf, pid_t pid)
+{
+ struct tbl_procinfo procinfo;
+ task_basic_info_data_t taskinfo;
+ struct user u;
+ task_t thistask;
+ int ret, info_count;
+
+ memset (buf, 0, sizeof (glibtop_procdata));
+
+ glibtop_init ();
+
+ memset (buf, 0, sizeof (glibtop_procdata));
+
+ ret = table (TBL_PROCINFO, pid, (char *) &procinfo, 1,
+ sizeof (struct tbl_procinfo));
+
+ if (ret != 1) return;
+
+ strcpy (buf->cmd, procinfo.pi_comm);
+
+ buf->uid = procinfo.pi_uid;
+ buf->pid = procinfo.pi_pid;
+ buf->ppid = procinfo.pi_ppid;
+ buf->pgrp = procinfo.pi_pgrp;
+ buf->tty = procinfo.pi_ttyd;
+ buf->k_flags = procinfo.pi_flag;
+ buf->session = procinfo.pi_session;
+ buf->tpgid = procinfo.pi_tpgrp;
+ buf->sigignore = procinfo.pi_sigignore;
+ buf->sigcatch = procinfo.pi_sigcatch;
+ buf->signal = procinfo.pi_sig;
+
+ buf->flags [0] += _glibtop_sysdeps_procdata_0;
+
+ if (procinfo.pi_status != PI_ACTIVE) return;
+
+ /* From that point on, we are only interested in active processes. */
+
+ buf->nice = getpriority (PRIO_PROCESS, pid);
+
+ /* Get task structure. */
+
+ ret = task_by_unix_pid (task_self(), procinfo.pi_pid, &thistask);
+
+ if (ret != KERN_SUCCESS) return;
+
+ /* Get taskinfo about this task. */
+
+ info_count = TASK_BASIC_INFO_COUNT;
+
+ ret = task_info (thistask, TASK_BASIC_INFO, (task_info_t) &taskinfo, &info_count);
+
+ if (ret != KERN_SUCCESS) return;
+
+ buf->priority = taskinfo.base_priority;
+ buf->resident = taskinfo.resident_size;
+ buf->rss = taskinfo.resident_size;
+ buf->vsize = taskinfo.virtual_size;
+
+ buf->flags [0] += BIT_SHIFT(GLIBTOP_PROCDATA_PRIORITY) +
+ BIT_SHIFT(GLIBTOP_PROCDATA_RESIDENT) +
+ BIT_SHIFT(GLIBTOP_PROCDATA_RSS) +
+ BIT_SHIFT(GLIBTOP_PROCDATA_VSIZE);
+
+ ret = table (TBL_UAREA, pid, (char *) &u, 1,
+ sizeof (struct user));
+
+ if (ret != 1) return;
+
+ buf->start_code = (unsigned long) u.u_text_start;
+ buf->end_code = (unsigned long) u.u_data_start;
+ buf->start_stack = (unsigned long) u.u_stack_start;
+
+ buf->trs = u.u_tsize;
+ buf->drs = u.u_dsize;
+
+ buf->start_time = u.u_start.tv_sec;
+
+ buf->utime = u.u_ru.ru_utime.tv_sec;
+ buf->stime = u.u_ru.ru_stime.tv_sec;
+ buf->cutime = u.u_cru.ru_utime.tv_sec;
+ buf->cstime = u.u_cru.ru_stime.tv_sec;
+
+ buf->flags [0] += BIT_SHIFT(GLIBTOP_PROCDATA_START_TIME) +
+ BIT_SHIFT(GLIBTOP_PROCDATA_UTIME) + BIT_SHIFT(GLIBTOP_PROCDATA_STIME) +
+ BIT_SHIFT(GLIBTOP_PROCDATA_CUTIME) + BIT_SHIFT(GLIBTOP_PROCDATA_CSTIME) +
+ BIT_SHIFT(GLIBTOP_PROCDATA_TRS) + BIT_SHIFT(GLIBTOP_PROCDATA_DRS);
+
+ buf->flags [1] += BIT_SHIFT(GLIBTOP_PROCDATA_START_CODE) +
+ BIT_SHIFT(GLIBTOP_PROCDATA_END_CODE) +
+ BIT_SHIFT(GLIBTOP_PROCDATA_START_STACK);
+}
diff --git a/sysdeps/osf1/prockernel.c b/sysdeps/osf1/prockernel.c
new file mode 100644
index 00000000..e7d961a1
--- /dev/null
+++ b/sysdeps/osf1/prockernel.c
@@ -0,0 +1,49 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <glibtop.h>
+#include <glibtop/error.h>
+#include <glibtop/prockernel.h>
+
+#include <glibtop_suid.h>
+
+static const unsigned long _glibtop_sysdeps_proc_kernel = 0;
+
+/* Init function. */
+
+void
+glibtop_init_proc_kernel_p (glibtop *server)
+{
+ server->sysdeps.proc_kernel = _glibtop_sysdeps_proc_kernel;
+}
+
+/* Provides detailed information about a process. */
+
+void
+glibtop_get_proc_kernel_p (glibtop *server, glibtop_proc_kernel *buf,
+ pid_t pid)
+{
+ glibtop_init_p (server, GLIBTOP_SYSDEPS_PROC_KERNEL, 0);
+
+ memset (buf, 0, sizeof (glibtop_proc_kernel));
+}
diff --git a/sysdeps/osf1/proclist.c b/sysdeps/osf1/proclist.c
new file mode 100644
index 00000000..607aeeae
--- /dev/null
+++ b/sysdeps/osf1/proclist.c
@@ -0,0 +1,172 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <glibtop.h>
+#include <glibtop/error.h>
+#include <glibtop/xmalloc.h>
+#include <glibtop/proclist.h>
+
+#include <glibtop_suid.h>
+
+static const unsigned long _glibtop_sysdeps_proclist =
+(1L << GLIBTOP_PROCLIST_TOTAL) + (1L << GLIBTOP_PROCLIST_NUMBER) +
+(1L << GLIBTOP_PROCLIST_SIZE);
+
+/* Init function. */
+
+void
+glibtop_init_proclist_p (glibtop *server)
+{
+ server->sysdeps.proclist = _glibtop_sysdeps_proclist;
+}
+
+/* How many elements are there per proctable entry? */
+
+#define ELEMENTS_PER_ENTRY 8
+
+/* We have a buffer for BLOCK_COUNT pids; when it's full, it is copied
+ * to a newly realloc()ed area. */
+
+#define BLOCK_COUNT 256
+#define BLOCK_SIZE (BLOCK_COUNT * sizeof (unsigned))
+
+/* Fetch list of currently running processes.
+ *
+ * The interface of this function is a little bit different from the others:
+ * buf->flags is only set if the call succeeded, in this case pids_chain,
+ * a list of the pids of all currently running processes is returned,
+ * buf->number is the number of elements of this list and buf->size is
+ * the size of one single element (sizeof (unsigned)). The total size is
+ * stored in buf->total.
+ *
+ * The calling function has to free the memory to which a pointer is returned.
+ *
+ * On error, NULL is returned and buf->flags is zero. */
+
+/* !!! THIS FUNCTION RUNS SUID ROOT - CHANGE WITH CAUTION !!! */
+
+unsigned *
+glibtop_get_proclist_p (glibtop *server, glibtop_proclist *buf,
+ int64_t which, int64_t arg)
+{
+ unsigned count = 0, total = 0;
+ unsigned pids [BLOCK_COUNT], *pids_chain = NULL;
+ unsigned pids_size = 0, pids_offset = 0, new_size;
+ struct tbl_procinfo procinfo [8];
+ int entry, max_elements, k;
+
+ glibtop_init_p (server, GLIBTOP_SYSDEPS_PROCLIST, 0);
+
+ memset (buf, 0, sizeof (glibtop_proclist));
+
+ for (entry = 0; entry < server->machine.proctable_entries;
+ entry += ELEMENTS_PER_ENTRY)
+ {
+ /* !!! THE FOLLOWING CODE RUNS SUID ROOT -
+ * CHANGE WITH CAUTION !!! */
+
+ glibtop_suid_enter (server);
+
+ max_elements = table
+ (TBL_PROCINFO, entry, (char *) &procinfo,
+ ELEMENTS_PER_ENTRY, sizeof (struct tbl_procinfo));
+
+ glibtop_suid_leave (server);
+
+ /* !!! END OF SUID ROOT PART !!! */
+
+ for (k = 0; k < max_elements; k++)
+ {
+ /* Does this entry contain a real process? */
+
+ if (procinfo [k].pi_status == 0)
+ continue;
+
+ /* Fine. Now we first try to store it in pids.
+ * If this buffer is full, we copy it to the
+ * pids_chain. */
+
+ if (count >= BLOCK_COUNT) {
+
+ /* The following call to glibtop_realloc ()
+ * will be equivalent to glibtop_malloc ()
+ * if `pids_chain' is NULL. We just calculate
+ * the new size and copy `pids' to the
+ * beginning of the newly allocated block. */
+
+ new_size = pids_size + BLOCK_SIZE;
+
+ pids_chain = glibtop_realloc_r
+ (server, pids_chain, new_size);
+
+ memcpy (pids_chain + pids_offset,
+ pids, BLOCK_SIZE);
+
+ pids_size = new_size;
+
+ pids_offset += BLOCK_COUNT;
+
+ count = 0;
+ }
+
+ /* pids is now big enough to hold at least
+ * one single pid. */
+
+ pids [count++] = procinfo [k].pi_pid;
+
+ total++;
+ }
+ }
+
+ /* count is only zero if an error occured
+ * (eg. the server is not suid root). */
+
+ if (!count) return NULL;
+
+ /* The following call to glibtop_realloc () will be equivalent to
+ * glibtop_malloc () if `pids_chain' is NULL. We just calculate the
+ * new size and copy `pids' to the beginning of the newly allocated
+ * block. */
+
+ new_size = pids_size + count * sizeof (unsigned);
+
+ pids_chain = glibtop_realloc_r (server, pids_chain, new_size);
+
+ memcpy (pids_chain + pids_offset, pids, count * sizeof (unsigned));
+
+ pids_size = new_size;
+
+ pids_offset += BLOCK_COUNT;
+
+ /* Since everything is ok now, we can set buf->flags, fill in the
+ * remaining fields and return `pids_chain'. */
+
+ buf->flags = _glibtop_sysdeps_proclist;
+
+ buf->size = sizeof (unsigned);
+ buf->number = total;
+
+ buf->total = total * sizeof (unsigned);
+
+ return pids_chain;
+}
diff --git a/sysdeps/osf1/procmap.c b/sysdeps/osf1/procmap.c
new file mode 100644
index 00000000..0b9bd6e0
--- /dev/null
+++ b/sysdeps/osf1/procmap.c
@@ -0,0 +1,46 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <glibtop.h>
+#include <glibtop/error.h>
+#include <glibtop/xmalloc.h>
+#include <glibtop/procmap.h>
+
+static const unsigned long _glibtop_sysdeps_proc_map = 0;
+
+/* 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)
+{
+ memset (buf, 0, sizeof (glibtop_proc_map));
+ return NULL;
+}
diff --git a/sysdeps/osf1/procmem.c b/sysdeps/osf1/procmem.c
new file mode 100644
index 00000000..05038c5b
--- /dev/null
+++ b/sysdeps/osf1/procmem.c
@@ -0,0 +1,103 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <glibtop.h>
+#include <glibtop/error.h>
+#include <glibtop/procmem.h>
+
+#include <glibtop_suid.h>
+
+#include <sys/user.h>
+#include <sys/time.h>
+#include <sys/resource.h>
+
+#include <mach.h>
+#include <mach/mach_types.h>
+#include <mach/task_info.h>
+
+static const unsigned long _glibtop_sysdeps_proc_mem =
+(1L << GLIBTOP_PROC_MEM_VSIZE) + (1L << GLIBTOP_PROC_MEM_RESIDENT) +
+(1L << GLIBTOP_PROC_MEM_RSS);
+
+/* 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)
+{
+ task_basic_info_data_t taskinfo;
+ int ret, info_count;
+ task_t thistask;
+ struct user u;
+
+ glibtop_init_p (server, GLIBTOP_SYSDEPS_PROC_MEM, 0);
+
+ memset (buf, 0, sizeof (glibtop_proc_mem));
+
+ /* Get task structure. */
+
+ ret = task_by_unix_pid (task_self(), pid, &thistask);
+
+ if (ret != KERN_SUCCESS) return;
+
+ /* Get taskinfo about this task. */
+
+ info_count = TASK_BASIC_INFO_COUNT;
+
+ ret = task_info (thistask, TASK_BASIC_INFO,
+ (task_info_t) &taskinfo, &info_count);
+
+ if (ret != KERN_SUCCESS) return;
+
+ buf->resident = taskinfo.resident_size;
+ buf->rss = taskinfo.resident_size;
+ buf->vsize = taskinfo.virtual_size;
+
+ /* !!! THE FOLLOWING CODE RUNS SUID ROOT - CHANGE WITH CAUTION !!! */
+
+ glibtop_suid_enter (server);
+
+ ret = table (TBL_UAREA, pid, (char *) &u, 1,
+ sizeof (struct user));
+
+ glibtop_suid_leave (server);
+
+ /* !!! END OF SUID ROOT PART !!! */
+
+ if (ret != 1) return;
+
+ buf->rss_rlim = u.u_rlimit [RLIMIT_RSS].rlim_cur;
+
+ buf->share = u.u_ru.ru_ixrss;
+
+ buf->flags |= (1L << GLIBTOP_PROC_MEM_RSS_RLIM) |
+ (1L << GLIBTOP_PROC_MEM_SHARE);
+}
diff --git a/sysdeps/osf1/procsegment.c b/sysdeps/osf1/procsegment.c
new file mode 100644
index 00000000..935a1b0b
--- /dev/null
+++ b/sysdeps/osf1/procsegment.c
@@ -0,0 +1,80 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <glibtop.h>
+#include <glibtop/procsegment.h>
+
+#include <glibtop_suid.h>
+
+#include <sys/user.h>
+
+static const unsigned long _glibtop_sysdeps_proc_segment =
+(1L << GLIBTOP_PROC_SEGMENT_TEXT_RSS) +
+(1L << GLIBTOP_PROC_SEGMENT_DATA_RSS) +
+(1L << GLIBTOP_PROC_SEGMENT_START_CODE) +
+(1L << GLIBTOP_PROC_SEGMENT_END_CODE) +
+(1L << GLIBTOP_PROC_SEGMENT_START_STACK);
+
+/* Init function. */
+
+void
+glibtop_init_proc_segment_p (glibtop *server)
+{
+ 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)
+{
+ int ret;
+ struct user u;
+
+ glibtop_init_p (server, GLIBTOP_SYSDEPS_PROC_SEGMENT, 0);
+
+ memset (buf, 0, sizeof (glibtop_proc_segment));
+
+ /* !!! THE FOLLOWING CODE RUNS SUID ROOT - CHANGE WITH CAUTION !!! */
+
+ glibtop_suid_enter (server);
+
+ ret = table (TBL_UAREA, pid, (char *) &u, 1,
+ sizeof (struct user));
+
+ glibtop_suid_leave (server);
+
+ /* !!! END OF SUID ROOT PART !!! */
+
+ if (ret != 1) return;
+
+ buf->start_code = (unsigned long) u.u_text_start;
+ buf->end_code = (unsigned long) u.u_data_start;
+ buf->start_stack = (unsigned long) u.u_stack_start;
+
+ buf->text_rss = u.u_tsize;
+ buf->data_rss = u.u_dsize;
+
+ buf->flags = _glibtop_sysdeps_proc_segment;
+}
diff --git a/sysdeps/osf1/procsignal.c b/sysdeps/osf1/procsignal.c
new file mode 100644
index 00000000..36e1e2b9
--- /dev/null
+++ b/sysdeps/osf1/procsignal.c
@@ -0,0 +1,74 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <glibtop.h>
+#include <glibtop/error.h>
+#include <glibtop/procsignal.h>
+
+#include <glibtop_suid.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;
+}
+
+/* Provides detailed information about a process. */
+
+void
+glibtop_get_proc_signal_p (glibtop *server, glibtop_proc_signal *buf,
+ pid_t pid)
+{
+ struct tbl_procinfo procinfo;
+ int ret;
+
+ glibtop_init_p (server, GLIBTOP_SYSDEPS_PROC_SIGNAL, 0);
+
+ memset (buf, 0, sizeof (glibtop_proc_signal));
+
+ /* !!! THE FOLLOWING CODE RUNS SUID ROOT - CHANGE WITH CAUTION !!! */
+
+ glibtop_suid_enter (server);
+
+ ret = table (TBL_PROCINFO, pid, (char *) &procinfo, 1,
+ sizeof (struct tbl_procinfo));
+
+ glibtop_suid_leave (server);
+
+ /* !!! END OF SUID ROOT PART !!! */
+
+ if (ret != 1) return;
+
+ buf->signal [0] = procinfo.pi_sig;
+ buf->blocked [0] = procinfo.pi_sigmask;
+ buf->sigignore [0] = procinfo.pi_sigignore;
+ buf->sigcatch [0] = procinfo.pi_sigcatch;
+
+ buf->flags = _glibtop_sysdeps_proc_signal;
+}
diff --git a/sysdeps/osf1/procstate.c b/sysdeps/osf1/procstate.c
new file mode 100644
index 00000000..108291c7
--- /dev/null
+++ b/sysdeps/osf1/procstate.c
@@ -0,0 +1,155 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <glibtop.h>
+#include <glibtop/error.h>
+#include <glibtop/procstate.h>
+
+#include <glibtop_suid.h>
+
+#include <mach.h>
+#include <mach/mach_types.h>
+#include <mach/task_info.h>
+
+static const unsigned long _glibtop_sysdeps_proc_state =
+(1L << GLIBTOP_PROC_STATE_CMD) +
+(1L << GLIBTOP_PROC_STATE_UID) + (1L << GLIBTOP_PROC_STATE_GID) +
+(1L << GLIBTOP_PROC_STATE_RUID) + (1L << GLIBTOP_PROC_STATE_RGID);
+
+/* 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 tbl_procinfo procinfo;
+ int minim_state = 99, ret;
+ task_t thistask;
+
+ glibtop_init_p (server, GLIBTOP_SYSDEPS_PROC_STATE, 0);
+
+ memset (buf, 0, sizeof (glibtop_proc_state));
+
+ /* !!! THE FOLLOWING CODE RUNS SUID ROOT - CHANGE WITH CAUTION !!! */
+
+ glibtop_suid_enter (server);
+
+ ret = table (TBL_PROCINFO, pid, (char *) &procinfo, 1,
+ sizeof (struct tbl_procinfo));
+
+ glibtop_suid_leave (server);
+
+ /* !!! END OF SUID ROOT PART !!! */
+
+ if (ret != 1) return;
+
+ /* Check whether the process actually exists. */
+ if (procinfo.pi_status == PI_EMPTY) return;
+
+ /* Check whether it is not a zombie. */
+ if (procinfo.pi_status == PI_ZOMBIE) {
+ buf->state = GLIBTOP_PROCESS_ZOMBIE;
+ buf->flags = (1L << GLIBTOP_PROC_STATE_STATE);
+ return;
+ }
+
+ strncpy (buf->cmd, procinfo.pi_comm, sizeof (buf->cmd)-1);
+
+ buf->cmd [sizeof (buf->cmd)-1] = 0;
+
+ buf->uid = procinfo.pi_svuid;
+ buf->gid = procinfo.pi_svgid;
+ buf->ruid = procinfo.pi_ruid;
+ buf->rgid = procinfo.pi_rgid;
+
+ buf->flags = _glibtop_sysdeps_proc_state;
+
+ /* !!! THE FOLLOWING CODE RUNS SUID ROOT - CHANGE WITH CAUTION !!! */
+
+ glibtop_suid_enter (server);
+
+ /* Get task structure. */
+ ret = task_by_unix_pid (task_self(), procinfo.pi_pid, &thistask);
+
+ if (ret == KERN_SUCCESS) {
+ thread_array_t threadarr;
+ unsigned int threadarr_l;
+ thread_basic_info_t threadinfo;
+ thread_basic_info_data_t threadinfodata;
+ int j;
+
+ /* Get thread array. */
+ (void) task_threads (thistask, &threadarr, &threadarr_l);
+
+ threadinfo = &threadinfodata;
+ for (j = 0; j < threadarr_l; j++) {
+ unsigned int threadinfo_l = THREAD_BASIC_INFO_COUNT;
+ int tret;
+
+ tret = thread_info (threadarr [j], THREAD_BASIC_INFO,
+ (thread_info_t) threadinfo, &threadinfo_l);
+
+ if (tret == KERN_SUCCESS) {
+ if (minim_state > threadinfo->run_state)
+ minim_state=threadinfo->run_state;
+ }
+ }
+ }
+
+ glibtop_suid_leave (server);
+
+ /* !!! END OF SUID ROOT PART !!! */
+
+ if (ret != KERN_SUCCESS) return;
+
+ switch (minim_state) {
+ case TH_STATE_RUNNING:
+ buf->state = GLIBTOP_PROCESS_RUNNING;
+ break;
+ case TH_STATE_UNINTERRUPTIBLE:
+ buf->state = GLIBTOP_PROCESS_UNINTERRUPTIBLE;
+ break;
+ case TH_STATE_WAITING:
+ buf->state = GLIBTOP_PROCESS_INTERRUPTIBLE;
+ break;
+ case TH_STATE_STOPPED:
+ case TH_STATE_HALTED:
+ buf->state = GLIBTOP_PROCESS_STOPPED;
+ break;
+ default:
+ if (ret != KERN_SUCCESS)
+ buf->state = GLIBTOP_PROCESS_ZOMBIE;
+ break;
+ }
+
+ if (buf->state)
+ buf->flags |= (1L << GLIBTOP_PROC_STATE_STATE);
+}
diff --git a/sysdeps/osf1/proctime.c b/sysdeps/osf1/proctime.c
new file mode 100644
index 00000000..dc06da42
--- /dev/null
+++ b/sysdeps/osf1/proctime.c
@@ -0,0 +1,79 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <glibtop.h>
+#include <glibtop/proctime.h>
+
+#include <glibtop_suid.h>
+
+#include <sys/user.h>
+#include <sys/time.h>
+
+static const unsigned long _glibtop_sysdeps_proc_time =
+(1L << GLIBTOP_PROC_TIME_UTIME) + (1L << GLIBTOP_PROC_TIME_CUTIME) +
+(1L << GLIBTOP_PROC_TIME_STIME) + (1L << GLIBTOP_PROC_TIME_CSTIME) +
+(1L << GLIBTOP_PROC_TIME_START_TIME);
+
+/* Init function. */
+
+void
+glibtop_init_proc_time_p (glibtop *server)
+{
+ server->sysdeps.proc_time = _glibtop_sysdeps_proc_time;
+}
+
+/* Provides detailed information about a process. */
+
+void
+glibtop_get_proc_time_p (glibtop *server, glibtop_proc_time *buf,
+ pid_t pid)
+{
+ struct user u;
+ int ret;
+
+ glibtop_init_p (server, GLIBTOP_SYSDEPS_PROC_TIME, 0);
+
+ memset (buf, 0, sizeof (glibtop_proc_time));
+
+ /* !!! THE FOLLOWING CODE RUNS SUID ROOT - CHANGE WITH CAUTION !!! */
+
+ glibtop_suid_enter (server);
+
+ ret = table (TBL_UAREA, pid, (char *) &u, 1,
+ sizeof (struct user));
+
+ glibtop_suid_leave (server);
+
+ /* !!! END OF SUID ROOT PART !!! */
+
+ if (ret != 1) return;
+
+ buf->start_time = u.u_start.tv_sec;
+
+ buf->utime = u.u_ru.ru_utime.tv_sec;
+ buf->stime = u.u_ru.ru_stime.tv_sec;
+ buf->cutime = u.u_cru.ru_utime.tv_sec;
+ buf->cstime = u.u_cru.ru_stime.tv_sec;
+
+ buf->flags = _glibtop_sysdeps_proc_time;
+}
diff --git a/sysdeps/osf1/procuid.c b/sysdeps/osf1/procuid.c
new file mode 100644
index 00000000..f5ca4636
--- /dev/null
+++ b/sysdeps/osf1/procuid.c
@@ -0,0 +1,132 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <glibtop.h>
+#include <glibtop/procuid.h>
+
+#include <glibtop_suid.h>
+
+#include <sys/table.h>
+#include <sys/resource.h>
+
+#include <mach.h>
+#include <mach/mach_types.h>
+#include <mach/task_info.h>
+
+/* Provides detailed information about a process. */
+
+static const unsigned long _glibtop_sysdeps_proc_uid =
+(1L << GLIBTOP_PROC_UID_UID) + (1L << GLIBTOP_PROC_UID_EUID) +
+(1L << GLIBTOP_PROC_UID_GID) + (1L << GLIBTOP_PROC_UID_EGID) +
+(1L << GLIBTOP_PROC_UID_PID) + (1L << GLIBTOP_PROC_UID_PPID) +
+(1L << GLIBTOP_PROC_UID_PGRP) + (1L << GLIBTOP_PROC_UID_SESSION) +
+(1L << GLIBTOP_PROC_UID_TTY) + (1L << GLIBTOP_PROC_UID_TPGID);
+
+/* Init function. */
+
+void
+glibtop_init_proc_uid_p (glibtop *server)
+{
+ server->sysdeps.proc_uid = _glibtop_sysdeps_proc_uid;
+}
+
+void
+glibtop_get_proc_uid_p (glibtop *server, glibtop_proc_uid *buf,
+ pid_t pid)
+{
+ struct tbl_procinfo procinfo;
+ task_basic_info_data_t taskinfo;
+ int ret, info_count;
+ task_t thistask;
+
+ glibtop_init_p (server, GLIBTOP_SYSDEPS_PROC_UID, 0);
+
+ memset (buf, 0, sizeof (glibtop_proc_uid));
+
+ /* !!! THE FOLLOWING CODE RUNS SUID ROOT - CHANGE WITH CAUTION !!! */
+
+ glibtop_suid_enter (server);
+
+ ret = table (TBL_PROCINFO, pid, (char *) &procinfo, 1,
+ sizeof (struct tbl_procinfo));
+
+ glibtop_suid_leave (server);
+
+ /* !!! END OF SUID ROOT PART !!! */
+
+ if (ret != 1) return;
+
+ buf->uid = procinfo.pi_ruid;
+ buf->euid = procinfo.pi_svuid;
+ buf->gid = procinfo.pi_rgid;
+ buf->egid = procinfo.pi_svgid;
+
+ buf->pid = procinfo.pi_pid;
+ buf->ppid = procinfo.pi_ppid;
+ buf->pgrp = procinfo.pi_pgrp;
+ buf->tty = procinfo.pi_ttyd;
+ buf->session = procinfo.pi_session;
+ buf->tpgid = procinfo.pi_tpgrp;
+
+ buf->flags = _glibtop_sysdeps_proc_uid;
+
+ /* !!! THE FOLLOWING CODE RUNS SUID ROOT - CHANGE WITH CAUTION !!! */
+
+ glibtop_suid_enter (server);
+
+ /* Get task structure. */
+
+ ret = task_by_unix_pid (task_self(), procinfo.pi_pid, &thistask);
+
+ if (ret == KERN_SUCCESS) {
+
+ /* Get taskinfo about this task. */
+
+ info_count = TASK_BASIC_INFO_COUNT;
+
+ ret = task_info (thistask, TASK_BASIC_INFO,
+ (task_info_t) &taskinfo, &info_count);
+
+ /* `ret' is evaluated outside the `if' clause. */
+ }
+
+ glibtop_suid_leave (server);
+
+ /* !!! END OF SUID ROOT PART !!! */
+
+ if (ret != KERN_SUCCESS) return;
+
+ buf->priority = taskinfo.base_priority;
+
+ buf->flags += (1L << GLIBTOP_PROC_UID_PRIORITY);
+
+ errno = 0;
+
+ ret = getpriority (PRIO_PROCESS, pid);
+
+ if ((ret == -1) && (errno != 0)) return;
+
+ buf->nice = ret;
+
+ buf->flags += (1L << GLIBTOP_PROC_UID_NICE);
+}
diff --git a/sysdeps/osf1/sem_limits.c b/sysdeps/osf1/sem_limits.c
new file mode 100644
index 00000000..c054c3c2
--- /dev/null
+++ b/sysdeps/osf1/sem_limits.c
@@ -0,0 +1,110 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <glibtop.h>
+#include <glibtop/error.h>
+#include <glibtop/sem_limits.h>
+
+static unsigned long _glibtop_sysdeps_sem_limits =
+(1L << GLIBTOP_IPC_SEMMNI) + (1L << GLIBTOP_IPC_SEMMSL) +
+(1L << GLIBTOP_IPC_SEMOPM) + (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)
+{
+ int ret, value;
+
+ glibtop_init_s (&server, 0, 0);
+
+ memset (buf, 0, sizeof (glibtop_sem_limits));
+
+ ret = table (TBL_SEMINFO, SEMINFO_MNI, (char *) &value, 1,
+ sizeof (value));
+
+ if (ret != 1) return;
+
+ buf->flags += (1L << GLIBTOP_IPC_SEMMNI);
+
+ buf->semmni = value;
+
+
+ ret = table (TBL_SEMINFO, SEMINFO_MSL, (char *) &value, 1,
+ sizeof (value));
+
+ if (ret != 1) return;
+
+ buf->flags += (1L << GLIBTOP_IPC_SEMMSL);
+
+ buf->semmsl = value;
+
+
+ ret = table (TBL_SEMINFO, SEMINFO_OPM, (char *) &value, 1,
+ sizeof (value));
+
+ if (ret != 1) return;
+
+ buf->flags += (1L << GLIBTOP_IPC_SEMOPM);
+
+ buf->semopm = value;
+
+
+ ret = table (TBL_SEMINFO, SEMINFO_UME, (char *) &value, 1,
+ sizeof (value));
+
+ if (ret != 1) return;
+
+ buf->flags += (1L << GLIBTOP_IPC_SEMUME);
+
+ buf->semume = value;
+
+
+ ret = table (TBL_SEMINFO, SEMINFO_VMX, (char *) &value, 1,
+ sizeof (value));
+
+ if (ret != 1) return;
+
+ buf->flags += (1L << GLIBTOP_IPC_SEMVMX);
+
+ buf->semvmx = value;
+
+
+ ret = table (TBL_SEMINFO, SEMINFO_AEM, (char *) &value, 1,
+ sizeof (value));
+
+ if (ret != 1) return;
+
+ buf->flags += (1L << GLIBTOP_IPC_SEMAEM);
+
+ buf->semaem = value;
+}
diff --git a/sysdeps/osf1/shm_limits.c b/sysdeps/osf1/shm_limits.c
new file mode 100644
index 00000000..03069205
--- /dev/null
+++ b/sysdeps/osf1/shm_limits.c
@@ -0,0 +1,89 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <glibtop.h>
+#include <glibtop/error.h>
+#include <glibtop/shm_limits.h>
+
+static unsigned long _glibtop_sysdeps_shm_limits =
+(1L << GLIBTOP_IPC_SHMMAX) + (1L << GLIBTOP_IPC_SHMMIN) +
+(1L << GLIBTOP_IPC_SHMMNI) + (1L << GLIBTOP_IPC_SHMSEG);
+
+/* 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)
+{
+ int ret, value;
+
+ glibtop_init_s (&server, 0, 0);
+
+ memset (buf, 0, sizeof (glibtop_shm_limits));
+
+ ret = table (TBL_SHMINFO, SHMINFO_MAX, (char *) &value, 1,
+ sizeof (value));
+
+ if (ret != 1) return;
+
+ buf->flags += (1L << GLIBTOP_IPC_SHMMAX);
+
+ buf->shmmax = value;
+
+
+ ret = table (TBL_SHMINFO, SHMINFO_MIN, (char *) &value, 1,
+ sizeof (value));
+
+ if (ret != 1) return;
+
+ buf->flags += (1L << GLIBTOP_IPC_SHMMIN);
+
+ buf->shmmin = value;
+
+
+ ret = table (TBL_SHMINFO, SHMINFO_MNI, (char *) &value, 1,
+ sizeof (value));
+
+ if (ret != 1) return;
+
+ buf->flags += (1L << GLIBTOP_IPC_SHMMNI);
+
+ buf->shmmni = value;
+
+
+ ret = table (TBL_SHMINFO, SHMINFO_SEG, (char *) &value, 1,
+ sizeof (value));
+
+ if (ret != 1) return;
+
+ buf->flags += (1L << GLIBTOP_IPC_SHMSEG);
+
+ buf->shmseg = value;
+}
diff --git a/sysdeps/osf1/siglist.c b/sysdeps/osf1/siglist.c
new file mode 100644
index 00000000..c5bd59c0
--- /dev/null
+++ b/sysdeps/osf1/siglist.c
@@ -0,0 +1,60 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <glibtop.h>
+#include <glibtop/signal.h>
+
+const glibtop_signame glibtop_sys_siglist [] =
+{ { 1, "SIGHUP", N_("Hangup") },
+ { 2, "SIGINT", N_("Interrupt") },
+ { 3, "SIGQUIT", N_("Quit") },
+ { 4, "SIGILL", N_("Illegal instruction") },
+ { 5, "SIGTRAP", N_("Trace trap") },
+ { 6, "SIGABRT", N_("Abort") },
+ { 7, "SIGEMT", N_("EMT error") },
+ { 8, "SIGFPE", N_("Floating-point exception") },
+ { 9, "SIGKILL", N_("Kill") },
+ { 10, "SIGBUS", N_("Bus error") },
+ { 11, "SIGSEGV", N_("Segmentation violation") },
+ { 12, "SIGSYS", N_("Bad argument to system call") },
+ { 13, "SIGPIPE", N_("Broken pipe") },
+ { 14, "SIGALRM", N_("Alarm clock") },
+ { 15, "SIGTERM", N_("Termination") },
+ { 16, "SIGURG", N_("Urgent condition on socket") },
+ { 17, "SIGSTOP", N_("Stop") },
+ { 18, "SIGTSTP", N_("Keyboard stop") },
+ { 19, "SIGCONT", N_("Continue") },
+ { 20, "SIGCHLD", N_("Child status has changed") },
+ { 21, "SIGTTIN", N_("Background read from tty") },
+ { 22, "SIGTTOU", N_("Background write to tty") },
+ { 23, "SIGIO", N_("I/O now possible") },
+ { 24, "SIGXCPU", N_("CPU limit exceeded") },
+ { 25, "SIGXFSZ", N_("File size limit exceeded") },
+ { 26, "SIGVTALRM", N_("Virtual alarm clock") },
+ { 27, "SIGPROF", N_("Profiling alarm clock") },
+ { 28, "SIGWINCH", N_("Window size change") },
+ { 29, "SIGINFO", N_("Information request") },
+ { 30, "SIGUSR1", N_("User defined signal 1") },
+ { 31, "SIGUSR2", N_("User defined signal 2") },
+ { 0, NULL, NULL },
+};
diff --git a/sysdeps/osf1/swap.c b/sysdeps/osf1/swap.c
new file mode 100644
index 00000000..db322413
--- /dev/null
+++ b/sysdeps/osf1/swap.c
@@ -0,0 +1,64 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <glibtop.h>
+#include <glibtop/error.h>
+#include <glibtop/swap.h>
+
+static unsigned long _glibtop_sysdeps_swap =
+(1L << GLIBTOP_SWAP_TOTAL) + (1L << GLIBTOP_SWAP_USED) +
+(1L << GLIBTOP_SWAP_FREE);
+
+/* Init function. */
+
+void
+glibtop_init_swap_s (glibtop *server)
+{
+ server->sysdeps.swap = _glibtop_sysdeps_swap;
+}
+
+/* Provides information about swap usage. */
+
+void
+glibtop_get_swap_s (glibtop *server, glibtop_swap *buf)
+{
+ struct tbl_swapinfo swapinfo;
+ int i;
+
+ glibtop_init_s (&server, GLIBTOP_SYSDEPS_SWAP, 0);
+
+ memset (buf, 0, sizeof (glibtop_swap));
+
+ i = 0;
+
+ while (table (TBL_SWAPINFO, i, (char *) &swapinfo, 1,
+ sizeof (struct tbl_swapinfo)) > 0) {
+ buf->total += swapinfo.size * getpagesize ();
+ buf->free += swapinfo.free * getpagesize ();
+ i++;
+ }
+
+ buf->flags = _glibtop_sysdeps_swap;
+
+ buf->used = buf->total - buf->free;
+}
diff --git a/sysdeps/osf1/uptime.c b/sysdeps/osf1/uptime.c
new file mode 100644
index 00000000..4e968a1b
--- /dev/null
+++ b/sysdeps/osf1/uptime.c
@@ -0,0 +1,61 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <glibtop.h>
+#include <glibtop/error.h>
+#include <glibtop/uptime.h>
+
+#include <time.h>
+
+static unsigned long _glibtop_sysdeps_uptime =
+(1L << GLIBTOP_UPTIME_UPTIME);
+
+/* 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)
+{
+ struct tbl_sysinfo sysinfo;
+ int ret;
+
+ glibtop_init_s (&server, GLIBTOP_SYSDEPS_UPTIME, 0);
+
+ memset (buf, 0, sizeof (glibtop_uptime));
+
+ ret = table (TBL_SYSINFO, 0, (char *) &sysinfo, 1,
+ sizeof (struct tbl_sysinfo));
+
+ if (ret != 1) return;
+
+ buf->uptime = (double) (time (NULL) - sysinfo.si_boottime);
+
+ buf->flags = _glibtop_sysdeps_uptime;
+}
diff --git a/sysdeps/solaris/.cvsignore b/sysdeps/solaris/.cvsignore
new file mode 100644
index 00000000..facaec43
--- /dev/null
+++ b/sysdeps/solaris/.cvsignore
@@ -0,0 +1,7 @@
+.deps
+.libs
+Makefile
+Makefile.in
+libgtop_sysdeps.la
+*.lo
+libgtop_sysdeps_suid.la
diff --git a/sysdeps/solaris/AUTHORS b/sysdeps/solaris/AUTHORS
new file mode 100644
index 00000000..37b903af
--- /dev/null
+++ b/sysdeps/solaris/AUTHORS
@@ -0,0 +1,2 @@
+Drazen Kacar (dave@srce.hr)
+Martin Baulig (martin@home-of-linux.org)
diff --git a/sysdeps/solaris/ChangeLog b/sysdeps/solaris/ChangeLog
new file mode 100644
index 00000000..16c829a7
--- /dev/null
+++ b/sysdeps/solaris/ChangeLog
@@ -0,0 +1,284 @@
+2001-10-17 Abel Cheung <maddog@linux.org.hk>
+
+ * Makefile.am: move header to $(includedir)/libgtop-1.0/glibtop.
+
+2001-02-18 Martin Baulig <baulig@suse.de>
+
+ Applied a patch from Laszlo PETER <Laszlo.Peter@ireland.sun.com>
+ for Solaris 8.
+
+ * msg_limits.c: `struct msginfo' no longer has msgmap and msgssz.
+ * sem_limits.c: `struct seminfo' no longer has a semmap field.
+
+1999-10-17 Martin Baulig <martin@home-of-linux.org>
+
+ * Makefile.am (libgtop_sysdeps_la_LIBADD): Added `@DL_LIB@'.
+
+1999-09-28 Drazen Kacar <dave@srce.hr>
+
+ * proclist.c (glibtop_get_proclist_s): Bugfix. It wasn't
+ excluding system, non-tty or idle processes if that was
+ requested.
+
+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.
+
+1999-07-16 Drazen Kacar <dave@srce.hr>
+
+ * proclist.c: Bug fix. All Solaris versions have RUID and
+ RGID in /proc.
+
+1999-06-07 Drazen Kacar <dave@srce.hr>
+
+ * glibtop_machine.h, open.c, procargs.c, proclist.c, procmap.c:
+ Solaris 2.5 & 2.5.1 portability fixes, based on patches
+ from Steve Murphy <murf@e-tools.com>.
+
+1999-05-30 Drazen Kacar <dave@srce.hr>
+
+ * procargs.c: Fixed bug in calculation of process argument list.
+
+1999-05-27 Drazen Kacar <dave@srce.hr>
+
+ * glibtop_machine.h, open.c, procmap.c: Get the file name
+ from inode number.
+
+1999-05-17 Drazen Kacar <dave@srce.hr>
+
+ * procargs.c: Implemented what Solaris has to offer cheaply.
+ It sucks, but digging in process address space would be
+ too slow.
+
+1999-05-11 Drazen Kacar <dave@srce.hr>
+
+ * proctime.c: Return 0 usage times for scheaduler (PID 0).
+
+1999-05-10 Drazen Kacar <dave@srce.hr>
+
+ * proclist.c: Added process selection mechanism. It's not
+ included in Solaris 2.5 build, since we first have to decide
+ what will be dispatched to daemon.
+
+1999-05-10 Drazen Kacar <dave@srce.hr>
+
+ There be some useful documentation now. Syncing...
+
+ * mem.c: Output values in bytes, as the documentation requires.
+ It was a bit odd when gtop reported 256K of total memory.
+
+1999-05-09 Drazen Kacar <dave@srce.hr>
+
+ * glibtop_machine.h, procdata.c, proclist.c, procmap.c, procmem.c,
+ procsignal.c, procstate.c, procuid.c, open.c, mem.c: Initial
+ Solaris 2.5 port. It's far from being complete and hasn't been
+ tested properly. We'll need setuid root daemon, which is
+ currently not implemented. #ifdef symbols to check are
+ HAVE_PROCFS_H and KSTAT_DATA_UINT32. These will be defined on
+ Solaris 2.6 and later, but not on earlier releases.
+
+1999-05-08 Drazen Kacar <dave@srce.hr>
+
+ * safeio.c, safeio.h: Added s_open(), s_close() etc. with EINTR
+ wrappers.
+
+ * procdata.c, procmap.c, proclist.c: Use them.
+
+1999-05-08 Drazen Kacar <dave@srce.hr>
+
+ * procmem.c: Use bytes as units for memory consumption.
+
+1999-05-08 Drazen Kacar <dave@srce.hr>
+
+ * procuid.c: Fixed nice value.
+
+1999-05-08 Martin Baulig <martin@home-of-linux.org>
+
+ Use the setgid server for IPC Limits.
+
+ * shm_limits.c, msg_limits.c, sem_limits.c: Moved them into the
+ setgid server since they need to access kvm data.
+
+ * open_suid.c, close_suid.c: New file. We do the initialization and cleanup
+ for the setgid server here.
+
+ * glibtop_suid.h: New file. We include this in the setgid files.
+
+ * open.c: Moved kvm opening code into open_suid.c.
+
+1999-05-07 Drazen Kacar <dave@srce.hr>
+
+ * glibtop_machine.h, open.c, mem.c, procmem.c: machine.pagesize
+ is now number of bits we need for shifting, ie. 2^pagesize
+ will give pagesize in Kb.
+
+1999-05-07 Drazen Kacar <dave@srce.hr>
+
+ * procmem.c: Implemented size, vsize, resident and rss.
+
+1999-05-06 Drazen Kacar <dave@srce.hr>
+
+ * siglist.c: Fixed, valid for Solaris 2.6 & 7.
+
+1999-05-06 Drazen Kacar <dave@srce.hr>
+
+ * glibtop_private.h, procuid.c, procdata.c: List of supplementary
+ groups was not correct. Fixed.
+
+1999-05-04 Drazen Kacar <dave@srce.hr>
+
+ * glibtop_machine.h: Changed boot time to unsigned long long.
+
+ * open.c: Added proper type checking for boot value. There's
+ no point in saving a few nanoseconds in init function. And
+ one day it will become 64-bit value.
+
+ In glibtop_get_kstats(): Don't reread vminfo_snaptime when
+ reinitializing kstats.
+
+1999-05-03 Drazen Kacar <dave@srce.hr>
+
+ * glibtop_private.h: Fixed typoo.
+
+ * procmap.c (glibtop_get_proc_map_s): Implemented start, end,
+ offset and perm for mapped segments. File name and inode
+ should be accessible from bunyip kstat data. The only
+ obstacle is that the data format is undocumented and
+ possibly not the same accross releases.
+
+1999-05-03 Drazen Kacar <dave@srce.hr>
+
+ * glibtop_private.h, procdata.c (glibtop_get_proc_status_s):
+ Read pstatus info from /proc
+
+ * procsignal.c (glibtop_get_proc_signal_s): Implemented
+ set of pending and blocked signals. The rest should probably
+ be read from /proc/<pid>/sigact, but I'm not sure it's
+ worth implementing before thread API comes into place.
+
+ * siglist.c: Added Solaris 7 signals. Someone will gettextize
+ it eventually. Besides, signal list should become a pointer
+ instead of being fixed field. We need some run time initializations.
+ The code is written, but commented out.
+
+1999-05-03 Drazen Kacar <dave@srce.hr>
+
+ * glibtop_private.h: Ups, forgot to put prototypes in.
+
+1999-05-02 Drazen Kacar <dave@srce.hr>
+
+ * open.c (glibtop_get_kstats): Yet another kstat_chain_update
+ check. Added machine.cpu_stat_kstat[x] = NULL when processor
+ x is not configured.
+
+ * procdata.c (glibtop_get_proc_credentials_s): Read prcred
+ structure from /proc.
+
+ * procstate.c (glibtop_get_proc_state_s): Added ruid, rgid,
+ has_cpu, processor and last_processor.
+
+ * procuid.c (glibtop_get_proc_uid_s): Added priority, nice,
+ suid, sgid, ngroups and groups. The last four will be
+ filled only if our process has the authority to read prcred
+ structure of another process.
+
+1999-05-02 Drazen Kacar <dave@srce.hr>
+
+ procdata.c: Use pread() instead of read().
+
+1999-05-02 Drazen Kacar <dave@srce.hr>
+
+ * glibtop_machine.h: added fields for page size, clock ticks and
+ boot time. These are constants. Also added three new kstats.
+
+ * open.c (glibtop_get_kstats): Initialize kstats in *server.
+ We need to call this at init time (obviously) and each time
+ kstat_chain_update() says that kstat chain has changed. In this
+ case all kstat pointers and data are invalid, so we need to
+ reinitialize everything.
+
+ (glibtop_open_s): Made it call glibtop_get_kstats(). Added
+ initialization for run time constants in struct machine.
+
+ * cpu.c (glibtop_get_cpu_s): Call kstat_chain_update().
+ See if processor is on-line and set bits in xcpu_flags.
+ Added frequency (bad name, should have been ticks).
+
+ * swap.c (glibtop_get_swap_s): Call kstat_chain_update().
+ I probably broke vminfo_snaptime consistency. Fix later.
+
+ * uptime.c (glibtop_get_uptime_s): Implemented uptime and boot_time.
+ Still looking for a sane way to get idletime.
+
+ * mem.c (glibtop_get_mem_s): Implemented. Will use bunyip
+ module if it's loaded. Or when it gets loaded. kstat_chain_update()
+ is our friend. And with a friends like that...
+
+ * loadavg.c (glibtop_get_loadavg_s): Solaris 2.6 code brought
+ into sync with everything else.
+
+ * msg_limits.c (glibtop_init_msg_limits_s): Implemented.
+
+ * sem_limits.c (glibtop_get_sem_limits_s): Implemented.
+
+ Solaris takes kernel modularity too seriously. We can't get
+ IPC configuration data if the kernel module is not loaded and
+ it won't be loaded until some process actually asks for a
+ particular IPC resource. There's no way to tell our applications
+ about this. Possible API additions?
+
+ All three IPC functions should go into daemon, but I'm keeping
+ them in the normal library because I can't build daemon yet. All
+ praise 64 bits!
+
+1999-04-29 Drazen Kacar <dave@srce.hr>
+
+ * glibtop_machine.h: added field for kvm descriptor.
+
+ * open.c: added code for opening kernel name space.
+
+ * shm_limits.c: implemented.
+
+1999-03-31 Drazen Kacar <dave@srce.hr>
+
+ * loadavg.c: make it work with Solaris 2.6 and older. A part
+ of it should be moved to open.c.
+
+1999-03-19 Martin Baulig <martin@home-of-linux.org>
+
+ Added first kstat based implementation for Solaris 7.
+
+ * open.c (glibtop_open_s): Walk kstat list and save interesting
+ kstats in the `server->machine'.
+
+ * cpu.c: This can already provide `idle', `user' and `sys' with
+ full SMP support.
+
+ * swap.c: This can already provide `total', `used' and `free'.
+
+1999-03-17 Martin Baulig <martin@home-of-linux.org>
+
+ Initial import of my Solaris 7 port.
+
+ * loadavg.c: We use getloadavg () to get the `loadavg' field.
+
+ * procdata.c: This file will handle all interaction with the
+ /proc filesystem.
+ (glibtop_get_proc_data_psinfo_s): Read `/proc/<pid>/psinfo' and
+ return the resulting `struct psinfo'.
+ (glibtop_get_proc_data_usage_s): Read `/proc/<pid>/usage' and
+ return the resulting `struct prusage'.
+
+ * proclist.c: We use readdir () on /proc to get the list of
+ all pids.
+
+ * procstate.c: Read `uid' and `gid' from the `struct psinfo'.
+
+ * proctime.c: Read `start_time', `rtime', `utime' and `stime'
+ from the `struct prusage'.
+
+ * procuid.c: Read `euid', `uid', `egid', `gid', `pid', `ppid',
+ `pgrp', `session' and `tty' from the `struct psinfo'.
+
diff --git a/sysdeps/solaris/Makefile.am b/sysdeps/solaris/Makefile.am
new file mode 100644
index 00000000..1459140e
--- /dev/null
+++ b/sysdeps/solaris/Makefile.am
@@ -0,0 +1,28 @@
+LINK = $(LIBTOOL) --mode=link $(CC) $(CFLAGS) $(LDFLAGS) -o $@
+
+INCLUDES = @INCLUDES@
+
+lib_LTLIBRARIES = libgtop_sysdeps-2.0.la libgtop_sysdeps_suid-2.0.la
+
+libgtop_sysdeps_2_0_la_SOURCES = open.c close.c siglist.c cpu.c mem.c \
+ safeio.c swap.c uptime.c loadavg.c \
+ proclist.c procstate.c procuid.c \
+ proctime.c procmem.c procsignal.c \
+ prockernel.c procsegment.c procargs.c \
+ procmap.c netload.c ppp.c procdata.c
+
+libgtop_sysdeps_2_0_la_LDFLAGS = $(LT_VERSION_INFO)
+
+libgtop_sysdeps_2_0_la_LIBADD = @DL_LIB@
+
+libgtop_sysdeps_suid_2_0_la_SOURCES = open_suid.c close_suid.c \
+ shm_limits.c msg_limits.c sem_limits.c
+
+libgtop_sysdeps_suid_2_0_la_LDFLAGS = $(LT_VERSION_INFO)
+
+
+libgtopinclude_HEADERS = glibtop_server.h glibtop_machine.h
+libgtopincludedir = $(includedir)/libgtop-2.0
+
+noinst_HEADERS = glibtop_private.h glibtop_suid.h safeio.h
+
diff --git a/sysdeps/solaris/close.c b/sysdeps/solaris/close.c
new file mode 100644
index 00000000..4262d2f0
--- /dev/null
+++ b/sysdeps/solaris/close.c
@@ -0,0 +1,30 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <glibtop/close.h>
+
+/* Closes pipe to gtop server. */
+
+void
+glibtop_close_s (glibtop *server)
+{ }
diff --git a/sysdeps/solaris/close_suid.c b/sysdeps/solaris/close_suid.c
new file mode 100644
index 00000000..a8733f0f
--- /dev/null
+++ b/sysdeps/solaris/close_suid.c
@@ -0,0 +1,30 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <glibtop/close.h>
+
+/* Closes pipe to gtop server. */
+
+void
+glibtop_close_p (glibtop *server)
+{ }
diff --git a/sysdeps/solaris/cpu.c b/sysdeps/solaris/cpu.c
new file mode 100644
index 00000000..3ecb3503
--- /dev/null
+++ b/sysdeps/solaris/cpu.c
@@ -0,0 +1,113 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <glibtop.h>
+#include <glibtop/error.h>
+#include <glibtop/cpu.h>
+
+#include <assert.h>
+#include <sys/processor.h>
+
+#include <glibtop_private.h>
+
+static const unsigned long _glibtop_sysdeps_cpu =
+(1L << GLIBTOP_CPU_TOTAL) + (1L << GLIBTOP_CPU_USER) +
+(1L << GLIBTOP_CPU_SYS) + (1L << GLIBTOP_CPU_IDLE) +
+(1L << GLIBTOP_XCPU_TOTAL) + (1L << GLIBTOP_XCPU_USER) +
+(1L << GLIBTOP_XCPU_SYS) + (1L << GLIBTOP_XCPU_IDLE) +
+#if LIBGTOP_VERSION_CODE >= 1001002
+(1L << GLIBTOP_XCPU_FLAGS) +
+#endif
+(1L << GLIBTOP_CPU_FREQUENCY);
+
+/* Init function. */
+
+void
+glibtop_init_cpu_s (glibtop *server)
+{
+ server->sysdeps.cpu = _glibtop_sysdeps_cpu;
+}
+
+/* Provides information about cpu usage. */
+
+void
+glibtop_get_cpu_s (glibtop *server, glibtop_cpu *buf)
+{
+ kstat_ctl_t *kc = server->machine.kc;
+ cpu_stat_t cpu_stat;
+ processorid_t cpu;
+ int ncpu, found;
+ kid_t ret;
+
+ memset (buf, 0, sizeof (glibtop_cpu));
+
+ if(!kc)
+ return;
+ switch(kstat_chain_update(kc))
+ {
+ case -1: assert(0); /* Debugging purposes, shouldn't happen */
+ case 0: break;
+ default: glibtop_get_kstats(server);
+ }
+ ncpu = server->ncpu;
+ if (ncpu > GLIBTOP_NCPU)
+ ncpu = GLIBTOP_NCPU;
+
+ for (cpu = 0, found = 0; cpu < GLIBTOP_NCPU && found != ncpu; cpu++)
+ {
+ kstat_t *ksp = server->machine.cpu_stat_kstat [cpu];
+ if (!ksp) continue;
+
+ ++found;
+ if(p_online(cpu, P_STATUS) == P_ONLINE)
+#if LIBGTOP_VERSION_CODE >= 1001002
+ buf->xcpu_flags |= (1L << cpu);
+#else
+ ;
+#endif
+ else
+ continue;
+ ret = kstat_read (kc, ksp, &cpu_stat);
+
+ if (ret == -1) {
+ glibtop_warn_io_r (server, "kstat_read (cpu_stat%d)", cpu);
+ continue;
+ }
+
+ buf->xcpu_idle [cpu] = cpu_stat.cpu_sysinfo.cpu [CPU_IDLE];
+ buf->xcpu_user [cpu] = cpu_stat.cpu_sysinfo.cpu [CPU_USER];
+ buf->xcpu_sys [cpu] = cpu_stat.cpu_sysinfo.cpu [CPU_KERNEL];
+
+ buf->xcpu_total [cpu] = buf->xcpu_idle [cpu] + buf->xcpu_user [cpu] +
+ buf->xcpu_sys [cpu];
+
+ buf->idle += cpu_stat.cpu_sysinfo.cpu [CPU_IDLE];
+ buf->user += cpu_stat.cpu_sysinfo.cpu [CPU_USER];
+ buf->sys += cpu_stat.cpu_sysinfo.cpu [CPU_KERNEL];
+ }
+
+ buf->total = buf->idle + buf->user + buf->sys;
+ buf->frequency = server->machine.ticks;
+
+ buf->flags = _glibtop_sysdeps_cpu;
+}
diff --git a/sysdeps/solaris/glibtop_machine.h b/sysdeps/solaris/glibtop_machine.h
new file mode 100644
index 00000000..26a80de4
--- /dev/null
+++ b/sysdeps/solaris/glibtop_machine.h
@@ -0,0 +1,78 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, March 1999.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#ifndef __GLIBTOP_MACHINE_H__
+#define __GLIBTOP_MACHINE_H__
+
+#include <sys/param.h>
+#ifdef HAVE_PROCFS_H
+#include <procfs.h>
+#else
+#include <sys/procfs.h>
+#endif
+#include <fcntl.h>
+
+#include <kstat.h>
+#include <kvm.h>
+#include <sys/sysinfo.h>
+
+BEGIN_LIBGTOP_DECLS
+
+typedef struct _glibtop_machine glibtop_machine;
+
+struct _glibtop_machine
+{
+ uid_t uid, euid;
+ gid_t gid, egid;
+ pid_t me; /* Don't ask why we need this */
+
+ kvm_t *kd;
+
+ kstat_ctl_t *kc;
+
+ kstat_t *vminfo_kstat;
+ hrtime_t vminfo_snaptime;
+ vminfo_t vminfo;
+
+ kstat_t *cpu_stat_kstat [64];
+
+ kstat_t *system; /* boot_time & avenrun* where needed */
+ kstat_t *syspages; /* memory usage */
+ kstat_t *bunyip; /* more memory usage */
+
+ int pagesize; /* in bits to shift, ie. 2^pagesize gives Kb */
+ int ticks; /* clock ticks, as returned by sysconf() */
+ unsigned long long boot; /* boot time, although it's ui32 in kstat */
+ void *libproc; /* libproc handle */
+#if GLIBTOP_SOLARIS_RELEASE >= 560
+ void (*objname)(void *, uintptr_t, const char *, size_t);
+ struct ps_prochandle *(*pgrab)(pid_t, int, int *);
+ void (*pfree)(void *);
+#else
+ void *filler[3];
+#endif
+};
+
+END_LIBGTOP_DECLS
+
+#endif /* __GLIBTOP_MACHINE_H__ */
diff --git a/sysdeps/solaris/glibtop_private.h b/sysdeps/solaris/glibtop_private.h
new file mode 100644
index 00000000..7d921daf
--- /dev/null
+++ b/sysdeps/solaris/glibtop_private.h
@@ -0,0 +1,68 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, March 1999.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#ifndef __GLIBTOP_PRIVATE_H__
+#define __GLIBTOP_PRIVATE_H__
+
+#include <glibtop.h>
+#include <glibtop/error.h>
+
+#include <sys/param.h>
+#include <kstat.h>
+#include <fcntl.h>
+#if defined(HAVE_PROCFS_H)
+# include <procfs.h>
+#elif defined(HAVE_SYS_PROCFS_H)
+# include <sys/procfs.h>
+#else
+# error Cannot compile without <procfs.h> or <sys/procfs.h>
+#endif
+
+BEGIN_LIBGTOP_DECLS
+
+#ifdef HAVE_PROCFS_H
+
+/* Read /proc/<pid>/psinfo */
+int glibtop_get_proc_data_psinfo_s(glibtop *, struct psinfo *, pid_t pid);
+
+/* Read /proc/<pid>/status */
+int glibtop_get_proc_status_s(glibtop *, struct pstatus *, pid_t);
+#else
+int glibtop_get_proc_data_psinfo_s(glibtop *, struct prpsinfo *, pid_t);
+int glibtop_get_proc_status_s(glibtop *, struct prstatus *, pid_t);
+#endif
+
+/* Read /proc/<pid>/usage */
+int glibtop_get_proc_data_usage_s(glibtop *, struct prusage *, pid_t);
+
+#if LIBGTOP_VERSION_CODE >= 1001002
+/* Read /proc/<pid>/cred */
+int glibtop_get_proc_credentials_s(glibtop *, struct prcred *, gid_t *, pid_t);
+#endif
+
+/* Reread kstat chains */
+void glibtop_get_kstats(glibtop *);
+
+END_LIBGTOP_DECLS
+
+#endif /* __GLIBTOP_PRIVATE_H__ */
diff --git a/sysdeps/solaris/glibtop_server.h b/sysdeps/solaris/glibtop_server.h
new file mode 100644
index 00000000..0a13e6d4
--- /dev/null
+++ b/sysdeps/solaris/glibtop_server.h
@@ -0,0 +1,52 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#ifndef __GLIBTOP_SERVER_H__
+#define __GLIBTOP_SERVER_H__
+
+BEGIN_LIBGTOP_DECLS
+
+#define GLIBTOP_SUID_CPU 0
+#define GLIBTOP_SUID_MEM 0
+#define GLIBTOP_SUID_SWAP 0
+#define GLIBTOP_SUID_UPTIME 0
+#define GLIBTOP_SUID_LOADAVG 0
+#define GLIBTOP_SUID_SHM_LIMITS (1L << GLIBTOP_SYSDEPS_SHM_LIMITS)
+#define GLIBTOP_SUID_MSG_LIMITS (1L << GLIBTOP_SYSDEPS_MSG_LIMITS)
+#define GLIBTOP_SUID_SEM_LIMITS (1L << GLIBTOP_SYSDEPS_SEM_LIMITS)
+#define GLIBTOP_SUID_PROCLIST 0
+#define GLIBTOP_SUID_PROC_STATE 0
+#define GLIBTOP_SUID_PROC_UID 0
+#define GLIBTOP_SUID_PROC_MEM 0
+#define GLIBTOP_SUID_PROC_TIME 0
+#define GLIBTOP_SUID_PROC_SIGNAL 0
+#define GLIBTOP_SUID_PROC_KERNEL 0
+#define GLIBTOP_SUID_PROC_SEGMENT 0
+#define GLIBTOP_SUID_PROC_ARGS 0
+#define GLIBTOP_SUID_PROC_MAP 0
+#define GLIBTOP_SUID_NETLOAD 0
+#define GLIBTOP_SUID_PPP 0
+
+END_LIBGTOP_DECLS
+
+#endif
diff --git a/sysdeps/solaris/glibtop_suid.h b/sysdeps/solaris/glibtop_suid.h
new file mode 100644
index 00000000..b88421ff
--- /dev/null
+++ b/sysdeps/solaris/glibtop_suid.h
@@ -0,0 +1,48 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#ifndef __GLIBTOP_SUID_H__
+#define __GLIBTOP_SUID_H__
+
+BEGIN_LIBGTOP_DECLS
+
+static inline void glibtop_suid_enter (glibtop *server) {
+ setreuid (server->machine.uid, server->machine.euid);
+};
+
+static inline void glibtop_suid_leave (glibtop *server) {
+ if (setreuid (server->machine.euid, server->machine.uid))
+ _exit (1);
+};
+
+void
+glibtop_init_p (glibtop *server, const unsigned long features,
+ const unsigned flags);
+void
+glibtop_open_p (glibtop *server, const char *program_name,
+ const unsigned long features,
+ const unsigned flags);
+
+END_LIBGTOP_DECLS
+
+#endif
diff --git a/sysdeps/solaris/loadavg.c b/sysdeps/solaris/loadavg.c
new file mode 100644
index 00000000..9f4d4a37
--- /dev/null
+++ b/sysdeps/solaris/loadavg.c
@@ -0,0 +1,87 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, March 1999.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <glibtop.h>
+#include <glibtop/loadavg.h>
+
+#ifdef HAVE_GETLOADAVG
+#include <sys/loadavg.h>
+#else
+#include <assert.h>
+#include <sys/param.h>
+#include <kstat.h>
+#endif
+
+static const unsigned long _glibtop_sysdeps_loadavg =
+(1L << GLIBTOP_LOADAVG_LOADAVG);
+
+/* Init function. */
+
+void
+glibtop_init_loadavg_s (glibtop *server)
+{
+ server->sysdeps.loadavg = _glibtop_sysdeps_loadavg;
+}
+
+/* Provides load average. */
+
+void
+glibtop_get_loadavg_s (glibtop *server, glibtop_loadavg *buf)
+{
+#ifndef HAVE_GETLOADAVG
+ kstat_ctl_t *kc;
+ kstat_t *ksp;
+ int i;
+ static char *avestrings[] = { "avenrun_1min",
+ "avenrun_5min",
+ "avenrun_15min" };
+#endif
+ memset (buf, 0, sizeof (glibtop_loadavg));
+
+#ifdef HAVE_GETLOADAVG
+ if (getloadavg (buf->loadavg, 3))
+ return;
+#else
+ if(!(kc = server->machine.kc))
+ return;
+ switch(kstat_chain_update(kc))
+ {
+ case -1: assert(0); /* Debugging, shouldn't happen */
+ case 0: break;
+ default: glibtop_get_kstats(server);
+ }
+ if(!(ksp = server->machine.system))
+ return;
+ if(kstat_read(kc, ksp, NULL) < 0)
+ return;
+ for(i = 0; i < 3; ++i) /* Do we have a countof macro? */
+ {
+ kstat_named_t *kn;
+
+ kn = (kstat_named_t *)kstat_data_lookup(ksp, avestrings[i]);
+ if(kn)
+ buf->loadavg[i] = (double)kn->value.ul / FSCALE;
+ }
+#endif
+ buf->flags = _glibtop_sysdeps_loadavg;
+}
diff --git a/sysdeps/solaris/mem.c b/sysdeps/solaris/mem.c
new file mode 100644
index 00000000..50461992
--- /dev/null
+++ b/sysdeps/solaris/mem.c
@@ -0,0 +1,127 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <glibtop.h>
+#include <glibtop/mem.h>
+
+#include <assert.h>
+#include <unistd.h>
+
+#include <glibtop_private.h>
+
+static const unsigned long _glibtop_sysdeps_mem_os_sysconf =
+(1L << GLIBTOP_MEM_TOTAL);
+static const unsigned long _glibtop_sysdeps_mem_os_kstat =
+(1L << GLIBTOP_MEM_FREE) + (1L << GLIBTOP_MEM_USED) +
+(1L << GLIBTOP_MEM_LOCKED);
+static const unsigned long _glibtop_sysdeps_mem_bunyip =
+(1L << GLIBTOP_MEM_SHARED) + (1L << GLIBTOP_MEM_BUFFER) +
+(1L << GLIBTOP_MEM_USER);
+
+/* Init function. */
+
+void
+glibtop_init_mem_s (glibtop *server)
+{
+ server->sysdeps.mem = _glibtop_sysdeps_mem_os_sysconf +
+ _glibtop_sysdeps_mem_os_kstat + _glibtop_sysdeps_mem_bunyip;
+}
+
+/* Provides information about memory usage. */
+
+void
+glibtop_get_mem_s (glibtop *server, glibtop_mem *buf)
+{
+ kstat_ctl_t *kc = server->machine.kc;
+ kstat_t *ksp;
+ kstat_named_t *kn;
+ int pagesize = server->machine.pagesize;
+
+#ifndef KSTAT_DATA_UINT32
+#define ui32 ul
+#endif
+
+ memset (buf, 0, sizeof (glibtop_mem));
+
+ buf->total = (u_int64_t)sysconf(_SC_PHYS_PAGES) << pagesize << 10;
+ buf->flags = _glibtop_sysdeps_mem_os_sysconf;
+
+ if(!kc)
+ return;
+ switch(kstat_chain_update(kc))
+ {
+ case -1: assert(0); /* Debugging purposes, shouldn't happen */
+ case 0: break;
+ default: glibtop_get_kstats(server);
+ }
+
+ if((ksp = server->machine.syspages) && kstat_read(kc, ksp, NULL) >= 0)
+ {
+ kn = (kstat_named_t *)kstat_data_lookup(ksp, "pagesfree");
+ if(kn)
+ {
+#ifdef _LP64
+ buf->free = kn->value.ui64 << pagesize << 10;
+#else
+ buf->free = kn->value.ui32 << pagesize << 10;
+#endif
+ buf->used = buf->total - buf->free;
+ }
+ kn = (kstat_named_t *)kstat_data_lookup(ksp, "pageslocked");
+ if(kn)
+#ifdef _LP64
+ buf->locked = kn->value.ui64 << pagesize;
+#else
+ buf->locked = kn->value.ui32 << pagesize;
+#endif
+ buf->flags += _glibtop_sysdeps_mem_os_kstat;
+ }
+
+ /* Bunyip module provides data in multiples of system page size */
+
+ if((ksp = server->machine.bunyip) && kstat_read(kc, ksp, NULL) >= 0)
+ {
+ kn = (kstat_named_t *)kstat_data_lookup(ksp, "pages_anon");
+ if(kn)
+#ifdef _LP64
+ buf->user = kn->value.ui64 << pagesize << 10;
+#else
+ buf->user = kn->value.ui32 << pagesize << 10;
+#endif
+ kn = (kstat_named_t *)kstat_data_lookup(ksp, "pages_exec");
+ if(kn)
+#ifdef _LP64
+ buf->shared = kn->value.ui64 << pagesize << 10;
+#else
+ buf->shared = kn->value.ui32 << pagesize << 10;
+#endif
+ kn = (kstat_named_t *)kstat_data_lookup(ksp, "pages_vnode");
+ if(kn)
+#ifdef _LP64
+ buf->buffer = kn->value.ui64 << pagesize << 10;
+#else
+ buf->buffer = kn->value.ui32 << pagesize << 10;
+#endif
+ buf->flags += _glibtop_sysdeps_mem_bunyip;
+ }
+}
diff --git a/sysdeps/solaris/msg_limits.c b/sysdeps/solaris/msg_limits.c
new file mode 100644
index 00000000..b38d8303
--- /dev/null
+++ b/sysdeps/solaris/msg_limits.c
@@ -0,0 +1,80 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <glibtop.h>
+#include <glibtop/msg_limits.h>
+
+#include <kvm.h>
+#include <sys/msg.h>
+
+static struct nlist nlst[] = { {"msginfo"}, {NULL} };
+static const unsigned long _glibtop_sysdeps_msg_limits =
+#if GLIBTOP_SOLARIS_RELEASE <= 570
+(1L << GLIBTOP_IPC_MSGMAP) + (1L << GLIBTOP_IPC_MSGSSZ) +
+#endif
+(1L << GLIBTOP_IPC_MSGPOOL) + (1L << GLIBTOP_IPC_MSGMAX) +
+(1L << GLIBTOP_IPC_MSGMNB) + (1L << GLIBTOP_IPC_MSGMNI) +
+(1L << GLIBTOP_IPC_MSGTQL);
+
+/* Init function. */
+
+void
+glibtop_init_msg_limits_p (glibtop *server)
+{
+ kvm_t *kd = server->machine.kd;
+
+ if(kd && !kvm_nlist(kd, nlst))
+ server->sysdeps.msg_limits = _glibtop_sysdeps_msg_limits;
+ else
+ server->sysdeps.msg_limits = 0;
+}
+
+/* Provides information about sysv ipc limits. */
+
+void
+glibtop_get_msg_limits_p (glibtop *server, glibtop_msg_limits *buf)
+{
+ kvm_t *kd = server->machine.kd;
+ struct msginfo minfo;
+
+ memset (buf, 0, sizeof (glibtop_msg_limits));
+
+ if(!(server->sysdeps.msg_limits))
+ return;
+ if(kvm_read(kd, nlst[0].n_value, (void *)&minfo,
+ sizeof(struct msginfo)) != sizeof(struct msginfo))
+ return;
+
+#if GLIBTOP_SOLARIS_RELEASE <= 570
+ /* These fields don't exist anymore in Solaris 8.
+ * Thanks to Laszlo PETER <Laszlo.Peter@ireland.sun.com>. */
+ buf->msgmap = minfo.msgmap;
+ buf->msgssz = minfo.msgssz;
+#endif
+ buf->msgmax = minfo.msgmax;
+ buf->msgmnb = minfo.msgmnb;
+ buf->msgmni = minfo.msgmni;
+ buf->msgtql = minfo.msgtql;
+ buf->msgpool = minfo.msgmni * minfo.msgmnb >> 10;
+ buf->flags = _glibtop_sysdeps_msg_limits;
+}
diff --git a/sysdeps/solaris/netload.c b/sysdeps/solaris/netload.c
new file mode 100644
index 00000000..beebedba
--- /dev/null
+++ b/sysdeps/solaris/netload.c
@@ -0,0 +1,45 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, October 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <glibtop.h>
+#include <glibtop/error.h>
+#include <glibtop/netload.h>
+
+static const unsigned long _glibtop_sysdeps_netload = 0;
+
+/* Init function. */
+
+void
+glibtop_init_netload_s (glibtop *server)
+{
+ server->sysdeps.netload = _glibtop_sysdeps_netload;
+}
+
+/* Provides network statistics. */
+
+void
+glibtop_get_netload_s (glibtop *server, glibtop_netload *buf,
+ const char *interface)
+{
+ memset (buf, 0, sizeof (glibtop_netload));
+}
diff --git a/sysdeps/solaris/open.c b/sysdeps/solaris/open.c
new file mode 100644
index 00000000..7df43ca2
--- /dev/null
+++ b/sysdeps/solaris/open.c
@@ -0,0 +1,234 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <glibtop/open.h>
+#include <glibtop/cpu.h>
+
+#include <unistd.h>
+#include <dlfcn.h>
+#include <sys/types.h>
+#include <sys/processor.h>
+
+#include <glibtop_private.h>
+
+/* We need to call this when kstat_chain_update() returns new KID.
+ * In that case all kstat pointers and data are invalid, so we
+ * need to reread everything. The condition shouldn't happen very
+ * often.
+ */
+
+void
+glibtop_get_kstats(glibtop *server)
+{
+ kstat_ctl_t *kc = server->machine.kc;
+ kstat_t *ksp;
+ int nproc_same, new_ncpu;
+
+ new_ncpu = sysconf(_SC_NPROCESSORS_CONF);
+
+ if(!kc)
+ {
+ server->ncpu = new_ncpu;
+ server->machine.vminfo_kstat = NULL;
+ server->machine.system = NULL;
+ server->machine.syspages = NULL;
+ server->machine.bunyip = NULL;
+ return;
+ }
+
+ do {
+ ksp = kstat_lookup(kc, "unix", -1, "vminfo");
+ server->machine.vminfo_kstat = ksp;
+ if(ksp)
+ {
+ kstat_read(kc, ksp, &server->machine.vminfo);
+ /* Don't change snaptime if we only need to reinitialize kstats */
+ if(!(server->machine.vminfo_snaptime))
+ server->machine.vminfo_snaptime = ksp->ks_snaptime;
+ }
+
+ /* We don't know why was kstat chain invalidated. It could have
+ been because the number of processors changed. The sysconf()
+ man page says that values returned won't change during the
+ life time of a process, but let's hope that's just an error in
+ the documentation. */
+
+ if((nproc_same = new_ncpu) == server->ncpu)
+ {
+ int checked, i;
+ char cpu[20];
+
+ for(i = 0, checked = 0; i < GLIBTOP_NCPU || checked == new_ncpu; ++i)
+ if(server->machine.cpu_stat_kstat[i])
+ {
+ sprintf(cpu, "cpu_stat%d", i);
+ if(!(server->machine.cpu_stat_kstat[i] =
+ kstat_lookup(kc, "cpu_stat", -1, cpu)))
+ {
+ nproc_same = 0;
+ break;
+ }
+ ++checked;
+ }
+ }
+ if(!nproc_same)
+ {
+ processorid_t p;
+ int found;
+ char cpu[20];
+
+ if(new_ncpu > GLIBTOP_NCPU)
+ new_ncpu = GLIBTOP_NCPU;
+ server->ncpu = new_ncpu;
+ for(p = 0, found = 0; p < GLIBTOP_NCPU && found != new_ncpu; ++p)
+ {
+ if(p_online(p, P_STATUS) < 0)
+ {
+ server->machine.cpu_stat_kstat[p] = NULL;
+ continue;
+ }
+ sprintf(cpu, "cpu_stat%d", (int)p);
+ server->machine.cpu_stat_kstat[p] =
+ kstat_lookup(kc, "cpu_stat", -1, cpu);
+ ++found;
+ }
+ }
+
+ server->machine.system = kstat_lookup(kc, "unix", -1, "system_misc");
+ server->machine.syspages = kstat_lookup(kc, "unix", -1, "system_pages");
+ server->machine.bunyip = kstat_lookup(kc, "bunyip", -1, "mempages");
+
+ } while(kstat_chain_update(kc) > 0 &&
+ (new_ncpu = sysconf(_SC_NPROCESSORS_CONF)));
+
+ /* We'll ignore -1 from kstat_chain_update here, since it really
+ shouldn't happen */
+}
+
+void
+glibtop_open_s (glibtop *server, const char *program_name,
+ const unsigned long features, const unsigned flags)
+{
+ kstat_ctl_t *kc;
+ kstat_t *ksp;
+ kstat_named_t *kn;
+ int i, page;
+ void *dl;
+
+ server->name = program_name;
+
+ page = sysconf(_SC_PAGESIZE) >> 10;
+ for(i = 0; page; ++i, page >>= 1);
+ server->machine.pagesize = i - 1;
+ server->machine.ticks = sysconf(_SC_CLK_TCK);
+ server->machine.kc = kc = kstat_open ();
+
+#if 0
+ for (ksp = server->machine.kc->kc_chain; ksp != NULL; ksp = ksp->ks_next) {
+ if (!strcmp (ksp->ks_class, "vm") && !strcmp (ksp->ks_name, "vminfo")) {
+ server->machine.vminfo_kstat = ksp;
+ kstat_read (server->machine.kc, ksp, &server->machine.vminfo);
+ server->machine.vminfo_snaptime = ksp->ks_snaptime;
+ continue;
+ }
+
+ if (!strcmp (ksp->ks_class, "misc") && !strncmp (ksp->ks_name, "cpu_stat", 8)) {
+ int cpu;
+
+ if ((sscanf (ksp->ks_name+8, "%d", &cpu) != 1) || (cpu > 63))
+ continue;
+
+ if (cpu >= server->ncpu)
+ server->ncpu = cpu+1;
+
+ server->machine.cpu_stat_kstat [cpu] = ksp;
+ continue;
+ }
+ }
+
+#endif
+
+ if (!kc)
+ glibtop_warn_io_r (server, "kstat_open ()");
+
+ server->ncpu = -1; /* Force processor detection */
+ server->machine.vminfo_snaptime = 0; /* Force snaptime read */
+ glibtop_get_kstats(server);
+
+ server->machine.boot = 0;
+ if((ksp = server->machine.system) && kstat_read(kc, ksp, NULL) >= 0)
+ {
+ kn = (kstat_named_t *)kstat_data_lookup(ksp, "boot_time");
+ if(kn)
+ switch(kn->data_type)
+ {
+#ifdef KSTAT_DATA_INT32
+ case KSTAT_DATA_INT32: server->machine.boot = kn->value.i32;
+ break;
+ case KSTAT_DATA_UINT32: server->machine.boot = kn->value.ui32;
+ break;
+ case KSTAT_DATA_INT64: server->machine.boot = kn->value.i64;
+ break;
+ case KSTAT_DATA_UINT64: server->machine.boot = kn->value.ui64;
+ break;
+#else
+ case KSTAT_DATA_LONG: server->machine.boot = kn->value.l;
+ break;
+ case KSTAT_DATA_ULONG: server->machine.boot = kn->value.ul;
+ break;
+ case KSTAT_DATA_LONGLONG: server->machine.boot = kn->value.ll;
+ break;
+ case KSTAT_DATA_ULONGLONG: server->machine.boot = kn->value.ull;
+ break;
+#endif
+ }
+ }
+
+ /* Now let's have a bit of magic dust... */
+
+#if GLIBTOP_SOLARIS_RELEASE >= 560
+
+ dl = dlopen("/usr/lib/libproc.so", RTLD_LAZY);
+ server->machine.libproc = dl;
+ if(dl)
+ {
+ void *func;
+
+ func = dlsym(dl, "Pobjname"); /* Solaris 8 */
+ if(!func)
+ func = dlsym(dl, "proc_objname"); /* Solaris 7 */
+ server->machine.objname = (void (*)
+ (void *, uintptr_t, const char *, size_t))func;
+ server->machine.pgrab = (struct ps_prochandle *(*)(pid_t, int, int *))
+ dlsym(dl, "Pgrab");
+ server->machine.pfree = (void (*)(void *))dlsym(dl, "Pfree");
+ }
+ else
+ {
+ server->machine.objname = NULL;
+ server->machine.pgrab = NULL;
+ server->machine.pfree = NULL;
+ }
+#endif
+ server->machine.me = getpid();
+}
diff --git a/sysdeps/solaris/open_suid.c b/sysdeps/solaris/open_suid.c
new file mode 100644
index 00000000..502e7215
--- /dev/null
+++ b/sysdeps/solaris/open_suid.c
@@ -0,0 +1,92 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <glibtop.h>
+#include <glibtop/open.h>
+
+#include <glibtop_suid.h>
+
+#include <unistd.h>
+#include <sys/types.h>
+
+/* !!! THIS FUNCTION RUNS SUID ROOT - CHANGE WITH CAUTION !!! */
+
+void
+glibtop_init_p (glibtop *server, const unsigned long features,
+ const unsigned flags)
+{
+ glibtop_init_func_t *init_fkt;
+
+ if (server == NULL)
+ glibtop_error_r (NULL, "glibtop_init_p (server == NULL)");
+
+ /* Do the initialization, but only if not already initialized. */
+
+ if ((server->flags & _GLIBTOP_INIT_STATE_INIT) == 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_INIT;
+ }
+}
+
+/* !!! THIS FUNCTION RUNS SUID ROOT - CHANGE WITH CAUTION !!! */
+
+void
+glibtop_open_p (glibtop *server, const char *program_name,
+ const unsigned long features, const unsigned flags)
+{
+ /* !!! WE ARE ROOT HERE - CHANGE WITH CAUTION !!! */
+
+ server->name = program_name;
+
+ server->machine.uid = getuid ();
+ server->machine.euid = geteuid ();
+ server->machine.gid = getgid ();
+ server->machine.egid = getegid ();
+
+ server->machine.kd = kvm_open(NULL, NULL, NULL, O_RDONLY, NULL);
+ if(!server->machine.kd)
+ glibtop_warn_io_r(server, "kvm_open()");
+
+ /* Drop priviledges; we only become root when necessary.
+
+ setreuid (ruid, euid) - set real and effective user id;
+ setregid (rgid, egid) - set real and effective group id;
+
+ */
+
+ if (setreuid (server->machine.euid, server->machine.uid))
+ _exit (1);
+
+ if (setregid (server->machine.egid, server->machine.gid))
+ _exit (1);
+
+ /* !!! END OF SUID ROOT PART !!! */
+
+ /* Our effective uid is now those of the user invoking the server,
+ so we do no longer have any priviledges.
+ */
+}
diff --git a/sysdeps/solaris/ppp.c b/sysdeps/solaris/ppp.c
new file mode 100644
index 00000000..6d0905d5
--- /dev/null
+++ b/sysdeps/solaris/ppp.c
@@ -0,0 +1,44 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, October 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <glibtop.h>
+#include <glibtop/error.h>
+#include <glibtop/ppp.h>
+
+static const unsigned long _glibtop_sysdeps_ppp = 0;
+
+/* Init function. */
+
+void
+glibtop_init_ppp_s (glibtop *server)
+{
+ server->sysdeps.ppp = _glibtop_sysdeps_ppp;
+}
+
+/* Provides PPP/ISDN information. */
+
+void
+glibtop_get_ppp_s (glibtop *server, glibtop_ppp *buf, unsigned short device)
+{
+ memset (buf, 0, sizeof (glibtop_ppp));
+}
diff --git a/sysdeps/solaris/procargs.c b/sysdeps/solaris/procargs.c
new file mode 100644
index 00000000..ac2721d3
--- /dev/null
+++ b/sysdeps/solaris/procargs.c
@@ -0,0 +1,83 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <glibtop.h>
+#include <glibtop/error.h>
+#include <glibtop/xmalloc.h>
+#include <glibtop/procargs.h>
+
+static const unsigned long _glibtop_sysdeps_proc_args =
+(1L << GLIBTOP_PROC_ARGS_SIZE);
+
+/* Init function. */
+
+void
+glibtop_init_proc_args_s (glibtop *server)
+{
+ server->sysdeps.proc_args = _glibtop_sysdeps_proc_args;
+}
+
+/* Provides detailed information about a process. */
+
+char *
+glibtop_get_proc_args_s (glibtop *server, glibtop_proc_args *buf,
+ pid_t pid, unsigned max_len)
+{
+#ifdef HAVE_PROCFS_H
+ struct psinfo pinfo;
+#else
+ struct prpsinfo pinfo;
+#endif
+ int len, i;
+ char *ret, *p;
+
+ memset (buf, 0, sizeof (glibtop_proc_args));
+
+ if(glibtop_get_proc_data_psinfo_s(server, &pinfo, pid))
+ return NULL;
+
+ for(len = 0; len < PRARGSZ; ++len)
+ if(!(pinfo.pr_psargs[len]))
+ break;
+ if(max_len)
+ {
+ ret = glibtop_malloc_r(server, max_len + 1);
+ if(max_len < len)
+ len = max_len;
+ memcpy(ret, pinfo.pr_psargs, len);
+ ret[len] = 0;
+ }
+ else
+ {
+ ret = glibtop_malloc_r(server, len + 1);
+ memcpy(ret, pinfo.pr_psargs, len);
+ ret[len] = 0;
+
+ buf->size = len;
+ buf->flags = _glibtop_sysdeps_proc_args;
+ }
+ for(p = ret; *p; ++p)
+ if(*p == ' ')
+ *p = 0;
+ return ret;
+}
diff --git a/sysdeps/solaris/procdata.c b/sysdeps/solaris/procdata.c
new file mode 100644
index 00000000..e8353d00
--- /dev/null
+++ b/sysdeps/solaris/procdata.c
@@ -0,0 +1,268 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <glibtop.h>
+#include <glibtop_private.h>
+#include <glibtop/procuid.h>
+
+#include <errno.h>
+
+#include "safeio.h"
+
+/*
+ * The differences between old and new procfs API are:
+ * - old has /proc/<pid> file and ioctl() is used to obtain the data.
+ * - new has /proc/<pid>/* files and read() & friends are used to
+ * obtain the data.
+ * - names of structures and members are different. It's mostly the
+ * prefix. Old uses `pr' and new uses `ps'.
+ *
+ * Since almost every line would be in #ifdef, I think it would
+ * be more readable to just copy everything twice. This is not a big
+ * file, after all.
+ */
+
+#ifdef HAVE_PROCFS_H
+
+/* Read /proc/<pid>/psinfo. */
+
+int
+glibtop_get_proc_data_psinfo_s (glibtop *server, struct psinfo *psinfo, pid_t pid)
+{
+ int fd;
+ char buffer [BUFSIZ];
+
+ sprintf (buffer, "/proc/%d/psinfo", (int) pid);
+ fd = s_open (buffer, O_RDONLY);
+ if (fd < 0) {
+ glibtop_warn_io_r (server, "open (%s)", buffer);
+ return -1;
+ }
+
+ if (s_pread (fd, psinfo, sizeof (struct psinfo), 0) !=
+ sizeof (struct psinfo))
+ {
+ s_close (fd);
+ glibtop_warn_io_r (server, "pread (%s)", buffer);
+ return -1;
+ }
+
+ s_close (fd);
+ return 0;
+}
+
+int
+glibtop_get_proc_data_usage_s (glibtop *server, struct prusage *prusage, pid_t pid)
+{
+ int fd;
+ char buffer [BUFSIZ];
+
+ sprintf (buffer, "/proc/%d/usage", (int) pid);
+ fd = s_open (buffer, O_RDONLY);
+ if (fd < 0) {
+ glibtop_warn_io_r (server, "open (%s)", buffer);
+ return -1;
+ }
+
+ if (s_pread (fd, prusage, sizeof (struct prusage), 0) !=
+ sizeof (struct prusage))
+ {
+ s_close (fd);
+ glibtop_warn_io_r (server, "pread (%s)", buffer);
+ return -1;
+ }
+
+ s_close (fd);
+ return 0;
+}
+
+#if LIBGTOP_VERSION_CODE >= 1001002
+int
+glibtop_get_proc_credentials_s(glibtop *server,
+ struct prcred *prcred,
+ gid_t *groups,
+ pid_t pid)
+{
+ int fd;
+ size_t toread;
+ char buffer[BUFSIZ];
+
+ sprintf(buffer, "/proc/%d/cred", (int)pid);
+ if((fd = s_open(buffer, O_RDONLY)) < 0)
+ {
+ if(errno != EPERM && errno != EACCES)
+ glibtop_warn_io_r(server, "open (%s)", buffer);
+ return -1;
+ }
+ if(s_pread(fd, prcred, sizeof(struct prcred), 0) !=
+ sizeof(struct prcred))
+ {
+ s_close(fd);
+ glibtop_warn_io_r(server, "pread (%s)", buffer);
+ return -1;
+ }
+ if(prcred->pr_ngroups >= 0)
+ {
+ if(prcred->pr_ngroups <= GLIBTOP_MAX_GROUPS)
+ toread = prcred->pr_ngroups * sizeof(gid_t);
+ else
+ toread = GLIBTOP_MAX_GROUPS * sizeof(gid_t);
+ if(s_pread(fd, groups, toread,
+ &(((struct prcred *)0)->pr_groups[0])) != toread)
+ prcred->pr_ngroups = 0;
+ }
+ s_close(fd);
+ return 0;
+}
+#endif
+
+int
+glibtop_get_proc_status_s(glibtop *server, struct pstatus *pstatus, pid_t pid)
+{
+ int fd;
+ char buffer[BUFSIZ];
+
+ sprintf(buffer, "/proc/%d/status", (int)pid);
+ if((fd = s_open(buffer, O_RDONLY)) < 0)
+ {
+ if(errno != EPERM && errno != EACCES)
+ glibtop_warn_io_r(server, "open (%s)", buffer);
+ return -1;
+ }
+ if(s_pread(fd, pstatus, sizeof(struct pstatus), 0) !=
+ sizeof(struct pstatus))
+ {
+ s_close(fd);
+ glibtop_warn_io_r(server, "pread (%s)", buffer);
+ return -1;
+ }
+ s_close(fd);
+ return 0;
+}
+
+#else /* old API */
+
+int
+glibtop_get_proc_data_psinfo_s (glibtop *server,
+ struct prpsinfo *psinfo,
+ pid_t pid)
+{
+ int fd;
+ char buffer [BUFSIZ];
+
+ sprintf (buffer, "/proc/%d", (int) pid);
+ fd = s_open (buffer, O_RDONLY);
+ if (fd < 0) {
+ if(errno != EPERM && errno != EACCES)
+ glibtop_warn_io_r (server, "open (%s)", buffer);
+ return -1;
+ }
+
+ if(ioctl(fd, PIOCPSINFO, psinfo) < 0)
+ {
+ s_close (fd);
+ glibtop_warn_io_r (server, "ioctl(%s, PIOCPSINFO)", buffer);
+ return -1;
+ }
+
+ s_close (fd);
+ return 0;
+}
+
+int
+glibtop_get_proc_data_usage_s (glibtop *server,
+ struct prusage *prusage,
+ pid_t pid)
+{
+ int fd;
+ char buffer [BUFSIZ];
+
+ sprintf (buffer, "/proc/%d", (int) pid);
+ fd = s_open (buffer, O_RDONLY);
+ if (fd < 0) {
+ if(errno != EPERM && errno != EACCES)
+ glibtop_warn_io_r (server, "open (%s)", buffer);
+ return -1;
+ }
+
+ if(ioctl(fd, PIOCUSAGE, prusage) < 0)
+ {
+ s_close (fd);
+ glibtop_warn_io_r (server, "ioctl(%s, PIOCUSAGE)", buffer);
+ return -1;
+ }
+
+ s_close (fd);
+ return 0;
+}
+
+int
+glibtop_get_proc_credentials_s(glibtop *server,
+ struct prcred *prcred,
+ gid_t *groups,
+ pid_t pid)
+{
+ int fd;
+ size_t toread;
+ char buffer[BUFSIZ];
+
+ sprintf(buffer, "/proc/%d", (int)pid);
+ if((fd = s_open(buffer, O_RDONLY)) < 0)
+ {
+ if(errno != EPERM && errno != EACCES)
+ glibtop_warn_io_r(server, "open (%s)", buffer);
+ return -1;
+ }
+ if(ioctl(fd, PIOCCRED, prcred) < 0)
+ {
+ s_close(fd);
+ glibtop_warn_io_r(server, "ioctl(%s, PIOCCRED)", buffer);
+ return -1;
+ }
+ s_close(fd);
+ return 0;
+}
+
+int
+glibtop_get_proc_status_s(glibtop *server, struct prstatus *pstatus, pid_t pid)
+{
+ int fd;
+ char buffer[BUFSIZ];
+
+ sprintf(buffer, "/proc/%d", (int)pid);
+ if((fd = s_open(buffer, O_RDONLY)) < 0)
+ {
+ if(errno != EPERM && errno != EACCES)
+ glibtop_warn_io_r(server, "open (%s)", buffer);
+ return -1;
+ }
+ if(ioctl(fd, PIOCSTATUS, pstatus) < 0)
+ {
+ s_close(fd);
+ glibtop_warn_io_r(server, "ioctl(%s, PIOCSTATUS)", buffer);
+ return -1;
+ }
+ s_close(fd);
+ return 0;
+}
+#endif
diff --git a/sysdeps/solaris/prockernel.c b/sysdeps/solaris/prockernel.c
new file mode 100644
index 00000000..d06f6cab
--- /dev/null
+++ b/sysdeps/solaris/prockernel.c
@@ -0,0 +1,44 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <glibtop.h>
+#include <glibtop/prockernel.h>
+
+static const unsigned long _glibtop_sysdeps_proc_kernel = 0;
+
+/* Init function. */
+
+void
+glibtop_init_proc_kernel_s (glibtop *server)
+{
+ server->sysdeps.proc_kernel = _glibtop_sysdeps_proc_kernel;
+}
+
+/* Provides detailed information about a process. */
+
+void
+glibtop_get_proc_kernel_s (glibtop *server, glibtop_proc_kernel *buf,
+ pid_t pid)
+{
+ memset (buf, 0, sizeof (glibtop_proc_kernel));
+}
diff --git a/sysdeps/solaris/proclist.c b/sysdeps/solaris/proclist.c
new file mode 100644
index 00000000..956ab0a0
--- /dev/null
+++ b/sysdeps/solaris/proclist.c
@@ -0,0 +1,251 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <glibtop.h>
+#include <glibtop/proclist.h>
+#include <glibtop/xmalloc.h>
+
+#include <sys/stat.h>
+#include <unistd.h>
+#include <dirent.h>
+#include <ctype.h>
+
+#define GLIBTOP_PROCLIST_FLAGS 3
+
+static const unsigned long _glibtop_sysdeps_proclist =
+(1L << GLIBTOP_PROCLIST_TOTAL) + (1L << GLIBTOP_PROCLIST_NUMBER) +
+(1L << GLIBTOP_PROCLIST_SIZE);
+
+/* Init function. */
+
+void
+glibtop_init_proclist_s (glibtop *server)
+{
+ server->sysdeps.proclist = _glibtop_sysdeps_proclist;
+}
+
+#define BLOCK_COUNT 256
+#define BLOCK_SIZE (BLOCK_COUNT * sizeof (unsigned))
+
+/* Fetch list of currently running processes.
+ *
+ * IMPORTANT NOTE:
+ * On error, this function MUST return NULL and set buf->flags to zero !
+ * On success, it returnes a pointer to a list of buf->number elements
+ * each buf->size big. The total size is stored in buf->total. */
+
+unsigned *
+glibtop_get_proclist_s (glibtop *server, glibtop_proclist *buf,
+ int64_t which, int64_t arg)
+{
+ DIR *proc;
+ struct dirent *entry;
+ char buffer [BUFSIZ];
+ unsigned count, total, pid, mask;
+ unsigned pids [BLOCK_COUNT], *pids_chain = NULL;
+ unsigned pids_size = 0, pids_offset = 0, new_size;
+ struct stat statb;
+ int len, i, ok;
+
+ memset (buf, 0, sizeof (glibtop_proclist));
+ mask = which & ~GLIBTOP_KERN_PROC_MASK;
+ which &= GLIBTOP_KERN_PROC_MASK;
+
+ /* Check if the user wanted only one process */
+
+ if(which == GLIBTOP_KERN_PROC_PID)
+ {
+ if(mask)
+ {
+#ifdef HAVE_PROCFS_H
+ struct psinfo psinfo;
+#else
+ struct prpsinfo psinfo;
+#endif
+ if(glibtop_get_proc_data_psinfo_s(server, &psinfo, pid))
+ return NULL;
+ if(mask & GLIBTOP_EXCLUDE_IDLE && !psinfo.pr_pctcpu)
+ return NULL;
+ if(mask & GLIBTOP_EXCLUDE_SYSTEM && psinfo.pr_flag & SSYS)
+ return NULL;
+ if(mask & GLIBTOP_EXCLUDE_NOTTY && psinfo.pr_ttydev == PRNODEV)
+ return NULL;
+ }
+ else
+ {
+ sprintf(buffer, "/proc/%d", arg);
+ if(s_stat(buffer, &statb) < 0)
+ return NULL;
+ }
+ if(!(pids_chain = glibtop_malloc(sizeof(unsigned))))
+ return NULL;
+ *pids_chain = pid;
+ return pids_chain;
+ }
+
+ proc = opendir ("/proc");
+ if (!proc) return NULL;
+
+ /* read every every entry in /proc */
+
+ for (count = total = 0, entry = readdir (proc);
+ entry; entry = readdir (proc)) {
+ ok = 1; len = strlen (entry->d_name);
+
+ /* does it consist entirely of digits? */
+#if 0
+ /* It does, except for "." and "..". Let's speed up */
+
+ for (i = 0; i < len; i++)
+ if (!isdigit (entry->d_name [i])) ok = 0;
+ if (!ok) continue;
+#else
+ if(entry->d_name[0] == '.')
+ continue;
+#endif
+
+ /* convert it in a number */
+#if 0
+ if (sscanf (entry->d_name, "%u", &pid) != 1) continue;
+#else
+ pid = (unsigned)atol(entry->d_name);
+#endif
+
+#ifdef HAVE_PROCFS_H
+
+ /* Can we skip it based on the request? We have
+ RUID and RGID in struct stat. But we can't do it
+ like this for LP64 process, because stat() will fail.
+ XXX Unimplemented for now */
+
+ if(!mask && which == GLIBTOP_KERN_PROC_RUID)
+ {
+ sprintf (buffer, "/proc/%d", pid);
+ if (s_stat (buffer, &statb)) continue;
+
+ if (!S_ISDIR (statb.st_mode)) continue;
+
+ if(statb.st_uid != arg) continue;
+ }
+
+ if(mask || which != GLIBTOP_KERN_PROC_ALL)
+ {
+ struct psinfo psinfo;
+
+ if(glibtop_get_proc_data_psinfo_s(server, &psinfo, pid))
+ continue;
+ if(mask)
+ {
+ if(mask & GLIBTOP_EXCLUDE_IDLE && !psinfo.pr_pctcpu)
+ continue;
+ if(mask & GLIBTOP_EXCLUDE_SYSTEM && psinfo.pr_flag & SSYS)
+ continue;
+ if(mask & GLIBTOP_EXCLUDE_NOTTY
+ && psinfo.pr_ttydev == PRNODEV)
+ continue;
+ }
+ switch(which)
+ {
+ case GLIBTOP_KERN_PROC_PGRP: if(psinfo.pr_pgid != arg)
+ continue;
+ break;
+ case GLIBTOP_KERN_PROC_SESSION: if(psinfo.pr_sid != arg)
+ continue;
+ break;
+ case GLIBTOP_KERN_PROC_TTY: if(psinfo.pr_ttydev != arg)
+ continue;
+ break;
+ case GLIBTOP_KERN_PROC_UID: if(psinfo.pr_euid != arg)
+ continue;
+ break;
+ case GLIBTOP_KERN_PROC_RUID: if(psinfo.pr_uid != arg)
+ continue;
+ break;
+ default: break;
+ }
+ }
+#endif
+ /* Fine. Now we first try to store it in pids. If this buffer is
+ * full, we copy it to the pids_chain. */
+
+ if (count >= BLOCK_COUNT) {
+ /* The following call to glibtop_realloc will be
+ * equivalent to glibtop_malloc () if `pids_chain' is
+ * NULL. We just calculate the new size and copy `pids'
+ * to the beginning of the newly allocated block. */
+
+ new_size = pids_size + BLOCK_SIZE;
+
+ pids_chain = glibtop_realloc_r
+ (server, pids_chain, new_size);
+
+ memcpy (pids_chain + pids_offset, pids, BLOCK_SIZE);
+
+ pids_size = new_size;
+
+ pids_offset += BLOCK_COUNT;
+
+ count = 0;
+ }
+
+ /* pids is now big enough to hold at least one single pid. */
+
+ pids [count++] = pid;
+
+ total++;
+ }
+
+ s_closedir (proc);
+
+ /* count is only zero if an error occured (one a running Linux system,
+ * we have at least one single process). */
+
+ if (!count) return NULL;
+
+ /* The following call to glibtop_realloc will be equivalent to
+ * glibtop_malloc if pids_chain is NULL. We just calculate the
+ * new size and copy pids to the beginning of the newly allocated
+ * block. */
+
+ new_size = pids_size + count * sizeof (unsigned);
+
+ pids_chain = glibtop_realloc_r (server, pids_chain, new_size);
+
+ memcpy (pids_chain + pids_offset, pids, count * sizeof (unsigned));
+
+ pids_size = new_size;
+
+ pids_offset += BLOCK_COUNT;
+
+ /* Since everything is ok now, we can set buf->flags, fill in the
+ * remaining fields and return the `pids_chain'. */
+
+ buf->flags = _glibtop_sysdeps_proclist;
+
+ buf->size = sizeof (unsigned);
+ buf->number = total;
+
+ buf->total = total * sizeof (unsigned);
+
+ return pids_chain;
+}
diff --git a/sysdeps/solaris/procmap.c b/sysdeps/solaris/procmap.c
new file mode 100644
index 00000000..daa2ba00
--- /dev/null
+++ b/sysdeps/solaris/procmap.c
@@ -0,0 +1,207 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+
+#include <glibtop.h>
+#include <glibtop/error.h>
+#include <glibtop/xmalloc.h>
+#include <glibtop/procmap.h>
+
+#include <errno.h>
+#include <alloca.h>
+
+#include "safeio.h"
+
+
+static const unsigned long _glibtop_sysdeps_proc_map =
+(1L << GLIBTOP_PROC_MAP_NUMBER) + (1L << GLIBTOP_PROC_MAP_TOTAL) +
+(1L << GLIBTOP_PROC_MAP_SIZE);
+static const unsigned long _glibtop_sysdeps_map_entry =
+(1L << GLIBTOP_MAP_ENTRY_START) + (1L << GLIBTOP_MAP_ENTRY_END) +
+(1L << GLIBTOP_MAP_ENTRY_OFFSET) + (1L << GLIBTOP_MAP_ENTRY_PERM);
+static const unsigned long _glibtop_sysdeps_map_device =
+(1L << GLIBTOP_MAP_ENTRY_DEVICE) + (1L << GLIBTOP_MAP_ENTRY_INODE);
+
+
+/* Init function. */
+
+void
+glibtop_init_proc_map_s (glibtop *server)
+{
+ server->sysdeps.proc_map = _glibtop_sysdeps_proc_map;
+}
+
+/* Provides detailed information about a process. */
+
+glibtop_map_entry *
+glibtop_get_proc_map_s (glibtop *server, glibtop_proc_map *buf, pid_t pid)
+{
+ int fd, i, nmaps, pr_err, heap;
+#if GLIBTOP_SOLARIS_RELEASE >= 560
+ prxmap_t *maps;
+ struct ps_prochandle *Pr;
+#else
+ prmap_t *maps;
+#endif
+
+ /* A few defines, to make it shorter down there */
+
+#ifdef HAVE_PROCFS_H
+# define OFFSET pr_offset
+#else
+# define OFFSET pr_off
+#endif
+
+ glibtop_map_entry *entry;
+ struct stat inode;
+ char buffer[BUFSIZ];
+
+ memset (buf, 0, sizeof (glibtop_proc_map));
+
+#ifdef HAVE_PROCFS_H
+ sprintf(buffer, "/proc/%d/xmap", (int)pid);
+#else
+ sprintf(buffer, "/proc/%d", (int)pid);
+#endif
+ if((fd = s_open(buffer, O_RDONLY)) < 0)
+ {
+ if(errno != EPERM && errno != EACCES)
+ glibtop_warn_io_r(server, "open (%s)", buffer);
+ return NULL;
+ }
+#ifdef HAVE_PROCFS_H
+ if(fstat(fd, &inode) < 0)
+ {
+ if(errno != EOVERFLOW)
+ glibtop_warn_io_r(server, "fstat (%s)", buffer);
+ /* else call daemon for 64-bit support */
+ s_close(fd);
+ return NULL;
+ }
+ maps = alloca(inode.st_size);
+ nmaps = inode.st_size / sizeof(prxmap_t);
+ if(s_pread(fd, maps, inode.st_size, 0) != inode.st_size)
+ {
+ glibtop_warn_io_r(server, "pread (%s)", buffer);
+ s_close(fd);
+ return NULL;
+ }
+#else
+ if(ioctl(fd, PIOCNMAP, &nmaps) < 0)
+ {
+ glibtop_warn_io_r(server, "ioctl(%s, PIOCNMAP)", buffer);
+ s_close(fd);
+ return NULL;
+ }
+ maps = alloca((nmaps + 1) * sizeof(prmap_t));
+ if(ioctl(fd, PIOCMAP, maps) < 0)
+ {
+ glibtop_warn_io_r(server, "ioctl(%s, PIOCMAP)", buffer);
+ s_close(fd);
+ return NULL;
+ }
+#endif
+ if(!(entry = glibtop_malloc_r(server,
+ nmaps * sizeof(glibtop_map_entry))))
+ return NULL;
+ buf->number = nmaps;
+ buf->size = sizeof(glibtop_map_entry);
+ buf->total = nmaps * sizeof(glibtop_map_entry);
+
+ memset(entry, 0, nmaps * sizeof(glibtop_map_entry));
+
+#if GLIBTOP_SOLARIS_RELEASE >= 560
+
+ if(server->machine.objname && server->machine.pgrab &&
+ server->machine.pfree)
+ Pr = (server->machine.pgrab)(pid, 1, &pr_err);
+#endif
+ for(heap = 0,i = 0; i < nmaps; ++i)
+ {
+ int len;
+
+ entry[i].start = maps[i].pr_vaddr;
+ entry[i].end = maps[i].pr_vaddr + maps[i].pr_size;
+
+#if GLIBTOP_SOLARIS_RELEASE >= 560
+
+ if(maps[i].pr_dev != PRNODEV)
+ {
+ entry[i].device = maps[i].pr_dev;
+ entry[i].inode = maps[i].pr_ino;
+ entry[i].flags |= _glibtop_sysdeps_map_device;
+ }
+#endif
+ entry[i].offset = maps[i].OFFSET;
+ if(maps[i].pr_mflags & MA_READ)
+ entry[i].perm |= GLIBTOP_MAP_PERM_READ;
+ if(maps[i].pr_mflags & MA_WRITE)
+ entry[i].perm |= GLIBTOP_MAP_PERM_WRITE;
+ if(maps[i].pr_mflags & MA_EXEC)
+ entry[i].perm |= GLIBTOP_MAP_PERM_EXECUTE;
+ if(maps[i].pr_mflags & MA_SHARED)
+ entry[i].perm |= GLIBTOP_MAP_PERM_SHARED;
+ else
+ entry[i].perm |= GLIBTOP_MAP_PERM_PRIVATE;
+ entry[i].flags = _glibtop_sysdeps_map_entry;
+
+#if GLIBTOP_SOLARIS_RELEASE >= 560
+
+ if(maps[i].pr_mflags & MA_ANON)
+ {
+ if(!heap)
+ {
+ ++heap;
+ strcpy(entry[i].filename, "[ heap ]");
+ }
+ else
+ if(i == nmaps - 1)
+ strcpy(entry[i].filename, "[ stack ]");
+ else
+ strcpy(entry[i].filename, "[ anon ]");
+ entry[i].flags |= (1L << GLIBTOP_MAP_ENTRY_FILENAME);
+ }
+ else
+ if(Pr)
+ {
+ server->machine.objname(Pr, maps[i].pr_vaddr, buffer,
+ BUFSIZ);
+ if((len = resolvepath(buffer, entry[i].filename,
+ GLIBTOP_MAP_FILENAME_LEN)) > 0)
+ {
+ entry[i].filename[len] = 0;
+ entry[i].flags |= (1L << GLIBTOP_MAP_ENTRY_FILENAME);
+ }
+ }
+#endif
+ }
+
+#if GLIBTOP_SOLARIS_RELEASE >= 560
+
+ if(Pr)
+ server->machine.pfree(Pr);
+#endif
+ buf->flags = _glibtop_sysdeps_proc_map;
+ s_close(fd);
+ return entry;
+}
diff --git a/sysdeps/solaris/procmem.c b/sysdeps/solaris/procmem.c
new file mode 100644
index 00000000..6452f0f7
--- /dev/null
+++ b/sysdeps/solaris/procmem.c
@@ -0,0 +1,64 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <glibtop.h>
+#include <glibtop/procmem.h>
+
+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);
+
+/* Init function. */
+
+void
+glibtop_init_proc_mem_s (glibtop *server)
+{
+ server->sysdeps.proc_mem = _glibtop_sysdeps_proc_mem;
+}
+
+/* Provides detailed information about a process. */
+
+void
+glibtop_get_proc_mem_s (glibtop *server, glibtop_proc_mem *buf, pid_t pid)
+{
+#ifdef HAVE_PROCFS_H
+ struct psinfo psinfo;
+#else
+ struct prpsinfo psinfo;
+ int pagesize = server->machine.pagesize;
+#endif
+
+ memset (buf, 0, sizeof (glibtop_proc_mem));
+
+ if(glibtop_get_proc_data_psinfo_s(server, &psinfo, pid))
+ return;
+
+#ifdef HAVE_PROCFS_H
+ buf->size = buf->vsize = psinfo.pr_size << 10;
+ buf->resident = buf->rss = psinfo.pr_rssize << 10;
+#else
+ buf->size = buf->vsize = psinfo.pr_size << pagesize << 10;
+ buf->resident = buf->rss = psinfo.pr_rssize << pagesize << 10;
+#endif
+ buf->flags = _glibtop_sysdeps_proc_mem;
+}
diff --git a/sysdeps/solaris/procsegment.c b/sysdeps/solaris/procsegment.c
new file mode 100644
index 00000000..b03709d4
--- /dev/null
+++ b/sysdeps/solaris/procsegment.c
@@ -0,0 +1,44 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <glibtop.h>
+#include <glibtop/procsegment.h>
+
+static const unsigned long _glibtop_sysdeps_proc_segment = 0;
+
+/* Init function. */
+
+void
+glibtop_init_proc_segment_s (glibtop *server)
+{
+ server->sysdeps.proc_segment = _glibtop_sysdeps_proc_segment;
+}
+
+/* Provides detailed information about a process. */
+
+void
+glibtop_get_proc_segment_s (glibtop *server, glibtop_proc_segment *buf,
+ pid_t pid)
+{
+ memset (buf, 0, sizeof (glibtop_proc_segment));
+}
diff --git a/sysdeps/solaris/procsignal.c b/sysdeps/solaris/procsignal.c
new file mode 100644
index 00000000..5b4d06a7
--- /dev/null
+++ b/sysdeps/solaris/procsignal.c
@@ -0,0 +1,74 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <glibtop.h>
+#include <glibtop/procsignal.h>
+
+#include <glibtop_private.h>
+
+static const unsigned long _glibtop_sysdeps_proc_signal =
+(1L << GLIBTOP_PROC_SIGNAL_SIGNAL) + (1L << GLIBTOP_PROC_SIGNAL_BLOCKED);
+
+/* Init function. */
+
+void
+glibtop_init_proc_signal_s (glibtop *server)
+{
+ server->sysdeps.proc_signal = _glibtop_sysdeps_proc_signal;
+}
+
+/* Provides detailed information about a process. */
+
+void
+glibtop_get_proc_signal_s (glibtop *server, glibtop_proc_signal *buf,
+ pid_t pid)
+{
+#ifdef HAVE_PROCFS_H
+ struct pstatus pstatus;
+#else
+ struct prstatus pstatus;
+#endif
+ int size;
+
+ memset (buf, 0, sizeof (glibtop_proc_signal));
+
+ if(glibtop_get_proc_status_s(server, &pstatus, pid))
+ return;
+
+ if(sizeof(buf->signal) < sizeof(sigset_t))
+ size = sizeof(buf->signal);
+ else
+ size = sizeof(sigset_t);
+
+ memcpy(buf->signal, &pstatus.pr_sigpend, size);
+#ifdef HAVE_PROCFS_H
+ memcpy(buf->blocked, &pstatus.pr_lwp.pr_lwphold, size);
+#else
+ memcpy(buf->blocked, &pstatus.pr_lwppend, size);
+#endif
+
+ /* Technically, most of this is meaningless on a process level,
+ but this should be a good enough approximation. */
+
+ buf->flags = _glibtop_sysdeps_proc_signal;
+}
diff --git a/sysdeps/solaris/procstate.c b/sysdeps/solaris/procstate.c
new file mode 100644
index 00000000..89647d22
--- /dev/null
+++ b/sysdeps/solaris/procstate.c
@@ -0,0 +1,122 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <glibtop.h>
+#include <glibtop/procstate.h>
+
+#include <glibtop_private.h>
+
+static const unsigned long _glibtop_sysdeps_proc_state =
+#if (LIBGTOP_VERSION_CODE >= 1001002) && defined(HAVE_PROCFS_H)
+(1L << GLIBTOP_PROC_STATE_HAS_CPU) + (1L << GLIBTOP_PROC_STATE_PROCESSOR) +
+(1L << GLIBTOP_PROC_STATE_LAST_PROCESSOR) +
+#endif
+#if LIBGTOP_VERSION_CODE >= 1001002
+(1L << GLIBTOP_PROC_STATE_RUID) + (1L << GLIBTOP_PROC_STATE_RGID) +
+#endif
+(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_s (glibtop *server)
+{
+ server->sysdeps.proc_state = _glibtop_sysdeps_proc_state;
+}
+
+/* Provides detailed information about a process. */
+
+void
+glibtop_get_proc_state_s (glibtop *server, glibtop_proc_state *buf, pid_t pid)
+{
+#ifdef HAVE_PROCFS_H
+ struct psinfo psinfo;
+#else
+ struct prpsinfo psinfo;
+#endif
+
+ memset (buf, 0, sizeof (glibtop_proc_state));
+
+ if (glibtop_get_proc_data_psinfo_s (server, &psinfo, pid))
+ return;
+
+ buf->uid = psinfo.pr_euid;
+ buf->gid = psinfo.pr_egid;
+#if LIBGTOP_VERSION_CODE >= 1001002
+ buf->ruid = psinfo.pr_uid;
+ buf->rgid = psinfo.pr_gid;
+#endif
+#ifdef HAVE_PROCFS_H
+ switch(psinfo.pr_lwp.pr_state)
+#else
+ switch(psinfo.pr_state)
+#endif
+ {
+ case SONPROC:
+#if (LIBGTOP_VERSION_CODE >= 1001002) && defined(HAVE_PROCFS_H)
+ buf->has_cpu = 1;
+ buf->processor = psinfo.pr_lwp.pr_onpro;
+#endif
+ case SRUN:
+#if LIBGTOP_VERSION_CODE >= 1001002
+ buf->state = GLIBTOP_PROCESS_RUNNING;
+#else
+ buf->state = 'R';
+#endif
+ break;
+ case SZOMB:
+#if LIBGTOP_VERSION_CODE >= 1001002
+ buf->state = GLIBTOP_PROCESS_ZOMBIE;
+#else
+ buf->state = 'Z';
+#endif
+ break;
+ case SSLEEP:
+#if LIBGTOP_VERSION_CODE >= 1001002
+ buf->state = GLIBTOP_PROCESS_INTERRUPTIBLE;
+#else
+ buf->state = 'S';
+#endif
+ break;
+ case SSTOP:
+#if LIBGTOP_VERSION_CODE >= 1001002
+ buf->state = GLIBTOP_PROCESS_STOPPED;
+#else
+ buf->state = 'T';
+#endif
+ break;
+ case SIDL:
+#if LIBGTOP_VERSION_CODE >= 1001002
+ buf->state = GLIBTOP_PROCESS_UNINTERRUPTIBLE;
+#else
+ buf->state = 'D';
+#endif
+ }
+#if (LIBGTOP_VERSION_CODE >= 1001002) && defined(HAVE_PROCFS_H)
+ buf->last_processor = psinfo.pr_lwp.pr_onpro;
+#endif
+ strncpy (buf->cmd, psinfo.pr_fname, 39);
+
+ buf->flags = _glibtop_sysdeps_proc_state;
+}
diff --git a/sysdeps/solaris/proctime.c b/sysdeps/solaris/proctime.c
new file mode 100644
index 00000000..6fef5169
--- /dev/null
+++ b/sysdeps/solaris/proctime.c
@@ -0,0 +1,69 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <glibtop.h>
+#include <glibtop/proctime.h>
+
+#include <glibtop_private.h>
+
+static const unsigned long _glibtop_sysdeps_proc_time =
+(1L << GLIBTOP_PROC_TIME_START_TIME) + (1L << GLIBTOP_PROC_TIME_RTIME) +
+(1L << GLIBTOP_PROC_TIME_UTIME) + (1L << GLIBTOP_PROC_TIME_STIME);
+
+/* Init function. */
+
+void
+glibtop_init_proc_time_s (glibtop *server)
+{
+ server->sysdeps.proc_time = _glibtop_sysdeps_proc_time;
+}
+
+/* Provides detailed information about a process. */
+
+void
+glibtop_get_proc_time_s (glibtop *server, glibtop_proc_time *buf,
+ pid_t pid)
+{
+ struct prusage prusage;
+
+ memset (buf, 0, sizeof (glibtop_proc_time));
+
+ /* Don't do it for scheduler, we don't want to frighten our users */
+
+ if(pid)
+ {
+ if (glibtop_get_proc_data_usage_s (server, &prusage, pid))
+ return;
+
+ buf->start_time = prusage.pr_create.tv_sec;
+
+ buf->rtime = prusage.pr_rtime.tv_sec * 1E+6 +
+ prusage.pr_rtime.tv_nsec / 1E+3;
+ buf->utime = prusage.pr_utime.tv_sec * 1E+6 +
+ prusage.pr_utime.tv_nsec / 1E+3;
+ buf->stime = prusage.pr_stime.tv_sec * 1E+6 +
+ prusage.pr_stime.tv_nsec / 1E+3;
+ }
+
+ buf->flags = _glibtop_sysdeps_proc_time;
+}
diff --git a/sysdeps/solaris/procuid.c b/sysdeps/solaris/procuid.c
new file mode 100644
index 00000000..f763757d
--- /dev/null
+++ b/sysdeps/solaris/procuid.c
@@ -0,0 +1,127 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <glibtop.h>
+#include <glibtop/procuid.h>
+
+#include <glibtop_private.h>
+
+static const unsigned long _glibtop_sysdeps_proc_uid_psinfo =
+(1L << GLIBTOP_PROC_UID_EUID) + (1L << GLIBTOP_PROC_UID_UID) +
+(1L << GLIBTOP_PROC_UID_EGID) + (1L << GLIBTOP_PROC_UID_GID) +
+(1L << GLIBTOP_PROC_UID_PID) + (1L << GLIBTOP_PROC_UID_PPID) +
+(1L << GLIBTOP_PROC_UID_PGRP) + (1L << GLIBTOP_PROC_UID_SESSION) +
+(1L << GLIBTOP_PROC_UID_TTY) + (1L << GLIBTOP_PROC_UID_PRIORITY) +
+(1L << GLIBTOP_PROC_UID_NICE);
+static const unsigned long _glibtop_sysdeps_proc_uid_prcred =
+#if LIBGTOP_VERSION_CODE >= 1001002
+#ifdef HAVE_PROCFS_H
+(1L << GLIBTOP_PROC_UID_GROUPS) +
+#endif
+(1L << GLIBTOP_PROC_UID_SUID) + (1L << GLIBTOP_PROC_UID_SGID) +
+(1L << GLIBTOP_PROC_UID_NGROUPS);
+#else
+0;
+#endif
+/* Init function. */
+
+void
+glibtop_init_proc_uid_s (glibtop *server)
+{
+ server->sysdeps.proc_uid = _glibtop_sysdeps_proc_uid_psinfo +
+ _glibtop_sysdeps_proc_uid_prcred;
+}
+
+/* Provides detailed information about a process. */
+
+void
+glibtop_get_proc_uid_s (glibtop *server, glibtop_proc_uid *buf, pid_t pid)
+{
+#if LIBGTOP_VERSION_CODE >= 1001002
+ struct prcred prcred;
+#endif
+#ifdef HAVE_PROCFS_H
+ struct psinfo psinfo;
+#if LIBGTOP_VERSION_CODE >= 1001002
+ gid_t groups[GLIBTOP_MAX_GROUPS];
+#endif
+#else
+ struct prpsinfo psinfo;
+ gid_t groups[1]; /* dummy for consistent function prototype */
+#endif
+
+ memset (buf, 0, sizeof (glibtop_proc_uid));
+
+ if (glibtop_get_proc_data_psinfo_s (server, &psinfo, pid))
+ return;
+
+ buf->euid = psinfo.pr_euid;
+ buf->uid = psinfo.pr_uid;
+ buf->egid = psinfo.pr_egid;
+ buf->gid = psinfo.pr_gid;
+
+ buf->pid = psinfo.pr_pid;
+ buf->ppid = psinfo.pr_ppid;
+#ifdef HAVE_PROCFS_H
+ buf->pgrp = psinfo.pr_pgid;
+#else
+ buf->pgrp = psinfo.pr_pgrp;
+#endif
+
+ buf->session = psinfo.pr_sid;
+ buf->tty = psinfo.pr_ttydev;
+
+#ifdef HAVE_PROCFS_H
+ buf->priority = psinfo.pr_lwp.pr_pri;
+ buf->nice = psinfo.pr_lwp.pr_nice - NZERO;
+#else
+ buf->priority = psinfo.pr_pri;
+ buf->nice = psinfo.pr_nice - NZERO;
+#endif
+
+ buf->flags = _glibtop_sysdeps_proc_uid_psinfo;
+
+#if LIBGTOP_VERSION_CODE >= 1001002
+ if(glibtop_get_proc_credentials_s(server, &prcred, groups, pid))
+ return;
+
+ buf->suid = prcred.pr_suid;
+ buf->sgid = prcred.pr_sgid;
+ buf->ngroups = (prcred.pr_ngroups <= GLIBTOP_MAX_GROUPS) ?
+ prcred.pr_ngroups : GLIBTOP_MAX_GROUPS;
+
+#ifdef HAVE_PROCFS_H
+ if(sizeof(int) == sizeof(gid_t))
+ memcpy(buf->groups, &groups, buf->ngroups * sizeof(gid_t));
+ else
+ {
+ int i;
+
+ for(i = 0; i < buf->ngroups; ++i)
+ buf->groups[i] = groups[i];
+ }
+#endif
+#endif
+
+ buf->flags += _glibtop_sysdeps_proc_uid_prcred;
+}
diff --git a/sysdeps/solaris/safeio.c b/sysdeps/solaris/safeio.c
new file mode 100644
index 00000000..ed9c784a
--- /dev/null
+++ b/sysdeps/solaris/safeio.c
@@ -0,0 +1,84 @@
+/* Copyright (C) 1999 Drazen Kacar
+ This file is part of LibGTop 1.0.
+
+ Contributed by Drazen Kacar <dave@srce.hr>, May 1999.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <unistd.h>
+#include <fcntl.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <dirent.h>
+#include <errno.h>
+
+int
+s_open(const char *file, int mode)
+{
+ int fd;
+
+ do {
+ fd = open(file, mode);
+ } while(fd < 0 && errno == EINTR);
+ return fd;
+}
+
+int
+s_stat(const char *path, struct stat *buf)
+{
+ int status;
+
+ do {
+ status = stat(path, buf);
+ } while(status < 0 && errno == EINTR);
+ return status;
+}
+
+int
+s_close(int fd)
+{
+ int status;
+
+ do {
+ status = close(fd);
+ } while(status < 0 && errno == EINTR);
+ return status;
+}
+
+ssize_t
+s_pread(int fd, void *buf, size_t nbytes, off_t offset)
+{
+ ssize_t len;
+
+ /* Now, why doesn't the pread(2) man page say anything about pread()
+ return values? Can it read less bytes than requested? */
+
+ do {
+ len = pread(fd, buf, nbytes, offset);
+ } while(len < 0 && errno == EINTR);
+ return len;
+}
+
+int s_closedir(DIR *dirp)
+{
+ int status;
+
+ do {
+ status = closedir(dirp);
+ } while(status < 0 && errno == EINTR);
+ return status;
+}
diff --git a/sysdeps/solaris/safeio.h b/sysdeps/solaris/safeio.h
new file mode 100644
index 00000000..b6808e81
--- /dev/null
+++ b/sysdeps/solaris/safeio.h
@@ -0,0 +1,48 @@
+/* Copyright (C) 1999 Drazen Kacar
+ This file is part of LibGTop 1.0.
+
+ Contributed by Drazen Kacar <dave@srce.hr>, May 1999.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#ifndef __GLIBTOP_SAFEIO_H__
+#define __GLIBTOP_SAFEIO_H__
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <dirent.h>
+
+BEGIN_LIBGTOP_DECLS
+
+int
+s_open(const char *, int);
+
+int
+s_stat(const char *, struct stat *);
+
+int
+s_close(int);
+
+ssize_t
+s_pread(int, void *, size_t, off_t);
+
+int
+s_closedir(DIR *);
+
+END_LIBGTOP_DECLS
+
+#endif
diff --git a/sysdeps/solaris/sem_limits.c b/sysdeps/solaris/sem_limits.c
new file mode 100644
index 00000000..e7e97436
--- /dev/null
+++ b/sysdeps/solaris/sem_limits.c
@@ -0,0 +1,85 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <glibtop.h>
+#include <glibtop/sem_limits.h>
+
+#include <kvm.h>
+#include <sys/sem.h>
+
+static struct nlist nlst[] = { {"seminfo"}, {NULL} };
+static const unsigned long _glibtop_sysdeps_sem_limits =
+#if GLIBTOP_SOLARIS_RELEASE <= 570
+(1L << GLIBTOP_IPC_SEMMAP) +
+#endif
+(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_p (glibtop *server)
+{
+ kvm_t *kd = server->machine.kd;
+
+ if(kd && !kvm_nlist(kd, nlst))
+ server->sysdeps.sem_limits = _glibtop_sysdeps_sem_limits;
+ else
+ server->sysdeps.sem_limits = 0;
+}
+
+/* Provides information about sysv sem limits. */
+
+void
+glibtop_get_sem_limits_p (glibtop *server, glibtop_sem_limits *buf)
+{
+ kvm_t *kd = server->machine.kd;
+ struct seminfo sinfo;
+
+ memset (buf, 0, sizeof (glibtop_sem_limits));
+
+ if(!(server->sysdeps.sem_limits))
+ return;
+ if(kvm_read(kd, nlst[0].n_value, (void *)&sinfo,
+ sizeof(struct seminfo)) != sizeof(struct seminfo))
+ return;
+
+#if GLIBTOP_SOLARIS_RELEASE <= 570
+ /* This field don't exist anymore in Solaris 8.
+ * Thanks to Laszlo PETER <Laszlo.Peter@ireland.sun.com>. */
+ buf->semmap = sinfo.semmap;
+#endif
+ buf->semmni = sinfo.semmni;
+ buf->semmns = sinfo.semmns;
+ buf->semmnu = sinfo.semmnu;
+ buf->semmsl = sinfo.semmsl;
+ buf->semopm = sinfo.semopm;
+ buf->semume = sinfo.semume;
+ buf->semusz = sinfo.semusz;
+ buf->semvmx = sinfo.semvmx;
+ buf->semaem = sinfo.semaem;
+ buf->flags = _glibtop_sysdeps_sem_limits;
+}
diff --git a/sysdeps/solaris/shm_limits.c b/sysdeps/solaris/shm_limits.c
new file mode 100644
index 00000000..24854b33
--- /dev/null
+++ b/sysdeps/solaris/shm_limits.c
@@ -0,0 +1,68 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <glibtop.h>
+#include <glibtop/shm_limits.h>
+
+#include <kvm.h>
+#include <sys/shm.h>
+
+static struct nlist nlst[] = { {"shminfo"}, {NULL} };
+static const unsigned long _glibtop_sysdeps_shm_limits =
+(1L << GLIBTOP_IPC_SHMMAX) + (1L << GLIBTOP_IPC_SHMMIN) +
+(1L << GLIBTOP_IPC_SHMMNI) + (1L << GLIBTOP_IPC_SHMSEG);
+
+/* Init function. */
+
+void
+glibtop_init_shm_limits_p (glibtop *server)
+{
+ kvm_t *kd = server->machine.kd;
+
+ if(kd && !kvm_nlist(kd, nlst))
+ server->sysdeps.shm_limits = _glibtop_sysdeps_shm_limits;
+ else
+ server->sysdeps.shm_limits = 0;
+}
+
+/* Provides information about sysv ipc limits. */
+
+void
+glibtop_get_shm_limits_p (glibtop *server, glibtop_shm_limits *buf)
+{
+ kvm_t *kd = server->machine.kd;
+ struct shminfo sinfo;
+
+ memset (buf, 0, sizeof (glibtop_shm_limits));
+
+ if(!(server->sysdeps.shm_limits))
+ return;
+ if(kvm_read(kd, nlst[0].n_value, (void *)&sinfo,
+ sizeof(struct shminfo)) != sizeof(struct shminfo))
+ return;
+ buf->shmmax = sinfo.shmmax;
+ buf->shmmin = sinfo.shmmin;
+ buf->shmmni = sinfo.shmmni;
+ buf->shmseg = sinfo.shmseg;
+ buf->flags = _glibtop_sysdeps_shm_limits;
+}
diff --git a/sysdeps/solaris/siglist.c b/sysdeps/solaris/siglist.c
new file mode 100644
index 00000000..292bb73e
--- /dev/null
+++ b/sysdeps/solaris/siglist.c
@@ -0,0 +1,74 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <glibtop.h>
+#include <glibtop/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, "SIGUSR1", "User Signal 1" },
+ { 17, "SIGUSR2", "User Signal 2" },
+ { 18, "SIGCHLD", "Child Status Changed" },
+ { 19, "SIGPWR", "Power-Fail/Restart" },
+ { 20, "SIGWINCH","Window Size Change" },
+ { 21, "SIGURG", "Urgent Socket Condition" },
+ { 22, "SIGPOLL", "Pollable Event" },
+ { 23, "SIGSTOP", "Stoped (signal)" },
+ { 24, "SIGTSTP", "Stopped (user)" },
+ { 25, "SIGCONT", "Continued" },
+ { 26, "SIGTTIN", "Stopped (tty input)" },
+ { 27, "SIGTTOU", "Stopped (tty output)" },
+ { 28, "SIGVTALRM","Virtual Timer Expired" },
+ { 29, "SIGPROF", "Profiling Timer Expired" },
+ { 30, "SIGXCPU", "Cpu Limit Exceeded" },
+ { 31, "SIGXFSZ", "File Size Limit Exceeded" },
+ { 32, "SIGWAITING","No runnable lwp" },
+ { 33, "SIGLWP", "Inter-lwp signal" },
+ { 34, "SIGFREEZE","Checkpoint Freeze" },
+ { 35, "SIGTHAW", "Checkpoint Thaw" },
+ { 36, "SIGCANCEL","Thread Cancelation" },
+ { 37, "SIGLOST", "Resource Lost" },
+ { 38, "SIGRTMIN","First Realtime Signal" },
+ { 39, "SIGRTMIN+1", "Second Realtime Signal" },
+ { 40, "SIGRTMIN+2", "Third Realtime Signal" },
+ { 41, "SIGRTMIN+3", "Fourth Realtime Signal" },
+ { 42, "SIGRTMAX-3", "Fourth Last Realtime Signal" },
+ { 43, "SIGRTMAX-2", "Third Last Realtime Signal" },
+ { 44, "SIGRTMAX-1", "Second Last Realtime Signal" },
+ { 45, "SIGRTMAX", "Last Realtime Signal" },
+ { 0, NULL, NULL }
+};
diff --git a/sysdeps/solaris/swap.c b/sysdeps/solaris/swap.c
new file mode 100644
index 00000000..b2e4721d
--- /dev/null
+++ b/sysdeps/solaris/swap.c
@@ -0,0 +1,89 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <glibtop.h>
+#include <glibtop/error.h>
+#include <glibtop/swap.h>
+
+#include <assert.h>
+#include <sys/sysinfo.h>
+
+#include <glibtop_private.h>
+
+static const unsigned long _glibtop_sysdeps_swap =
+(1L << GLIBTOP_SWAP_TOTAL) + (1L << GLIBTOP_SWAP_USED) +
+(1L << GLIBTOP_SWAP_FREE);
+
+/* Init function. */
+
+void
+glibtop_init_swap_s (glibtop *server)
+{
+ server->sysdeps.swap = _glibtop_sysdeps_swap;
+}
+
+/* Provides information about swap usage. */
+
+void
+glibtop_get_swap_s (glibtop *server, glibtop_swap *buf)
+{
+ kstat_ctl_t *kc = server->machine.kc;
+ kstat_t *ksp = server->machine.vminfo_kstat;
+ u_int64_t swap_resv, swap_alloc, swap_avail, swap_free;
+ vminfo_t vminfo;
+ double rate;
+ kid_t ret;
+
+ memset (buf, 0, sizeof (glibtop_swap));
+
+ if (!ksp) return;
+
+ switch(kstat_chain_update(kc))
+ {
+ case -1: assert(0); /* Debugging, shouldn't happen */
+ case 0: break;
+ default: glibtop_get_kstats(server);
+ }
+ ret = kstat_read (kc, ksp, &vminfo);
+
+ if (ret == -1) {
+ glibtop_warn_io_r (server, "kstat_read (vminfo)");
+ return;
+ }
+
+ rate = (ksp->ks_snaptime - server->machine.vminfo_snaptime) / 1E+9;
+
+ swap_resv = (vminfo.swap_resv - server->machine.vminfo.swap_resv) / rate;
+ swap_alloc = (vminfo.swap_alloc - server->machine.vminfo.swap_alloc) / rate;
+ swap_avail = (vminfo.swap_avail - server->machine.vminfo.swap_avail) / rate;
+ swap_free = (vminfo.swap_free - server->machine.vminfo.swap_free) / rate;
+
+ memcpy (&server->machine.vminfo, &vminfo, sizeof (vminfo_t));
+ server->machine.vminfo_snaptime = ksp->ks_snaptime;
+
+ buf->total = swap_resv + swap_avail;
+ buf->used = swap_alloc;
+ buf->free = buf->total - buf->used;
+
+ buf->flags = _glibtop_sysdeps_swap;
+}
diff --git a/sysdeps/solaris/uptime.c b/sysdeps/solaris/uptime.c
new file mode 100644
index 00000000..7ea2d0bf
--- /dev/null
+++ b/sysdeps/solaris/uptime.c
@@ -0,0 +1,58 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <glibtop.h>
+#include <glibtop/uptime.h>
+
+#include <time.h>
+
+static const unsigned long _glibtop_sysdeps_uptime =
+#if LIBGTOP_VERSION_CODE >= 1001002
+(1L <<GLIBTOP_UPTIME_BOOT_TIME) +
+#endif
+(1L << GLIBTOP_UPTIME_UPTIME);
+
+/* 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)
+{
+ memset (buf, 0, sizeof (glibtop_uptime));
+
+ if(!(server->machine.boot))
+ return;
+#if LIBGTOP_VERSION_CODE >= 1001002
+ buf->boot_time = server->machine.boot;
+#endif
+ buf->uptime = time(NULL) - server->machine.boot;
+
+ buf->flags = _glibtop_sysdeps_uptime;
+}
diff --git a/sysdeps/stub/.cvsignore b/sysdeps/stub/.cvsignore
new file mode 100644
index 00000000..e71d5287
--- /dev/null
+++ b/sysdeps/stub/.cvsignore
@@ -0,0 +1,27 @@
+.deps
+.libs
+Makefile
+Makefile.in
+close.lo
+cpu.lo
+init.lo
+libgtop_sysdeps.la
+loadavg.lo
+mem.lo
+msg_limits.lo
+open.lo
+prockernel.lo
+proclist.lo
+procmem.lo
+procsegment.lo
+procsignal.lo
+procstate.lo
+proctime.lo
+procuid.lo
+sem_limits.lo
+shm_limits.lo
+swap.lo
+sysdeps.lo
+uptime.lo
+*.lo
+so_locations
diff --git a/sysdeps/stub/ChangeLog b/sysdeps/stub/ChangeLog
new file mode 100644
index 00000000..0cb0e05c
--- /dev/null
+++ b/sysdeps/stub/ChangeLog
@@ -0,0 +1,22 @@
+2001-10-17 Abel Cheung <maddog@linux.org.hk>
+
+ * Makefile.am: move header to $(includedir)/libgtop-1.0/glibtop.
+
+1998-10-26 Martin Baulig <martin@home-of-linux.org>
+
+ * netload.c: New file.
+
+1998-10-26 Martin Baulig <martin@home-of-linux.org>
+
+ * procargs.c: New file.
+
+1998-10-25 Martin Baulig <martin@home-of-linux.org>
+
+ * ppp.c: New file.
+
+1998-08-24 Martin Baulig <martin@home-of-linux.org>
+
+ * *.c: Added initialization functions `glibtop_init_<feature>_s'.
+
+ * ChangeLog: New file.
+
diff --git a/sysdeps/stub/Makefile.am b/sysdeps/stub/Makefile.am
new file mode 100644
index 00000000..8e18f2cb
--- /dev/null
+++ b/sysdeps/stub/Makefile.am
@@ -0,0 +1,17 @@
+LINK = $(LIBTOOL) --mode=link $(CC) $(CFLAGS) $(LDFLAGS) -o $@
+
+INCLUDES = @INCLUDES@
+
+lib_LTLIBRARIES = libgtop_sysdeps-2.0.la
+
+libgtop_sysdeps_2_0_la_SOURCES = open.c close.c siglist.c cpu.c mem.c swap.c \
+ uptime.c loadavg.c shm_limits.c msg_limits.c \
+ sem_limits.c proclist.c procstate.c procuid.c \
+ proctime.c procmem.c procsignal.c prockernel.c \
+ procsegment.c procargs.c procmap.c netload.c \
+ ppp.c
+
+libgtop_sysdeps_2_0_la_LDFLAGS = $(LT_VERSION_INFO)
+
+libgtopinclude_HEADERS = glibtop_server.h
+libgtopincludedir = $(includedir)/libgtop-2.0
diff --git a/sysdeps/stub/close.c b/sysdeps/stub/close.c
new file mode 100644
index 00000000..4262d2f0
--- /dev/null
+++ b/sysdeps/stub/close.c
@@ -0,0 +1,30 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <glibtop/close.h>
+
+/* Closes pipe to gtop server. */
+
+void
+glibtop_close_s (glibtop *server)
+{ }
diff --git a/sysdeps/stub/cpu.c b/sysdeps/stub/cpu.c
new file mode 100644
index 00000000..3ddfdfb8
--- /dev/null
+++ b/sysdeps/stub/cpu.c
@@ -0,0 +1,43 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <glibtop.h>
+#include <glibtop/cpu.h>
+
+static const unsigned long _glibtop_sysdeps_cpu = 0;
+
+/* Init function. */
+
+void
+glibtop_init_cpu_s (glibtop *server)
+{
+ server->sysdeps.cpu = _glibtop_sysdeps_cpu;
+}
+
+/* Provides information about cpu usage. */
+
+void
+glibtop_get_cpu_s (glibtop *server, glibtop_cpu *buf)
+{
+ memset (buf, 0, sizeof (glibtop_cpu));
+}
diff --git a/sysdeps/stub/glibtop_server.h b/sysdeps/stub/glibtop_server.h
new file mode 100644
index 00000000..b3822d47
--- /dev/null
+++ b/sysdeps/stub/glibtop_server.h
@@ -0,0 +1,52 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#ifndef __GLIBTOP_SERVER_H__
+#define __GLIBTOP_SERVER_H__
+
+BEGIN_LIBGTOP_DECLS
+
+#define GLIBTOP_SUID_CPU 0
+#define GLIBTOP_SUID_MEM 0
+#define GLIBTOP_SUID_SWAP 0
+#define GLIBTOP_SUID_UPTIME 0
+#define GLIBTOP_SUID_LOADAVG 0
+#define GLIBTOP_SUID_SHM_LIMITS 0
+#define GLIBTOP_SUID_MSG_LIMITS 0
+#define GLIBTOP_SUID_SEM_LIMITS 0
+#define GLIBTOP_SUID_PROCLIST 0
+#define GLIBTOP_SUID_PROC_STATE 0
+#define GLIBTOP_SUID_PROC_UID 0
+#define GLIBTOP_SUID_PROC_MEM 0
+#define GLIBTOP_SUID_PROC_TIME 0
+#define GLIBTOP_SUID_PROC_SIGNAL 0
+#define GLIBTOP_SUID_PROC_KERNEL 0
+#define GLIBTOP_SUID_PROC_SEGMENT 0
+#define GLIBTOP_SUID_PROC_ARGS 0
+#define GLIBTOP_SUID_PROC_MAP 0
+#define GLIBTOP_SUID_NETLOAD 0
+#define GLIBTOP_SUID_PPP 0
+
+END_LIBGTOP_DECLS
+
+#endif
diff --git a/sysdeps/stub/loadavg.c b/sysdeps/stub/loadavg.c
new file mode 100644
index 00000000..9bf900f5
--- /dev/null
+++ b/sysdeps/stub/loadavg.c
@@ -0,0 +1,43 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <glibtop.h>
+#include <glibtop/loadavg.h>
+
+static const unsigned long _glibtop_sysdeps_loadavg = 0;
+
+/* Init function. */
+
+void
+glibtop_init_loadavg_s (glibtop *server)
+{
+ server->sysdeps.loadavg = _glibtop_sysdeps_loadavg;
+}
+
+/* Provides load averange. */
+
+void
+glibtop_get_loadavg_s (glibtop *server, glibtop_loadavg *buf)
+{
+ memset (buf, 0, sizeof (glibtop_loadavg));
+}
diff --git a/sysdeps/stub/mem.c b/sysdeps/stub/mem.c
new file mode 100644
index 00000000..8a2c31a5
--- /dev/null
+++ b/sysdeps/stub/mem.c
@@ -0,0 +1,43 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <glibtop.h>
+#include <glibtop/mem.h>
+
+static const unsigned long _glibtop_sysdeps_mem = 0;
+
+/* Init function. */
+
+void
+glibtop_init_mem_s (glibtop *server)
+{
+ server->sysdeps.mem = _glibtop_sysdeps_mem;
+}
+
+/* Provides information about memory usage. */
+
+void
+glibtop_get_mem_s (glibtop *server, glibtop_mem *buf)
+{
+ memset (buf, 0, sizeof (glibtop_mem));
+}
diff --git a/sysdeps/stub/msg_limits.c b/sysdeps/stub/msg_limits.c
new file mode 100644
index 00000000..adee0dae
--- /dev/null
+++ b/sysdeps/stub/msg_limits.c
@@ -0,0 +1,43 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <glibtop.h>
+#include <glibtop/msg_limits.h>
+
+static const unsigned long _glibtop_sysdeps_msg_limits = 0;
+
+/* 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)
+{
+ memset (buf, 0, sizeof (glibtop_msg_limits));
+}
diff --git a/sysdeps/stub/netload.c b/sysdeps/stub/netload.c
new file mode 100644
index 00000000..beebedba
--- /dev/null
+++ b/sysdeps/stub/netload.c
@@ -0,0 +1,45 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, October 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <glibtop.h>
+#include <glibtop/error.h>
+#include <glibtop/netload.h>
+
+static const unsigned long _glibtop_sysdeps_netload = 0;
+
+/* Init function. */
+
+void
+glibtop_init_netload_s (glibtop *server)
+{
+ server->sysdeps.netload = _glibtop_sysdeps_netload;
+}
+
+/* Provides network statistics. */
+
+void
+glibtop_get_netload_s (glibtop *server, glibtop_netload *buf,
+ const char *interface)
+{
+ memset (buf, 0, sizeof (glibtop_netload));
+}
diff --git a/sysdeps/stub/open.c b/sysdeps/stub/open.c
new file mode 100644
index 00000000..eef22d71
--- /dev/null
+++ b/sysdeps/stub/open.c
@@ -0,0 +1,33 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <glibtop/open.h>
+
+/* Opens pipe to gtop server. Returns 0 on success and -1 on error. */
+
+void
+glibtop_open_s (glibtop *server, const char *program_name,
+ const unsigned long features, const unsigned flags)
+{
+ server->name = program_name;
+}
diff --git a/sysdeps/stub/ppp.c b/sysdeps/stub/ppp.c
new file mode 100644
index 00000000..6d0905d5
--- /dev/null
+++ b/sysdeps/stub/ppp.c
@@ -0,0 +1,44 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, October 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <glibtop.h>
+#include <glibtop/error.h>
+#include <glibtop/ppp.h>
+
+static const unsigned long _glibtop_sysdeps_ppp = 0;
+
+/* Init function. */
+
+void
+glibtop_init_ppp_s (glibtop *server)
+{
+ server->sysdeps.ppp = _glibtop_sysdeps_ppp;
+}
+
+/* Provides PPP/ISDN information. */
+
+void
+glibtop_get_ppp_s (glibtop *server, glibtop_ppp *buf, unsigned short device)
+{
+ memset (buf, 0, sizeof (glibtop_ppp));
+}
diff --git a/sysdeps/stub/procargs.c b/sysdeps/stub/procargs.c
new file mode 100644
index 00000000..7d010d5e
--- /dev/null
+++ b/sysdeps/stub/procargs.c
@@ -0,0 +1,47 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <glibtop.h>
+#include <glibtop/error.h>
+#include <glibtop/xmalloc.h>
+#include <glibtop/procargs.h>
+
+static const unsigned long _glibtop_sysdeps_proc_args = 0;
+
+/* Init function. */
+
+void
+glibtop_init_proc_args_s (glibtop *server)
+{
+ server->sysdeps.proc_args = _glibtop_sysdeps_proc_args;
+}
+
+/* Provides detailed information about a process. */
+
+char *
+glibtop_get_proc_args_s (glibtop *server, glibtop_proc_args *buf,
+ pid_t pid, unsigned max_len)
+{
+ memset (buf, 0, sizeof (glibtop_proc_args));
+ return NULL;
+}
diff --git a/sysdeps/stub/prockernel.c b/sysdeps/stub/prockernel.c
new file mode 100644
index 00000000..d06f6cab
--- /dev/null
+++ b/sysdeps/stub/prockernel.c
@@ -0,0 +1,44 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <glibtop.h>
+#include <glibtop/prockernel.h>
+
+static const unsigned long _glibtop_sysdeps_proc_kernel = 0;
+
+/* Init function. */
+
+void
+glibtop_init_proc_kernel_s (glibtop *server)
+{
+ server->sysdeps.proc_kernel = _glibtop_sysdeps_proc_kernel;
+}
+
+/* Provides detailed information about a process. */
+
+void
+glibtop_get_proc_kernel_s (glibtop *server, glibtop_proc_kernel *buf,
+ pid_t pid)
+{
+ memset (buf, 0, sizeof (glibtop_proc_kernel));
+}
diff --git a/sysdeps/stub/proclist.c b/sysdeps/stub/proclist.c
new file mode 100644
index 00000000..7794cdba
--- /dev/null
+++ b/sysdeps/stub/proclist.c
@@ -0,0 +1,52 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <glibtop.h>
+#include <glibtop/proclist.h>
+
+#define GLIBTOP_PROCLIST_FLAGS 3
+
+static const unsigned long _glibtop_sysdeps_proclist = 0;
+
+/* Init function. */
+
+void
+glibtop_init_proclist_s (glibtop *server)
+{
+ server->sysdeps.proclist = _glibtop_sysdeps_proclist;
+}
+
+/* Fetch list of currently running processes.
+ *
+ * IMPORTANT NOTE:
+ * On error, this function MUST return NULL and set buf->flags to zero !
+ * On success, it returnes a pointer to a list of buf->number elements
+ * each buf->size big. The total size is stored in buf->total. */
+
+unsigned *
+glibtop_get_proclist_s (glibtop *server, glibtop_proclist *buf,
+ int64_t which, int64_t arg)
+{
+ memset (buf, 0, sizeof (glibtop_proclist));
+ return NULL;
+}
diff --git a/sysdeps/stub/procmap.c b/sysdeps/stub/procmap.c
new file mode 100644
index 00000000..5a6c479a
--- /dev/null
+++ b/sysdeps/stub/procmap.c
@@ -0,0 +1,50 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+
+#include <glibtop.h>
+#include <glibtop/error.h>
+#include <glibtop/xmalloc.h>
+#include <glibtop/procmap.h>
+
+static const unsigned long _glibtop_sysdeps_proc_map = 0;
+
+/* Init function. */
+
+void
+glibtop_init_proc_map_s (glibtop *server)
+{
+ server->sysdeps.proc_map = _glibtop_sysdeps_proc_map;
+}
+
+/* Provides detailed information about a process. */
+
+glibtop_map_entry *
+glibtop_get_proc_map_s (glibtop *server, glibtop_proc_map *buf, pid_t pid)
+{
+ glibtop_init_s (&server, GLIBTOP_SYSDEPS_PROC_MAP, 0);
+
+ memset (buf, 0, sizeof (glibtop_proc_map));
+
+ return NULL;
+}
diff --git a/sysdeps/stub/procmem.c b/sysdeps/stub/procmem.c
new file mode 100644
index 00000000..ab0c4170
--- /dev/null
+++ b/sysdeps/stub/procmem.c
@@ -0,0 +1,44 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <glibtop.h>
+#include <glibtop/procmem.h>
+
+static const unsigned long _glibtop_sysdeps_proc_mem = 0;
+
+/* Init function. */
+
+void
+glibtop_init_proc_mem_s (glibtop *server)
+{
+ server->sysdeps.proc_mem = _glibtop_sysdeps_proc_mem;
+}
+
+/* Provides detailed information about a process. */
+
+void
+glibtop_get_proc_mem_s (glibtop *server, glibtop_proc_mem *buf,
+ pid_t pid)
+{
+ memset (buf, 0, sizeof (glibtop_proc_mem));
+}
diff --git a/sysdeps/stub/procsegment.c b/sysdeps/stub/procsegment.c
new file mode 100644
index 00000000..b03709d4
--- /dev/null
+++ b/sysdeps/stub/procsegment.c
@@ -0,0 +1,44 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <glibtop.h>
+#include <glibtop/procsegment.h>
+
+static const unsigned long _glibtop_sysdeps_proc_segment = 0;
+
+/* Init function. */
+
+void
+glibtop_init_proc_segment_s (glibtop *server)
+{
+ server->sysdeps.proc_segment = _glibtop_sysdeps_proc_segment;
+}
+
+/* Provides detailed information about a process. */
+
+void
+glibtop_get_proc_segment_s (glibtop *server, glibtop_proc_segment *buf,
+ pid_t pid)
+{
+ memset (buf, 0, sizeof (glibtop_proc_segment));
+}
diff --git a/sysdeps/stub/procsignal.c b/sysdeps/stub/procsignal.c
new file mode 100644
index 00000000..540960f5
--- /dev/null
+++ b/sysdeps/stub/procsignal.c
@@ -0,0 +1,44 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <glibtop.h>
+#include <glibtop/procsignal.h>
+
+static const unsigned long _glibtop_sysdeps_proc_signal = 0;
+
+/* Init function. */
+
+void
+glibtop_init_proc_signal_s (glibtop *server)
+{
+ server->sysdeps.proc_signal = _glibtop_sysdeps_proc_signal;
+}
+
+/* Provides detailed information about a process. */
+
+void
+glibtop_get_proc_signal_s (glibtop *server, glibtop_proc_signal *buf,
+ pid_t pid)
+{
+ memset (buf, 0, sizeof (glibtop_proc_signal));
+}
diff --git a/sysdeps/stub/procstate.c b/sysdeps/stub/procstate.c
new file mode 100644
index 00000000..227f52ee
--- /dev/null
+++ b/sysdeps/stub/procstate.c
@@ -0,0 +1,44 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <glibtop.h>
+#include <glibtop/procstate.h>
+
+static const unsigned long _glibtop_sysdeps_proc_state = 0;
+
+/* Init function. */
+
+void
+glibtop_init_proc_state_s (glibtop *server)
+{
+ server->sysdeps.proc_state = _glibtop_sysdeps_proc_state;
+}
+
+/* Provides detailed information about a process. */
+
+void
+glibtop_get_proc_state_s (glibtop *server, glibtop_proc_state *buf,
+ pid_t pid)
+{
+ memset (buf, 0, sizeof (glibtop_proc_state));
+}
diff --git a/sysdeps/stub/proctime.c b/sysdeps/stub/proctime.c
new file mode 100644
index 00000000..4c060235
--- /dev/null
+++ b/sysdeps/stub/proctime.c
@@ -0,0 +1,44 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <glibtop.h>
+#include <glibtop/proctime.h>
+
+static const unsigned long _glibtop_sysdeps_proc_time = 0;
+
+/* Init function. */
+
+void
+glibtop_init_proc_time_s (glibtop *server)
+{
+ server->sysdeps.proc_time = _glibtop_sysdeps_proc_time;
+}
+
+/* Provides detailed information about a process. */
+
+void
+glibtop_get_proc_time_s (glibtop *server, glibtop_proc_time *buf,
+ pid_t pid)
+{
+ memset (buf, 0, sizeof (glibtop_proc_time));
+}
diff --git a/sysdeps/stub/procuid.c b/sysdeps/stub/procuid.c
new file mode 100644
index 00000000..f9f68311
--- /dev/null
+++ b/sysdeps/stub/procuid.c
@@ -0,0 +1,44 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <glibtop.h>
+#include <glibtop/procuid.h>
+
+static const unsigned long _glibtop_sysdeps_proc_uid = 0;
+
+/* Init function. */
+
+void
+glibtop_init_proc_uid_s (glibtop *server)
+{
+ server->sysdeps.proc_uid = _glibtop_sysdeps_proc_uid;
+}
+
+/* Provides detailed information about a process. */
+
+void
+glibtop_get_proc_uid_s (glibtop *server, glibtop_proc_uid *buf,
+ pid_t pid)
+{
+ memset (buf, 0, sizeof (glibtop_proc_uid));
+}
diff --git a/sysdeps/stub/sem_limits.c b/sysdeps/stub/sem_limits.c
new file mode 100644
index 00000000..474ce8c7
--- /dev/null
+++ b/sysdeps/stub/sem_limits.c
@@ -0,0 +1,43 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <glibtop.h>
+#include <glibtop/sem_limits.h>
+
+static const unsigned long _glibtop_sysdeps_sem_limits = 0;
+
+/* 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)
+{
+ memset (buf, 0, sizeof (glibtop_sem_limits));
+}
diff --git a/sysdeps/stub/shm_limits.c b/sysdeps/stub/shm_limits.c
new file mode 100644
index 00000000..8a024b4a
--- /dev/null
+++ b/sysdeps/stub/shm_limits.c
@@ -0,0 +1,43 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <glibtop.h>
+#include <glibtop/shm_limits.h>
+
+static const unsigned long _glibtop_sysdeps_shm_limits = 0;
+
+/* 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)
+{
+ memset (buf, 0, sizeof (glibtop_shm_limits));
+}
diff --git a/sysdeps/stub/siglist.c b/sysdeps/stub/siglist.c
new file mode 100644
index 00000000..94abfdc6
--- /dev/null
+++ b/sysdeps/stub/siglist.c
@@ -0,0 +1,28 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <glibtop.h>
+#include <glibtop/signal.h>
+
+const glibtop_signame glibtop_sys_siglist [] =
+{ { 0, NULL, NULL } };
diff --git a/sysdeps/stub/swap.c b/sysdeps/stub/swap.c
new file mode 100644
index 00000000..4731b8e3
--- /dev/null
+++ b/sysdeps/stub/swap.c
@@ -0,0 +1,43 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <glibtop.h>
+#include <glibtop/swap.h>
+
+static const unsigned long _glibtop_sysdeps_swap = 0;
+
+/* Init function. */
+
+void
+glibtop_init_swap_s (glibtop *server)
+{
+ server->sysdeps.swap = _glibtop_sysdeps_swap;
+}
+
+/* Provides information about swap usage. */
+
+void
+glibtop_get_swap_s (glibtop *server, glibtop_swap *buf)
+{
+ memset (buf, 0, sizeof (glibtop_swap));
+}
diff --git a/sysdeps/stub/uptime.c b/sysdeps/stub/uptime.c
new file mode 100644
index 00000000..a6189448
--- /dev/null
+++ b/sysdeps/stub/uptime.c
@@ -0,0 +1,43 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <glibtop.h>
+#include <glibtop/uptime.h>
+
+static const unsigned long _glibtop_sysdeps_uptime = 0;
+
+/* 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)
+{
+ memset (buf, 0, sizeof (glibtop_uptime));
+}
diff --git a/sysdeps/stub_suid/.cvsignore b/sysdeps/stub_suid/.cvsignore
new file mode 100644
index 00000000..d15c76bc
--- /dev/null
+++ b/sysdeps/stub_suid/.cvsignore
@@ -0,0 +1,28 @@
+.deps
+.libs
+Makefile
+Makefile.in
+close.lo
+cpu.lo
+init.lo
+libgtop_sysdeps.la
+loadavg.lo
+mem.lo
+msg_limits.lo
+open.lo
+prockernel.lo
+proclist.lo
+procmem.lo
+procsegment.lo
+procsignal.lo
+procstate.lo
+proctime.lo
+procuid.lo
+sem_limits.lo
+shm_limits.lo
+swap.lo
+sysdeps.lo
+uptime.lo
+*.lo
+*.la
+so_locations
diff --git a/sysdeps/stub_suid/ChangeLog b/sysdeps/stub_suid/ChangeLog
new file mode 100644
index 00000000..4d7d7bec
--- /dev/null
+++ b/sysdeps/stub_suid/ChangeLog
@@ -0,0 +1,18 @@
+2001-10-17 Abel Cheung <maddog@linux.org.hk>
+
+ * Makefile.am: move header to $(includedir)/libgtop-1.0/glibtop.
+
+1998-10-26 Martin Baulig <martin@home-of-linux.org>
+
+ * netload.c: New file.
+
+1998-10-26 Martin Baulig <martin@home-of-linux.org>
+
+ * procargs.c: New file.
+ * procmap.c: New file.
+
+1998-10-25 Martin Baulig <martin@home-of-linux.org>
+
+ * ChangeLog: New file.
+ * ppp.c: New file.
+
diff --git a/sysdeps/stub_suid/Makefile.am b/sysdeps/stub_suid/Makefile.am
new file mode 100644
index 00000000..3842ad14
--- /dev/null
+++ b/sysdeps/stub_suid/Makefile.am
@@ -0,0 +1,23 @@
+LINK = $(LIBTOOL) --mode=link $(CC) $(CFLAGS) $(LDFLAGS) -o $@
+
+INCLUDES = @INCLUDES@
+
+lib_LTLIBRARIES = libgtop_sysdeps-2.0.la libgtop_sysdeps_suid-2.0.la
+
+libgtop_sysdeps_2_0_la_SOURCES = nosuid.c siglist.c
+
+libgtop_sysdeps_2_0_la_LDFLAGS = $(LT_VERSION_INFO)
+
+libgtop_sysdeps_suid_2_0_la_SOURCES = open.c close.c siglist.c cpu.c mem.c swap.c \
+ uptime.c loadavg.c shm_limits.c msg_limits.c \
+ sem_limits.c proclist.c procstate.c procuid.c \
+ proctime.c procmem.c procsignal.c prockernel.c \
+ procsegment.c procargs.c procmap.c netload.c \
+ ppp.c
+
+libgtop_sysdeps_suid_2_0_la_LDFLAGS = $(LT_VERSION_INFO)
+
+libgtopinclude_HEADERS = glibtop_server.h glibtop_machine.h
+libgtopincludedir = $(includedir)/libgtop-2.0
+
+noinst_HEADERS = glibtop_suid.h
diff --git a/sysdeps/stub_suid/close.c b/sysdeps/stub_suid/close.c
new file mode 100644
index 00000000..4262d2f0
--- /dev/null
+++ b/sysdeps/stub_suid/close.c
@@ -0,0 +1,30 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <glibtop/close.h>
+
+/* Closes pipe to gtop server. */
+
+void
+glibtop_close_s (glibtop *server)
+{ }
diff --git a/sysdeps/stub_suid/cpu.c b/sysdeps/stub_suid/cpu.c
new file mode 100644
index 00000000..7f05c827
--- /dev/null
+++ b/sysdeps/stub_suid/cpu.c
@@ -0,0 +1,48 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <glibtop.h>
+#include <glibtop/error.h>
+#include <glibtop/cpu.h>
+
+#include <glibtop_suid.h>
+
+static const unsigned long _glibtop_sysdeps_cpu = 0;
+
+/* Init function. */
+
+void
+glibtop_init_cpu_p (glibtop *server)
+{
+ server->sysdeps.cpu = _glibtop_sysdeps_cpu;
+}
+
+/* Provides information about cpu usage. */
+
+void
+glibtop_get_cpu_p (glibtop *server, glibtop_cpu *buf)
+{
+ glibtop_init_p (server, GLIBTOP_SYSDEPS_CPU, 0);
+
+ memset (buf, 0, sizeof (glibtop_cpu));
+}
diff --git a/sysdeps/stub_suid/glibtop_machine.h b/sysdeps/stub_suid/glibtop_machine.h
new file mode 100644
index 00000000..835f177f
--- /dev/null
+++ b/sysdeps/stub_suid/glibtop_machine.h
@@ -0,0 +1,39 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#ifndef __GLIBTOP_MACHINE_H__
+#define __GLIBTOP_MACHINE_H__
+
+BEGIN_LIBGTOP_DECLS
+
+typedef struct _glibtop_machine glibtop_machine;
+
+struct _glibtop_machine
+{
+ uid_t uid, euid; /* Real and effective user id */
+ gid_t gid, egid; /* Real and effective group id */
+};
+
+END_LIBGTOP_DECLS
+
+#endif
diff --git a/sysdeps/stub_suid/glibtop_server.h b/sysdeps/stub_suid/glibtop_server.h
new file mode 100644
index 00000000..ccf3d29d
--- /dev/null
+++ b/sysdeps/stub_suid/glibtop_server.h
@@ -0,0 +1,52 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#ifndef __GLIBTOP_SERVER_H__
+#define __GLIBTOP_SERVER_H__
+
+BEGIN_LIBGTOP_DECLS
+
+#define GLIBTOP_SUID_CPU (1 << GLIBTOP_SYSDEPS_CPU)
+#define GLIBTOP_SUID_MEM (1 << GLIBTOP_SYSDEPS_MEM)
+#define GLIBTOP_SUID_SWAP (1 << GLIBTOP_SYSDEPS_SWAP)
+#define GLIBTOP_SUID_UPTIME (1 << GLIBTOP_SYSDEPS_UPTIME)
+#define GLIBTOP_SUID_LOADAVG (1 << GLIBTOP_SYSDEPS_LOADAVG)
+#define GLIBTOP_SUID_SHM_LIMITS (1 << GLIBTOP_SYSDEPS_SHM_LIMITS)
+#define GLIBTOP_SUID_MSG_LIMITS (1 << GLIBTOP_SYSDEPS_MSG_LIMITS)
+#define GLIBTOP_SUID_SEM_LIMITS (1 << GLIBTOP_SYSDEPS_SEM_LIMITS)
+#define GLIBTOP_SUID_PROCLIST (1 << GLIBTOP_SYSDEPS_PROCLIST)
+#define GLIBTOP_SUID_PROC_STATE (1 << GLIBTOP_SYSDEPS_PROC_STATE)
+#define GLIBTOP_SUID_PROC_UID (1 << GLIBTOP_SYSDEPS_PROC_UID)
+#define GLIBTOP_SUID_PROC_MEM (1 << GLIBTOP_SYSDEPS_PROC_MEM)
+#define GLIBTOP_SUID_PROC_TIME (1 << GLIBTOP_SYSDEPS_PROC_TIME)
+#define GLIBTOP_SUID_PROC_SIGNAL (1 << GLIBTOP_SYSDEPS_PROC_SIGNAL)
+#define GLIBTOP_SUID_PROC_KERNEL (1 << GLIBTOP_SYSDEPS_PROC_KERNEL)
+#define GLIBTOP_SUID_PROC_SEGMENT (1 << GLIBTOP_SYSDEPS_PROC_SEGMENT)
+#define GLIBTOP_SUID_PROC_ARGS (1 << GLIBTOP_SYSDEPS_PROC_ARGS)
+#define GLIBTOP_SUID_PROC_MAP (1 << GLIBTOP_SYSDEPS_PROC_MAP)
+#define GLIBTOP_SUID_NETLOAD (1 << GLIBTOP_SYSDEPS_NETLOAD)
+#define GLIBTOP_SUID_PPP (1 << GLIBTOP_SYSDEPS_PPP)
+
+END_LIBGTOP_DECLS
+
+#endif
diff --git a/sysdeps/stub_suid/glibtop_suid.h b/sysdeps/stub_suid/glibtop_suid.h
new file mode 100644
index 00000000..b88421ff
--- /dev/null
+++ b/sysdeps/stub_suid/glibtop_suid.h
@@ -0,0 +1,48 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#ifndef __GLIBTOP_SUID_H__
+#define __GLIBTOP_SUID_H__
+
+BEGIN_LIBGTOP_DECLS
+
+static inline void glibtop_suid_enter (glibtop *server) {
+ setreuid (server->machine.uid, server->machine.euid);
+};
+
+static inline void glibtop_suid_leave (glibtop *server) {
+ if (setreuid (server->machine.euid, server->machine.uid))
+ _exit (1);
+};
+
+void
+glibtop_init_p (glibtop *server, const unsigned long features,
+ const unsigned flags);
+void
+glibtop_open_p (glibtop *server, const char *program_name,
+ const unsigned long features,
+ const unsigned flags);
+
+END_LIBGTOP_DECLS
+
+#endif
diff --git a/sysdeps/stub_suid/init.c b/sysdeps/stub_suid/init.c
new file mode 100644
index 00000000..0f643bd0
--- /dev/null
+++ b/sysdeps/stub_suid/init.c
@@ -0,0 +1,45 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <glibtop.h>
+#include <glibtop/open.h>
+
+static glibtop _glibtop_global_server;
+glibtop *glibtop_global_server = NULL;
+
+glibtop *
+glibtop_init_r (glibtop **server,
+ const unsigned long features,
+ const unsigned flags)
+{
+ if (*server != NULL)
+ return *server;
+
+ if (glibtop_global_server == NULL) {
+ glibtop_global_server = &_glibtop_global_server;
+ glibtop_open (glibtop_global_server, "glibtop",
+ features, flags);
+ }
+
+ return *server = glibtop_global_server;
+}
diff --git a/sysdeps/stub_suid/loadavg.c b/sysdeps/stub_suid/loadavg.c
new file mode 100644
index 00000000..6118d614
--- /dev/null
+++ b/sysdeps/stub_suid/loadavg.c
@@ -0,0 +1,48 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <glibtop.h>
+#include <glibtop/error.h>
+#include <glibtop/loadavg.h>
+
+#include <glibtop_suid.h>
+
+static const unsigned long _glibtop_sysdeps_loadavg = 0;
+
+/* Init function. */
+
+void
+glibtop_init_loadavg_p (glibtop *server)
+{
+ server->sysdeps.loadavg = _glibtop_sysdeps_loadavg;
+}
+
+/* Provides load averange. */
+
+void
+glibtop_get_loadavg_p (glibtop *server, glibtop_loadavg *buf)
+{
+ glibtop_init_p (server, GLIBTOP_SYSDEPS_LOADAVG, 0);
+
+ memset (buf, 0, sizeof (glibtop_loadavg));
+}
diff --git a/sysdeps/stub_suid/mem.c b/sysdeps/stub_suid/mem.c
new file mode 100644
index 00000000..85c4fc5d
--- /dev/null
+++ b/sysdeps/stub_suid/mem.c
@@ -0,0 +1,48 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <glibtop.h>
+#include <glibtop/error.h>
+#include <glibtop/mem.h>
+
+#include <glibtop_suid.h>
+
+static const unsigned long _glibtop_sysdeps_mem = 0;
+
+/* Init function. */
+
+void
+glibtop_init_mem_p (glibtop *server)
+{
+ server->sysdeps.mem = _glibtop_sysdeps_mem;
+}
+
+/* Provides information about memory usage. */
+
+void
+glibtop_get_mem_p (glibtop *server, glibtop_mem *buf)
+{
+ glibtop_init_p (server, GLIBTOP_SYSDEPS_MEM, 0);
+
+ memset (buf, 0, sizeof (glibtop_mem));
+}
diff --git a/sysdeps/stub_suid/msg_limits.c b/sysdeps/stub_suid/msg_limits.c
new file mode 100644
index 00000000..7a2b8f93
--- /dev/null
+++ b/sysdeps/stub_suid/msg_limits.c
@@ -0,0 +1,48 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <glibtop.h>
+#include <glibtop/error.h>
+#include <glibtop/msg_limits.h>
+
+#include <glibtop_suid.h>
+
+static const unsigned long _glibtop_sysdeps_msg_limits = 0;
+
+/* Init function. */
+
+void
+glibtop_init_msg_limits_p (glibtop *server)
+{
+ server->sysdeps.msg_limits = _glibtop_sysdeps_msg_limits;
+}
+
+/* Provides information about sysv ipc limits. */
+
+void
+glibtop_get_msg_limits_p (glibtop *server, glibtop_msg_limits *buf)
+{
+ glibtop_init_p (server, GLIBTOP_SYSDEPS_MSG_LIMITS, 0);
+
+ memset (buf, 0, sizeof (glibtop_msg_limits));
+}
diff --git a/sysdeps/stub_suid/netload.c b/sysdeps/stub_suid/netload.c
new file mode 100644
index 00000000..bb1226ed
--- /dev/null
+++ b/sysdeps/stub_suid/netload.c
@@ -0,0 +1,45 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, October 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <glibtop.h>
+#include <glibtop/error.h>
+#include <glibtop/netload.h>
+
+static const unsigned long _glibtop_sysdeps_netload = 0;
+
+/* 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)
+{
+ memset (buf, 0, sizeof (glibtop_netload));
+}
diff --git a/sysdeps/stub_suid/nosuid.c b/sysdeps/stub_suid/nosuid.c
new file mode 100644
index 00000000..9f6ce9cb
--- /dev/null
+++ b/sysdeps/stub_suid/nosuid.c
@@ -0,0 +1,34 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <glibtop.h>
+#include <glibtop/open.h>
+
+void
+glibtop_open_s (glibtop *server, const char *program_name,
+ const unsigned long features, const unsigned flags)
+{ }
+
+void
+glibtop_close_s (glibtop *server)
+{ }
diff --git a/sysdeps/stub_suid/open.c b/sysdeps/stub_suid/open.c
new file mode 100644
index 00000000..3357ad25
--- /dev/null
+++ b/sysdeps/stub_suid/open.c
@@ -0,0 +1,77 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <glibtop.h>
+#include <glibtop/open.h>
+#include <glibtop/xmalloc.h>
+
+/* !!! THIS FUNCTION RUNS SUID ROOT - CHANGE WITH CAUTION !!! */
+
+void
+glibtop_init_p (glibtop *server, const unsigned long features,
+ const unsigned flags)
+{
+ glibtop_init_func_t *init_fkt;
+
+ if (server == NULL)
+ glibtop_error_r (NULL, "glibtop_init_p (server == NULL)");
+
+ /* Do the initialization, but only if not already initialized. */
+
+ if ((server->flags & _GLIBTOP_INIT_STATE_INIT) == 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_INIT;
+ }
+}
+
+void
+glibtop_open_p (glibtop *server, const char *program_name,
+ const unsigned long features, const unsigned flags)
+{
+ /* !!! WE ARE ROOT HERE - CHANGE WITH CAUTION !!! */
+
+ server->name = program_name;
+
+ server->machine.uid = getuid ();
+ server->machine.euid = geteuid ();
+ server->machine.gid = getgid ();
+ server->machine.egid = getegid ();
+
+ /* Drop priviledges. */
+
+ if (setreuid (server->machine.euid, server->machine.uid))
+ _exit (1);
+
+ if (setregid (server->machine.egid, server->machine.gid))
+ _exit (1);
+
+ /* !!! END OF SUID ROOT PART !!! */
+
+ /* Our effective uid is now those of the user invoking the server,
+ * so we do no longer have any priviledges. */
+}
+
diff --git a/sysdeps/stub_suid/ppp.c b/sysdeps/stub_suid/ppp.c
new file mode 100644
index 00000000..67d01fcf
--- /dev/null
+++ b/sysdeps/stub_suid/ppp.c
@@ -0,0 +1,44 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, October 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <glibtop.h>
+#include <glibtop/error.h>
+#include <glibtop/ppp.h>
+
+static const unsigned long _glibtop_sysdeps_ppp = 0;
+
+/* Init function. */
+
+void
+glibtop_init_ppp_p (glibtop *server)
+{
+ server->sysdeps.ppp = _glibtop_sysdeps_ppp;
+}
+
+/* Provides PPP/ISDN information. */
+
+void
+glibtop_get_ppp_p (glibtop *server, glibtop_ppp *buf, unsigned short device)
+{
+ memset (buf, 0, sizeof (glibtop_ppp));
+}
diff --git a/sysdeps/stub_suid/procargs.c b/sysdeps/stub_suid/procargs.c
new file mode 100644
index 00000000..67c183e8
--- /dev/null
+++ b/sysdeps/stub_suid/procargs.c
@@ -0,0 +1,47 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <glibtop.h>
+#include <glibtop/error.h>
+#include <glibtop/xmalloc.h>
+#include <glibtop/procargs.h>
+
+static const unsigned long _glibtop_sysdeps_proc_args = 0;
+
+/* 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)
+{
+ memset (buf, 0, sizeof (glibtop_proc_args));
+ return NULL;
+}
diff --git a/sysdeps/stub_suid/procdata.c b/sysdeps/stub_suid/procdata.c
new file mode 100644
index 00000000..1f24d61a
--- /dev/null
+++ b/sysdeps/stub_suid/procdata.c
@@ -0,0 +1,180 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <config.h>
+#include <glibtop/procdata.h>
+
+#include <sys/stat.h>
+
+#define LINUX_VERSION(x,y,z) (0x10000*(x) + 0x100*(y) + z)
+
+#define BIT_SHIFT(x) (1 << (x % 32))
+
+static const unsigned long _glibtop_sysdeps_procdata_0 =
+BIT_SHIFT(GLIBTOP_PROCDATA_CMD) +
+BIT_SHIFT(GLIBTOP_PROCDATA_STATE) +
+BIT_SHIFT(GLIBTOP_PROCDATA_UID) +
+BIT_SHIFT(GLIBTOP_PROCDATA_PID) +
+BIT_SHIFT(GLIBTOP_PROCDATA_PPID) +
+BIT_SHIFT(GLIBTOP_PROCDATA_PGRP) +
+BIT_SHIFT(GLIBTOP_PROCDATA_SESSION) +
+BIT_SHIFT(GLIBTOP_PROCDATA_TTY) +
+BIT_SHIFT(GLIBTOP_PROCDATA_TPGID) +
+BIT_SHIFT(GLIBTOP_PROCDATA_PRIORITY) +
+BIT_SHIFT(GLIBTOP_PROCDATA_NICE) +
+BIT_SHIFT(GLIBTOP_PROCDATA_SIGNAL) +
+BIT_SHIFT(GLIBTOP_PROCDATA_BLOCKED) +
+BIT_SHIFT(GLIBTOP_PROCDATA_SIGIGNORE) +
+BIT_SHIFT(GLIBTOP_PROCDATA_SIGCATCH) +
+BIT_SHIFT(GLIBTOP_PROCDATA_START_TIME) +
+BIT_SHIFT(GLIBTOP_PROCDATA_UTIME) +
+BIT_SHIFT(GLIBTOP_PROCDATA_STIME) +
+BIT_SHIFT(GLIBTOP_PROCDATA_CUTIME) +
+BIT_SHIFT(GLIBTOP_PROCDATA_CSTIME) +
+BIT_SHIFT(GLIBTOP_PROCDATA_SIZE) +
+BIT_SHIFT(GLIBTOP_PROCDATA_RESIDENT) +
+BIT_SHIFT(GLIBTOP_PROCDATA_SHARE) +
+BIT_SHIFT(GLIBTOP_PROCDATA_TRS) +
+BIT_SHIFT(GLIBTOP_PROCDATA_LRS) +
+BIT_SHIFT(GLIBTOP_PROCDATA_DRS) +
+BIT_SHIFT(GLIBTOP_PROCDATA_DT) +
+BIT_SHIFT(GLIBTOP_PROCDATA_VSIZE) +
+BIT_SHIFT(GLIBTOP_PROCDATA_RSS) +
+BIT_SHIFT(GLIBTOP_PROCDATA_RSS_RLIM) +
+BIT_SHIFT(GLIBTOP_PROCDATA_TIMEOUT) +
+BIT_SHIFT(GLIBTOP_PROCDATA_IT_REAL_VALUE);
+
+static const unsigned long _glibtop_sysdeps_procdata_1 =
+BIT_SHIFT(GLIBTOP_PROCDATA_K_FLAGS) +
+BIT_SHIFT(GLIBTOP_PROCDATA_MIN_FLT) +
+BIT_SHIFT(GLIBTOP_PROCDATA_MAJ_FLT) +
+BIT_SHIFT(GLIBTOP_PROCDATA_CMIN_FLT) +
+BIT_SHIFT(GLIBTOP_PROCDATA_CMAJ_FLT) +
+BIT_SHIFT(GLIBTOP_PROCDATA_START_CODE) +
+BIT_SHIFT(GLIBTOP_PROCDATA_END_CODE) +
+BIT_SHIFT(GLIBTOP_PROCDATA_START_STACK) +
+BIT_SHIFT(GLIBTOP_PROCDATA_KSTK_ESP) +
+BIT_SHIFT(GLIBTOP_PROCDATA_KSTK_EIP) +
+BIT_SHIFT(GLIBTOP_PROCDATA_WCHAN);
+
+/* Provides detailed information about a process. */
+
+void
+glibtop_get_procdata_s (glibtop *server, glibtop_procdata *buf, pid_t pid)
+{
+ char input [BUFSIZ], *tmp;
+ struct stat statb;
+ int nread;
+ FILE *f;
+
+ glibtop_init_r (&server, 0, 0);
+
+ memset (buf, 0, sizeof (glibtop_procdata));
+
+ if (pid == 0) {
+ /* Client is only interested in the flags. */
+ buf->flags [0] = _glibtop_sysdeps_procdata_0;
+ buf->flags [1] = _glibtop_sysdeps_procdata_1;
+ return;
+ }
+
+
+ sprintf (input, "/proc/%d/stat", pid);
+
+ if (stat (input, &statb)) return;
+
+ buf->uid = statb.st_uid;
+
+ f = fopen (input, "r");
+ if (!f) return;
+
+ nread = fread (input, 1, BUFSIZ, f);
+
+ if (nread < 0) {
+ fclose (f);
+ return;
+ }
+
+ input [nread] = 0;
+
+ /* This is from guile-utils/gtop/proc/readproc.c */
+
+ /* split into "PID (cmd" and "<rest>" */
+ tmp = strrchr (input, ')');
+ *tmp = '\0'; /* replace trailing ')' with NUL */
+ /* parse these two strings separately, skipping the leading "(". */
+ memset (buf->cmd, 0, sizeof (buf->cmd));
+ sscanf (input, "%d (%39c", &buf->pid, buf->cmd);
+ sscanf(tmp + 2, /* skip space after ')' too */
+ "%c %d %d %d %d %d %lu %lu %lu %lu %lu "
+ "%ld %ld %ld %ld %d %d %lu %lu %ld %lu "
+ "%lu %lu %lu %lu %lu %lu %lu %d %d %d %d %lu",
+ &buf->state, &buf->ppid, &buf->pgrp, &buf->session,
+ &buf->tty, &buf->tpgid, &buf->k_flags, &buf->min_flt,
+ &buf->cmin_flt, &buf->maj_flt, &buf->cmaj_flt,
+ &buf->utime, &buf->stime, &buf->cutime, &buf->cstime,
+ &buf->priority, &buf->nice, &buf->timeout,
+ &buf->it_real_value, &buf->start_time, &buf->vsize,
+ &buf->rss, &buf->rss_rlim, &buf->start_code,
+ &buf->end_code, &buf->start_stack, &buf->kstk_esp,
+ &buf->kstk_eip, &buf->signal, &buf->blocked,
+ &buf->sigignore, &buf->sigcatch, &buf->wchan);
+
+ if (buf->tty == 0)
+ /* the old notty val, update elsewhere bef. moving to 0 */
+ buf->tty = -1;
+
+ if (server->os_version_code < LINUX_VERSION(1,3,39)) {
+ /* map old meanings to new */
+ buf->priority = 2*15 - buf->priority;
+ buf->nice = 15 - buf->nice;
+ }
+ if (server->os_version_code < LINUX_VERSION(1,1,30) && buf->tty != -1)
+ /* when tty wasn't full devno */
+ buf->tty = 4*0x100 + buf->tty;
+
+ fclose (f);
+
+ sprintf (input, "/proc/%d/statm", pid);
+
+ f = fopen (input, "r");
+ if (!f) return;
+
+ nread = fread (input, 1, BUFSIZ, f);
+
+ if (nread < 0) {
+ fclose (f);
+ return;
+ }
+
+ input [nread] = 0;
+
+ sscanf (input, "%ld %ld %ld %ld %ld %ld %ld",
+ &buf->size, &buf->resident, &buf->share,
+ &buf->trs, &buf->lrs, &buf->drs, &buf->dt);
+
+ fclose (f);
+
+ buf->flags [0] = _glibtop_sysdeps_procdata_0;
+ buf->flags [1] = _glibtop_sysdeps_procdata_1;
+}
diff --git a/sysdeps/stub_suid/prockernel.c b/sysdeps/stub_suid/prockernel.c
new file mode 100644
index 00000000..e7d961a1
--- /dev/null
+++ b/sysdeps/stub_suid/prockernel.c
@@ -0,0 +1,49 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <glibtop.h>
+#include <glibtop/error.h>
+#include <glibtop/prockernel.h>
+
+#include <glibtop_suid.h>
+
+static const unsigned long _glibtop_sysdeps_proc_kernel = 0;
+
+/* Init function. */
+
+void
+glibtop_init_proc_kernel_p (glibtop *server)
+{
+ server->sysdeps.proc_kernel = _glibtop_sysdeps_proc_kernel;
+}
+
+/* Provides detailed information about a process. */
+
+void
+glibtop_get_proc_kernel_p (glibtop *server, glibtop_proc_kernel *buf,
+ pid_t pid)
+{
+ glibtop_init_p (server, GLIBTOP_SYSDEPS_PROC_KERNEL, 0);
+
+ memset (buf, 0, sizeof (glibtop_proc_kernel));
+}
diff --git a/sysdeps/stub_suid/proclist.c b/sysdeps/stub_suid/proclist.c
new file mode 100644
index 00000000..908dadb9
--- /dev/null
+++ b/sysdeps/stub_suid/proclist.c
@@ -0,0 +1,49 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <glibtop.h>
+#include <glibtop/error.h>
+#include <glibtop/proclist.h>
+
+#include <glibtop_suid.h>
+
+static const unsigned long _glibtop_sysdeps_proclist = 0;
+
+/* Init function. */
+
+void
+glibtop_init_proclist_p (glibtop *server)
+{
+ server->sysdeps.proclist = _glibtop_sysdeps_proclist;
+}
+
+unsigned *
+glibtop_get_proclist_p (glibtop *server, glibtop_proclist *buf,
+ int64_t which, int64_t arg)
+{
+ glibtop_init_p (server, GLIBTOP_SYSDEPS_PROCLIST, 0);
+
+ memset (buf, 0, sizeof (glibtop_proclist));
+
+ return NULL;
+}
diff --git a/sysdeps/stub_suid/procmap.c b/sysdeps/stub_suid/procmap.c
new file mode 100644
index 00000000..0b9bd6e0
--- /dev/null
+++ b/sysdeps/stub_suid/procmap.c
@@ -0,0 +1,46 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <glibtop.h>
+#include <glibtop/error.h>
+#include <glibtop/xmalloc.h>
+#include <glibtop/procmap.h>
+
+static const unsigned long _glibtop_sysdeps_proc_map = 0;
+
+/* 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)
+{
+ memset (buf, 0, sizeof (glibtop_proc_map));
+ return NULL;
+}
diff --git a/sysdeps/stub_suid/procmem.c b/sysdeps/stub_suid/procmem.c
new file mode 100644
index 00000000..6084aa66
--- /dev/null
+++ b/sysdeps/stub_suid/procmem.c
@@ -0,0 +1,49 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <glibtop.h>
+#include <glibtop/error.h>
+#include <glibtop/procmem.h>
+
+#include <glibtop_suid.h>
+
+static const unsigned long _glibtop_sysdeps_proc_mem = 0;
+
+/* 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)
+{
+ glibtop_init_p (server, GLIBTOP_SYSDEPS_PROC_MEM, 0);
+
+ memset (buf, 0, sizeof (glibtop_proc_mem));
+}
diff --git a/sysdeps/stub_suid/procsegment.c b/sysdeps/stub_suid/procsegment.c
new file mode 100644
index 00000000..38499f83
--- /dev/null
+++ b/sysdeps/stub_suid/procsegment.c
@@ -0,0 +1,49 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <glibtop.h>
+#include <glibtop/error.h>
+#include <glibtop/procsegment.h>
+
+#include <glibtop_suid.h>
+
+static const unsigned long _glibtop_sysdeps_proc_segment = 0;
+
+/* Init function. */
+
+void
+glibtop_init_proc_segment_p (glibtop *server)
+{
+ 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)
+{
+ glibtop_init_p (server, GLIBTOP_SYSDEPS_PROC_SEGMENT, 0);
+
+ memset (buf, 0, sizeof (glibtop_proc_segment));
+}
diff --git a/sysdeps/stub_suid/procsignal.c b/sysdeps/stub_suid/procsignal.c
new file mode 100644
index 00000000..9a89e8ab
--- /dev/null
+++ b/sysdeps/stub_suid/procsignal.c
@@ -0,0 +1,49 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <glibtop.h>
+#include <glibtop/error.h>
+#include <glibtop/procsignal.h>
+
+#include <glibtop_suid.h>
+
+static const unsigned long _glibtop_sysdeps_proc_signal = 0;
+
+/* Init function. */
+
+void
+glibtop_init_proc_signal_p (glibtop *server)
+{
+ server->sysdeps.proc_signal = _glibtop_sysdeps_proc_signal;
+}
+
+/* Provides detailed information about a process. */
+
+void
+glibtop_get_proc_signal_p (glibtop *server, glibtop_proc_signal *buf,
+ pid_t pid)
+{
+ glibtop_init_p (server, GLIBTOP_SYSDEPS_PROC_SIGNAL, 0);
+
+ memset (buf, 0, sizeof (glibtop_proc_signal));
+}
diff --git a/sysdeps/stub_suid/procstate.c b/sysdeps/stub_suid/procstate.c
new file mode 100644
index 00000000..576889c1
--- /dev/null
+++ b/sysdeps/stub_suid/procstate.c
@@ -0,0 +1,49 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <glibtop.h>
+#include <glibtop/error.h>
+#include <glibtop/procstate.h>
+
+#include <glibtop_suid.h>
+
+static const unsigned long _glibtop_sysdeps_proc_state = 0;
+
+/* 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)
+{
+ glibtop_init_p (server, GLIBTOP_SYSDEPS_PROC_STATE, 0);
+
+ memset (buf, 0, sizeof (glibtop_proc_state));
+}
diff --git a/sysdeps/stub_suid/proctime.c b/sysdeps/stub_suid/proctime.c
new file mode 100644
index 00000000..bc6c6c09
--- /dev/null
+++ b/sysdeps/stub_suid/proctime.c
@@ -0,0 +1,49 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <glibtop.h>
+#include <glibtop/error.h>
+#include <glibtop/proctime.h>
+
+#include <glibtop_suid.h>
+
+static const unsigned long _glibtop_sysdeps_proc_time = 0;
+
+/* Init function. */
+
+void
+glibtop_init_proc_time_p (glibtop *server)
+{
+ server->sysdeps.proc_time = _glibtop_sysdeps_proc_time;
+}
+
+/* Provides detailed information about a process. */
+
+void
+glibtop_get_proc_time_p (glibtop *server, glibtop_proc_time *buf,
+ pid_t pid)
+{
+ glibtop_init_p (server, GLIBTOP_SYSDEPS_PROC_TIME, 0);
+
+ memset (buf, 0, sizeof (glibtop_proc_time));
+}
diff --git a/sysdeps/stub_suid/procuid.c b/sysdeps/stub_suid/procuid.c
new file mode 100644
index 00000000..e487375e
--- /dev/null
+++ b/sysdeps/stub_suid/procuid.c
@@ -0,0 +1,49 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <glibtop.h>
+#include <glibtop/error.h>
+#include <glibtop/procuid.h>
+
+#include <glibtop_suid.h>
+
+static const unsigned long _glibtop_sysdeps_proc_uid = 0;
+
+/* 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)
+{
+ glibtop_init_p (server, GLIBTOP_SYSDEPS_PROC_UID, 0);
+
+ memset (buf, 0, sizeof (glibtop_proc_uid));
+}
diff --git a/sysdeps/stub_suid/sem_limits.c b/sysdeps/stub_suid/sem_limits.c
new file mode 100644
index 00000000..b1aa85cd
--- /dev/null
+++ b/sysdeps/stub_suid/sem_limits.c
@@ -0,0 +1,48 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <glibtop.h>
+#include <glibtop/error.h>
+#include <glibtop/sem_limits.h>
+
+#include <glibtop_suid.h>
+
+static const unsigned long _glibtop_sysdeps_sem_limits = 0;
+
+/* Init function. */
+
+void
+glibtop_init_sem_limits_p (glibtop *server)
+{
+ server->sysdeps.sem_limits = _glibtop_sysdeps_sem_limits;
+}
+
+/* Provides information about sysv sem limits. */
+
+void
+glibtop_get_sem_limits_p (glibtop *server, glibtop_sem_limits *buf)
+{
+ glibtop_init_p (server, GLIBTOP_SYSDEPS_SEM_LIMITS, 0);
+
+ memset (buf, 0, sizeof (glibtop_sem_limits));
+}
diff --git a/sysdeps/stub_suid/shm_limits.c b/sysdeps/stub_suid/shm_limits.c
new file mode 100644
index 00000000..9aa3574c
--- /dev/null
+++ b/sysdeps/stub_suid/shm_limits.c
@@ -0,0 +1,48 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <glibtop.h>
+#include <glibtop/error.h>
+#include <glibtop/shm_limits.h>
+
+#include <glibtop_suid.h>
+
+static const unsigned long _glibtop_sysdeps_shm_limits = 0;
+
+/* Init function. */
+
+void
+glibtop_init_shm_limits_p (glibtop *server)
+{
+ server->sysdeps.shm_limits = _glibtop_sysdeps_shm_limits;
+}
+
+/* Provides information about sysv ipc limits. */
+
+void
+glibtop_get_shm_limits_p (glibtop *server, glibtop_shm_limits *buf)
+{
+ glibtop_init_p (server, GLIBTOP_SYSDEPS_SHM_LIMITS, 0);
+
+ memset (buf, 0, sizeof (glibtop_shm_limits));
+}
diff --git a/sysdeps/stub_suid/siglist.c b/sysdeps/stub_suid/siglist.c
new file mode 100644
index 00000000..94abfdc6
--- /dev/null
+++ b/sysdeps/stub_suid/siglist.c
@@ -0,0 +1,28 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <glibtop.h>
+#include <glibtop/signal.h>
+
+const glibtop_signame glibtop_sys_siglist [] =
+{ { 0, NULL, NULL } };
diff --git a/sysdeps/stub_suid/swap.c b/sysdeps/stub_suid/swap.c
new file mode 100644
index 00000000..2c97ebc6
--- /dev/null
+++ b/sysdeps/stub_suid/swap.c
@@ -0,0 +1,48 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <glibtop.h>
+#include <glibtop/error.h>
+#include <glibtop/swap.h>
+
+#include <glibtop_suid.h>
+
+static const unsigned long _glibtop_sysdeps_swap = 0;
+
+/* Init function. */
+
+void
+glibtop_init_swap_p (glibtop *server)
+{
+ server->sysdeps.swap = _glibtop_sysdeps_swap;
+}
+
+/* Provides information about swap usage. */
+
+void
+glibtop_get_swap_p (glibtop *server, glibtop_swap *buf)
+{
+ glibtop_init_p (server, GLIBTOP_SYSDEPS_SWAP, 0);
+
+ memset (buf, 0, sizeof (glibtop_swap));
+}
diff --git a/sysdeps/stub_suid/uptime.c b/sysdeps/stub_suid/uptime.c
new file mode 100644
index 00000000..76a1d5b6
--- /dev/null
+++ b/sysdeps/stub_suid/uptime.c
@@ -0,0 +1,48 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <glibtop.h>
+#include <glibtop/error.h>
+#include <glibtop/uptime.h>
+
+#include <glibtop_suid.h>
+
+static const unsigned long _glibtop_sysdeps_uptime = 0;
+
+/* Init function. */
+
+void
+glibtop_init_uptime_p (glibtop *server)
+{
+ server->sysdeps.uptime = _glibtop_sysdeps_uptime;
+}
+
+/* Provides uptime and idle time. */
+
+void
+glibtop_get_uptime_p (glibtop *server, glibtop_uptime *buf)
+{
+ glibtop_init_p (server, GLIBTOP_SYSDEPS_UPTIME, 0);
+
+ memset (buf, 0, sizeof (glibtop_uptime));
+}
diff --git a/sysdeps/sun4/.cvsignore b/sysdeps/sun4/.cvsignore
new file mode 100644
index 00000000..dd420e7f
--- /dev/null
+++ b/sysdeps/sun4/.cvsignore
@@ -0,0 +1,17 @@
+.deps
+.libs
+Makefile
+Makefile.in
+close.lo
+cpu.lo
+libgtop_sysdeps.la
+loadavg.lo
+mem.lo
+msg_limits.lo
+open.lo
+proclist.lo
+sem_limits.lo
+shm_limits.lo
+swap.lo
+sysdeps.lo
+uptime.lo
diff --git a/sysdeps/sun4/ChangeLog b/sysdeps/sun4/ChangeLog
new file mode 100644
index 00000000..f05eac85
--- /dev/null
+++ b/sysdeps/sun4/ChangeLog
@@ -0,0 +1,17 @@
+2001-10-17 Abel Cheung <maddog@linux.org.hk>
+
+ * Makefile.am: move header to $(includedir)/libgtop-1.0/glibtop.
+
+1998-10-25 Martin Baulig <martin@home-of-linux.org>
+
+ * ppp.c: New file.
+
+1998-08-25 Martin Baulig <martin@home-of-linux.org>
+
+ * *.c (glibtop_init_p): Using correct `(1 << GLIBTOP_SYSDPES_*)'.
+ (<glibtop_suid.h>): Include.
+
+ * glibtop_suid.h: New file.
+
+ * ChangeLog: New file.
+
diff --git a/sysdeps/sun4/Makefile.am b/sysdeps/sun4/Makefile.am
new file mode 100644
index 00000000..87ac8c74
--- /dev/null
+++ b/sysdeps/sun4/Makefile.am
@@ -0,0 +1,22 @@
+LINK = $(LIBTOOL) --mode=link $(CC) $(CFLAGS) $(LDFLAGS) -o $@
+
+INCLUDES = @INCLUDES@
+
+lib_LTLIBRARIES = libgtop_sysdeps-2.0.la libgtop_sysdeps_suid-2.0.la
+
+libgtop_sysdeps_2_0_la_SOURCES = nosuid.c siglist.c
+libgtop_sysdeps_2_0_la_LDFLAGS = $(LT_VERSION_INFO)
+libgtop_sysdeps_2_0_la_LIBADD = -lkvm
+
+libgtop_sysdeps_suid_2_0_la_SOURCES = open.c close.c cpu.c mem.c swap.c \
+ uptime.c loadavg.c shm_limits.c msg_limits.c \
+ sem_limits.c proclist.c procstate.c procuid.c \
+ proctime.c procmem.c procsignal.c prockernel.c \
+ procsegment.c ppp.c
+libgtop_sysdeps_suid_2_0_la_LDFLAGS = $(LT_VERSION_INFO)
+libgtop_sysdeps_suid_2_0_la_LIBADD = -lkvm
+
+libgtopinclude_HEADERS = glibtop_server.h glibtop_machine.h
+libgtopincludedir = $(includedir)/libgtop-2.0
+
+noinst_HEADERS = glibtop_suid.h
diff --git a/sysdeps/sun4/close.c b/sysdeps/sun4/close.c
new file mode 100644
index 00000000..a8733f0f
--- /dev/null
+++ b/sysdeps/sun4/close.c
@@ -0,0 +1,30 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <glibtop/close.h>
+
+/* Closes pipe to gtop server. */
+
+void
+glibtop_close_p (glibtop *server)
+{ }
diff --git a/sysdeps/sun4/cpu.c b/sysdeps/sun4/cpu.c
new file mode 100644
index 00000000..9c27e538
--- /dev/null
+++ b/sysdeps/sun4/cpu.c
@@ -0,0 +1,107 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <glibtop.h>
+#include <glibtop/cpu.h>
+
+#include <glibtop_suid.h>
+
+static const unsigned long _glibtop_sysdeps_cpu =
+(1 << GLIBTOP_CPU_TOTAL) + (1 << GLIBTOP_CPU_USER) +
+(1 << GLIBTOP_CPU_NICE) + (1 << GLIBTOP_CPU_SYS) +
+(1 << GLIBTOP_CPU_IDLE) + (1 << GLIBTOP_CPU_FREQUENCY);
+
+/* Provides information about cpu usage. */
+
+void
+glibtop_get_cpu_p (glibtop *server, glibtop_cpu *buf)
+{
+ long cp_time [CPUSTATES], mp_time [NCPU][CPUSTATES];
+ int i;
+
+ glibtop_init_p (server, (1 << GLIBTOP_SYSDEPS_CPU), 0);
+
+ memset (buf, 0, sizeof (glibtop_cpu));
+
+ /* !!! THE FOLLOWING CODE RUNS SGID KMEM - CHANGE WITH CAUTION !!! */
+
+ glibtop_suid_enter (server);
+
+ /* get the cp_time array */
+
+ (void) _glibtop_getkval (server, _glibtop_nlist [X_CP_TIME].n_value,
+ (int *) cp_time, sizeof (cp_time),
+ _glibtop_nlist [X_CP_TIME].n_name);
+
+#ifdef MULTIPROCESSOR
+ /* get the mp_time array as well */
+
+ if (server->machine.ncpu > 1) {
+ (void) _glibtop_getkval (server, _glibtop_nlist [X_MP_TIME].n_value,
+ (int *) mp_time, sizeof (mp_time),
+ _glibtop_nlist [X_MP_TIME].n_name);
+ }
+#endif
+
+ glibtop_suid_leave (server);
+
+ /* !!! END OF SUID ROOT PART !!! */
+
+#ifdef MULTIPROCESSOR
+ /* If we have multiple processors, we add the times for each of them
+ * and set frequency to 100 times the number of the processors. */
+
+ /* [FIXME]: I had no machine with more than one processor to test
+ * this code !!! */
+
+ if (server->machine.ncpu > 1) {
+ for (i = 0; i < server->machine.ncpu; i++) {
+ buf->user += mp_time [i][CP_USER];
+ buf->nice += mp_time [i][CP_NICE];
+ buf->sys += mp_time [i][CP_SYS];
+ buf->idle += mp_time [i][CP_IDLE];
+ buf->frequency += 100;
+ }
+ } else {
+ buf->user = cp_time [CP_USER];
+ buf->nice = cp_time [CP_NICE];
+ buf->sys = cp_time [CP_SYS];
+ buf->idle = cp_time [CP_IDLE];
+ buf->frequency = 100;
+ }
+#else
+ buf->user = cp_time [CP_USER];
+ buf->nice = cp_time [CP_NICE];
+ buf->sys = cp_time [CP_SYS];
+ buf->idle = cp_time [CP_IDLE];
+ buf->frequency = 100;
+#endif
+
+ /* Calculate total time. */
+
+ buf->total = buf->user + buf->nice + buf->sys + buf->idle;
+
+ /* Now we can set the flags. */
+
+ buf->flags = _glibtop_sysdeps_cpu;
+}
diff --git a/sysdeps/sun4/glibtop_machine.h b/sysdeps/sun4/glibtop_machine.h
new file mode 100644
index 00000000..8ab56840
--- /dev/null
+++ b/sysdeps/sun4/glibtop_machine.h
@@ -0,0 +1,117 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#ifndef __GLIBTOP_MACHINE_H__
+#define __GLIBTOP_MACHINE_H__
+
+/* make sure param.h gets loaded with KERNEL defined to get PZERO & NZERO */
+#define KERNEL
+#include <sys/param.h>
+#undef KERNEL
+
+#include <stdio.h>
+#include <kvm.h>
+#include <nlist.h>
+#include <math.h>
+#include <sys/dir.h>
+#include <sys/user.h>
+#include <sys/proc.h>
+#include <sys/dk.h>
+#include <sys/vm.h>
+#include <sys/file.h>
+#include <sys/time.h>
+#include <vm/page.h>
+
+#ifdef solbourne
+#include <sys/syscall.h>
+#endif
+
+#include "loadavg.h"
+
+BEGIN_LIBGTOP_DECLS
+
+/* Older versions of SunOS don't have a typedef for pid_t.
+ Hopefully this will catch all those cases without causing other problems.
+ */
+#ifndef __sys_stdtypes_h
+typedef int pid_t;
+#endif
+
+/* definitions for indices in the nlist array */
+#define X_AVENRUN 0
+#define X_CCPU 1
+#define X_MPID 2
+#define X_NPROC 3
+#define X_PROC 4
+#define X_TOTAL 5
+#define X_CP_TIME 6
+#define X_PAGES 7
+#define X_EPAGES 8
+#define X_SHMINFO 9
+#define X_MSGINFO 10
+#define X_SEMINFO 11
+
+#ifdef MULTIPROCESSOR
+#define X_NCPU 12
+#define X_MP_TIME 13
+#endif
+
+/* Log base 2 of 1024 is 10 (2^10 == 1024) */
+#define LOG1024 10
+
+typedef struct _glibtop_machine glibtop_machine;
+
+struct _glibtop_machine
+{
+ uid_t uid, euid; /* Real and effective user id */
+ gid_t gid, egid; /* Real and effective group id */
+ int nlist_count; /* Number of symbols in the nlist */
+ int ncpu; /* Number of CPUs we have */
+ int nproc; /* Number of entries in the process array */
+ size_t ptable_size; /* Size of process array. */
+ unsigned long ptable_offset; /* Offset of process array in kernel. */
+ struct proc *proc_table; /* Process array. */
+ unsigned long pages, epages;
+ struct page *physpage;
+ int bytesize, count;
+ int pageshift; /* log base 2 of the pagesize */
+ kvm_t *kd;
+};
+
+/* Those functions are used internally in libgtop */
+
+#ifdef _IN_LIBGTOP
+
+extern struct nlist _glibtop_nlist[];
+
+int _glibtop_check_nlist (void *server, register struct nlist *nlst);
+int _glibtop_getkval (void *void_server, unsigned long offset, int *ptr,
+ int size, char *refstr);
+void _glibtop_read_proc_table (void *void_server);
+struct proc *_glibtop_find_pid (void *void_server, pid_t pid);
+
+#endif
+
+END_LIBGTOP_DECLS
+
+#endif
diff --git a/sysdeps/sun4/glibtop_server.h b/sysdeps/sun4/glibtop_server.h
new file mode 100644
index 00000000..e631e43e
--- /dev/null
+++ b/sysdeps/sun4/glibtop_server.h
@@ -0,0 +1,49 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#ifndef __GLIBTOP_SERVER_H__
+#define __GLIBTOP_SERVER_H__
+
+BEGIN_LIBGTOP_DECLS
+
+#define GLIBTOP_SUID_CPU (1 << GLIBTOP_SYSDEPS_CPU)
+#define GLIBTOP_SUID_MEM (1 << GLIBTOP_SYSDEPS_MEM)
+#define GLIBTOP_SUID_SWAP (1 << GLIBTOP_SYSDEPS_SWAP)
+#define GLIBTOP_SUID_UPTIME (1 << GLIBTOP_SYSDEPS_UPTIME)
+#define GLIBTOP_SUID_LOADAVG (1 << GLIBTOP_SYSDEPS_LOADAVG)
+#define GLIBTOP_SUID_SHM_LIMITS (1 << GLIBTOP_SYSDEPS_SHM_LIMITS)
+#define GLIBTOP_SUID_MSG_LIMITS (1 << GLIBTOP_SYSDEPS_MSG_LIMITS)
+#define GLIBTOP_SUID_SEM_LIMITS (1 << GLIBTOP_SYSDEPS_SEM_LIMITS)
+#define GLIBTOP_SUID_PROCLIST (1 << GLIBTOP_SYSDEPS_PROCLIST)
+#define GLIBTOP_SUID_PROC_STATE (1 << GLIBTOP_SYSDEPS_PROC_STATE)
+#define GLIBTOP_SUID_PROC_UID (1 << GLIBTOP_SYSDEPS_PROC_UID)
+#define GLIBTOP_SUID_PROC_MEM (1 << GLIBTOP_SYSDEPS_PROC_MEM)
+#define GLIBTOP_SUID_PROC_TIME (1 << GLIBTOP_SYSDEPS_PROC_TIME)
+#define GLIBTOP_SUID_PROC_SIGNAL (1 << GLIBTOP_SYSDEPS_PROC_SIGNAL)
+#define GLIBTOP_SUID_PROC_KERNEL (1 << GLIBTOP_SYSDEPS_PROC_KERNEL)
+#define GLIBTOP_SUID_PROC_SEGMENT (1 << GLIBTOP_SYSDEPS_PROC_SEGMENT)
+#define GLIBTOP_SUID_PROC_MAP (1 << GLIBTOP_SYSDEPS_PROC_MAP)
+
+END_LIBGTOP_DECLS
+
+#endif
diff --git a/sysdeps/sun4/glibtop_suid.h b/sysdeps/sun4/glibtop_suid.h
new file mode 100644
index 00000000..18d3b1d3
--- /dev/null
+++ b/sysdeps/sun4/glibtop_suid.h
@@ -0,0 +1,48 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#ifndef __GLIBTOP_SUID_H__
+#define __GLIBTOP_SUID_H__
+
+BEGIN_LIBGTOP_DECLS
+
+static inline void glibtop_suid_enter (glibtop *server) {
+ setregid (server->machine.gid, server->machine.egid);
+};
+
+static inline void glibtop_suid_leave (glibtop *server) {
+ if (setregid (server->machine.egid, server->machine.gid))
+ _exit (1);
+};
+
+void
+glibtop_init_p (glibtop *server, const unsigned long features,
+ const unsigned flags);
+void
+glibtop_open_p (glibtop *server, const char *program_name,
+ const unsigned long features,
+ const unsigned flags);
+
+END_LIBGTOP_DECLS
+
+#endif
diff --git a/sysdeps/sun4/loadavg.c b/sysdeps/sun4/loadavg.c
new file mode 100644
index 00000000..530efb9a
--- /dev/null
+++ b/sysdeps/sun4/loadavg.c
@@ -0,0 +1,67 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <glibtop.h>
+#include <glibtop/loadavg.h>
+
+#include <glibtop_suid.h>
+
+static const unsigned long _glibtop_sysdeps_loadavg =
+(1 << GLIBTOP_LOADAVG_LOADAVG);
+
+/* Provides load averange. */
+
+void
+glibtop_get_loadavg_p (glibtop *server, glibtop_loadavg *buf)
+{
+ load_avg avenrun [3];
+ int i;
+
+ glibtop_init_p (server, (1 << GLIBTOP_SYSDEPS_LOADAVG), 0);
+
+ memset (buf, 0, sizeof (glibtop_loadavg));
+
+ /* !!! THE FOLLOWING CODE RUNS SGID KMEM - CHANGE WITH CAUTION !!! */
+
+ setregid (server->machine.gid, server->machine.egid);
+
+ /* get the load average array */
+
+ (void) _glibtop_getkval (server, _glibtop_nlist [X_AVENRUN].n_value,
+ (int *) avenrun, sizeof (avenrun),
+ _glibtop_nlist [X_AVENRUN].n_name);
+
+ if (setregid (server->machine.egid, server->machine.gid))
+ _exit (1);
+
+ /* !!! END OF SGID KMEM PART !!! */
+
+ for (i = 0; i < 3; i++) {
+ /* Calculate loadavg values from avenrun. */
+ buf->loadavg [i] = loaddouble (avenrun [i]);
+ }
+
+ /* Now we can set the flags. */
+
+ buf->flags = _glibtop_sysdeps_loadavg;
+}
diff --git a/sysdeps/sun4/loadavg.h b/sysdeps/sun4/loadavg.h
new file mode 100644
index 00000000..f49541e7
--- /dev/null
+++ b/sysdeps/sun4/loadavg.h
@@ -0,0 +1,57 @@
+/*
+ * Top - a top users display for Berkeley Unix
+ *
+ * Defines required to access load average figures.
+ *
+ * This include file sets up everything we need to access the load average
+ * values in the kernel in a machine independent way. First, it sets the
+ * typedef "load_avg" to be either double or long (depending on what is
+ * needed), then it defines these macros appropriately:
+ *
+ * loaddouble(la) - convert load_avg to double.
+ * intload(i) - convert integer to load_avg.
+ */
+
+/*
+ * We assume that if FSCALE is defined, then avenrun and ccpu are type long.
+ * If your machine is an exception (mips, perhaps?) then make adjustments
+ * here.
+ *
+ * Defined types: load_avg for load averages, pctcpu for cpu percentages.
+ */
+#if defined(mips) && !defined(NetBSD)
+# include <sys/fixpoint.h>
+# if defined(FBITS) && !defined(FSCALE)
+# define FSCALE (1 << FBITS) /* mips */
+# endif
+#endif
+
+#ifdef FSCALE
+# define FIXED_LOADAVG FSCALE
+# define FIXED_PCTCPU FSCALE
+#endif
+
+#ifdef ibm032
+# undef FIXED_LOADAVG
+# undef FIXED_PCTCPU
+# define FIXED_PCTCPU PCT_SCALE
+#endif
+
+
+#ifdef FIXED_PCTCPU
+ typedef long pctcpu;
+# define pctdouble(p) ((double)(p) / FIXED_PCTCPU)
+#else
+typedef double pctcpu;
+# define pctdouble(p) (p)
+#endif
+
+#ifdef FIXED_LOADAVG
+ typedef long load_avg;
+# define loaddouble(la) ((double)(la) / FIXED_LOADAVG)
+# define intload(i) ((int)((i) * FIXED_LOADAVG))
+#else
+ typedef double load_avg;
+# define loaddouble(la) (la)
+# define intload(i) ((double)(i))
+#endif
diff --git a/sysdeps/sun4/mem.c b/sysdeps/sun4/mem.c
new file mode 100644
index 00000000..6bbac96b
--- /dev/null
+++ b/sysdeps/sun4/mem.c
@@ -0,0 +1,91 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <glibtop.h>
+#include <glibtop/mem.h>
+
+#include <glibtop_suid.h>
+
+static const unsigned long _glibtop_sysdeps_mem =
+(1 << GLIBTOP_MEM_TOTAL) + (1 << GLIBTOP_MEM_USED) +
+(1 << GLIBTOP_MEM_FREE) + (1 << GLIBTOP_MEM_LOCKED);
+
+/* define pagetok in terms of pageshift */
+
+#define pagetok(size) ((size) << server->machine.pageshift)
+
+/* Provides information about memory usage. */
+
+void
+glibtop_get_mem_p (glibtop *server, glibtop_mem *buf)
+{
+ glibtop_init_p (server, (1 << GLIBTOP_SYSDEPS_MEM), 0);
+
+ memset (buf, 0, sizeof (glibtop_mem));
+
+ /* !!! THE FOLLOWING CODE RUNS SGID KMEM - CHANGE WITH CAUTION !!! */
+
+ glibtop_suid_enter (server);
+
+ /* get the array of physpage descriptors */
+
+ (void) _glibtop_getkval (server, server->machine.pages,
+ (int *) server->machine.physpage,
+ server->machine.bytesize,
+ "array _page");
+
+ glibtop_suid_leave (server);
+
+ /* !!! END OF SGID KMEM PART !!! */
+
+
+ { /* sum memory statistics */
+ register struct page *pp;
+ register int cnt;
+ register int inuse;
+ register int free;
+ register int locked;
+
+ /* bop thru the array counting page types */
+
+ pp = server->machine.physpage;
+ inuse = free = locked = 0;
+ for (cnt = server->machine.count; --cnt >= 0; pp++) {
+ if (pp->p_free)
+ free++;
+ else if (pp->p_lock || pp->p_keepcnt > 0)
+ locked++;
+ else
+ inuse++;
+ }
+
+ /* convert memory stats to Kbytes */
+
+ buf->total = pagetok (inuse + free);
+ buf->used = pagetok (inuse);
+ buf->free = pagetok (free);
+ buf->locked = pagetok (locked);
+
+ buf->flags = _glibtop_sysdeps_mem;
+ }
+}
diff --git a/sysdeps/sun4/msg_limits.c b/sysdeps/sun4/msg_limits.c
new file mode 100644
index 00000000..7a01740c
--- /dev/null
+++ b/sysdeps/sun4/msg_limits.c
@@ -0,0 +1,75 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <glibtop.h>
+#include <glibtop/msg_limits.h>
+
+#include <glibtop_suid.h>
+
+/* #define KERNEL to get declaration of `struct msginfo'. */
+
+#define KERNEL
+
+#include <sys/ipc.h>
+#include <sys/msg.h>
+
+static const unsigned long _glibtop_sysdeps_msg_limits =
+(1 << GLIBTOP_IPC_MSGMAP) + (1 << GLIBTOP_IPC_MSGMAX) +
+(1 << GLIBTOP_IPC_MSGMNB) + (1 << GLIBTOP_IPC_MSGMNI) +
+(1 << GLIBTOP_IPC_MSGSSZ) + (1 << GLIBTOP_IPC_MSGTQL);
+
+/* Provides information about sysv ipc limits. */
+
+void
+glibtop_get_msg_limits_p (glibtop *server, glibtop_msg_limits *buf)
+{
+ struct msginfo msginfo;
+
+ glibtop_init_p (server, (1 << GLIBTOP_SYSDEPS_MSG_LIMITS), 0);
+
+ memset (buf, 0, sizeof (glibtop_msg_limits));
+
+ /* !!! THE FOLLOWING CODE RUNS SGID KMEM - CHANGE WITH CAUTION !!! */
+
+ setregid (server->machine.gid, server->machine.egid);
+
+ /* get the load average array */
+
+ (void) _glibtop_getkval (server, _glibtop_nlist [X_MSGINFO].n_value,
+ (int *) &msginfo, sizeof (msginfo),
+ _glibtop_nlist [X_MSGINFO].n_name);
+
+ if (setregid (server->machine.egid, server->machine.gid))
+ _exit (1);
+
+ /* !!! END OF SGID KMEM PART !!! */
+
+ buf->msgmap = msginfo.msgmap;
+ buf->msgmax = msginfo.msgmax;
+ buf->msgmnb = msginfo.msgmnb;
+ buf->msgmni = msginfo.msgmni;
+ buf->msgssz = msginfo.msgssz;
+ buf->msgtql = msginfo.msgtql;
+
+ buf->flags = _glibtop_sysdeps_msg_limits;
+}
diff --git a/sysdeps/sun4/nosuid.c b/sysdeps/sun4/nosuid.c
new file mode 100644
index 00000000..cd52852c
--- /dev/null
+++ b/sysdeps/sun4/nosuid.c
@@ -0,0 +1,35 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <glibtop.h>
+#include <glibtop/open.h>
+#include <glibtop/close.h>
+
+void
+glibtop_open_s (glibtop *server, const char *program_name,
+ const unsigned long features, const unsigned flags)
+{ }
+
+void
+glibtop_close_s (glibtop *server)
+{ }
diff --git a/sysdeps/sun4/open.c b/sysdeps/sun4/open.c
new file mode 100644
index 00000000..30fd3e1e
--- /dev/null
+++ b/sysdeps/sun4/open.c
@@ -0,0 +1,308 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <glibtop.h>
+#include <glibtop/open.h>
+#include <glibtop/xmalloc.h>
+
+struct nlist _glibtop_nlist[] = {
+#ifdef i386
+ { "avenrun" }, /* 0 */
+ { "ccpu" }, /* 1 */
+ { "mpid" }, /* 2 */
+ { "nproc" }, /* 3 */
+ { "proc" }, /* 4 */
+ { "total" }, /* 5 */
+ { "cp_time" }, /* 6 */
+ { "pages" }, /* 7 */
+ { "epages" }, /* 8 */
+ { "shminfo" }, /* 9 */
+ { "msginfo" }, /* 10 */
+ { "seminfo" }, /* 11 */
+#else
+ { "_avenrun" }, /* 0 */
+ { "_ccpu" }, /* 1 */
+ { "_mpid" }, /* 2 */
+ { "_nproc" }, /* 3 */
+ { "_proc" }, /* 4 */
+ { "_total" }, /* 5 */
+ { "_cp_time" }, /* 6 */
+ { "_pages" }, /* 7 */
+ { "_epages" }, /* 8 */
+ { "_shminfo" }, /* 9 */
+ { "_msginfo" }, /* 10 */
+ { "_seminfo" }, /* 11 */
+#ifdef MULTIPROCESSOR
+ { "_ncpu" },
+ { "_mp_time" },
+#endif
+#endif
+ { 0 }
+};
+
+/* Opens pipe to gtop server. Returns 0 on success and -1 on error. */
+
+/* !!! THIS FUNCTION RUNS SUID ROOT - CHANGE WITH CAUTION !!! */
+
+void
+glibtop_init_p (glibtop *server, const unsigned long features,
+ const unsigned flags)
+{
+ if (server == NULL)
+ glibtop_error_r (NULL, "glibtop_init_p (server == NULL)");
+
+ glibtop_open_p (server, "glibtop", features, flags);
+}
+
+void
+glibtop_open_p (glibtop *server, const char *program_name,
+ const unsigned long features, const unsigned flags)
+{
+ register int pagesize;
+
+ /* !!! WE ARE ROOT HERE - CHANGE WITH CAUTION !!! */
+
+ server->name = program_name;
+
+ server->machine.uid = getuid ();
+ server->machine.euid = geteuid ();
+ server->machine.gid = getgid ();
+ server->machine.egid = getegid ();
+
+ /* initialize the kernel interface */
+
+ server->machine.kd = kvm_open (NULL, NULL, NULL, O_RDONLY, "libgtop");
+
+ if (server->machine.kd == NULL)
+ glibtop_error_io_r (server, "kvm_open");
+
+ /* get the list of symbols we want to access in the kernel */
+
+ server->machine.nlist_count = kvm_nlist
+ (server->machine.kd, _glibtop_nlist);
+
+ if (server->machine.nlist_count < 0)
+ glibtop_error_io_r (server, "nlist");
+
+#ifdef MULTIPROCESSOR
+ /* were ncpu and xp_time not found in the nlist? */
+
+ if ((server->machine.nlist_count > 0) &&
+ (_glibtop_nlist[X_NCPU].n_type == 0) &&
+ (_glibtop_nlist[X_MP_TIME].n_type == 0)) {
+ /* we were compiled on an MP system but we are not running
+ * on one, so we will pretend this didn't happen and set
+ * ncpu = 1 */
+ server->machine.nlist_count -= 2;
+ server->machine.ncpu = 1;
+ }
+#endif
+
+#ifdef solbourne
+ {
+ unsigned int status, type;
+
+ /* Get the number of CPUs on this system. */
+ syscall(SYS_getcpustatus, &status,
+ &server->machine.ncpu, &type);
+ }
+#endif
+
+ /* Make sure all of the symbols were found. */
+
+ if ((server->machine.nlist_count > 0) &&
+ (_glibtop_check_nlist (server, _glibtop_nlist) > 0))
+ _exit (1);
+
+ /* Get process array stuff. */
+
+ (void) _glibtop_getkval (server, _glibtop_nlist[X_NPROC].n_value,
+ (int *)(&server->machine.nproc),
+ sizeof (server->machine.nproc),
+ _glibtop_nlist[X_NPROC].n_name);
+
+ (void) _glibtop_getkval (server, _glibtop_nlist[X_PROC].n_value,
+ (int *)(&server->machine.ptable_offset),
+ sizeof (server->machine.ptable_offset),
+ _glibtop_nlist[X_PROC].n_name);
+
+ server->machine.ptable_size = (unsigned long) server->machine.nproc *
+ (unsigned long) sizeof (struct proc);
+
+ server->machine.proc_table = glibtop_malloc_r
+ (server, server->machine.ptable_size);
+
+ /* This are for the memory statistics. */
+
+ (void) _glibtop_getkval (server, _glibtop_nlist[X_PAGES].n_value,
+ (int *)(&server->machine.pages),
+ sizeof (server->machine.pages),
+ _glibtop_nlist[X_PAGES].n_name);
+
+ (void) _glibtop_getkval (server, _glibtop_nlist[X_EPAGES].n_value,
+ (int *)(&server->machine.epages),
+ sizeof (server->machine.epages),
+ _glibtop_nlist[X_EPAGES].n_name);
+
+ server->machine.bytesize = server->machine.epages -
+ server->machine.pages;
+ server->machine.count = server->machine.bytesize /
+ sizeof (struct page);
+
+ server->machine.physpage = (struct page *)
+ glibtop_malloc_r (server, server->machine.bytesize);
+
+ /* get the page size with "getpagesize" and
+ * calculate pageshift from it */
+
+ pagesize = getpagesize();
+
+ server->machine.pageshift = 0;
+
+ while (pagesize > 1) {
+ server->machine.pageshift++;
+ pagesize >>= 1;
+ }
+
+ /* we only need the amount of log(2)1024 for our conversion */
+
+ server->machine.pageshift -= LOG1024;
+
+ /* Drop priviledges. */
+
+ if (setreuid (server->machine.euid, server->machine.uid))
+ _exit (1);
+
+ if (setregid (server->machine.egid, server->machine.gid))
+ _exit (1);
+
+ /* !!! END OF SUID ROOT PART !!! */
+
+ /* Our effective uid is now those of the user invoking the server,
+ * so we do no longer have any priviledges. */
+
+ /* NOTE: On SunOS, 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. */
+}
+
+/* Used internally. Returns number of symbols that cannot be found in
+ * the nlist. */
+
+int
+_glibtop_check_nlist (void *server, register struct nlist *nlst)
+{
+ register int not_found;
+
+ /* check to see if we got ALL the symbols we requested */
+ /* this will write one line to stderr for every symbol not found */
+
+ not_found = 0;
+
+ while (nlst->n_name != NULL) {
+
+#ifdef i386
+ if (nlst->n_value == 0) {
+ glibtop_error_r (server,
+ "kernel: no symbol named `%s'",
+ nlst->n_name);
+ not_found++;
+ }
+#else
+ if (nlst->n_type == 0) {
+ glibtop_error_r (server,
+ "kernel: no symbol named `%s'",
+ nlst->n_name);
+ not_found++;
+ }
+#endif
+
+ nlst++;
+ }
+
+ return not_found;
+}
+
+/* Used internally. Fetches value from kernel. */
+
+int
+_glibtop_getkval (void *void_server, unsigned long offset, int *ptr,
+ int size, char *refstr)
+{
+ glibtop *server = (glibtop *) void_server;
+
+ if (kvm_read (server->machine.kd, offset, ptr, size) != size)
+ {
+ if (*refstr == '!') return 0;
+
+ glibtop_error_r (server, "kvm_read(%s): %s",
+ refstr, strerror (errno));
+ }
+
+ return 1;
+}
+
+/* Used internally. Reads process table from kernel. */
+
+void
+_glibtop_read_proc_table (void *void_server)
+{
+ glibtop *server = (glibtop *) void_server;
+
+ /* !!! THE FOLLOWING CODE RUNS SGID KMEM - CHANGE WITH CAUTION !!! */
+
+ setregid (server->machine.gid, server->machine.egid);
+
+ /* Read process table from kernel. */
+
+ (void) _glibtop_getkval (server, server->machine.ptable_offset,
+ (int *) server->machine.proc_table,
+ (size_t) server->machine.ptable_size,
+ _glibtop_nlist[X_PROC].n_name);
+
+ if (setregid (server->machine.egid, server->machine.gid))
+ _exit (1);
+
+ /* !!! END OF SGID KMEM PART !!! */
+}
+
+/* Used internally. Finds pid in process table. */
+
+struct proc *
+_glibtop_find_pid (void *void_server, pid_t pid)
+{
+ register struct proc *pp;
+ register int i;
+
+ glibtop *server = (glibtop *) void_server;
+
+ for (pp = server->machine.proc_table, i = 0;
+ i < server->machine.nproc; pp++, i++) {
+ if ((pp->p_stat != 0) && (pp->p_pid == pid))
+ return pp;
+ }
+
+ return NULL;
+}
diff --git a/sysdeps/sun4/ppp.c b/sysdeps/sun4/ppp.c
new file mode 100644
index 00000000..6d0905d5
--- /dev/null
+++ b/sysdeps/sun4/ppp.c
@@ -0,0 +1,44 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, October 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <glibtop.h>
+#include <glibtop/error.h>
+#include <glibtop/ppp.h>
+
+static const unsigned long _glibtop_sysdeps_ppp = 0;
+
+/* Init function. */
+
+void
+glibtop_init_ppp_s (glibtop *server)
+{
+ server->sysdeps.ppp = _glibtop_sysdeps_ppp;
+}
+
+/* Provides PPP/ISDN information. */
+
+void
+glibtop_get_ppp_s (glibtop *server, glibtop_ppp *buf, unsigned short device)
+{
+ memset (buf, 0, sizeof (glibtop_ppp));
+}
diff --git a/sysdeps/sun4/procdata.c b/sysdeps/sun4/procdata.c
new file mode 100644
index 00000000..50756730
--- /dev/null
+++ b/sysdeps/sun4/procdata.c
@@ -0,0 +1,33 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <config.h>
+#include <glibtop/procdata.h>
+
+/* Provides detailed information about a process. */
+
+void
+glibtop_get_procdata_p (glibtop *server, glibtop_procdata *buf, pid_t pid)
+{
+ memset (buf, 0, sizeof (glibtop_procdata));
+}
diff --git a/sysdeps/sun4/prockernel.c b/sysdeps/sun4/prockernel.c
new file mode 100644
index 00000000..603e881b
--- /dev/null
+++ b/sysdeps/sun4/prockernel.c
@@ -0,0 +1,60 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <glibtop.h>
+#include <glibtop/prockernel.h>
+
+#include <glibtop_suid.h>
+
+static const unsigned long _glibtop_sysdeps_proc_kernel =
+(1 << GLIBTOP_PROC_KERNEL_K_FLAGS) + (1 << GLIBTOP_PROC_KERNEL_WCHAN);
+
+/* Provides detailed information about a process. */
+
+void
+glibtop_get_proc_kernel_p (glibtop *server, glibtop_proc_kernel *buf,
+ pid_t pid)
+{
+ struct proc *pp;
+
+ glibtop_init_p (server, (1 << GLIBTOP_SYSDEPS_PROC_KERNEL), 0);
+
+ memset (buf, 0, sizeof (glibtop_proc_kernel));
+
+ /* Read process table from kernel. */
+
+ _glibtop_read_proc_table (server);
+
+ /* Find the pid in the process table. */
+
+ pp = _glibtop_find_pid (server, pid);
+
+ if (pp == NULL) return;
+
+ /* Fill in data fields. */
+
+ buf->k_flags = pp->p_flag;
+ buf->nwchan = (unsigned long) pp->p_wchan;
+
+ buf->flags = _glibtop_sysdeps_proc_kernel;
+}
diff --git a/sysdeps/sun4/proclist.c b/sysdeps/sun4/proclist.c
new file mode 100644
index 00000000..4b6fc42e
--- /dev/null
+++ b/sysdeps/sun4/proclist.c
@@ -0,0 +1,97 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <glibtop.h>
+#include <glibtop/xmalloc.h>
+#include <glibtop/proclist.h>
+
+#include <glibtop_suid.h>
+
+static const unsigned long _glibtop_sysdeps_proclist =
+(1 << GLIBTOP_PROCLIST_TOTAL) + (1 << GLIBTOP_PROCLIST_NUMBER) +
+(1 << GLIBTOP_PROCLIST_SIZE);
+
+/* Fetch list of currently running processes.
+ *
+ * IMPORTANT NOTE:
+ * On error, this function MUST return NULL and set buf->flags to zero !
+ * On success, it returnes a pointer to a list of buf->number elements
+ * each buf->size big. The total size is stored in buf->total. */
+
+unsigned *
+glibtop_get_proclist_p (glibtop *server, glibtop_proclist *buf,
+ int64_t which, int64_t arg)
+{
+ register struct proc *pp;
+ register int i, nproc = 0;
+ unsigned *proc_list = NULL;
+ size_t proc_size;
+
+ glibtop_init_p (server, (1 << GLIBTOP_SYSDEPS_PROCLIST), 0);
+
+ memset (buf, 0, sizeof (glibtop_proclist));
+
+ /* Read process table from kernel. */
+
+ _glibtop_read_proc_table (server);
+
+ /* Count number of processes. */
+
+ for (pp = server->machine.proc_table, i = 0;
+ i < server->machine.nproc; pp++, i++) {
+ if (pp->p_stat == 0)
+ continue;
+ else
+ nproc++;
+ }
+
+ if (nproc == 0) /* Should never happen. */
+ return NULL;
+
+ /* Allocate space for process list. */
+
+ proc_size = nproc * sizeof (unsigned);
+
+ proc_list = glibtop_malloc_r (server, proc_size);
+
+ /* Write process list. */
+
+ for (pp = server->machine.proc_table, i = 0, nproc = 0;
+ i < server->machine.nproc; pp++, i++) {
+ if (pp->p_stat == 0)
+ continue;
+ proc_list [nproc++] = pp->p_pid;
+ }
+
+ /* Since everything is ok now, we can set buf->flags, fill in the remaining fields
+ and return proc_list. */
+
+ buf->flags = _glibtop_sysdeps_proclist;
+
+ buf->size = sizeof (unsigned);
+ buf->number = nproc;
+
+ buf->total = nproc * sizeof (unsigned);
+
+ return proc_list;
+}
diff --git a/sysdeps/sun4/procmem.c b/sysdeps/sun4/procmem.c
new file mode 100644
index 00000000..979fc7af
--- /dev/null
+++ b/sysdeps/sun4/procmem.c
@@ -0,0 +1,63 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <config.h>
+#include <glibtop/procmem.h>
+
+#include <glibtop_suid.h>
+
+static const unsigned long _glibtop_sysdeps_proc_mem =
+(1 << GLIBTOP_PROC_MEM_SIZE) + (1 << GLIBTOP_PROC_MEM_RSS) +
+(1 << GLIBTOP_PROC_MEM_RSS_RLIM);
+
+/* Provides detailed information about a process. */
+
+void
+glibtop_get_proc_mem_p (glibtop *server, glibtop_proc_mem *buf,
+ pid_t pid)
+{
+ struct proc *pp;
+
+ glibtop_init_p (server, (1 << GLIBTOP_SYSDEPS_PROC_MEM), 0);
+
+ memset (buf, 0, sizeof (glibtop_proc_mem));
+
+ /* Read process table from kernel. */
+
+ _glibtop_read_proc_table (server);
+
+ /* Find the pid in the process table. */
+
+ pp = _glibtop_find_pid (server, pid);
+
+ if (pp == NULL) return;
+
+ /* Fill in data fields. */
+
+ buf->size = (pp)->p_tsize + (pp)->p_dsize + (pp)->p_ssize;
+
+ buf->rss = pp->p_rssize;
+ buf->rss_rlim = pp->p_maxrss;
+
+ buf->flags = _glibtop_sysdeps_proc_mem;
+}
diff --git a/sysdeps/sun4/procsegment.c b/sysdeps/sun4/procsegment.c
new file mode 100644
index 00000000..8dd64bea
--- /dev/null
+++ b/sysdeps/sun4/procsegment.c
@@ -0,0 +1,61 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <glibtop.h>
+#include <glibtop/procsegment.h>
+
+#include <glibtop_suid.h>
+
+static const unsigned long _glibtop_sysdeps_proc_segment =
+(1 << GLIBTOP_PROC_SEGMENT_TEXT_RSS) +
+(1 << GLIBTOP_PROC_SEGMENT_DATA_RSS);
+
+/* Provides detailed information about a process. */
+
+void
+glibtop_get_proc_segment_p (glibtop *server, glibtop_proc_segment *buf,
+ pid_t pid)
+{
+ struct proc *pp;
+
+ glibtop_init_p (server, (1 << GLIBTOP_SYSDEPS_PROC_SEGMENT), 0);
+
+ memset (buf, 0, sizeof (glibtop_proc_segment));
+
+ /* Read process table from kernel. */
+
+ _glibtop_read_proc_table (server);
+
+ /* Find the pid in the process table. */
+
+ pp = _glibtop_find_pid (server, pid);
+
+ if (pp == NULL) return;
+
+ /* Fill in data fields. */
+
+ buf->text_rss = pp->p_tsize;
+ buf->data_rss = pp->p_dsize;
+
+ buf->flags = _glibtop_sysdeps_proc_segment;
+}
diff --git a/sysdeps/sun4/procsignal.c b/sysdeps/sun4/procsignal.c
new file mode 100644
index 00000000..66a5a2bc
--- /dev/null
+++ b/sysdeps/sun4/procsignal.c
@@ -0,0 +1,63 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <glibtop.h>
+#include <glibtop/procsignal.h>
+
+#include <glibtop_suid.h>
+
+static const unsigned long _glibtop_sysdeps_proc_signal =
+(1 << GLIBTOP_PROC_SIGNAL_SIGNAL) + (1 << GLIBTOP_PROC_SIGNAL_BLOCKED) +
+(1 << GLIBTOP_PROC_SIGNAL_SIGIGNORE) + (1 << GLIBTOP_PROC_SIGNAL_SIGCATCH);
+
+/* Provides detailed information about a process. */
+
+void
+glibtop_get_proc_signal_p (glibtop *server, glibtop_proc_signal *buf,
+ pid_t pid)
+{
+ struct proc *pp;
+
+ glibtop_init_p (server, (1 << GLIBTOP_SYSDEPS_PROC_SIGNAL), 0);
+
+ memset (buf, 0, sizeof (glibtop_proc_signal));
+
+ /* Read process table from kernel. */
+
+ _glibtop_read_proc_table (server);
+
+ /* Find the pid in the process table. */
+
+ pp = _glibtop_find_pid (server, pid);
+
+ if (pp == NULL) return;
+
+ /* Fill in data fields. */
+
+ buf->signal [0] = pp->p_sig;
+ buf->blocked [0] = pp->p_sigmask;
+ buf->sigignore [0] = pp->p_sigignore;
+ buf->sigcatch [0] = pp->p_sigcatch;
+
+ buf->flags = _glibtop_sysdeps_proc_signal;
+}
diff --git a/sysdeps/sun4/procstate.c b/sysdeps/sun4/procstate.c
new file mode 100644
index 00000000..4ce3734d
--- /dev/null
+++ b/sysdeps/sun4/procstate.c
@@ -0,0 +1,60 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <glibtop.h>
+#include <glibtop/procstate.h>
+
+#include <glibtop_suid.h>
+
+static const unsigned long _glibtop_sysdeps_proc_state =
+(1 << GLIBTOP_PROC_STATE_STATE) + (1 << GLIBTOP_PROC_STATE_UID);
+
+/* Provides detailed information about a process. */
+
+void
+glibtop_get_proc_state_p (glibtop *server, glibtop_proc_state *buf,
+ pid_t pid)
+{
+ struct proc *pp;
+
+ glibtop_init_p (server, (1 << GLIBTOP_SYSDEPS_PROC_STATE), 0);
+
+ memset (buf, 0, sizeof (glibtop_proc_state));
+
+ /* Read process table from kernel. */
+
+ _glibtop_read_proc_table (server);
+
+ /* Find the pid in the process table. */
+
+ pp = _glibtop_find_pid (server, pid);
+
+ if (pp == NULL) return;
+
+ /* Fill in data fields. */
+
+ buf->state = pp->p_stat;
+ buf->uid = pp->p_uid;
+
+ buf->flags = _glibtop_sysdeps_proc_state;
+}
diff --git a/sysdeps/sun4/proctime.c b/sysdeps/sun4/proctime.c
new file mode 100644
index 00000000..9541f948
--- /dev/null
+++ b/sysdeps/sun4/proctime.c
@@ -0,0 +1,60 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <glibtop.h>
+#include <glibtop/proctime.h>
+
+#include <glibtop_suid.h>
+
+static const unsigned long _glibtop_sysdeps_proc_time =
+(1 << GLIBTOP_PROC_TIME_START_TIME) + (1 << GLIBTOP_PROC_TIME_UTIME);
+
+/* Provides detailed information about a process. */
+
+void
+glibtop_get_proc_time_p (glibtop *server, glibtop_proc_time *buf,
+ pid_t pid)
+{
+ struct proc *pp;
+
+ glibtop_init_p (server, (1 << GLIBTOP_SYSDEPS_PROC_TIME), 0);
+
+ memset (buf, 0, sizeof (glibtop_proc_time));
+
+ /* Read process table from kernel. */
+
+ _glibtop_read_proc_table (server);
+
+ /* Find the pid in the process table. */
+
+ pp = _glibtop_find_pid (server, pid);
+
+ if (pp == NULL) return;
+
+ /* Fill in data fields. */
+
+ buf->start_time = pp->p_time;
+ buf->utime = pp->p_cpticks;
+
+ buf->flags = _glibtop_sysdeps_proc_time;
+}
diff --git a/sysdeps/sun4/procuid.c b/sysdeps/sun4/procuid.c
new file mode 100644
index 00000000..5ff0e5bf
--- /dev/null
+++ b/sysdeps/sun4/procuid.c
@@ -0,0 +1,71 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <glibtop.h>
+#include <glibtop/procuid.h>
+
+#include <glibtop_suid.h>
+
+static const unsigned long _glibtop_sysdeps_proc_uid =
+(1 << GLIBTOP_PROC_UID_UID) + (1 << GLIBTOP_PROC_UID_EUID) +
+(1 << GLIBTOP_PROC_UID_EGID) + (1 << GLIBTOP_PROC_UID_PID) +
+(1 << GLIBTOP_PROC_UID_PPID) + (1 << GLIBTOP_PROC_UID_PGRP) +
+(1 << GLIBTOP_PROC_UID_TPGID) + (1 << GLIBTOP_PROC_UID_PRIORITY) +
+(1 << GLIBTOP_PROC_UID_NICE);
+
+/* Provides detailed information about a process. */
+
+void
+glibtop_get_proc_uid_p (glibtop *server, glibtop_proc_uid *buf,
+ pid_t pid)
+{
+ struct proc *pp;
+
+ glibtop_init_p (server, (1 << GLIBTOP_SYSDEPS_PROC_UID), 0);
+
+ memset (buf, 0, sizeof (glibtop_proc_uid));
+
+ /* Read process table from kernel. */
+
+ _glibtop_read_proc_table (server);
+
+ /* Find the pid in the process table. */
+
+ pp = _glibtop_find_pid (server, pid);
+
+ if (pp == NULL) return;
+
+ /* Fill in data fields. */
+
+ buf->uid = pp->p_uid;
+ buf->euid = pp->p_suid;
+ buf->egid = pp->p_sgid;
+ buf->pid = pp->p_pid;
+ buf->ppid = pp->p_ppid;
+ buf->pgrp = pp->p_pgrp;
+ buf->tpgid = pp->p_pgrp;
+ buf->priority = pp->p_pri;
+ buf->nice = pp->p_nice;
+
+ buf->flags = _glibtop_sysdeps_proc_uid;
+}
diff --git a/sysdeps/sun4/sem_limits.c b/sysdeps/sun4/sem_limits.c
new file mode 100644
index 00000000..e6f07c6c
--- /dev/null
+++ b/sysdeps/sun4/sem_limits.c
@@ -0,0 +1,81 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <glibtop.h>
+#include <glibtop/sem_limits.h>
+
+#include <glibtop_suid.h>
+
+/* #define KERNEL to get declaration of `struct seminfo'. */
+
+#define KERNEL
+
+#include <sys/ipc.h>
+#include <sys/sem.h>
+
+static unsigned long _glibtop_sysdeps_sem_limits =
+(1 << GLIBTOP_IPC_SEMMAP) + (1 << GLIBTOP_IPC_SEMMNI) +
+(1 << GLIBTOP_IPC_SEMMNS) + (1 << GLIBTOP_IPC_SEMMNU) +
+(1 << GLIBTOP_IPC_SEMMSL) + (1 << GLIBTOP_IPC_SEMOPM) +
+(1 << GLIBTOP_IPC_SEMUME) + (1 << GLIBTOP_IPC_SEMUSZ) +
+(1 << GLIBTOP_IPC_SEMVMX) + (1 << GLIBTOP_IPC_SEMAEM);
+
+/* Provides information about sysv sem limits. */
+
+void
+glibtop_get_sem_limits_p (glibtop *server, glibtop_sem_limits *buf)
+{
+ struct seminfo seminfo;
+
+ glibtop_init_p (server, (1 << GLIBTOP_SYSDEPS_SEM_LIMITS), 0);
+
+ memset (buf, 0, sizeof (glibtop_sem_limits));
+
+ /* !!! THE FOLLOWING CODE RUNS SGID KMEM - CHANGE WITH CAUTION !!! */
+
+ setregid (server->machine.gid, server->machine.egid);
+
+ /* get the load average array */
+
+ (void) _glibtop_getkval (server, _glibtop_nlist [X_SEMINFO].n_value,
+ (int *) &seminfo, sizeof (seminfo),
+ _glibtop_nlist [X_SEMINFO].n_name);
+
+ if (setregid (server->machine.egid, server->machine.gid))
+ _exit (1);
+
+ /* !!! END OF SGID KMEM PART !!! */
+
+ buf->semmap = seminfo.semmap;
+ buf->semmni = seminfo.semmni;
+ buf->semmns = seminfo.semmns;
+ buf->semmnu = seminfo.semmnu;
+ buf->semmsl = seminfo.semmsl;
+ buf->semopm = seminfo.semopm;
+ buf->semume = seminfo.semume;
+ buf->semusz = seminfo.semusz;
+ buf->semvmx = seminfo.semvmx;
+ buf->semaem = seminfo.semaem;
+
+ buf->flags = _glibtop_sysdeps_sem_limits;
+}
diff --git a/sysdeps/sun4/shm_limits.c b/sysdeps/sun4/shm_limits.c
new file mode 100644
index 00000000..a5f638f2
--- /dev/null
+++ b/sysdeps/sun4/shm_limits.c
@@ -0,0 +1,74 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <glibtop.h>
+#include <glibtop/shm_limits.h>
+
+#include <glibtop_suid.h>
+
+/* #define KERNEL to get declaration of `struct shminfo'. */
+
+#define KERNEL
+
+#include <sys/ipc.h>
+#include <sys/shm.h>
+
+static unsigned long _glibtop_sysdeps_shm_limits =
+(1 << GLIBTOP_IPC_SHMMAX) + (1 << GLIBTOP_IPC_SHMMIN) +
+(1 << GLIBTOP_IPC_SHMMNI) + (1 << GLIBTOP_IPC_SHMSEG) +
+(1 << GLIBTOP_IPC_SHMALL);
+
+/* Provides information about sysv ipc limits. */
+
+void
+glibtop_get_shm_limits_p (glibtop *server, glibtop_shm_limits *buf)
+{
+ struct shminfo shminfo;
+
+ glibtop_init_p (server, (1 << GLIBTOP_SYSDEPS_SHM_LIMITS), 0);
+
+ memset (buf, 0, sizeof (glibtop_shm_limits));
+
+ /* !!! THE FOLLOWING CODE RUNS SGID KMEM - CHANGE WITH CAUTION !!! */
+
+ setregid (server->machine.gid, server->machine.egid);
+
+ /* get the load average array */
+
+ (void) _glibtop_getkval (server, _glibtop_nlist [X_SHMINFO].n_value,
+ (int *) &shminfo, sizeof (shminfo),
+ _glibtop_nlist [X_SHMINFO].n_name);
+
+ if (setregid (server->machine.egid, server->machine.gid))
+ _exit (1);
+
+ /* !!! END OF SGID KMEM PART !!! */
+
+ buf->shmmax = shminfo.shmmax;
+ buf->shmmin = shminfo.shmmin;
+ buf->shmmni = shminfo.shmmni;
+ buf->shmseg = shminfo.shmseg;
+ buf->shmall = shminfo.shmall;
+
+ buf->flags = _glibtop_sysdeps_shm_limits;
+}
diff --git a/sysdeps/sun4/siglist.c b/sysdeps/sun4/siglist.c
new file mode 100644
index 00000000..c5bd59c0
--- /dev/null
+++ b/sysdeps/sun4/siglist.c
@@ -0,0 +1,60 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <glibtop.h>
+#include <glibtop/signal.h>
+
+const glibtop_signame glibtop_sys_siglist [] =
+{ { 1, "SIGHUP", N_("Hangup") },
+ { 2, "SIGINT", N_("Interrupt") },
+ { 3, "SIGQUIT", N_("Quit") },
+ { 4, "SIGILL", N_("Illegal instruction") },
+ { 5, "SIGTRAP", N_("Trace trap") },
+ { 6, "SIGABRT", N_("Abort") },
+ { 7, "SIGEMT", N_("EMT error") },
+ { 8, "SIGFPE", N_("Floating-point exception") },
+ { 9, "SIGKILL", N_("Kill") },
+ { 10, "SIGBUS", N_("Bus error") },
+ { 11, "SIGSEGV", N_("Segmentation violation") },
+ { 12, "SIGSYS", N_("Bad argument to system call") },
+ { 13, "SIGPIPE", N_("Broken pipe") },
+ { 14, "SIGALRM", N_("Alarm clock") },
+ { 15, "SIGTERM", N_("Termination") },
+ { 16, "SIGURG", N_("Urgent condition on socket") },
+ { 17, "SIGSTOP", N_("Stop") },
+ { 18, "SIGTSTP", N_("Keyboard stop") },
+ { 19, "SIGCONT", N_("Continue") },
+ { 20, "SIGCHLD", N_("Child status has changed") },
+ { 21, "SIGTTIN", N_("Background read from tty") },
+ { 22, "SIGTTOU", N_("Background write to tty") },
+ { 23, "SIGIO", N_("I/O now possible") },
+ { 24, "SIGXCPU", N_("CPU limit exceeded") },
+ { 25, "SIGXFSZ", N_("File size limit exceeded") },
+ { 26, "SIGVTALRM", N_("Virtual alarm clock") },
+ { 27, "SIGPROF", N_("Profiling alarm clock") },
+ { 28, "SIGWINCH", N_("Window size change") },
+ { 29, "SIGINFO", N_("Information request") },
+ { 30, "SIGUSR1", N_("User defined signal 1") },
+ { 31, "SIGUSR2", N_("User defined signal 2") },
+ { 0, NULL, NULL },
+};
diff --git a/sysdeps/sun4/swap.c b/sysdeps/sun4/swap.c
new file mode 100644
index 00000000..3c93e3a7
--- /dev/null
+++ b/sysdeps/sun4/swap.c
@@ -0,0 +1,37 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <glibtop.h>
+#include <glibtop/swap.h>
+
+#include <glibtop_suid.h>
+
+/* Provides information about swap usage. */
+
+void
+glibtop_get_swap_p (glibtop *server, glibtop_swap *buf)
+{
+ glibtop_init_p (server, (1 << GLIBTOP_SYSDEPS_SWAP), 0);
+
+ memset (buf, 0, sizeof (glibtop_swap));
+}
diff --git a/sysdeps/sun4/uptime.c b/sysdeps/sun4/uptime.c
new file mode 100644
index 00000000..023cf3f3
--- /dev/null
+++ b/sysdeps/sun4/uptime.c
@@ -0,0 +1,61 @@
+/* $Id$ */
+
+/* Copyright (C) 1998-99 Martin Baulig
+ This file is part of LibGTop 1.0.
+
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <glibtop.h>
+#include <glibtop/cpu.h>
+#include <glibtop/uptime.h>
+
+#include <glibtop_suid.h>
+
+static const unsigned long _glibtop_sysdeps_uptime =
+(1 << GLIBTOP_UPTIME_UPTIME) + (1 << GLIBTOP_UPTIME_IDLETIME);
+
+/* Provides uptime and idle time. */
+
+void
+glibtop_get_uptime_p (glibtop *server, glibtop_uptime *buf)
+{
+ glibtop_cpu cpu;
+
+ glibtop_init_p (server, (1 << GLIBTOP_SYSDEPS_UPTIME), 0);
+
+ /* Get currect cpu usage. */
+
+ glibtop_get_cpu_p (server, &cpu);
+
+ /* Make sure all required fields are present. */
+
+ if (((cpu.flags & (1 << GLIBTOP_CPU_TOTAL)) == 0) ||
+ ((cpu.flags & (1 << GLIBTOP_CPU_IDLE)) == 0) ||
+ ((cpu.flags & (1 << GLIBTOP_CPU_FREQUENCY)) == 0) ||
+ (cpu.frequency == 0))
+ return;
+
+ /* Simply calculate uptime and idle time from
+ * cpu usage. */
+
+ buf->uptime = (double) cpu.total / (double) cpu.frequency;
+ buf->idletime = (double) cpu.idle / (double) cpu.frequency;
+
+ buf->flags = _glibtop_sysdeps_uptime;
+}