summaryrefslogtreecommitdiffstats
path: root/ksysguard/ksysguardd/Solaris
diff options
context:
space:
mode:
authortoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
committertoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
commit4aed2c8219774f5d797760606b8489a92ddc5163 (patch)
tree3f8c130f7d269626bf6a9447407ef6c35954426a /ksysguard/ksysguardd/Solaris
downloadtdebase-4aed2c8219774f5d797760606b8489a92ddc5163.tar.gz
tdebase-4aed2c8219774f5d797760606b8489a92ddc5163.zip
Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features.
BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdebase@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'ksysguard/ksysguardd/Solaris')
-rw-r--r--ksysguard/ksysguardd/Solaris/LoadAvg.c120
-rw-r--r--ksysguard/ksysguardd/Solaris/LoadAvg.h41
-rw-r--r--ksysguard/ksysguardd/Solaris/Makefile.am10
-rw-r--r--ksysguard/ksysguardd/Solaris/Memory.c223
-rw-r--r--ksysguard/ksysguardd/Solaris/Memory.h46
-rw-r--r--ksysguard/ksysguardd/Solaris/NetDev.c679
-rw-r--r--ksysguard/ksysguardd/Solaris/NetDev.h59
-rw-r--r--ksysguard/ksysguardd/Solaris/ProcessList.c436
-rw-r--r--ksysguard/ksysguardd/Solaris/ProcessList.h43
9 files changed, 1657 insertions, 0 deletions
diff --git a/ksysguard/ksysguardd/Solaris/LoadAvg.c b/ksysguard/ksysguardd/Solaris/LoadAvg.c
new file mode 100644
index 000000000..aea38a212
--- /dev/null
+++ b/ksysguard/ksysguardd/Solaris/LoadAvg.c
@@ -0,0 +1,120 @@
+/*
+ KSysGuard, the KDE System Guard
+
+ Copyright (c) 1999, 2000 Chris Schlaeger <cs@kde.org>
+
+ Solaris support by Torsten Kasch <tk@Genetik.Uni-Bielefeld.DE>
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of version 2 of the GNU General Public
+ License as published by the Free Software Foundation.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+*/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <sys/stat.h>
+
+#include "config.h"
+
+#ifdef HAVE_KSTAT
+#include <kstat.h>
+#endif
+
+#include "ksysguardd.h"
+#include "Command.h"
+#include "LoadAvg.h"
+
+double loadavg1 = 0.0;
+double loadavg5 = 0.0;
+double loadavg15 = 0.0;
+
+void initLoadAvg( struct SensorModul* sm ) {
+#ifdef HAVE_KSTAT
+ registerMonitor( "cpu/loadavg1", "float",
+ printLoadAvg1, printLoadAvg1Info, sm );
+ registerMonitor( "cpu/loadavg5", "float",
+ printLoadAvg5, printLoadAvg5Info, sm );
+ registerMonitor( "cpu/loadavg15", "float",
+ printLoadAvg15, printLoadAvg15Info, sm );
+#endif
+}
+
+void exitLoadAvg( void ) {
+}
+
+int updateLoadAvg( void ) {
+
+#ifdef HAVE_KSTAT
+ kstat_ctl_t *kctl;
+ kstat_t *ksp;
+ kstat_named_t *kdata;
+
+ /*
+ * get a kstat handle and update the user's kstat chain
+ */
+ if( (kctl = kstat_open()) == NULL )
+ return( 0 );
+ while( kstat_chain_update( kctl ) != 0 )
+ ;
+
+ /*
+ * traverse the kstat chain to find the appropriate statistics
+ */
+ if( (ksp = kstat_lookup( kctl, "unix", 0, "system_misc" )) == NULL )
+ return( 0 );
+ if( kstat_read( kctl, ksp, NULL ) == -1 )
+ return( 0 );
+
+ /*
+ * lookup the data
+ */
+ kdata = (kstat_named_t *) kstat_data_lookup( ksp, "avenrun_1min" );
+ if( kdata != NULL )
+ loadavg1 = LOAD( kdata->value.ui32 );
+ kdata = (kstat_named_t *) kstat_data_lookup( ksp, "avenrun_5min" );
+ if( kdata != NULL )
+ loadavg5 = LOAD( kdata->value.ui32 );
+ kdata = (kstat_named_t *) kstat_data_lookup( ksp, "avenrun_15min" );
+ if( kdata != NULL )
+ loadavg15 = LOAD( kdata->value.ui32 );
+
+ kstat_close( kctl );
+#endif /* ! HAVE_KSTAT */
+
+ return( 0 );
+}
+
+void printLoadAvg1Info( const char *cmd ) {
+ fprintf(CurrentClient, "avnrun 1min\t0\t0\n" );
+}
+
+void printLoadAvg1( const char *cmd ) {
+ fprintf(CurrentClient, "%f\n", loadavg1 );
+}
+
+void printLoadAvg5Info( const char *cmd ) {
+ fprintf(CurrentClient, "avnrun 5min\t0\t0\n" );
+}
+
+void printLoadAvg5( const char *cmd ) {
+ fprintf(CurrentClient, "%f\n", loadavg5 );
+}
+
+void printLoadAvg15Info( const char *cmd ) {
+ fprintf(CurrentClient, "avnrun 15min\t0\t0\n" );
+}
+
+void printLoadAvg15( const char *cmd ) {
+ fprintf(CurrentClient, "%f\n", loadavg15 );
+}
diff --git a/ksysguard/ksysguardd/Solaris/LoadAvg.h b/ksysguard/ksysguardd/Solaris/LoadAvg.h
new file mode 100644
index 000000000..eea8ad82e
--- /dev/null
+++ b/ksysguard/ksysguardd/Solaris/LoadAvg.h
@@ -0,0 +1,41 @@
+/*
+ KSysGuard, the KDE System Guard
+
+ Copyright (c) 1999 Chris Schlaeger <cs@kde.org>
+
+ Solaris support by Torsten Kasch <tk@Genetik.Uni-Bielefeld.DE>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+*/
+
+#ifndef _LoadAvg_h_
+#define _LoadAvg_h_
+
+#define LOAD(a) ((double)(a) / (1 << 8 ))
+
+void initLoadAvg(struct SensorModul* sm);
+void exitLoadAvg(void);
+
+int updateLoadAvg(void);
+
+void printLoadAvg1( const char *cmd );
+void printLoadAvg1Info( const char *cmd );
+void printLoadAvg5( const char *cmd );
+void printLoadAvg5Info( const char *cmd );
+void printLoadAvg15( const char *cmd );
+void printLoadAvg15Info( const char *cmd );
+
+#endif /* _LoadAvg_h_ */
diff --git a/ksysguard/ksysguardd/Solaris/Makefile.am b/ksysguard/ksysguardd/Solaris/Makefile.am
new file mode 100644
index 000000000..f5dd51c96
--- /dev/null
+++ b/ksysguard/ksysguardd/Solaris/Makefile.am
@@ -0,0 +1,10 @@
+#
+#
+
+# Sun's C++ compiler doesn't support -Wall
+#AM_CFLAGS = -Wall
+
+INCLUDES = -I$(srcdir)/../../CContLib -I$(srcdir)/..
+
+noinst_LIBRARIES = libksysguardd.a
+libksysguardd_a_SOURCES = Memory.c LoadAvg.c ProcessList.c NetDev.c
diff --git a/ksysguard/ksysguardd/Solaris/Memory.c b/ksysguard/ksysguardd/Solaris/Memory.c
new file mode 100644
index 000000000..efc2f18ac
--- /dev/null
+++ b/ksysguard/ksysguardd/Solaris/Memory.c
@@ -0,0 +1,223 @@
+/*
+ KSysGuard, the KDE System Guard
+
+ Copyright (c) 1999, 2000 Chris Schlaeger <cs@kde.org>
+
+ Solaris support by Torsten Kasch <tk@Genetik.Uni-Bielefeld.DE>
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of version 2 of the GNU General Public
+ License as published by the Free Software Foundation.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+*/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+#include "config.h"
+
+/* Stop <sys/swap.h> from crapping out on 32-bit architectures. */
+
+#if !defined(_LP64) && _FILE_OFFSET_BITS == 64
+# undef _FILE_OFFSET_BITS
+# define _FILE_OFFSET_BITS 32
+#endif
+
+#include <sys/stat.h>
+#include <sys/swap.h>
+#include <vm/anon.h>
+
+#ifdef HAVE_KSTAT
+#include <kstat.h>
+#endif
+
+#include "ksysguardd.h"
+#include "Command.h"
+#include "Memory.h"
+
+static int Dirty = 1;
+static t_memsize totalmem = (t_memsize) 0;
+static t_memsize freemem = (t_memsize) 0;
+static long totalswap = 0L;
+static long freeswap = 0L;
+static struct anoninfo am_swap;
+
+/*
+ * this is borrowed from top's m_sunos5 module
+ * used by permission from William LeFebvre
+ */
+static int pageshift;
+static long (*p_pagetok) ();
+#define pagetok(size) ((*p_pagetok)(size))
+
+long pagetok_none( long size ) {
+ return( size );
+}
+
+long pagetok_left( long size ) {
+ return( size << pageshift );
+}
+
+long pagetok_right( long size ) {
+ return( size >> pageshift );
+}
+
+void initMemory( struct SensorModul* sm ) {
+
+ long i = sysconf( _SC_PAGESIZE );
+
+ pageshift = 0;
+ while( (i >>= 1) > 0 )
+ pageshift++;
+
+ /* calculate an amount to shift to K values */
+ /* remember that log base 2 of 1024 is 10 (i.e.: 2^10 = 1024) */
+ pageshift -= 10;
+
+ /* now determine which pageshift function is appropriate for the
+ result (have to because x << y is undefined for y < 0) */
+ if( pageshift > 0 ) {
+ /* this is the most likely */
+ p_pagetok = pagetok_left;
+ } else if( pageshift == 0 ) {
+ p_pagetok = pagetok_none;
+ } else {
+ p_pagetok = pagetok_right;
+ pageshift = -pageshift;
+ }
+
+#ifdef HAVE_KSTAT
+ registerMonitor( "mem/physical/free", "integer",
+ printMemFree, printMemFreeInfo, sm );
+ registerMonitor( "mem/physical/used", "integer",
+ printMemUsed, printMemUsedInfo, sm );
+#endif
+ registerMonitor( "mem/swap/free", "integer",
+ printSwapFree, printSwapFreeInfo, sm );
+ registerMonitor( "mem/swap/used", "integer",
+ printSwapUsed, printSwapUsedInfo, sm );
+}
+
+void exitMemory( void ) {
+}
+
+int updateMemory( void ) {
+
+ long swaptotal;
+ long swapfree;
+ long swapused;
+#ifdef HAVE_KSTAT
+ kstat_ctl_t *kctl;
+ kstat_t *ksp;
+ kstat_named_t *kdata;
+#endif /* HAVE_KSTAT */
+ swaptotal = swapused = swapfree = 0L;
+
+ /*
+ * Retrieve overall swap information from anonymous memory structure -
+ * which is the same way "swap -s" retrieves it's statistics.
+ *
+ * swapctl(SC_LIST, void *arg) does not return what we are looking for.
+ */
+
+ if (swapctl(SC_AINFO, &am_swap) == -1)
+ return(0);
+
+ swaptotal = am_swap.ani_max;
+ swapused = am_swap.ani_resv;
+ swapfree = swaptotal - swapused;
+
+ totalswap = pagetok(swaptotal);
+ freeswap = pagetok(swapfree);
+
+#ifdef HAVE_KSTAT
+ /*
+ * get a kstat handle and update the user's kstat chain
+ */
+ if( (kctl = kstat_open()) == NULL )
+ return( 0 );
+ while( kstat_chain_update( kctl ) != 0 )
+ ;
+
+ totalmem = pagetok( sysconf( _SC_PHYS_PAGES ));
+
+ /*
+ * traverse the kstat chain to find the appropriate statistics
+ */
+ if( (ksp = kstat_lookup( kctl, "unix", 0, "system_pages" )) == NULL )
+ return( 0 );
+ if( kstat_read( kctl, ksp, NULL ) == -1 )
+ return( 0 );
+
+ /*
+ * lookup the data
+ */
+ kdata = (kstat_named_t *) kstat_data_lookup( ksp, "freemem" );
+ if( kdata != NULL )
+ freemem = pagetok( kdata->value.ui32 );
+
+ kstat_close( kctl );
+#endif /* ! HAVE_KSTAT */
+
+ Dirty = 0;
+
+ return( 0 );
+}
+
+void printMemFreeInfo( const char *cmd ) {
+ if( Dirty )
+ updateMemory();
+ fprintf(CurrentClient, "Free Memory\t0\t%ld\tKB\n", totalmem );
+}
+
+void printMemFree( const char *cmd ) {
+ if( Dirty )
+ updateMemory();
+ fprintf(CurrentClient, "%ld\n", freemem );
+}
+
+void printMemUsedInfo( const char *cmd ) {
+ if( Dirty )
+ updateMemory();
+ fprintf(CurrentClient, "Used Memory\t0\t%ld\tKB\n", totalmem );
+}
+
+void printMemUsed( const char *cmd ) {
+ if( Dirty )
+ updateMemory();
+ fprintf(CurrentClient, "%ld\n", totalmem - freemem );
+}
+
+void printSwapFreeInfo( const char *cmd ) {
+ if( Dirty )
+ updateMemory();
+ fprintf(CurrentClient, "Free Swap\t0\t%ld\tKB\n", totalswap );
+}
+
+void printSwapFree( const char *cmd ) {
+ if( Dirty )
+ updateMemory();
+ fprintf(CurrentClient, "%ld\n", freeswap );
+}
+
+void printSwapUsedInfo( const char *cmd ) {
+ if( Dirty )
+ updateMemory();
+ fprintf(CurrentClient, "Used Swap\t0\t%ld\tKB\n", totalswap );
+}
+
+void printSwapUsed( const char *cmd ) {
+ if( Dirty )
+ updateMemory();
+ fprintf(CurrentClient, "%ld\n", totalswap - freeswap );
+}
diff --git a/ksysguard/ksysguardd/Solaris/Memory.h b/ksysguard/ksysguardd/Solaris/Memory.h
new file mode 100644
index 000000000..7df6eb033
--- /dev/null
+++ b/ksysguard/ksysguardd/Solaris/Memory.h
@@ -0,0 +1,46 @@
+/*
+ KSysGuard, the KDE System Guard
+
+ Copyright (c) 1999 Chris Schlaeger <cs@kde.org>
+
+ Solaris support by Torsten Kasch <tk@Genetik.Uni-Bielefeld.DE>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+*/
+
+#ifndef _Memory_h_
+#define _Memory_h_
+
+typedef unsigned long t_memsize;
+
+#define PAGETOK(a) ((( (t_memsize) sysconf( _SC_PAGESIZE )) / (t_memsize) 1024) * (t_memsize) (a))
+
+void initMemory(struct SensorModul* sm);
+void exitMemory(void);
+
+int updateMemory(void);
+
+void printMemFree( const char *cmd );
+void printMemFreeInfo( const char *cmd );
+void printMemUsed( const char *cmd );
+void printMemUsedInfo( const char *cmd );
+
+void printSwapFree( const char *cmd );
+void printSwapFreeInfo( const char *cmd );
+void printSwapUsed( const char *cmd );
+void printSwapUsedInfo( const char *cmd );
+
+#endif /* _Memory_h */
diff --git a/ksysguard/ksysguardd/Solaris/NetDev.c b/ksysguard/ksysguardd/Solaris/NetDev.c
new file mode 100644
index 000000000..89db266cb
--- /dev/null
+++ b/ksysguard/ksysguardd/Solaris/NetDev.c
@@ -0,0 +1,679 @@
+/*
+ KSysGuard, the KDE System Guard
+
+ Copyright (c) 1999, 2000 Chris Schlaeger <cs@kde.org>
+
+ Solaris support by Torsten Kasch <tk@Genetik.Uni-Bielefeld.DE>
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of version 2 of the GNU General Public
+ License as published by the Free Software Foundation.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+*/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+#include <errno.h>
+#include <stropts.h>
+#include <ctype.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <sys/sockio.h>
+#include <net/if.h>
+
+#include "config.h"
+
+#ifdef HAVE_KSTAT
+#include <kstat.h>
+#endif
+
+#include "ksysguardd.h"
+#include "Command.h"
+#include "NetDev.h"
+
+/*
+ * available network interface statistics through kstat(3):
+ *
+ * kstat name value
+ * ----------------------------------------------------------------------
+ * for the loopback interface(s) we can get
+ * ipackets # packets received
+ * opackets # packets sent
+ * in addition to those, for "real" interfaces:
+ * oerrors # xmit errors
+ * ierrors # recv errors
+ * macxmt_errors # xmit errors reported by hardware?
+ * macrcv_errors # recv errors reported by hardware?
+ * opackets64 same as opackets (64bit)
+ * ipackets64 same as ipackets (64bit)
+ * obytes # bytes sent
+ * rbytes # bytes received
+ * obytes64 same as obytes (64bit)
+ * rbytes64 same as ibytes (64bit)
+ * collisions # collisions
+ * multixmt # multicasts sent?
+ * multircv # multicasts received?
+ * brdcstxmt # broadcasts transmitted
+ * brdcstrcv # broadcasts received
+ * unknowns
+ * blocked
+ * ex_collisions
+ * defer_xmts
+ * align_errors
+ * fcs_errors
+ * oflo # overflow errors
+ * uflo # underflow errors
+ * runt_errors
+ * missed
+ * tx_late_collisions
+ * carrier_errors
+ * noxmtbuf
+ * norcvbuf
+ * xmt_badinterp
+ * rcv_badinterp
+ * intr # interrupts?
+ * xmtretry # xmit retries?
+ * ifspeed interface speed: 10000000 for 10BaseT
+ * duplex "half" or "full"
+ * media e.g. "PHY/MII"
+ * promisc promiscuous mode (e.g. "off")
+ * first_collisions
+ * multi_collisions
+ * sqe_errors
+ * toolong_errors
+ */
+
+typedef struct {
+ char *Name;
+ short flags;
+ unsigned long ipackets;
+ unsigned long OLDipackets;
+ unsigned long opackets;
+ unsigned long OLDopackets;
+ unsigned long ierrors;
+ unsigned long OLDierrors;
+ unsigned long oerrors;
+ unsigned long OLDoerrors;
+ unsigned long collisions;
+ unsigned long OLDcollisions;
+ unsigned long multixmt;
+ unsigned long OLDmultixmt;
+ unsigned long multircv;
+ unsigned long OLDmultircv;
+ unsigned long brdcstxmt;
+ unsigned long OLDbrdcstxmt;
+ unsigned long brdcstrcv;
+ unsigned long OLDbrdcstrcv;
+} NetDevInfo;
+
+
+#define NBUFFERS 64
+#define MAXNETDEVS 64
+static NetDevInfo IfInfo[MAXNETDEVS];
+
+static int NetDevCount;
+
+/*
+ * insertnetdev() -- insert device name & flags into our list
+ */
+int insertnetdev( const char *name, const short flags ) {
+
+ int i = 0;
+
+ /*
+ * interface "aliases" don't seem to have
+ * separate kstat statistics, so we skip them
+ */
+ if( strchr( name, (int) ':' ) != NULL )
+ return( 0 );
+
+ while( (i < NetDevCount) && (strcmp( IfInfo[i].Name, name ) != 0) ) {
+ if( strcmp( IfInfo[i].Name, name ) == 0 )
+ return( 0 );
+ i++;
+ }
+
+ /*
+ * init new slot
+ */
+ IfInfo[i].Name = strdup( name );
+ IfInfo[i].flags = flags;
+ IfInfo[i].ipackets = 0L;
+ IfInfo[i].OLDipackets = 0L;
+ IfInfo[i].opackets = 0L;
+ IfInfo[i].OLDopackets = 0L;
+ IfInfo[i].ierrors = 0L;
+ IfInfo[i].OLDierrors = 0L;
+ IfInfo[i].oerrors = 0L;
+ IfInfo[i].OLDoerrors = 0L;
+ IfInfo[i].collisions = 0L;
+ IfInfo[i].OLDcollisions = 0L;
+ IfInfo[i].multixmt = 0L;
+ IfInfo[i].OLDmultixmt = 0L;
+ IfInfo[i].multircv = 0L;
+ IfInfo[i].OLDmultircv = 0L;
+ IfInfo[i].brdcstxmt = 0L;
+ IfInfo[i].OLDbrdcstxmt = 0L;
+ IfInfo[i].brdcstrcv = 0L;
+ IfInfo[i].OLDbrdcstrcv = 0L;
+ NetDevCount = ++i;
+
+ /* XXX: need sanity checks! */
+ return( 0 );
+}
+
+/*
+ * getnetdevlist() -- get a list of all "up" interfaces
+ */
+int getnetdevlist( void ) {
+
+ int fd;
+ int buffsize;
+ int prevsize;
+ int prevCount;
+ struct ifconf ifc;
+ struct ifreq *ifr;
+
+ if( (fd = socket( PF_INET, SOCK_DGRAM, 0 )) < 0 ) {
+ return( -1 );
+ }
+
+ /*
+ * get the interface list via iotl( SIOCGIFCONF )
+ * the following algorithm based on ideas from W.R. Stevens'
+ * "UNIX Network Programming", Vol. 1:
+ * Since the ioctl may return 0, indicating success, even if the
+ * ifreq buffer was too small, we have to make sure, it didn't
+ * get truncated by comparing our initial size guess with the
+ * actual returned size.
+ */
+ prevsize = 0;
+ buffsize = NBUFFERS * sizeof( struct ifreq );
+ while( 1 ) {
+ if( (ifc.ifc_buf = malloc( buffsize )) == NULL )
+ return( -1 );
+
+ ifc.ifc_len = buffsize;
+ if( ioctl( fd, SIOCGIFCONF, &ifc ) < 0 ) {
+ if( errno != EINVAL || prevsize != 0 ) {
+ free( ifc.ifc_buf );
+ return( -1 );
+ }
+ } else {
+ if( ifc.ifc_len == prevsize )
+ /* success */
+ break;
+ prevsize = ifc.ifc_len;
+ }
+ /*
+ * initial buffer guessed too small, allocate a bigger one
+ */
+ free( ifc.ifc_buf );
+ buffsize = (NBUFFERS + 10) * sizeof( struct ifreq );
+ }
+
+ /*
+ * get the names for all interfaces which are configured "up"
+ * we're not interested in the ifc data (address), so we reuse the
+ * same structure (with ifc.len set) for the next ioctl()
+ */
+ prevCount = NetDevCount;
+ for( ifr = (struct ifreq *) ifc.ifc_buf;
+ ifr < (struct ifreq *) (ifc.ifc_buf + ifc.ifc_len);
+ ifr++ ) {
+ if( ioctl( fd, SIOCGIFFLAGS, ifr ) < 0 ) {
+ free( ifc.ifc_buf );
+ return( -1 );
+ }
+ if( ifr->ifr_flags & IFF_UP )
+ insertnetdev( ifr->ifr_name, ifr->ifr_flags );
+ }
+ free( ifc.ifc_buf );
+ close( fd );
+
+ if( (prevCount > 0) && (prevCount != NetDevCount) ) {
+ print_error( "RECONFIGURE\n" );
+ prevCount = NetDevCount;
+ }
+
+ return( NetDevCount );
+}
+
+void initNetDev( struct SensorModul* sm ) {
+#ifdef HAVE_KSTAT
+ char mon[128];
+ int i;
+
+ getnetdevlist();
+ for( i = 0; i < NetDevCount; i++ ) {
+ sprintf( mon, "network/%s/ipackets", IfInfo[i].Name );
+ registerMonitor( mon, "integer",
+ printIPackets, printIPacketsInfo, sm );
+ sprintf( mon, "network/%s/opackets", IfInfo[i].Name );
+ registerMonitor( mon, "integer",
+ printOPackets, printOPacketsInfo, sm );
+ /*
+ * if this isn't a loopback interface,
+ * register additional monitors
+ */
+ if( ! (IfInfo[i].flags & IFF_LOOPBACK) ) {
+ /*
+ * recv errors
+ */
+ sprintf( mon, "network/%s/ierrors",
+ IfInfo[i].Name );
+ registerMonitor( mon, "integer",
+ printIErrors, printIErrorsInfo, sm );
+ /*
+ * xmit errors
+ */
+ sprintf( mon, "network/%s/oerrors",
+ IfInfo[i].Name );
+ registerMonitor( mon, "integer",
+ printOErrors, printOErrorsInfo, sm );
+ /*
+ * collisions
+ */
+ sprintf( mon, "network/%s/collisions",
+ IfInfo[i].Name );
+ registerMonitor( mon, "integer",
+ printCollisions, printCollisionsInfo, sm );
+ /*
+ * multicast xmits
+ */
+ sprintf( mon, "network/%s/multixmt",
+ IfInfo[i].Name );
+ registerMonitor( mon, "integer",
+ printMultiXmits, printMultiXmitsInfo, sm );
+ /*
+ * multicast recvs
+ */
+ sprintf( mon, "network/%s/multircv",
+ IfInfo[i].Name );
+ registerMonitor( mon, "integer",
+ printMultiRecvs, printMultiRecvsInfo, sm );
+ /*
+ * broadcast xmits
+ */
+ sprintf( mon, "network/%s/brdcstxmt",
+ IfInfo[i].Name );
+ registerMonitor( mon, "integer",
+ printBcastXmits, printBcastXmitsInfo, sm );
+ /*
+ * broadcast recvs
+ */
+ sprintf( mon, "network/%s/brdcstrcv",
+ IfInfo[i].Name );
+ registerMonitor( mon, "integer",
+ printBcastRecvs, printBcastRecvsInfo, sm );
+ }
+ }
+#endif
+}
+
+void exitNetDev( void ) {
+}
+
+int updateNetDev( void ) {
+
+#ifdef HAVE_KSTAT
+ kstat_ctl_t *kctl;
+ kstat_t *ksp;
+ kstat_named_t *kdata;
+ int i;
+
+ /*
+ * get a kstat handle and update the user's kstat chain
+ */
+ if( (kctl = kstat_open()) == NULL )
+ return( 0 );
+ while( kstat_chain_update( kctl ) != 0 )
+ ;
+
+ for( i = 0; i < NetDevCount; i++ ) {
+ char *name;
+ char *ptr;
+
+ /*
+ * chop off the trailing interface no
+ */
+ name = strdup( IfInfo[i].Name );
+ ptr = name + strlen( name ) - 1;
+ while( (ptr > name) && isdigit( (int) *ptr ) ) {
+ *ptr = '\0';
+ ptr--;
+ }
+
+ /*
+ * traverse the kstat chain
+ * to find the appropriate statistics
+ */
+ if( (ksp = kstat_lookup( kctl,
+ name, 0, IfInfo[i].Name )) == NULL ) {
+ free( name );
+ return( 0 );
+ }
+ if( kstat_read( kctl, ksp, NULL ) == -1 ) {
+ free( name );
+ return( 0 );
+ }
+ free( name );
+
+ /*
+ * lookup & store the data
+ */
+ kdata = (kstat_named_t *) kstat_data_lookup( ksp, "ipackets" );
+ if( kdata != NULL ) {
+ IfInfo[i].OLDipackets = IfInfo[i].ipackets;
+ IfInfo[i].ipackets = kdata->value.ul;
+ }
+ kdata = (kstat_named_t *) kstat_data_lookup( ksp, "opackets" );
+ if( kdata != NULL ) {
+ IfInfo[i].OLDopackets = IfInfo[i].opackets;
+ IfInfo[i].opackets = kdata->value.ul;
+ }
+ kdata = (kstat_named_t *) kstat_data_lookup( ksp, "ierrors" );
+ if( kdata != NULL ) {
+ IfInfo[i].OLDierrors = IfInfo[i].ierrors;
+ IfInfo[i].ierrors = kdata->value.ul;
+ }
+ kdata = (kstat_named_t *) kstat_data_lookup( ksp, "oerrors" );
+ if( kdata != NULL ) {
+ IfInfo[i].OLDoerrors = IfInfo[i].oerrors;
+ IfInfo[i].oerrors = kdata->value.ul;
+ }
+ kdata = (kstat_named_t *) kstat_data_lookup( ksp, "collisions" );
+ if( kdata != NULL ) {
+ IfInfo[i].OLDcollisions = IfInfo[i].collisions;
+ IfInfo[i].collisions = kdata->value.ul;
+ }
+ kdata = (kstat_named_t *) kstat_data_lookup( ksp, "multixmt" );
+ if( kdata != NULL ) {
+ IfInfo[i].OLDmultixmt = IfInfo[i].multixmt;
+ IfInfo[i].multixmt = kdata->value.ul;
+ }
+ kdata = (kstat_named_t *) kstat_data_lookup( ksp, "multircv" );
+ if( kdata != NULL ) {
+ IfInfo[i].OLDmultircv = IfInfo[i].multircv;
+ IfInfo[i].multircv = kdata->value.ul;
+ }
+ kdata = (kstat_named_t *) kstat_data_lookup( ksp, "brdcstxmt" );
+ if( kdata != NULL ) {
+ IfInfo[i].OLDbrdcstxmt = IfInfo[i].brdcstxmt;
+ IfInfo[i].brdcstxmt = kdata->value.ul;
+ }
+ kdata = (kstat_named_t *) kstat_data_lookup( ksp, "brdcstrcv" );
+ if( kdata != NULL ) {
+ IfInfo[i].OLDbrdcstrcv = IfInfo[i].brdcstrcv;
+ IfInfo[i].brdcstrcv = kdata->value.ul;
+ }
+ }
+
+ kstat_close( kctl );
+#endif /* ! HAVE_KSTAT */
+
+ return( 0 );
+}
+
+void printIPacketsInfo( const char *cmd ) {
+ fprintf(CurrentClient, "Received Packets\t0\t0\tPackets\n" );
+}
+
+void printIPackets( const char *cmd ) {
+
+ char *cmdcopy = strdup( cmd );
+ char *name, *ptr;
+ int i;
+
+ ptr = strchr( cmdcopy, (int) '/' );
+ name = ++ptr;
+ ptr = strchr( name, (int) '/' );
+ *ptr = '\0';
+
+ for( i = 0; i < NetDevCount; i++ ) {
+ if( (IfInfo[i].OLDipackets > 0)
+ && (strcmp( IfInfo[i].Name, name ) == 0) ) {
+ fprintf(CurrentClient, "%ld\n",
+ IfInfo[i].ipackets - IfInfo[i].OLDipackets);
+ free( cmdcopy );
+ return;
+ }
+ }
+ free( cmdcopy );
+ fprintf(CurrentClient, "0\n" );
+}
+
+void printOPacketsInfo( const char *cmd ) {
+ fprintf(CurrentClient, "Transmitted Packets\t0\t0\tPackets\n" );
+}
+
+void printOPackets( const char *cmd ) {
+
+ char *cmdcopy = strdup( cmd );
+ char *name, *ptr;
+ int i;
+
+ ptr = strchr( cmdcopy, (int) '/' );
+ name = ++ptr;
+ ptr = strchr( name, (int) '/' );
+ *ptr = '\0';
+
+ for( i = 0; i < NetDevCount; i++ ) {
+ if( (IfInfo[i].OLDopackets > 0)
+ && (strcmp( IfInfo[i].Name, name ) == 0) ) {
+ fprintf(CurrentClient, "%ld\n",
+ IfInfo[i].opackets - IfInfo[i].OLDopackets );
+ free( cmdcopy );
+ return;
+ }
+ }
+ free( cmdcopy );
+ fprintf(CurrentClient, "0\n" );
+}
+
+void printIErrorsInfo( const char *cmd ) {
+ fprintf(CurrentClient, "Input Errors\t0\t0\tPackets\n" );
+}
+
+void printIErrors( const char *cmd ) {
+
+ char *cmdcopy = strdup( cmd );
+ char *name, *ptr;
+ int i;
+
+ ptr = strchr( cmdcopy, (int) '/' );
+ name = ++ptr;
+ ptr = strchr( name, (int) '/' );
+ *ptr = '\0';
+
+ for( i = 0; i < NetDevCount; i++ ) {
+ if( (IfInfo[i].OLDierrors > 0)
+ && (strcmp( IfInfo[i].Name, name ) == 0) ) {
+ fprintf(CurrentClient, "%ld\n",
+ IfInfo[i].ierrors - IfInfo[i].OLDierrors );
+ free( cmdcopy );
+ return;
+ }
+ }
+ free( cmdcopy );
+ fprintf(CurrentClient, "0\n" );
+}
+
+void printOErrorsInfo( const char *cmd ) {
+ fprintf(CurrentClient, "Output Errors\t0\t0\tPackets\n" );
+}
+
+void printOErrors( const char *cmd ) {
+
+ char *cmdcopy = strdup( cmd );
+ char *name, *ptr;
+ int i;
+
+ ptr = strchr( cmdcopy, (int) '/' );
+ name = ++ptr;
+ ptr = strchr( name, (int) '/' );
+ *ptr = '\0';
+
+ for( i = 0; i < NetDevCount; i++ ) {
+ if( (IfInfo[i].OLDoerrors > 0)
+ && (strcmp( IfInfo[i].Name, name ) == 0) ) {
+ fprintf(CurrentClient, "%ld\n",
+ IfInfo[i].oerrors - IfInfo[i].OLDoerrors );
+ free( cmdcopy );
+ return;
+ }
+ }
+ free( cmdcopy );
+ fprintf(CurrentClient, "0\n" );
+}
+
+void printCollisionsInfo( const char *cmd ) {
+ fprintf(CurrentClient, "Collisions\t0\t0\tPackets\n" );
+}
+
+void printCollisions( const char *cmd ) {
+
+ char *cmdcopy = strdup( cmd );
+ char *name, *ptr;
+ int i;
+
+ ptr = strchr( cmdcopy, (int) '/' );
+ name = ++ptr;
+ ptr = strchr( name, (int) '/' );
+ *ptr = '\0';
+
+ for( i = 0; i < NetDevCount; i++ ) {
+ if( (IfInfo[i].OLDcollisions > 0)
+ && (strcmp( IfInfo[i].Name, name ) == 0) ) {
+ fprintf(CurrentClient, "%ld\n",
+ IfInfo[i].collisions - IfInfo[i].OLDcollisions );
+ free( cmdcopy );
+ return;
+ }
+ }
+ free( cmdcopy );
+ fprintf(CurrentClient, "0\n" );
+}
+
+void printMultiXmitsInfo( const char *cmd ) {
+ fprintf(CurrentClient, "Multicasts Sent\t0\t0\tPackets\n" );
+}
+
+void printMultiXmits( const char *cmd ) {
+
+ char *cmdcopy = strdup( cmd );
+ char *name, *ptr;
+ int i;
+
+ ptr = strchr( cmdcopy, (int) '/' );
+ name = ++ptr;
+ ptr = strchr( name, (int) '/' );
+ *ptr = '\0';
+
+ for( i = 0; i < NetDevCount; i++ ) {
+ if( (IfInfo[i].OLDmultixmt > 0)
+ && (strcmp( IfInfo[i].Name, name ) == 0) ) {
+ fprintf(CurrentClient, "%ld\n",
+ IfInfo[i].multixmt - IfInfo[i].OLDmultixmt );
+ free( cmdcopy );
+ return;
+ }
+ }
+ free( cmdcopy );
+ fprintf(CurrentClient, "0\n" );
+}
+
+void printMultiRecvsInfo( const char *cmd ) {
+ fprintf(CurrentClient, "Multicasts Received\t0\t0\tPackets\n" );
+}
+
+void printMultiRecvs( const char *cmd ) {
+
+ char *cmdcopy = strdup( cmd );
+ char *name, *ptr;
+ int i;
+
+ ptr = strchr( cmdcopy, (int) '/' );
+ name = ++ptr;
+ ptr = strchr( name, (int) '/' );
+ *ptr = '\0';
+
+ for( i = 0; i < NetDevCount; i++ ) {
+ if( (IfInfo[i].OLDmultircv > 0)
+ && (strcmp( IfInfo[i].Name, name ) == 0) ) {
+ fprintf(CurrentClient, "%ld\n",
+ IfInfo[i].multircv - IfInfo[i].OLDmultircv );
+ free( cmdcopy );
+ return;
+ }
+ }
+ free( cmdcopy );
+ fprintf(CurrentClient, "0\n" );
+}
+
+void printBcastXmitsInfo( const char *cmd ) {
+ fprintf(CurrentClient, "Broadcasts Sent\t0\t0\tPackets\n" );
+}
+
+void printBcastXmits( const char *cmd ) {
+
+ char *cmdcopy = strdup( cmd );
+ char *name, *ptr;
+ int i;
+
+ ptr = strchr( cmdcopy, (int) '/' );
+ name = ++ptr;
+ ptr = strchr( name, (int) '/' );
+ *ptr = '\0';
+
+ for( i = 0; i < NetDevCount; i++ ) {
+ if( (IfInfo[i].OLDbrdcstxmt > 0)
+ && (strcmp( IfInfo[i].Name, name ) == 0) ) {
+ fprintf(CurrentClient, "%ld\n",
+ IfInfo[i].brdcstxmt - IfInfo[i].OLDbrdcstxmt );
+ free( cmdcopy );
+ return;
+ }
+ }
+ free( cmdcopy );
+ fprintf(CurrentClient, "0\n" );
+}
+
+void printBcastRecvsInfo( const char *cmd ) {
+ fprintf(CurrentClient, "Broadcasts Received\t0\t0\tPackets\n" );
+}
+
+void printBcastRecvs( const char *cmd ) {
+
+ char *cmdcopy = strdup( cmd );
+ char *name, *ptr;
+ int i;
+
+ ptr = strchr( cmdcopy, (int) '/' );
+ name = ++ptr;
+ ptr = strchr( name, (int) '/' );
+ *ptr = '\0';
+
+ for( i = 0; i < NetDevCount; i++ ) {
+ if( (IfInfo[i].OLDbrdcstrcv > 0)
+ && (strcmp( IfInfo[i].Name, name ) == 0) ) {
+ fprintf(CurrentClient, "%ld\n",
+ IfInfo[i].brdcstrcv - IfInfo[i].OLDbrdcstrcv );
+ free( cmdcopy );
+ return;
+ }
+ }
+ free( cmdcopy );
+ fprintf(CurrentClient, "0\n" );
+}
diff --git a/ksysguard/ksysguardd/Solaris/NetDev.h b/ksysguard/ksysguardd/Solaris/NetDev.h
new file mode 100644
index 000000000..b6ff54448
--- /dev/null
+++ b/ksysguard/ksysguardd/Solaris/NetDev.h
@@ -0,0 +1,59 @@
+/*
+ KSysGuard, the KDE System Guard
+
+ Copyright (c) 1999 Chris Schlaeger <cs@kde.org>
+
+ Solaris support by Torsten Kasch <tk@Genetik.Uni-Bielefeld.DE>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+*/
+
+#ifndef _NetDev_h_
+#define _NetDev_h_
+
+void initNetDev(struct SensorModul* sm);
+void exitNetDev(void);
+
+int updateNetDev(void);
+
+void printIPacketsInfo( const char *cmd );
+void printIPackets( const char *cmd );
+
+void printOPacketsInfo( const char *cmd );
+void printOPackets( const char *cmd );
+
+void printIErrorsInfo( const char *cmd );
+void printIErrors( const char *cmd );
+
+void printOErrorsInfo( const char *cmd );
+void printOErrors( const char *cmd );
+
+void printCollisionsInfo( const char *cmd );
+void printCollisions( const char *cmd );
+
+void printMultiXmitsInfo( const char *cmd );
+void printMultiXmits( const char *cmd );
+
+void printMultiRecvsInfo( const char *cmd );
+void printMultiRecvs( const char *cmd );
+
+void printBcastXmitsInfo( const char *cmd );
+void printBcastXmits( const char *cmd );
+
+void printBcastRecvsInfo( const char *cmd );
+void printBcastRecvs( const char *cmd );
+
+#endif /* _NetDev_h */
diff --git a/ksysguard/ksysguardd/Solaris/ProcessList.c b/ksysguard/ksysguardd/Solaris/ProcessList.c
new file mode 100644
index 000000000..771371b76
--- /dev/null
+++ b/ksysguard/ksysguardd/Solaris/ProcessList.c
@@ -0,0 +1,436 @@
+/*
+ KSysGuard, the KDE System Guard
+
+ Copyright (c) 1999, 2000 Chris Schlaeger <cs@kde.org>
+
+ Solaris support by Torsten Kasch <tk@Genetik.Uni-Bielefeld.DE>
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of version 2 of the GNU General Public
+ License as published by the Free Software Foundation.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+*/
+
+/* Stop <sys/procfs.h> from crapping out on 32-bit architectures. */
+
+#if !defined(_LP64) && _FILE_OFFSET_BITS == 64
+# undef _FILE_OFFSET_BITS
+# define _FILE_OFFSET_BITS 32
+#endif
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <signal.h>
+#include <sys/types.h>
+#include <dirent.h>
+#include <pwd.h>
+#include <procfs.h>
+#include <sys/proc.h>
+#include <sys/resource.h>
+
+#include "ccont.h"
+#include "../../gui/SignalIDs.h"
+#include "ksysguardd.h"
+
+#include "Command.h"
+#include "ProcessList.h"
+
+#define BUFSIZE 1024
+
+typedef struct {
+ int alive; /* for "garbage collection" */
+ pid_t pid; /* process ID */
+ pid_t ppid; /* parent process ID */
+ uid_t uid; /* process owner (real UID) */
+ gid_t gid; /* process group (real GID) */
+ char *userName; /* process owner (name) */
+ int nThreads; /* # of threads in this process */
+ int Prio; /* scheduling priority */
+ size_t Size; /* total size of process image */
+ size_t RSSize; /* resident set size */
+ char *State; /* process state */
+ int Time; /* CPU time for the process */
+ double Load; /* CPU load in % */
+ char *Command; /* command name */
+ char *CmdLine; /* command line */
+} ProcessInfo;
+
+static CONTAINER ProcessList = 0;
+static unsigned ProcessCount = 0; /* # of processes */
+static DIR *procdir; /* handle for /proc */
+
+/*
+ * lwpStateName() -- return string representation of process state
+ */
+char *lwpStateName( lwpsinfo_t lwpinfo ) {
+
+ char result[8];
+ int processor;
+
+ switch( (int) lwpinfo.pr_state ) {
+ case SSLEEP:
+ sprintf( result, "%s", "sleep" );
+ break;
+ case SRUN:
+ sprintf( result, "%s", "run" );
+ break;
+ case SZOMB:
+ sprintf( result, "%s", "zombie" );
+ break;
+ case SSTOP:
+ sprintf( result, "%s", "stop" );
+ break;
+ case SIDL:
+ sprintf( result, "%s", "start" );
+ break;
+ case SONPROC:
+ processor = (int) lwpinfo.pr_onpro;
+ sprintf( result, "%s/%d", "cpu", processor );
+ break;
+ default:
+ sprintf( result, "%s", "???" );
+ break;
+ }
+
+ return( strdup( result ));
+}
+
+static void validateStr( char *string ) {
+
+ char *ptr = string;
+
+ /*
+ * remove all chars that might screw up communication
+ */
+ while( *ptr != '\0' ) {
+ if( *ptr == '\t' || *ptr == '\n' || *ptr == '\r' )
+ *ptr = ' ';
+ ptr++;
+ }
+ /*
+ * make sure there's at least one char
+ */
+ if( string[0] == '\0' )
+ strcpy( string, " " );
+}
+
+static int processCmp( void *p1, void *p2 ) {
+
+ return( ((ProcessInfo *) p1)->pid - ((ProcessInfo *) p2)->pid );
+}
+
+static ProcessInfo *findProcessInList( pid_t pid ) {
+
+ ProcessInfo key;
+ long index;
+
+ key.pid = pid;
+ if( (index = search_ctnr( ProcessList, processCmp, &key )) < 0 )
+ return( NULL );
+
+ return( get_ctnr( ProcessList, index ));
+}
+
+static int updateProcess( pid_t pid ) {
+
+ ProcessInfo *ps;
+ int fd;
+ char buf[BUFSIZE];
+ psinfo_t psinfo;
+ struct passwd *pw;
+
+ if( (ps = findProcessInList( pid )) == NULL ) {
+ if( (ps = (ProcessInfo *) malloc( sizeof( ProcessInfo )))
+ == NULL ) {
+ print_error( "cannot malloc()\n" );
+ return( -1 );
+ }
+ ps->pid = pid;
+ ps->userName = NULL;
+ ps->State = NULL;
+ ps->Command = NULL;
+ ps->CmdLine = NULL;
+ ps->alive = 0;
+
+ push_ctnr( ProcessList, ps );
+ bsort_ctnr( ProcessList, processCmp );
+ }
+
+ snprintf( buf, BUFSIZE - 1, "%s/%ld/psinfo", PROCDIR, pid );
+ if( (fd = open( buf, O_RDONLY )) < 0 ) {
+ return( -1 );
+ }
+
+ if( read( fd, &psinfo, sizeof( psinfo_t )) != sizeof( psinfo_t )) {
+ close( fd );
+ return( -1 );
+ }
+ close( fd );
+
+ ps->ppid = psinfo.pr_ppid;
+ ps->uid = psinfo.pr_uid;
+ ps->gid = psinfo.pr_gid;
+
+ pw = getpwuid( psinfo.pr_uid );
+ if( ps->userName != NULL )
+ free( ps->userName );
+ ps->userName = strdup( pw->pw_name );
+
+ if( ps->State != NULL )
+ free( ps->State );
+ ps->State = lwpStateName( psinfo.pr_lwp );
+
+ /*
+ * the following data is invalid for zombies, so...
+ */
+ if( (ps->nThreads = psinfo.pr_nlwp ) != 0 ) {
+ ps->Prio = psinfo.pr_lwp.pr_pri;
+ ps->Time = psinfo.pr_lwp.pr_time.tv_sec * 100
+ + psinfo.pr_lwp.pr_time.tv_nsec * 10000000;
+ ps->Load = (double) psinfo.pr_lwp.pr_pctcpu
+ / (double) 0x8000 * 100.0;
+ } else {
+ ps->Prio = 0;
+ ps->Time = 0;
+ ps->Load = 0.0;
+ }
+
+ ps->Size = psinfo.pr_size;
+ ps->RSSize = psinfo.pr_rssize;
+
+ if( ps->Command != NULL )
+ free( ps->Command );
+ ps->Command = strdup( psinfo.pr_fname );
+ if( ps->CmdLine != NULL )
+ free( ps->CmdLine );
+ ps->CmdLine = strdup( psinfo.pr_psargs );
+
+ validateStr( ps->Command );
+ validateStr( ps->CmdLine );
+
+ ps->alive = 1;
+
+ return( 0 );
+}
+
+static void cleanupProcessList( void ) {
+
+ ProcessInfo *ps;
+
+ ProcessCount = 0;
+ for( ps = first_ctnr( ProcessList ); ps; ps = next_ctnr( ProcessList )) {
+ if( ps->alive ) {
+ ps->alive = 0;
+ ProcessCount++;
+ } else {
+ free( remove_ctnr( ProcessList ));
+ }
+ }
+}
+
+void initProcessList( struct SensorModul* sm ) {
+
+ if( (procdir = opendir( PROCDIR )) == NULL ) {
+ print_error( "cannot open \"%s\" for reading\n", PROCDIR );
+ return;
+ }
+
+ ProcessList = new_ctnr();
+
+ /*
+ * register the supported monitors & commands
+ */
+ registerMonitor( "pscount", "integer",
+ printProcessCount, printProcessCountInfo, sm );
+ registerMonitor( "ps", "table",
+ printProcessList, printProcessListInfo, sm );
+
+ registerCommand( "kill", killProcess );
+ registerCommand( "setpriority", setPriority );
+}
+
+void exitProcessList( void ) {
+
+ destr_ctnr( ProcessList, free );
+}
+
+int updateProcessList( void ) {
+
+ struct dirent *de;
+
+ rewinddir( procdir );
+ while( (de = readdir( procdir )) != NULL ) {
+ /*
+ * skip '.' and '..'
+ */
+ if( de->d_name[0] == '.' )
+ continue;
+
+ /*
+ * fetch the process info and insert it into the info table
+ */
+ updateProcess( (pid_t) atol( de->d_name ));
+ }
+ cleanupProcessList();
+
+ return( 0 );
+}
+
+void printProcessListInfo( const char *cmd ) {
+ fprintf(CurrentClient, "Name\tPID\tPPID\tGID\tStatus\tUser\tThreads"
+ "\tSize\tResident\t%% CPU\tPriority\tCommand\n" );
+ fprintf(CurrentClient, "s\td\td\td\ts\ts\td\tD\tD\tf\td\ts\n" );
+}
+
+void printProcessList( const char *cmd ) {
+
+ ProcessInfo *ps;
+
+ for( ps = first_ctnr( ProcessList ); ps; ps = next_ctnr( ProcessList )) {
+ fprintf(CurrentClient,
+ "%s\t%ld\t%ld\t%ld\t%s\t%s\t%d\t%d\t%d\t%.2f\t%d\t%s\n",
+ ps->Command,
+ (long) ps->pid,
+ (long) ps->ppid,
+ (long) ps->gid,
+ ps->State,
+ ps->userName,
+ ps->nThreads,
+ ps->Size,
+ ps->RSSize,
+ ps->Load,
+ ps->Prio,
+ ps->CmdLine);
+ }
+
+ fprintf(CurrentClient, "\n");
+}
+
+void printProcessCount( const char *cmd ) {
+ fprintf(CurrentClient, "%d\n", ProcessCount );
+}
+
+void printProcessCountInfo( const char *cmd ) {
+ fprintf(CurrentClient, "Number of Processes\t0\t0\t\n" );
+}
+
+void killProcess( const char *cmd ) {
+
+ int sig, pid;
+
+ sscanf( cmd, "%*s %d %d", &pid, &sig );
+
+ switch( sig ) {
+ case MENU_ID_SIGABRT:
+ sig = SIGABRT;
+ break;
+ case MENU_ID_SIGALRM:
+ sig = SIGALRM;
+ break;
+ case MENU_ID_SIGCHLD:
+ sig = SIGCHLD;
+ break;
+ case MENU_ID_SIGCONT:
+ sig = SIGCONT;
+ break;
+ case MENU_ID_SIGFPE:
+ sig = SIGFPE;
+ break;
+ case MENU_ID_SIGHUP:
+ sig = SIGHUP;
+ break;
+ case MENU_ID_SIGILL:
+ sig = SIGILL;
+ break;
+ case MENU_ID_SIGINT:
+ sig = SIGINT;
+ break;
+ case MENU_ID_SIGKILL:
+ sig = SIGKILL;
+ break;
+ case MENU_ID_SIGPIPE:
+ sig = SIGPIPE;
+ break;
+ case MENU_ID_SIGQUIT:
+ sig = SIGQUIT;
+ break;
+ case MENU_ID_SIGSEGV:
+ sig = SIGSEGV;
+ break;
+ case MENU_ID_SIGSTOP:
+ sig = SIGSTOP;
+ break;
+ case MENU_ID_SIGTERM:
+ sig = SIGTERM;
+ break;
+ case MENU_ID_SIGTSTP:
+ sig = SIGTSTP;
+ break;
+ case MENU_ID_SIGTTIN:
+ sig = SIGTTIN;
+ break;
+ case MENU_ID_SIGTTOU:
+ sig = SIGTTOU;
+ break;
+ case MENU_ID_SIGUSR1:
+ sig = SIGUSR1;
+ break;
+ case MENU_ID_SIGUSR2:
+ sig = SIGUSR2;
+ break;
+ }
+ if( kill( (pid_t) pid, sig )) {
+ switch( errno ) {
+ case EINVAL:
+ fprintf(CurrentClient, "4\n" );
+ break;
+ case ESRCH:
+ fprintf(CurrentClient, "3\n" );
+ break;
+ case EPERM:
+ fprintf(CurrentClient, "2\n" );
+ break;
+ default:
+ fprintf(CurrentClient, "1\n" ); /* unknown error */
+ break;
+ }
+ } else
+ fprintf(CurrentClient, "0\n");
+}
+
+void setPriority( const char *cmd ) {
+ int pid, prio;
+
+ sscanf( cmd, "%*s %d %d", &pid, &prio );
+ if( setpriority( PRIO_PROCESS, pid, prio )) {
+ switch( errno ) {
+ case EINVAL:
+ fprintf(CurrentClient, "4\n" );
+ break;
+ case ESRCH:
+ fprintf(CurrentClient, "3\n" );
+ break;
+ case EPERM:
+ case EACCES:
+ fprintf(CurrentClient, "2\n" );
+ break;
+ default:
+ fprintf(CurrentClient, "1\n" ); /* unknown error */
+ break;
+ }
+ } else
+ fprintf(CurrentClient, "0\n");
+}
diff --git a/ksysguard/ksysguardd/Solaris/ProcessList.h b/ksysguard/ksysguardd/Solaris/ProcessList.h
new file mode 100644
index 000000000..90333f5b8
--- /dev/null
+++ b/ksysguard/ksysguardd/Solaris/ProcessList.h
@@ -0,0 +1,43 @@
+/*
+ KSysGuard, the KDE System Guard
+
+ Copyright (c) 1999 Chris Schlaeger <cs@kde.org>
+
+ Solaris support by Torsten Kasch <tk@Genetik.Uni-Bielefeld.DE>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+*/
+
+#ifndef _ProcessList_H_
+#define _ProcessList_H_
+
+#define PROCDIR "/proc"
+
+void initProcessList(struct SensorModul* sm);
+void exitProcessList(void);
+
+int updateProcessList(void);
+
+void printProcessList(const char*);
+void printProcessListInfo(const char*);
+
+void printProcessCount(const char* cmd);
+void printProcessCountInfo(const char* cmd);
+
+void killProcess(const char* cmd);
+void setPriority(const char* cmd);
+
+#endif