summaryrefslogtreecommitdiff
path: root/sysdeps/solaris
diff options
context:
space:
mode:
authorCarlos Perelló Marín <carlos@gnome.org>2003-10-19 16:55:56 +0000
committerCarlos Perelló Marín <carlos@src.gnome.org>2003-10-19 16:55:56 +0000
commit4c8ae9e25c1940d8876ca3f2330426863cae4737 (patch)
treec43f97bc0647546b0ed87022db0749c137f24edc /sysdeps/solaris
parentbae16b467f90df94d80feae41dceb7e816f16c61 (diff)
downloadlibgtop-4c8ae9e25c1940d8876ca3f2330426863cae4737.tar.gz
Reverted libgtop changes. It's a common module and I should not modify it.
2003-10-19 Carlos Perelló Marín <carlos@gnome.org> * support/*: Reverted libgtop changes. It's a common module and I should not modify it. * Added/removed files. Now the move should be done.
Diffstat (limited to 'sysdeps/solaris')
-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
36 files changed, 3308 insertions, 0 deletions
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;
+}