summaryrefslogtreecommitdiffstats
path: root/ksysguard/ksysguardd/NetBSD
diff options
context:
space:
mode:
Diffstat (limited to 'ksysguard/ksysguardd/NetBSD')
-rw-r--r--ksysguard/ksysguardd/NetBSD/CPU.c206
-rw-r--r--ksysguard/ksysguardd/NetBSD/CPU.h49
-rw-r--r--ksysguard/ksysguardd/NetBSD/Makefile.am8
-rw-r--r--ksysguard/ksysguardd/NetBSD/Memory.c202
-rw-r--r--ksysguard/ksysguardd/NetBSD/Memory.h43
-rw-r--r--ksysguard/ksysguardd/NetBSD/ProcessList.c457
-rw-r--r--ksysguard/ksysguardd/NetBSD/ProcessList.h38
-rw-r--r--ksysguard/ksysguardd/NetBSD/apm.c100
-rw-r--r--ksysguard/ksysguardd/NetBSD/apm.h34
-rw-r--r--ksysguard/ksysguardd/NetBSD/diskstat.c249
-rw-r--r--ksysguard/ksysguardd/NetBSD/diskstat.h40
-rw-r--r--ksysguard/ksysguardd/NetBSD/loadavg.c96
-rw-r--r--ksysguard/ksysguardd/NetBSD/loadavg.h36
-rw-r--r--ksysguard/ksysguardd/NetBSD/logfile.c175
-rw-r--r--ksysguard/ksysguardd/NetBSD/logfile.h36
-rw-r--r--ksysguard/ksysguardd/NetBSD/netdev.c304
-rw-r--r--ksysguard/ksysguardd/NetBSD/netdev.h35
17 files changed, 2108 insertions, 0 deletions
diff --git a/ksysguard/ksysguardd/NetBSD/CPU.c b/ksysguard/ksysguardd/NetBSD/CPU.c
new file mode 100644
index 000000000..959924087
--- /dev/null
+++ b/ksysguard/ksysguardd/NetBSD/CPU.c
@@ -0,0 +1,206 @@
+/*
+ KSysGuard, the KDE System Guard
+
+ Copyright (c) 1999 Chris Schlaeger <cs@kde.org>
+
+ 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.
+
+*/
+
+#include <sys/dkstat.h>
+#include <sys/sched.h> /* CPUSTATES */
+#include <fcntl.h>
+#include <kvm.h>
+#include <nlist.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/types.h>
+
+#include "CPU.h"
+#include "Command.h"
+#include "ksysguardd.h"
+
+long percentages(int cnt, int *out, long *new, long *old, long *diffs);
+
+struct nlist my_nlist[] = {
+ {"_cp_time"},
+ { 0 }
+};
+
+kvm_t *kd;
+
+unsigned long cp_time_offset;
+
+long cp_time[CPUSTATES];
+long cp_old[CPUSTATES];
+long cp_diff[CPUSTATES];
+int cpu_states[CPUSTATES];
+
+void
+initCpuInfo(struct SensorModul* sm)
+{
+ /* Total CPU load */
+ registerMonitor("cpu/user", "integer", printCPUUser,
+ printCPUUserInfo, sm);
+ registerMonitor("cpu/nice", "integer", printCPUNice,
+ printCPUNiceInfo, sm);
+ registerMonitor("cpu/sys", "integer", printCPUSys,
+ printCPUSysInfo, sm);
+ registerMonitor("cpu/idle", "integer", printCPUIdle,
+ printCPUIdleInfo, sm);
+ kd = kvm_open(NULL, NULL, NULL, O_RDONLY, "kvm_open");
+ kvm_nlist(kd, my_nlist);
+ cp_time_offset = my_nlist[0].n_value;
+
+ updateCpuInfo();
+}
+
+void
+exitCpuInfo(void)
+{
+ kvm_close(kd);
+}
+
+int
+updateCpuInfo(void)
+{
+ kvm_read(kd, cp_time_offset, (char *)cp_time, sizeof(cp_time));
+ percentages(CPUSTATES, cpu_states, cp_time, cp_old, cp_diff);
+ return (0);
+}
+
+void
+printCPUUser(const char* cmd)
+{
+ fprintf(CurrentClient, "%d\n", cpu_states[CP_USER]/10);
+}
+
+void
+printCPUUserInfo(const char* cmd)
+{
+ fprintf(CurrentClient, "CPU User Load\t0\t100\t%%\n");
+}
+
+void
+printCPUNice(const char* cmd)
+{
+ fprintf(CurrentClient, "%d\n", cpu_states[CP_NICE]/10);
+}
+
+void
+printCPUNiceInfo(const char* cmd)
+{
+ fprintf(CurrentClient, "CPU Nice Load\t0\t100\t%%\n");
+}
+
+void
+printCPUSys(const char* cmd)
+{
+ fprintf(CurrentClient, "%d\n", cpu_states[CP_SYS]/10);
+}
+
+void
+printCPUSysInfo(const char* cmd)
+{
+ fprintf(CurrentClient, "CPU System Load\t0\t100\t%%\n");
+}
+
+void
+printCPUIdle(const char* cmd)
+{
+ fprintf(CurrentClient, "%d\n", cpu_states[CP_IDLE]/10);
+}
+
+void
+printCPUIdleInfo(const char* cmd)
+{
+ fprintf(CurrentClient, "CPU Idle Load\t0\t100\t%%\n");
+}
+
+
+/* The part ripped from top... */
+/*
+ * Top users/processes display for Unix
+ * Version 3
+ *
+ * This program may be freely redistributed,
+ * but this entire comment MUST remain intact.
+ *
+ * Copyright (c) 1984, 1989, William LeFebvre, Rice University
+ * Copyright (c) 1989, 1990, 1992, William LeFebvre, Northwestern University
+ */
+
+/*
+ * percentages(cnt, out, new, old, diffs) - calculate percentage change
+ * between array "old" and "new", putting the percentages i "out".
+ * "cnt" is size of each array and "diffs" is used for scratch space.
+ * The array "old" is updated on each call.
+ * The routine assumes modulo arithmetic. This function is especially
+ * useful on BSD mchines for calculating cpu state percentages.
+ */
+
+long percentages(cnt, out, new, old, diffs)
+
+int cnt;
+int *out;
+register long *new;
+register long *old;
+long *diffs;
+
+{
+ register int i;
+ register long change;
+ register long total_change;
+ register long *dp;
+ long half_total;
+
+ /* initialization */
+ total_change = 0;
+ dp = diffs;
+
+ /* calculate changes for each state and the overall change */
+ for (i = 0; i < cnt; i++)
+ {
+ if ((change = *new - *old) < 0)
+ {
+ /* this only happens when the counter wraps */
+ change = (int)
+ ((unsigned long)*new-(unsigned long)*old);
+ }
+ total_change += (*dp++ = change);
+ *old++ = *new++;
+ }
+
+ /* avoid divide by zero potential */
+ if (total_change == 0)
+ {
+ total_change = 1;
+ }
+
+ /* calculate percentages based on overall change, rounding up */
+ half_total = total_change / 2l;
+
+ /* Do not divide by 0. Causes Floating point exception */
+ if(total_change) {
+ for (i = 0; i < cnt; i++)
+ {
+ *out++ = (int)((*diffs++ * 1000 + half_total) / total_change);
+ }
+ }
+
+ /* return the total in case the caller wants to use it */
+ return(total_change);
+}
diff --git a/ksysguard/ksysguardd/NetBSD/CPU.h b/ksysguard/ksysguardd/NetBSD/CPU.h
new file mode 100644
index 000000000..c35932ac8
--- /dev/null
+++ b/ksysguard/ksysguardd/NetBSD/CPU.h
@@ -0,0 +1,49 @@
+/*
+ KSysGuard, the KDE System Guard
+
+ Copyright (c) 1999 Chris Schlaeger <cs@kde.org>
+
+ 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 _cpuinfo_h_
+#define _cpuinfo_h_
+
+struct SensorModul;
+
+void initCpuInfo(struct SensorModul* sm);
+void exitCpuInfo(void);
+
+int updateCpuInfo(void);
+
+void printCPUUser(const char* cmd);
+void printCPUUserInfo(const char* cmd);
+void printCPUNice(const char* cmd);
+void printCPUNiceInfo(const char* cmd);
+void printCPUSys(const char* cmd);
+void printCPUSysInfo(const char* cmd);
+void printCPUIdle(const char* cmd);
+void printCPUIdleInfo(const char* cmd);
+void printCPUxUser(const char* cmd);
+void printCPUxUserInfo(const char* cmd);
+void printCPUxNice(const char* cmd);
+void printCPUxNiceInfo(const char* cmd);
+void printCPUxSys(const char* cmd);
+void printCPUxSysInfo(const char* cmd);
+void printCPUxIdle(const char* cmd);
+void printCPUxIdleInfo(const char* cmd);
+
+#endif
diff --git a/ksysguard/ksysguardd/NetBSD/Makefile.am b/ksysguard/ksysguardd/NetBSD/Makefile.am
new file mode 100644
index 000000000..29860a407
--- /dev/null
+++ b/ksysguard/ksysguardd/NetBSD/Makefile.am
@@ -0,0 +1,8 @@
+#
+#
+
+INCLUDES = -I$(srcdir)/../../CContLib -I$(srcdir)/..
+
+noinst_LIBRARIES = libksysguardd.a
+libksysguardd_a_SOURCES = CPU.c Memory.c ProcessList.c apm.c diskstat.c \
+ loadavg.c logfile.c netdev.c
diff --git a/ksysguard/ksysguardd/NetBSD/Memory.c b/ksysguard/ksysguardd/NetBSD/Memory.c
new file mode 100644
index 000000000..8e9779506
--- /dev/null
+++ b/ksysguard/ksysguardd/NetBSD/Memory.c
@@ -0,0 +1,202 @@
+/*
+ KSysGuard, the KDE System Guard
+
+ Copyright (c) 1999-2000 Hans Petter Bieker <bieker@kde.org>
+ Copyright (c) 1999 Chris Schlaeger <cs@kde.org>
+
+ 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.
+
+*/
+
+#include <fcntl.h>
+#include <kvm.h>
+#include <limits.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/param.h>
+#include <sys/sysctl.h>
+#include <sys/types.h>
+#include <sys/vmmeter.h>
+#include <unistd.h>
+/* Everything post 1.5.x uses uvm/uvm_* includes */
+#if __NetBSD_Version__ >= 105010000
+#include <uvm/uvm_param.h>
+#else
+#include <vm/vm_param.h>
+#endif
+
+#include "Command.h"
+#include "Memory.h"
+#include "ksysguardd.h"
+
+static size_t Total = 0;
+static size_t MFree = 0;
+static size_t Used = 0;
+static size_t Buffers = 0;
+static size_t Cached = 0;
+static size_t STotal = 0;
+static size_t SFree = 0;
+static size_t SUsed = 0;
+static kvm_t *kd;
+
+void
+initMemory(struct SensorModul* sm)
+{
+ char *nlistf = NULL;
+ char *memf = NULL;
+ char buf[_POSIX2_LINE_MAX];
+
+ if ((kd = kvm_openfiles(nlistf, memf, NULL, O_RDONLY, buf)) == NULL) {
+ log_error("kvm_openfiles()");
+ return;
+ }
+
+ registerMonitor("mem/physical/free", "integer", printMFree, printMFreeInfo, sm);
+ registerMonitor("mem/physical/used", "integer", printUsed, printUsedInfo, sm);
+ registerMonitor("mem/physical/buf", "integer", printBuffers, printBuffersInfo, sm);
+ registerMonitor("mem/physical/cached", "integer", printCached, printCachedInfo, sm);
+ registerMonitor("mem/swap/free", "integer", printSwapFree, printSwapFreeInfo, sm);
+ registerMonitor("mem/swap/used", "integer", printSwapUsed, printSwapUsedInfo, sm);
+}
+
+void
+exitMemory(void)
+{
+ kvm_close(kd);
+}
+
+int
+updateMemory(void)
+{
+
+#define ARRLEN(X) (sizeof(X)/sizeof(X[0]))
+ long pagesize; /* using a long promotes the arithmetic */
+ size_t len;
+
+ {
+ static int mib[]={ CTL_HW, HW_PHYSMEM };
+
+ len = sizeof(Total);
+ sysctl(mib, ARRLEN(mib), &Total, &len, NULL, 0);
+ Total >>= 10;
+ }
+
+ {
+ struct uvmexp x;
+ static int mib[] = { CTL_VM, VM_UVMEXP };
+
+ len = sizeof(x);
+ STotal = SUsed = SFree = -1;
+ pagesize = 1;
+ if (-1 < sysctl(mib, ARRLEN(mib), &x, &len, NULL, 0)) {
+ pagesize = x.pagesize;
+ STotal = (pagesize*x.swpages) >> 10;
+ SUsed = (pagesize*x.swpginuse) >> 10;
+ SFree = STotal - SUsed;
+ }
+ }
+
+ /* can't find NetBSD filesystem buffer info */
+ Buffers = -1;
+
+ /* NetBSD doesn't know about vm.stats */
+ Cached = -1;
+
+ {
+ static int mib[]={ CTL_VM, VM_METER };
+ struct vmtotal x;
+
+ len = sizeof(x);
+ MFree = Used = -1;
+ if (sysctl(mib, ARRLEN(mib), &x, &len, NULL, 0) > -1) {
+ MFree = (x.t_free * pagesize) >> 10;
+ Used = (x.t_rm * pagesize) >> 10;
+ }
+ }
+ return 0;
+}
+
+void
+printMFree(const char* cmd)
+{
+ fprintf(CurrentClient, "%d\n", MFree);
+}
+
+void
+printMFreeInfo(const char* cmd)
+{
+ fprintf(CurrentClient, "Free Memory\t0\t%d\tKB\n", Total);
+}
+
+void
+printUsed(const char* cmd)
+{
+ fprintf(CurrentClient, "%d\n", Used);
+}
+
+void
+printUsedInfo(const char* cmd)
+{
+ fprintf(CurrentClient, "Used Memory\t0\t%d\tKB\n", Total);
+}
+
+void
+printBuffers(const char* cmd)
+{
+ fprintf(CurrentClient, "%d\n", Buffers);
+}
+
+void
+printBuffersInfo(const char* cmd)
+{
+ fprintf(CurrentClient, "Buffer Memory\t0\t%d\tKB\n", Total);
+}
+
+void
+printCached(const char* cmd)
+{
+ fprintf(CurrentClient, "%d\n", Cached);
+}
+
+void
+printCachedInfo(const char* cmd)
+{
+ fprintf(CurrentClient, "Cached Memory\t0\t%d\tKB\n", Total);
+}
+
+void
+printSwapUsed(const char* cmd)
+{
+ fprintf(CurrentClient, "%d\n", SUsed);
+}
+
+void
+printSwapUsedInfo(const char* cmd)
+{
+ fprintf(CurrentClient, "Used Swap Memory\t0\t%d\tKB\n", STotal);
+}
+
+void
+printSwapFree(const char* cmd)
+{
+ fprintf(CurrentClient, "%d\n", SFree);
+}
+
+void
+printSwapFreeInfo(const char* cmd)
+{
+ fprintf(CurrentClient, "Free Swap Memory\t0\t%d\tKB\n", STotal);
+}
diff --git a/ksysguard/ksysguardd/NetBSD/Memory.h b/ksysguard/ksysguardd/NetBSD/Memory.h
new file mode 100644
index 000000000..57abb73a2
--- /dev/null
+++ b/ksysguard/ksysguardd/NetBSD/Memory.h
@@ -0,0 +1,43 @@
+/*
+ KSysGuard, the KDE System Guard
+
+ Copyright (c) 1999 Chris Schlaeger <cs@kde.org>
+
+ 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_
+
+void initMemory(struct SensorModul* sm);
+void exitMemory(void);
+
+int updateMemory(void);
+
+void printMFree(const char* cmd);
+void printMFreeInfo(const char* cmd);
+void printUsed(const char* cmd);
+void printUsedInfo(const char* cmd);
+void printBuffers(const char* cmd);
+void printBuffersInfo(const char* cmd);
+void printCached(const char* cmd);
+void printCachedInfo(const char* cmd);
+void printSwapUsed(const char* cmd);
+void printSwapUsedInfo(const char* cmd);
+void printSwapFree(const char* cmd);
+void printSwapFreeInfo(const char* cmd);
+
+#endif
diff --git a/ksysguard/ksysguardd/NetBSD/ProcessList.c b/ksysguard/ksysguardd/NetBSD/ProcessList.c
new file mode 100644
index 000000000..54ab65513
--- /dev/null
+++ b/ksysguard/ksysguardd/NetBSD/ProcessList.c
@@ -0,0 +1,457 @@
+/*
+ KSysGuard, the KDE System Guard
+
+ Copyright (c) 1999-2000 Hans Petter Bieker<bieker@kde.org>
+ Copyright (c) 1999 Chris Schlaeger <cs@kde.org>
+
+ 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.
+
+*/
+
+#include <config.h>
+
+#include <ctype.h>
+#include <dirent.h>
+#include <pwd.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/param.h>
+#include <sys/sysctl.h>
+#include <sys/time.h>
+#include <sys/types.h>
+#include <sys/user.h>
+#include <unistd.h>
+#include <signal.h>
+
+#include "../../gui/SignalIDs.h"
+#include "Command.h"
+#include "ProcessList.h"
+#include "ccont.h"
+#include "ksysguardd.h"
+
+CONTAINER ProcessList = 0;
+
+#define BUFSIZE 1024
+
+typedef struct
+{
+ /* This flag is set for all found processes at the beginning of the
+ * process list update. Processes that do not have this flag set will
+ * be assumed dead and removed from the list. The flag is cleared after
+ * each list update. */
+ int alive;
+
+ /* the process ID */
+ pid_t pid;
+
+ /* the parent process ID */
+ pid_t ppid;
+
+ /* the real user ID */
+ uid_t uid;
+
+ /* the real group ID */
+ gid_t gid;
+
+ /* a character description of the process status */
+ char status[16];
+
+ /* the number of the tty the process owns */
+ int ttyNo;
+
+ /*
+ * The nice level. The range should be -20 to 20. I'm not sure
+ * whether this is true for all platforms.
+ */
+ int niceLevel;
+
+ /*
+ * The scheduling priority.
+ */
+ int priority;
+
+ /*
+ * The total amount of memory the process uses. This includes shared and
+ * swapped memory.
+ */
+ unsigned int vmSize;
+
+ /*
+ * The amount of physical memory the process currently uses.
+ */
+ unsigned int vmRss;
+
+ /*
+ * The amount of memory (shared/swapped/etc) the process shares with
+ * other processes.
+ */
+ unsigned int vmLib;
+
+ /*
+ * The number of 1/100 of a second the process has spend in user space.
+ * If a machine has an uptime of 1 1/2 years or longer this is not a
+ * good idea. I never thought that the stability of UNIX could get me
+ * into trouble! ;)
+ */
+ unsigned int userTime;
+
+ /*
+ * The number of 1/100 of a second the process has spend in system space.
+ * If a machine has an uptime of 1 1/2 years or longer this is not a
+ * good idea. I never thought that the stability of UNIX could get me
+ * into trouble! ;)
+ */
+ unsigned int sysTime;
+
+ /* system time as multime of 100ms */
+ int centStamp;
+
+ /* the current CPU load (in %) from user space */
+ double userLoad;
+
+ /* the current CPU load (in %) from system space */
+ double sysLoad;
+
+ /* the name of the process */
+ char name[64];
+
+ /* the command used to start the process */
+ char cmdline[256];
+
+ /* the login name of the user that owns this process */
+ char userName[32];
+} ProcessInfo;
+
+static unsigned ProcessCount;
+
+static int
+processCmp(void* p1, void* p2)
+{
+ return (((ProcessInfo*) p1)->pid - ((ProcessInfo*) p2)->pid);
+}
+
+static ProcessInfo*
+findProcessInList(int pid)
+{
+ ProcessInfo key;
+ long index;
+
+ key.pid = pid;
+ if ((index = search_ctnr(ProcessList, processCmp, &key)) < 0)
+ return (0);
+
+ return (get_ctnr(ProcessList, index));
+}
+
+static int
+updateProcess(int pid)
+{
+ static char *statuses[] = { "idle","run","sleep","stop","zombie" };
+
+ ProcessInfo* ps;
+ struct passwd* pwent;
+ int mib[4];
+ struct kinfo_proc p;
+ size_t len;
+
+ if ((ps = findProcessInList(pid)) == 0)
+ {
+ ps = (ProcessInfo*) malloc(sizeof(ProcessInfo));
+ ps->pid = pid;
+ ps->centStamp = 0;
+ push_ctnr(ProcessList, ps);
+ bsort_ctnr(ProcessList, processCmp);
+ }
+
+ ps->alive = 1;
+
+ mib[0] = CTL_KERN;
+ mib[1] = KERN_PROC;
+ mib[2] = KERN_PROC_PID;
+ mib[3] = pid;
+
+ len = sizeof (p);
+ if (sysctl(mib, 4, &p, &len, NULL, 0) == -1 || !len)
+ return -1;
+
+ ps->pid = p.kp_proc.p_pid;
+ ps->ppid = p.kp_eproc.e_ppid;
+ ps->uid = p.kp_eproc.e_ucred.cr_uid;
+ ps->gid = p.kp_eproc.e_pgid;
+ ps->priority = p.kp_proc.p_priority;
+ ps->niceLevel = p.kp_proc.p_nice;
+
+ /* this isn't usertime -- it's total time (??) */
+ ps->userTime = p.kp_proc.p_rtime.tv_sec*100+p.kp_proc.p_rtime.tv_usec/100;
+ ps->sysTime = 0;
+ ps->sysLoad = 0;
+
+ /* memory, process name, process uid */
+ /* find out user name with process uid */
+ pwent = getpwuid(ps->uid);
+ strlcpy(ps->userName,pwent&&pwent->pw_name? pwent->pw_name:"????",sizeof(ps->userName));
+ ps->userName[sizeof(ps->userName)-1]='\0';
+
+ ps->userLoad = p.kp_proc.p_pctcpu / 100;
+ ps->vmSize = (p.kp_eproc.e_vm.vm_tsize +
+ p.kp_eproc.e_vm.vm_dsize +
+ p.kp_eproc.e_vm.vm_ssize) * getpagesize();
+ ps->vmRss = p.kp_eproc.e_vm.vm_rssize * getpagesize();
+ strlcpy(ps->name,p.kp_proc.p_comm ? p.kp_proc.p_comm : "????", sizeof(ps->name));
+ strlcpy(ps->status,(p.kp_proc.p_stat>=1)&&(p.kp_proc.p_stat<=5)? statuses[p.kp_proc.p_stat-1]:"????", sizeof(ps->status));
+
+ /* process command line */
+ /* the following line causes segfaults on some FreeBSD systems... why?
+ strncpy(ps->cmdline, p.kp_proc.p_args->ar_args, sizeof(ps->cmdline) - 1);
+ */
+ strcpy(ps->cmdline, "????");
+
+ return (0);
+}
+
+static void
+cleanupProcessList(void)
+{
+ ProcessInfo* ps;
+
+ ProcessCount = 0;
+ /* All processes that do not have the active flag set are assumed dead
+ * and will be removed from the list. The alive flag is cleared. */
+ for (ps = first_ctnr(ProcessList); ps; ps = next_ctnr(ProcessList))
+ {
+ if (ps->alive)
+ {
+ /* Process is still alive. Just clear flag. */
+ ps->alive = 0;
+ ProcessCount++;
+ }
+ else
+ {
+ /* Process has probably died. We remove it from the list and
+ * destruct the data structure. i needs to be decremented so
+ * that after i++ the next list element will be inspected. */
+ free(remove_ctnr(ProcessList));
+ }
+ }
+}
+
+/*
+================================ public part ==================================
+*/
+
+void
+initProcessList(struct SensorModul* sm)
+{
+ ProcessList = new_ctnr();
+
+ registerMonitor("ps", "table", printProcessList, printProcessListInfo, sm);
+ registerMonitor("pscount", "integer", printProcessCount, printProcessCountInfo, sm);
+
+ if (!RunAsDaemon)
+ {
+ registerCommand("kill", killProcess);
+ registerCommand("setpriority", setPriority);
+ }
+
+ updateProcessList();
+}
+
+void
+exitProcessList(void)
+{
+ removeMonitor("ps");
+ removeMonitor("pscount");
+
+ if (ProcessList)
+ free (ProcessList);
+}
+
+int
+updateProcessList(void)
+{
+ int mib[3];
+ size_t len;
+ size_t num;
+ struct kinfo_proc *p;
+
+
+ mib[0] = CTL_KERN;
+ mib[1] = KERN_PROC;
+ mib[2] = KERN_PROC_ALL;
+ sysctl(mib, 3, NULL, &len, NULL, 0);
+ p = malloc(len);
+ sysctl(mib, 3, p, &len, NULL, 0);
+
+ for (num = 0; num < len / sizeof(struct kinfo_proc); num++)
+ updateProcess(p[num].kp_proc.p_pid);
+ free(p);
+ cleanupProcessList();
+
+ return (0);
+}
+
+void
+printProcessListInfo(const char* cmd)
+{
+ fprintf(CurrentClient, "Name\tPID\tPPID\tUID\tGID\tStatus\tUser%%\tSystem%%\tNice\tVmSize\tVmRss\tLogin\tCommand\n");
+ fprintf(CurrentClient, "s\td\td\td\td\tS\tf\tf\td\tD\tD\ts\ts\n");
+}
+
+void
+printProcessList(const char* cmd)
+{
+ ProcessInfo* ps;
+
+ ps = first_ctnr(ProcessList); /* skip 'kernel' entry */
+ for (ps = next_ctnr(ProcessList); ps; ps = next_ctnr(ProcessList))
+ {
+ fprintf(CurrentClient, "%s\t%ld\t%ld\t%ld\t%ld\t%s\t%.2f\t%.2f\t%d\t%d\t%d\t%s\t%s\n",
+ ps->name, (long)ps->pid, (long)ps->ppid,
+ (long)ps->uid, (long)ps->gid, ps->status,
+ ps->userLoad, ps->sysLoad, ps->niceLevel,
+ ps->vmSize / 1024, ps->vmRss / 1024, ps->userName, ps->cmdline);
+ }
+}
+
+void
+printProcessCount(const char* cmd)
+{
+ fprintf(CurrentClient, "%d\n", ProcessCount);
+}
+
+void
+printProcessCountInfo(const char* cmd)
+{
+ fprintf(CurrentClient, "Number of Processes\t1\t65535\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\t%d\n", pid);
+ break;
+ case ESRCH:
+ fprintf(CurrentClient, "3\t%d\n", pid);
+ break;
+ case EPERM:
+ fprintf(CurrentClient, "2\t%d\n", pid);
+ break;
+ default:
+ fprintf(CurrentClient, "1\t%d\n", pid); /* unknown error */
+ break;
+ }
+
+ }
+ else
+ fprintf(CurrentClient, "0\t%d\n", pid);
+}
+
+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/NetBSD/ProcessList.h b/ksysguard/ksysguardd/NetBSD/ProcessList.h
new file mode 100644
index 000000000..925c55f5a
--- /dev/null
+++ b/ksysguard/ksysguardd/NetBSD/ProcessList.h
@@ -0,0 +1,38 @@
+/*
+ KSysGuard, the KDE System Guard
+
+ Copyright (c) 1999 Chris Schlaeger <cs@kde.org>
+
+ 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 _process_list_h_
+#define _process_list_h_
+
+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
diff --git a/ksysguard/ksysguardd/NetBSD/apm.c b/ksysguard/ksysguardd/NetBSD/apm.c
new file mode 100644
index 000000000..f24887483
--- /dev/null
+++ b/ksysguard/ksysguardd/NetBSD/apm.c
@@ -0,0 +1,100 @@
+/*
+ KSysGuard, the KDE System Guard
+
+ Copyright (c) 2001 Tobias Koenig <tokoe@kde.org>
+
+ 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 <fcntl.h>
+#include <machine/apmvar.h>
+#include <sys/ioctl.h>
+#include <unistd.h>
+#include <stdio.h>
+
+#include "Command.h"
+#include "apm.h"
+#include "ksysguardd.h"
+
+static int ApmFD, BattFill, BattTime;
+
+#define APMDEV "/dev/apm"
+
+/*
+================================ public part =================================
+*/
+
+void
+initApm(struct SensorModul* sm)
+{
+ if ((ApmFD = open(APMDEV, O_RDONLY)) < 0)
+ return;
+
+ if (updateApm() < 0)
+ return;
+
+ registerMonitor("apm/batterycharge", "integer", printApmBatFill,
+ printApmBatFillInfo, sm);
+ registerMonitor("apm/remainingtime", "integer", printApmBatTime,
+ printApmBatTimeInfo, sm);
+}
+
+void
+exitApm(void)
+{
+ removeMonitor("apm/batterycharge");
+ removeMonitor("apm/remainingtime");
+
+ close(ApmFD);
+}
+
+int
+updateApm(void)
+{
+ int retval;
+ struct apm_power_info info;
+ retval = ioctl(ApmFD, APM_IOC_GETPOWER, &info);
+
+ BattFill = info.battery_life;
+ BattTime = info.minutes_left;
+
+ return retval;
+}
+
+void
+printApmBatFill(const char* c)
+{
+ fprintf(CurrentClient, "%d\n", BattFill);
+}
+
+void
+printApmBatFillInfo(const char* c)
+{
+ fprintf(CurrentClient, "Battery charge\t0\t100\t%%\n");
+}
+
+void
+printApmBatTime(const char* c)
+{
+ fprintf(CurrentClient, "%d\n", BattTime);
+}
+
+void
+printApmBatTimeInfo(const char* c)
+{
+ fprintf(CurrentClient, "Remaining battery time\t0\t0\tmin\n");
+}
+
diff --git a/ksysguard/ksysguardd/NetBSD/apm.h b/ksysguard/ksysguardd/NetBSD/apm.h
new file mode 100644
index 000000000..4e3c0c0d3
--- /dev/null
+++ b/ksysguard/ksysguardd/NetBSD/apm.h
@@ -0,0 +1,34 @@
+/*
+ KSysGuard, the KDE System Guard
+
+ Copyright (c) 2001 Tobias Koenig <tokoe@kde.org>
+
+ 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.
+
+*/
+
+#ifndef _apm_h_
+#define _apm_h_
+
+void initApm(struct SensorModul* sm);
+void exitApm(void);
+
+int updateApm(void);
+
+void printApmBatFill(const char*);
+void printApmBatFillInfo(const char*);
+void printApmBatTime(const char*);
+void printApmBatTimeInfo(const char*);
+
+#endif
diff --git a/ksysguard/ksysguardd/NetBSD/diskstat.c b/ksysguard/ksysguardd/NetBSD/diskstat.c
new file mode 100644
index 000000000..818eee1d4
--- /dev/null
+++ b/ksysguard/ksysguardd/NetBSD/diskstat.c
@@ -0,0 +1,249 @@
+/*
+ KSysGuard, the KDE System Guard
+
+ Copyright (c) 2001 Tobias Koenig <tokoe@kde.org>
+
+ 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 <config.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/param.h>
+#include <sys/stat.h>
+#include <sys/ucred.h>
+#include <sys/mount.h>
+#include <time.h>
+#include <unistd.h>
+
+#include "Command.h"
+#include "ccont.h"
+#include "diskstat.h"
+#include "ksysguardd.h"
+
+typedef struct {
+ char device[256];
+ char mntpnt[256];
+ long blocks;
+ long bfree;
+ long bused;
+ int bused_percent;
+} DiskInfo;
+
+static CONTAINER DiskStatList = 0;
+static struct SensorModul* DiskStatSM;
+
+char *getMntPnt(const char *cmd)
+{
+ static char device[1025];
+ char *ptr;
+
+ memset(device, 0, sizeof(device));
+ sscanf(cmd, "partitions%1024s", device);
+
+ ptr = (char *)rindex(device, '/');
+ *ptr = '\0';
+
+ return (char *)device;
+}
+
+int numMntPnt(void)
+{
+ struct statfs *fs_info;
+ int i, n, counter = 0;
+
+ n = getmntinfo(&fs_info, MNT_WAIT);
+ for (i = 0; i < n; i++)
+ if (strcmp(fs_info[i].f_fstypename, "procfs") && strcmp(fs_info[i].f_fstypename, "swap") && strcmp(fs_info[i].f_fstypename, "devfs"))
+ counter++;
+
+ return counter;
+}
+
+/* ------------------------------ public part --------------------------- */
+
+void initDiskStat(struct SensorModul* sm)
+{
+ char monitor[1024];
+ DiskInfo* disk_info;
+
+ DiskStatList = new_ctnr();
+ DiskStatSM = sm;
+
+ updateDiskStat();
+
+ registerMonitor("partitions/list", "listview", printDiskStat, printDiskStatInfo, DiskStatSM);
+
+ for (disk_info = first_ctnr(DiskStatList); disk_info; disk_info = next_ctnr(DiskStatList)) {
+ snprintf(monitor, sizeof(monitor), "partitions%s/usedspace", disk_info->mntpnt);
+ registerMonitor(monitor, "integer", printDiskStatUsed, printDiskStatUsedInfo, DiskStatSM);
+ snprintf(monitor, sizeof(monitor), "partitions%s/freespace", disk_info->mntpnt);
+ registerMonitor(monitor, "integer", printDiskStatFree, printDiskStatFreeInfo, DiskStatSM);
+ snprintf(monitor, sizeof(monitor), "partitions%s/filllevel", disk_info->mntpnt);
+ registerMonitor(monitor, "integer", printDiskStatPercent, printDiskStatPercentInfo, DiskStatSM);
+ }
+}
+
+void checkDiskStat(void)
+{
+ if (numMntPnt() != level_ctnr(DiskStatList)) {
+ /* a filesystem was mounted or unmounted
+ so we do a reset */
+ exitDiskStat();
+ initDiskStat(DiskStatSM);
+ }
+}
+
+void exitDiskStat(void)
+{
+ DiskInfo *disk_info;
+ char monitor[1024];
+
+ removeMonitor("partitions/list");
+
+ for (disk_info = first_ctnr(DiskStatList); disk_info; disk_info = next_ctnr(DiskStatList)) {
+ snprintf(monitor, sizeof(monitor), "partitions%s/usedspace", disk_info->mntpnt);
+ removeMonitor(monitor);
+ snprintf(monitor, sizeof(monitor), "partitions%s/freespace", disk_info->mntpnt);
+ removeMonitor(monitor);
+ snprintf(monitor, sizeof(monitor), "partitions%s/filllevel", disk_info->mntpnt);
+ removeMonitor(monitor);
+ }
+
+ destr_ctnr(DiskStatList, free);
+}
+
+int updateDiskStat(void)
+{
+ struct statfs *fs_info;
+ struct statfs fs;
+ float percent;
+ int i, mntcount;
+ DiskInfo *disk_info;
+
+ /* let's hope there is no difference between the DiskStatList and
+ the number of mounted filesystems */
+ for (i = level_ctnr(DiskStatList); i >= 0; --i)
+ free(pop_ctnr(DiskStatList));
+
+ mntcount = getmntinfo(&fs_info, MNT_WAIT);
+
+ for (i = 0; i < mntcount; i++) {
+ fs = fs_info[i];
+ if (strcmp(fs.f_fstypename, "procfs") && strcmp(fs.f_fstypename, "devfs") && strcmp(fs.f_fstypename, "devfs")) {
+ percent = (((float)fs.f_blocks - (float)fs.f_bfree)/(float)fs.f_blocks);
+ percent = percent * 100;
+ if ((disk_info = (DiskInfo *)malloc(sizeof(DiskInfo))) == NULL) {
+ continue;
+ }
+ memset(disk_info, 0, sizeof(DiskInfo));
+ strlcpy(disk_info->device, fs.f_mntfromname, sizeof(disk_info->device));
+ if (!strcmp(fs.f_mntonname, "/")) {
+ strncpy(disk_info->mntpnt, "/root", 6);
+ } else {
+ strlcpy(disk_info->mntpnt, fs.f_mntonname, sizeof(disk_info->mntpnt));
+ }
+ disk_info->blocks = fs.f_blocks;
+ disk_info->bfree = fs.f_bfree;
+ disk_info->bused = (fs.f_blocks - fs.f_bfree);
+ disk_info->bused_percent = (int)percent;
+
+ push_ctnr(DiskStatList, disk_info);
+ }
+ }
+
+ return 0;
+}
+
+void printDiskStat(const char* cmd)
+{
+ DiskInfo* disk_info;
+
+ for (disk_info = first_ctnr(DiskStatList); disk_info; disk_info = next_ctnr(DiskStatList)) {
+ fprintf(CurrentClient, "%s\t%ld\t%ld\t%ld\t%d\t%s\n",
+ disk_info->device,
+ disk_info->blocks,
+ disk_info->bused,
+ disk_info->bfree,
+ disk_info->bused_percent,
+ disk_info->mntpnt);
+ }
+
+ fprintf(CurrentClient, "\n");
+}
+
+void printDiskStatInfo(const char* cmd)
+{
+ fprintf(CurrentClient, "Device\tBlocks\tUsed\tAvailable\tUsed %%\tMountPoint\nM\tD\tD\tD\td\ts\n");
+}
+
+void printDiskStatUsed(const char* cmd)
+{
+ DiskInfo* disk_info;
+ char *mntpnt = (char *)getMntPnt(cmd);
+
+ for (disk_info = first_ctnr(DiskStatList); disk_info; disk_info = next_ctnr(DiskStatList)) {
+ if (!strcmp(mntpnt, disk_info->mntpnt)) {
+ fprintf(CurrentClient, "%ld\n", disk_info->bused);
+ }
+ }
+
+ fprintf(CurrentClient, "\n");
+}
+
+void printDiskStatUsedInfo(const char* cmd)
+{
+ fprintf(CurrentClient, "Used Blocks\t0\t-\tBlocks\n");
+}
+
+void printDiskStatFree(const char* cmd)
+{
+ DiskInfo* disk_info;
+ char *mntpnt = (char *)getMntPnt(cmd);
+
+ for (disk_info = first_ctnr(DiskStatList); disk_info; disk_info = next_ctnr(DiskStatList)) {
+ if (!strcmp(mntpnt, disk_info->mntpnt)) {
+ fprintf(CurrentClient, "%ld\n", disk_info->bfree);
+ }
+ }
+
+ fprintf(CurrentClient, "\n");
+}
+
+void printDiskStatFreeInfo(const char* cmd)
+{
+ fprintf(CurrentClient, "Free Blocks\t0\t-\tBlocks\n");
+}
+
+void printDiskStatPercent(const char* cmd)
+{
+ DiskInfo* disk_info;
+ char *mntpnt = (char *)getMntPnt(cmd);
+
+ for (disk_info = first_ctnr(DiskStatList); disk_info; disk_info = next_ctnr(DiskStatList)) {
+ if (!strcmp(mntpnt, disk_info->mntpnt)) {
+ fprintf(CurrentClient, "%d\n", disk_info->bused_percent);
+ }
+ }
+
+ fprintf(CurrentClient, "\n");
+}
+
+void printDiskStatPercentInfo(const char* cmd)
+{
+ fprintf(CurrentClient, "Used Blocks\t0\t100\t%%\n");
+}
diff --git a/ksysguard/ksysguardd/NetBSD/diskstat.h b/ksysguard/ksysguardd/NetBSD/diskstat.h
new file mode 100644
index 000000000..06f247837
--- /dev/null
+++ b/ksysguard/ksysguardd/NetBSD/diskstat.h
@@ -0,0 +1,40 @@
+/*
+ KSysGuard, the KDE System Guard
+
+ Copyright (c) 2001 Tobias Koenig <tokoe@kde.org>
+
+ 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.
+
+*/
+
+#ifndef _diskstat_h_
+#define _diskstat_h_
+
+void initDiskStat(struct SensorModul* sm);
+void exitDiskStat(void);
+
+int updateDiskStat(void);
+void checkDiskStat(void);
+
+void printDiskStat(const char* cmd);
+void printDiskStatInfo(const char* cmd);
+
+void printDiskStatUsed(const char* cmd);
+void printDiskStatUsedInfo(const char* cmd);
+void printDiskStatFree(const char* cmd);
+void printDiskStatFreeInfo(const char* cmd);
+void printDiskStatPercent(const char* cmd);
+void printDiskStatPercentInfo(const char* cmd);
+
+#endif
diff --git a/ksysguard/ksysguardd/NetBSD/loadavg.c b/ksysguard/ksysguardd/NetBSD/loadavg.c
new file mode 100644
index 000000000..53eb9fc4e
--- /dev/null
+++ b/ksysguard/ksysguardd/NetBSD/loadavg.c
@@ -0,0 +1,96 @@
+/*
+ KSysGuard, the KDE System Guard
+
+ Copyright (c) 2001 Tobias Koenig <tokoe@kde.org>
+
+ 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 "Command.h"
+#include "ksysguardd.h"
+#include "loadavg.h"
+
+static double LoadAvg[3];
+
+/*
+================================ public part =================================
+*/
+
+void
+initLoadAvg(struct SensorModul* sm)
+{
+ if (updateLoadAvg() < 0)
+ return;
+
+ registerMonitor("cpu/loadavg1", "float", printLoadAvg1,
+ printLoadAvg1Info, sm);
+ registerMonitor("cpu/loadavg5", "float", printLoadAvg5,
+ printLoadAvg5Info, sm);
+ registerMonitor("cpu/loadavg15", "float", printLoadAvg15,
+ printLoadAvg15Info, sm);
+}
+
+void
+exitLoadAvg(void)
+{
+ removeMonitor("cpu/loadavg1");
+ removeMonitor("cpu/loadavg5");
+ removeMonitor("cpu/loadavg15");
+}
+
+int
+updateLoadAvg(void)
+{
+ return getloadavg(LoadAvg, 3);
+}
+
+void
+printLoadAvg1(const char* c)
+{
+ fprintf(CurrentClient, "%f\n", LoadAvg[0]);
+}
+
+void
+printLoadAvg1Info(const char* c)
+{
+ fprintf(CurrentClient, "Load average 1 min\t0\t0\t\n");
+}
+
+void
+printLoadAvg5(const char* c)
+{
+ fprintf(CurrentClient, "%f\n", LoadAvg[1]);
+}
+
+void
+printLoadAvg5Info(const char* c)
+{
+ fprintf(CurrentClient, "Load average 5 min\t0\t0\t\n");
+}
+
+void
+printLoadAvg15(const char* c)
+{
+ fprintf(CurrentClient, "%f\n", LoadAvg[2]);
+}
+
+void
+printLoadAvg15Info(const char* c)
+{
+ fprintf(CurrentClient, "Load average 15 min\t0\t0\t\n");
+}
diff --git a/ksysguard/ksysguardd/NetBSD/loadavg.h b/ksysguard/ksysguardd/NetBSD/loadavg.h
new file mode 100644
index 000000000..801e4ef8d
--- /dev/null
+++ b/ksysguard/ksysguardd/NetBSD/loadavg.h
@@ -0,0 +1,36 @@
+/*
+ KSysGuard, the KDE System Guard
+
+ Copyright (c) 2001 Tobias Koenig <tokoe@kde.org>
+
+ 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.
+
+*/
+
+#ifndef _loadavg_h_
+#define _loadavg_h_
+
+void initLoadAvg(struct SensorModul* sm);
+void exitLoadAvg(void);
+
+int updateLoadAvg(void);
+
+void printLoadAvg1(const char*);
+void printLoadAvg1Info(const char*);
+void printLoadAvg5(const char*);
+void printLoadAvg5Info(const char*);
+void printLoadAvg15(const char*);
+void printLoadAvg15Info(const char*);
+
+#endif
diff --git a/ksysguard/ksysguardd/NetBSD/logfile.c b/ksysguard/ksysguardd/NetBSD/logfile.c
new file mode 100644
index 000000000..3b07ad8ac
--- /dev/null
+++ b/ksysguard/ksysguardd/NetBSD/logfile.c
@@ -0,0 +1,175 @@
+/*
+ KSysGuard, the KDE System Guard
+
+ Copyright (c) 2001 Tobias Koenig <tokoe@kde.org>
+
+ 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 <config.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "Command.h"
+#include "ccont.h"
+#include "conf.h"
+#include "ksysguardd.h"
+#include "logfile.h"
+
+static CONTAINER LogFiles = 0;
+static unsigned long counter = 1;
+
+typedef struct {
+ char name[256];
+ FILE* fh;
+ unsigned long id;
+} LogFileEntry;
+
+extern CONTAINER LogFileList;
+
+/*
+================================ public part =================================
+*/
+
+void initLogFile(struct SensorModul* sm)
+{
+ char monitor[1024];
+ ConfigLogFile *entry;
+
+ registerCommand("logfile_register", registerLogFile);
+ registerCommand("logfile_unregister", unregisterLogFile);
+ registerCommand("logfile_registered", printRegistered);
+
+ for (entry = first_ctnr(LogFileList); entry; entry = next_ctnr(LogFileList))
+ {
+ FILE* fp;
+
+ /* register the log file if we can actually read the file. */
+ if ((fp = fopen(entry->path, "r")) != NULL)
+ {
+ fclose(fp);
+ snprintf(monitor, 1024, "logfiles/%s", entry->name);
+ registerMonitor(monitor, "logfile", printLogFile,
+ printLogFileInfo, sm);
+ }
+ }
+
+ LogFiles = new_ctnr();
+}
+
+void exitLogFile(void)
+{
+ destr_ctnr(LogFiles, free);
+}
+
+void printLogFile(const char* cmd)
+{
+ char line[1024];
+ unsigned long id;
+ int i;
+ char ch;
+ LogFileEntry *entry;
+
+ sscanf(cmd, "%*s %lu", &id);
+
+ for (entry = first_ctnr(LogFiles); entry; entry = next_ctnr(LogFiles)) {
+ if (entry->id == id) {
+ while (fgets(line, sizeof(line), entry->fh) != NULL) {
+ fprintf(CurrentClient, "%s", line);
+ }
+ clearerr(entry->fh);
+ }
+ }
+
+ fprintf(CurrentClient, "\n");
+}
+
+void printLogFileInfo(const char* cmd)
+{
+ fprintf(CurrentClient, "LogFile\n");
+}
+
+void registerLogFile(const char* cmd)
+{
+ char name[257];
+ FILE* file;
+ LogFileEntry *entry;
+ ConfigLogFile *conf;
+
+ memset(name, 0, sizeof(name));
+ sscanf(cmd, "%*s %256s", name);
+
+ for (conf = first_ctnr(LogFileList); conf; conf = next_ctnr(LogFileList)) {
+ if (!strcmp(conf->name, name)) {
+ if ((file = fopen(conf->path, "r")) == NULL) {
+ print_error("fopen()");
+ fprintf(CurrentClient, "0\n");
+ return;
+ }
+
+ fseek(file, 0, SEEK_END);
+
+ if ((entry = (LogFileEntry *)malloc(sizeof(LogFileEntry))) == NULL) {
+ print_error("malloc()");
+ fprintf(CurrentClient, "0\n");
+ return;
+ }
+
+ entry->fh = file;
+ strlcpy(entry->name, conf->name, sizeof(entry->name));
+ entry->id = counter;
+
+ push_ctnr(LogFiles, entry);
+
+ fprintf(CurrentClient, "%lu\n", counter);
+ counter++;
+
+ return;
+ }
+ }
+
+ fprintf(CurrentClient, "0\n");
+}
+
+void unregisterLogFile(const char* cmd)
+{
+ unsigned long id;
+ LogFileEntry *entry;
+
+ sscanf(cmd, "%*s %lu", &id);
+
+ for (entry = first_ctnr(LogFiles); entry; entry = next_ctnr(LogFiles)) {
+ if (entry->id == id) {
+ fclose(entry->fh);
+ free(remove_ctnr(LogFiles));
+ fprintf(CurrentClient, "\n");
+ return;
+ }
+ }
+
+ fprintf(CurrentClient, "\n");
+}
+
+void printRegistered(const char* cmd)
+{
+ LogFileEntry *entry;
+
+ for (entry = first_ctnr(LogFiles); entry; entry = next_ctnr(LogFiles))
+ fprintf(CurrentClient, "%s:%lu\n", entry->name, entry->id);
+
+ fprintf(CurrentClient, "\n");
+}
diff --git a/ksysguard/ksysguardd/NetBSD/logfile.h b/ksysguard/ksysguardd/NetBSD/logfile.h
new file mode 100644
index 000000000..45ade9013
--- /dev/null
+++ b/ksysguard/ksysguardd/NetBSD/logfile.h
@@ -0,0 +1,36 @@
+/*
+ KSysGuard, the KDE System Guard
+
+ Copyright (c) 2001 Tobias Koenig <tokoe@kde.org>
+
+ 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.
+
+*/
+
+#ifndef _logfile_h_
+#define _logfile_h_
+
+void initLogFile(struct SensorModul* sm);
+void exitLogFile(void);
+
+void printLogFile(const char* cmd);
+void printLogFileInfo(const char* cmd);
+
+void registerLogFile(const char* cmd);
+void unregisterLogFile(const char* cmd);
+
+/* debug command */
+void printRegistered(const char* cmd);
+
+#endif
diff --git a/ksysguard/ksysguardd/NetBSD/netdev.c b/ksysguard/ksysguardd/NetBSD/netdev.c
new file mode 100644
index 000000000..477acc40e
--- /dev/null
+++ b/ksysguard/ksysguardd/NetBSD/netdev.c
@@ -0,0 +1,304 @@
+/*
+ KSysGuard, the KDE System Guard
+
+ Copyright (c) 2001 Tobias Koenig <tokoe@kde.org>
+
+ 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 <sys/types.h>
+#include <sys/param.h>
+#include <sys/sysctl.h>
+#include <sys/socket.h>
+
+#include <net/route.h>
+#include <net/if.h>
+#include <net/if_dl.h>
+
+#include <ifaddrs.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "Command.h"
+#include "ksysguardd.h"
+#include "netdev.h"
+
+
+#define I_bytes 0
+#define I_packs 1
+#define I_errs 2
+#define I_mcasts 3
+#define I_lost 4
+
+typedef struct {
+ char name[32];
+ u_long recv[5], Drecv[5], sent[5], Dsent[5];
+} NetDevInfo;
+
+#define LEN(X) (sizeof(X)/sizeof(X[0]))
+
+#define MAXNETDEVS 64
+static NetDevInfo NetDevs[MAXNETDEVS], newval[MAXNETDEVS];
+static int NetDevCnt = 0;
+static struct SensorModul *NetDevSM;
+
+/* Read the system's traffic registers.
+ * Merely count the IFs if countp nonzero.
+ * Returns count of IFs read, or -1; the data are written into newval.
+ * Based on getifaddrs source; getifaddrs itself seems to
+ * compile incorrectly, omitting the traffic data. (It also
+ * does things this doesn't need, thus this is slightly more efficient.)
+ */
+static int readSys(int countp)
+{
+ size_t len;
+ char *bfr, *ptr;
+ struct rt_msghdr *rtm;
+ NetDevInfo *nv;
+ static int mib[] = {
+ /* see sysctl(3): */
+ CTL_NET,
+ PF_ROUTE,
+ 0, /* `currently always 0' */
+ 0, /* `may be set to 0 to select all address families' */
+ NET_RT_IFLIST,
+ 0 /* ignored but six levels are needed */
+ };
+
+ if (-1==sysctl(mib, LEN(mib), NULL, &len, NULL, 0))
+ return -1;
+ if (!(bfr = malloc(len)))
+ return -1;
+ if (-1==sysctl(mib, LEN(mib), bfr, &len, NULL, 0)) {
+ free(bfr);
+ return -1;
+ }
+ nv = newval;
+ for (ptr=bfr; ptr<bfr+len; ptr+=rtm->rtm_msglen) {
+ struct if_msghdr *ifm;
+
+ rtm = (void*)ptr; /* chg ptr type to router msg */
+
+ if (rtm->rtm_version != RTM_VERSION) {
+ continue;
+ }
+
+ if (rtm->rtm_type != RTM_IFINFO) {
+ continue;
+ }
+
+ ifm = (void*)rtm; /* chg ptr type to interface msg */
+ if (!(ifm->ifm_flags & IFF_UP)) {
+ continue;
+ }
+
+ if (!countp) {
+ /* a sdl is concat'd to the if msg */
+ struct sockaddr_dl *sdl = (void*)(ifm+1);
+
+ /* copy and terminate the name */
+ /*fixme: check for overruns */
+ memcpy(nv->name, sdl->sdl_data, sdl->sdl_nlen);
+ nv->name[sdl->sdl_nlen] = 0;
+
+ /* copy the data */
+ nv->recv[I_bytes] = ifm->ifm_data.ifi_ibytes;
+ nv->recv[I_packs] = ifm->ifm_data.ifi_ipackets;
+ nv->recv[I_errs] = ifm->ifm_data.ifi_ierrors;
+ nv->recv[I_mcasts] = ifm->ifm_data.ifi_imcasts;
+ nv->recv[I_lost] = ifm->ifm_data.ifi_iqdrops;
+ nv->sent[I_bytes] = ifm->ifm_data.ifi_obytes;
+ nv->sent[I_packs] = ifm->ifm_data.ifi_opackets;
+ nv->sent[I_errs] = ifm->ifm_data.ifi_oerrors;
+ nv->sent[I_mcasts] = ifm->ifm_data.ifi_omcasts;
+ nv->sent[I_lost] = ifm->ifm_data.ifi_collisions;
+ }
+
+ /*fixme: guard against buffer overrun */
+ nv++;
+ }
+ free(bfr);
+ return nv-newval;
+}
+
+
+/* ------------------------------ public part --------------------------- */
+
+static void prVal(const char*, int);
+void printNetDevRecv(const char *cmd) { prVal(cmd,0); }
+void printNetDevSent(const char *cmd) { prVal(cmd,1); }
+
+static void prInfo(const char*, int);
+void printNetDevRecvInfo(const char *cmd) { prInfo(cmd,0); }
+void printNetDevSentInfo(const char *cmd) { prInfo(cmd,1); }
+
+static struct {
+ char *label;
+ cmdExecutor read, inform;
+ struct {
+ char *label, *info;
+ int index;
+ } op[5];
+} opTable[] = {
+ {"receiver",
+ printNetDevRecv, printNetDevRecvInfo,
+ {{"data", "Received Data\t0\t0\tB/s\n", I_bytes},
+ {"packets", "Received Packets\t0\t0\tHz\n", I_packs},
+ {"errors", "Receiver Errors\t0\t0\tHz\n", I_errs},
+ {"multicast", "Received Multicast Packets\t0\t0\tHz\n", I_mcasts},
+ {"drops", "Receiver Drops\t0\t0\tHz\n", I_lost}}},
+ {"transmitter",
+ printNetDevSent, printNetDevSentInfo,
+ {{"data", "Sent Data\t0\t0\tB/s\n", I_bytes},
+ {"packets", "Sent Packets\t0\t0\tHz\n", I_packs},
+ {"errors", "Transmitter Errors\t0\t0\tHz\n", I_errs},
+ {"multicast", "Sent Multicast Packets\t0\t0\tHz\n", I_mcasts},
+ {"collisions", "Transmitter Collisions\t0\t0\tHz\n", I_lost}}}
+};
+
+
+static void prVal(const char *cmd, int N) {
+ char *p, *q, *r;
+ int i, d;
+
+ if (!(p=rindex(cmd, '/')))
+ return;
+ *p=0;
+ q=rindex(cmd, '/');
+ *q=0;
+ r=rindex(cmd, '/');
+ r++;
+ for (d=NetDevCnt; d--; )
+ if (!strcmp(r, NetDevs[d].name))
+ break;
+ *q=*p='/';
+
+ if (-1 == d) return;
+
+ p++;
+ for (i=0; i<LEN(opTable[0].op); i++)
+ if (!strcmp(p, opTable[N].op[i].label))
+ fprintf(CurrentClient, "%lu",
+ /*fixme: ugly and presumptuous */
+ (N?NetDevs[d].Dsent:NetDevs[d].Drecv)[opTable[N].op[i].index]);
+ fprintf(CurrentClient, "\n");
+}
+
+
+static void prInfo(const char *cmd, int N) {
+ char *p, *q;
+ int i;
+
+ if (!(p=rindex(cmd, '/'))) return;
+ p++;
+
+ q = p+strlen(p)-1;
+ if ('?' != *q) return;
+ *q=0;
+
+ for (i=0; i<LEN(opTable[0].op); i++)
+ if (!strcmp(p, opTable[N].op[i].label))
+ fputs(opTable[N].op[i].info, CurrentClient);
+ *q='?';
+}
+
+
+
+static void NDreg (int setp)
+{
+ int i;
+
+ for (i = 0; i<NetDevCnt; i++) {
+ int j;
+
+ for (j=0; j<LEN(opTable); j++) {
+ int k;
+
+ for (k=0; k<LEN(opTable[0].op); k++) {
+ char buffer[1024];
+
+ snprintf(buffer, sizeof(buffer),
+ "network/interfaces/%s/%s/%s",
+ NetDevs[i].name,
+ opTable[j].label,
+ opTable[j].op[k].label);
+
+ /* printf("%d %d %d %s\n",i,j,k,buffer); */
+
+ if (setp)
+ registerMonitor(buffer,
+ "integer",
+ opTable[j].read,
+ opTable[j].inform, NetDevSM);
+ else
+ removeMonitor(buffer);
+ }
+
+ }
+ }
+}
+
+void initNetDev(struct SensorModul* sm) {
+ int i;
+
+ NetDevSM = sm;
+
+ updateNetDev();
+
+ for (i=LEN(NetDevs); i--;) {
+ strcpy(NetDevs[i].name, newval[i].name);
+ }
+
+ NDreg(!0);
+}
+
+
+void exitNetDev(void) {
+ NDreg(0);
+}
+
+void updateNetDev(void) {
+ NetDevInfo *p, *q;
+ int n;
+
+ if (-1==(n = readSys(0)))
+ return;
+
+ NetDevCnt = n;
+ /*fixme: assumes the interfaces are in the same order each time */
+ for (p=NetDevs, q=newval; n--; p++, q++) {
+ int i;
+ /* calculate deltas */
+ for (i=0; i<5; i++) {
+ p->Drecv[i] = q->recv[i]-p->recv[i];
+ p->recv[i] = q->recv[i];
+ p->Dsent[i] = q->sent[i]-p->sent[i];
+ p->sent[i] = q->sent[i];
+
+ }
+ }
+}
+
+void checkNetDev(void) {
+ if (readSys(!0) != NetDevCnt) {
+ /* interface has been added or removed
+ so we do a reset */
+ exitNetDev();
+ initNetDev(NetDevSM);
+ }
+}
+
+
+/* eof */
diff --git a/ksysguard/ksysguardd/NetBSD/netdev.h b/ksysguard/ksysguardd/NetBSD/netdev.h
new file mode 100644
index 000000000..4287c9203
--- /dev/null
+++ b/ksysguard/ksysguardd/NetBSD/netdev.h
@@ -0,0 +1,35 @@
+/*
+ KSysGuard, the KDE System Guard
+
+ Copyright (c) 2001 Tobias Koenig <tokoe@kde.org>
+
+ 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.
+
+*/
+
+#ifndef _netdev_h_
+#define _netdev_h_
+
+void initNetDev(struct SensorModul* sm);
+void exitNetDev(void);
+
+void updateNetDev(void);
+void checkNetDev(void);
+
+void printNetDevRecBytes(const char* cmd);
+void printNetDevRecBytesInfo(const char* cmd);
+void printNetDevSentBytes(const char* cmd);
+void printNetDevSentBytesInfo(const char* cmd);
+
+#endif