aboutsummaryrefslogtreecommitdiff
path: root/sysutils
diff options
context:
space:
mode:
authorPav Lucistnik <pav@FreeBSD.org>2004-07-30 20:47:55 +0000
committerPav Lucistnik <pav@FreeBSD.org>2004-07-30 20:47:55 +0000
commitdb95a8d61a9e914c3193359e3914b46aab1a6ebb (patch)
tree482548b95e39a3de4bb181c2a3793b8357446fb1 /sysutils
parenta07e6951758927784d3331ce298ba13886a81cbc (diff)
downloadports-db95a8d61a9e914c3193359e3914b46aab1a6ebb.tar.gz
ports-db95a8d61a9e914c3193359e3914b46aab1a6ebb.zip
Add torsmo, a system monitor that sits in the corner of your desktop. Torsmo can
show various information about your system and it's peripherals. PR: ports/69743 Submitted by: Roman Bogorodskiy <bogorodskiy@inbox.ru>
Notes
Notes: svn path=/head/; revision=115108
Diffstat (limited to 'sysutils')
-rw-r--r--sysutils/Makefile1
-rw-r--r--sysutils/torsmo/Makefile44
-rw-r--r--sysutils/torsmo/distinfo2
-rw-r--r--sysutils/torsmo/files/freebsd.c369
-rw-r--r--sysutils/torsmo/files/patch-Makefile.am15
-rw-r--r--sysutils/torsmo/files/patch-configure.in35
-rw-r--r--sysutils/torsmo/pkg-descr4
7 files changed, 470 insertions, 0 deletions
diff --git a/sysutils/Makefile b/sysutils/Makefile
index 10d156a9660c..744a4f1bd96d 100644
--- a/sysutils/Makefile
+++ b/sysutils/Makefile
@@ -402,6 +402,7 @@
SUBDIR += timelimit
SUBDIR += tmpwatch
SUBDIR += top
+ SUBDIR += torsmo
SUBDIR += toshctl
SUBDIR += tree
SUBDIR += ttyload
diff --git a/sysutils/torsmo/Makefile b/sysutils/torsmo/Makefile
new file mode 100644
index 000000000000..060988df4a71
--- /dev/null
+++ b/sysutils/torsmo/Makefile
@@ -0,0 +1,44 @@
+# New ports collection makefile for: torsmo
+# Date created: 2004-07-29
+# Whom: Roman Bogorodskiy <bogorodskiy@inbox.ru>
+#
+# $FreeBSD$
+#
+
+PORTNAME= torsmo
+PORTVERSION= 0.17
+CATEGORIES= sysutils
+MASTER_SITES= ${MASTER_SITE_SOURCEFORGE}
+MASTER_SITE_SUBDIR= ${PORTNAME}
+
+MAINTAINER= bogorodskiy@inbox.ru
+COMMENT= System monitor that renders text on desktop
+
+USE_AUTOCONF_VER=259
+USE_AUTOMAKE_VER=14
+USE_X_PREFIX= yes
+MAN1= torsmo.1
+
+PLIST_FILES= bin/torsmo \
+ %%EXAMPLESDIR%%/torsmorc.sample
+PLIST_DIRS= %%EXAMPLESDIR%%
+PORTDOCS= AUTHORS ChangeLog NEWS README
+
+.include <bsd.port.pre.mk>
+
+.if ${OSVERSION} < 500000
+BROKEN= does not build, use statvfs interface which is only present on FreeBSD 5.0 or newer
+.endif
+
+post-extract:
+ @${CP} ${FILESDIR}/freebsd.c ${WRKSRC}
+
+post-install:
+.if !defined(NOPORTDOCS)
+ @${MKDIR} ${DOCSDIR}
+ @cd ${WRKSRC} && ${INSTALL_DATA} ${PORTDOCS} ${DOCSDIR}
+.endif
+ @${MKDIR} ${EXAMPLESDIR}
+ @${INSTALL_DATA} ${WRKSRC}/torsmorc.sample ${EXAMPLESDIR}
+
+.include <bsd.port.post.mk>
diff --git a/sysutils/torsmo/distinfo b/sysutils/torsmo/distinfo
new file mode 100644
index 000000000000..3582d3348d50
--- /dev/null
+++ b/sysutils/torsmo/distinfo
@@ -0,0 +1,2 @@
+MD5 (torsmo-0.17.tar.gz) = 8c82134cd78f9d4a7b6f6721ee2c16f9
+SIZE (torsmo-0.17.tar.gz) = 80286
diff --git a/sysutils/torsmo/files/freebsd.c b/sysutils/torsmo/files/freebsd.c
new file mode 100644
index 000000000000..fed04d33cb53
--- /dev/null
+++ b/sysutils/torsmo/files/freebsd.c
@@ -0,0 +1,369 @@
+/*
+ * Copyright (c) 2004 Roman Bogorodskiy <bogorodskiy@inbox.ru>
+ *
+ * $FreeBSD$
+ */
+
+#include "torsmo.h"
+#include <fcntl.h>
+#include <limits.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <kvm.h>
+#include <sys/param.h>
+#include <sys/resource.h>
+#include <sys/sysctl.h>
+#include <sys/types.h>
+#include <sys/time.h>
+#include <sys/vmmeter.h>
+#include <unistd.h>
+#include <sys/user.h>
+#include <sys/socket.h>
+#include <net/if.h>
+#include <net/if_mib.h>
+
+void net_init();
+
+#define GETSYSCTL(name, var) getsysctl(name, &(var), sizeof(var))
+
+static int getsysctl(char *name, void *ptr, size_t len)
+{
+ size_t nlen = len;
+ if (sysctlbyname(name, ptr, &nlen, NULL, 0) == -1) {
+ return -1;
+ }
+
+ if (nlen != len) {
+ return -1;
+ }
+
+ return 0;
+}
+
+static kvm_t *kd = NULL;
+struct ifmibdata *data = NULL;
+size_t len = 0;
+
+static int swapmode(int *retavail, int *retfree)
+{
+ int n;
+ int pagesize = getpagesize();
+ struct kvm_swap swapary[1];
+ static int kd_init = 1;
+
+ if(kd_init) {
+ kd_init = 0;
+ if ((kd = kvm_open("/dev/null", "/dev/null", "/dev/null",
+ O_RDONLY, "kvm_open")) == NULL) {
+ (void)fprintf(stderr, "Cannot read kvm\n");
+ return -1;
+ }
+ }
+
+ if(kd == NULL) {
+ return -1;
+ }
+
+ *retavail = 0;
+ *retfree = 0;
+
+#define CONVERT(v) ((quad_t)(v) * pagesize / 1024)
+
+ n = kvm_getswapinfo(kd, swapary, 1, 0);
+ if (n < 0 || swapary[0].ksw_total == 0)
+ return(0);
+
+ *retavail = CONVERT(swapary[0].ksw_total);
+ *retfree = CONVERT(swapary[0].ksw_total - swapary[0].ksw_used);
+
+ n = (int)((double)swapary[0].ksw_used * 100.0 /
+ (double)swapary[0].ksw_total);
+
+ return n;
+}
+
+
+void prepare_update() {
+}
+
+double get_uptime()
+{
+ int mib[2] = {CTL_KERN, KERN_BOOTTIME};
+ struct timeval boottime;
+ time_t now;
+ int size = sizeof(boottime);
+ double uptime;
+
+ if((sysctl(mib, 2, &boottime, &size, NULL, 0) != -1) && (boottime.tv_sec != 0)) {
+ time(&now);
+ uptime = now - boottime.tv_sec;
+ } else {
+ (void)fprintf(stderr, "Could not get uptime\n");
+ uptime = 0;
+ }
+
+ return uptime;
+}
+
+
+void update_meminfo() {
+ int total_pages,
+ inactive_pages,
+ free_pages;
+ int swap_avail,
+ swap_free;
+
+ int pagesize = getpagesize();
+
+ if (GETSYSCTL("vm.stats.vm.v_page_count", total_pages))
+ (void)fprintf(stderr, "Cannot read sysctl \"vm.stats.vm.v_page_count\"\n");
+
+ if (GETSYSCTL("vm.stats.vm.v_free_count", free_pages))
+ (void)fprintf(stderr, "Cannot read sysctl \"vm.stats.vm.v_free_count\"\n");
+
+ if (GETSYSCTL("vm.stats.vm.v_inactive_count", inactive_pages))
+ (void)fprintf(stderr, "Cannot read sysctl \"vm.stats.vm.v_inactive_count\"\n");
+
+ memmax = (total_pages*pagesize) >> 10;
+ mem = ((total_pages-free_pages-inactive_pages) * pagesize) >> 10;
+
+
+ if ((swapmode(&swap_avail, &swap_free)) >= 0) {
+ swapmax = swap_avail;
+ swap = (swap_avail - swap_free);
+ } else {
+ swapmax = 0;
+ swap = 0;
+ }
+}
+
+void net_init()
+{
+/* XXX */
+#if 0
+ struct ifmibdata tempndata;
+ int numifaces;
+ size_t len2;
+ int mib[5], datamib[6];
+ int i;
+
+ mib[0] = CTL_NET;
+ mib[1] = PF_LINK;
+ mib[2] = NETLINK_GENERIC;
+ mib[3] = IFMIB_SYSTEM;
+ mib[4] = IFMIB_IFCOUNT;
+
+ datamib[0] = CTL_NET;
+ datamib[1] = PF_LINK;
+ datamib[2] = NETLINK_GENERIC;
+ datamib[3] = IFMIB_IFDATA;
+ datamib[4] = 1;
+ datamib[5] = IFDATA_GENERAL;
+
+ len = sizeof(struct ifmibdata);
+ len2 = sizeof(numifaces);
+
+ if(sysctl(mib, 5, &numifaces, &len2, NULL, 0) < 0)
+ fprintf( stderr, "wmnet: failed to perform sysctl" );
+
+ for(i = 1; i <= numifaces; i++)
+ {
+ datamib[4] = i;
+ if(sysctl(datamib, 6, &tempndata, &len, NULL, 0) < 0)
+ {
+ fprintf( stderr, "wmnet: failed to get device(%d) data", i );
+ break;
+ }
+
+ }
+
+
+ /* calculate and allocate mem for ifmibdata containing the if stats */
+ data = malloc(len);
+
+#endif
+}
+
+void update_net_stats() {
+#if 0
+ static int rep;
+ unsigned int i;
+ char buf[256];
+ double delta;
+
+ /* get delta */
+ delta = current_update_time - last_update_time;
+ if (delta <= 0.0001)
+ return;
+
+ net_init();
+
+ /* read each interface */
+ for (i=0; i<16; i++) {
+ struct net_stat *ns;
+ char *s, *p;
+ long long r, t, last_recv, last_trans;
+ int datamib[6];
+
+ ns = get_net_stat(s);
+ last_recv = ns->recv;
+ last_trans = ns->trans;
+
+ datamib[0] = CTL_NET;
+ datamib[1] = PF_LINK;
+ datamib[2] = NETLINK_GENERIC;
+ datamib[3] = IFMIB_IFDATA;
+ datamib[4] = i;
+ datamib[5] = IFDATA_GENERAL;
+
+ if (sysctl(datamib, 6, data, &len, NULL, 0) < 0 ) {
+ perror("sysctl");
+ }
+
+ r = data->ifmd_data.ifi_ipackets;
+ t = data->ifmd_data.ifi_opackets;
+
+ if (r < ns->last_read_recv)
+ ns->recv += ((long long) 4294967295U - ns->last_read_recv) + r;
+ else
+ ns->recv += (r - ns->last_read_recv);
+ ns->last_read_recv = r;
+
+ if (t < ns->last_read_trans)
+ ns->trans += ((long long) 4294967295U - ns->last_read_trans) + t;
+ else
+ ns->trans += (t - ns->last_read_trans);
+ ns->last_read_trans = t;
+
+ /* calculate speeds */
+ ns->recv_speed = (ns->recv - last_recv) / delta;
+ ns->trans_speed = (ns->trans - last_trans) / delta;
+ }
+
+#endif
+}
+
+int get_total_processes() {
+ /* It's easier to use kvm here than sysctl */
+
+ int n_processes;
+ static int kd_init = 1;
+
+ if (kd_init) {
+ kd_init = 0;
+ if ((kd = kvm_open("/dev/null", "/dev/null", "/dev/null",
+ O_RDONLY, "kvm_open")) == NULL) {
+ (void)fprintf(stderr, "Cannot read kvm\n");
+ return 0;
+ }
+ }
+
+
+ if (kd != NULL)
+ kvm_getprocs(kd, KERN_PROC_ALL, 0, &n_processes);
+ else
+ return 0;
+
+ return n_processes;
+}
+
+int get_running_processes() {
+ static int kd_init = 1;
+ struct kinfo_proc *p;
+ int n_processes;
+ int i,
+ cnt = 0;
+
+ if(kd_init) {
+ kd_init = 0;
+ if ((kd = kvm_open("/dev/null", "/dev/null", "/dev/null", O_RDONLY, "kvm_open")) == NULL) {
+ (void)fprintf(stderr, "Cannot read kvm\n");
+ return 0;
+ }
+ }
+
+ if (kd != NULL) {
+ p = kvm_getprocs(kd, KERN_PROC_ALL, 0, &n_processes);
+ for (i = 0; i<n_processes; i++) {
+ if (p[i].ki_stat == SRUN)
+ cnt++;
+ }
+ } else
+ return 0;
+
+ return cnt;
+}
+
+struct cpu_load_struct {
+ unsigned long load[5];
+};
+
+struct cpu_load_struct fresh = {{0, 0, 0, 0, 0}};
+long cpu_used, oldtotal, oldused;
+
+void update_cpu_usage() {
+ long used, total;
+ long cp_time[CPUSTATES];
+ size_t len = sizeof(cp_time);
+
+ if (sysctlbyname("kern.cp_time", &cp_time, &len, NULL, 0) < 0) {
+ (void)fprintf(stderr, "Cannot get kern.cp_time");
+ }
+
+ fresh.load[0] = cp_time[CP_USER];
+ fresh.load[1] = cp_time[CP_NICE];
+ fresh.load[2] = cp_time[CP_SYS];
+ fresh.load[3] = cp_time[CP_IDLE];
+ fresh.load[4] = cp_time[CP_IDLE];
+
+ used = fresh.load[0] + fresh.load[1] + fresh.load[2];
+ total = fresh.load[0] + fresh.load[1] + fresh.load[2] + fresh.load[3];
+
+ if ((total - oldtotal) != 0)
+ {
+ cpu_usage = ((double)(used - oldused)) / (double)(total - oldtotal);
+ } else {
+ cpu_usage = 0;
+ }
+
+ oldused = used;
+ oldtotal = total;
+}
+
+double get_i2c_info(int fd, int div) {
+ return 0;
+}
+
+void get_load_average(double v[3]) {
+ getloadavg(v, 3);
+}
+
+double get_acpi_temperature(int fd) {
+ double temp;
+
+ temp = 0;
+
+ return temp;
+}
+
+void get_battery_stuff(char *buf, unsigned int n, int b) {
+}
+
+int open_i2c_sensor(const char *dev, const char *type, int n, int *div)
+{
+ return 0;
+}
+
+int open_acpi_temperature(const char *name) {
+ return 0;
+}
+
+char* get_acpi_ac_adapter(void)
+{
+ return "blah";
+}
+
+char* get_acpi_fan() {
+ return "";
+}
diff --git a/sysutils/torsmo/files/patch-Makefile.am b/sysutils/torsmo/files/patch-Makefile.am
new file mode 100644
index 000000000000..067a421610cf
--- /dev/null
+++ b/sysutils/torsmo/files/patch-Makefile.am
@@ -0,0 +1,15 @@
+--- Makefile.am.orig Thu Jul 29 08:32:01 2004
++++ Makefile.am Thu Jul 29 08:32:10 2004
+@@ -8,7 +8,11 @@
+ solaris = solaris.c
+ endif
+
+-torsmo_SOURCES = torsmo.c torsmo.h fs.c $(linux) $(solaris)
++if BUILD_FREEBSD
++freebsd = freebsd.c
++endif
++
++torsmo_SOURCES = torsmo.c torsmo.h fs.c $(linux) $(solaris) $(freebsd)
+
+ torsmo_LDFLAGS = $(X11_LIBS)
+
diff --git a/sysutils/torsmo/files/patch-configure.in b/sysutils/torsmo/files/patch-configure.in
new file mode 100644
index 000000000000..1db7fab5336c
--- /dev/null
+++ b/sysutils/torsmo/files/patch-configure.in
@@ -0,0 +1,35 @@
+--- configure.in.orig Thu Jul 29 08:30:12 2004
++++ configure.in Thu Jul 29 08:30:23 2004
+@@ -9,7 +9,9 @@
+ Linux*)
+ WANT_SYSINFO=yes
+ ;;
+-
++ FreeBSD*)
++ WANT_KVM=yes
++ ;;
+ # Solaris doesn't work at all right now
+ # SunOS*)
+ # WANT_KSTAT=yes
+@@ -24,6 +26,8 @@
+
+ AM_CONDITIONAL(BUILD_LINUX, test x$uname = xLinux)
+ AM_CONDITIONAL(BUILD_SOLARIS, test x$uname = xSunOS)
++AM_CONDITIONAL(BUILD_FREEBSD, test x$uname = xFreeBSD)
++
+
+ dnl OWN_WINDOW option
+
+@@ -108,6 +112,12 @@
+ fi
+ fi
+
++if test x$WANT_KVM = xyes; then
++ AC_CHECK_LIB(kvm, kvm_open,
++ LIBS="$LIBS -lkvm",
++ AC_MSG_ERROR([Could not find kvm_open in -lkvm.])
++ )
++fi
+ dnl Check getloadavg
+
+ AC_MSG_CHECKING(for getloadavg)
diff --git a/sysutils/torsmo/pkg-descr b/sysutils/torsmo/pkg-descr
new file mode 100644
index 000000000000..83f2718265d1
--- /dev/null
+++ b/sysutils/torsmo/pkg-descr
@@ -0,0 +1,4 @@
+Torsmo is a system monitor that sits in the corner of your desktop. Torsmo can
+show various information about your system and it's peripherals.
+
+WWW: http://torsmo.sourceforge.net/