1
0
mirror of https://git.FreeBSD.org/ports.git synced 2025-01-30 10:19:20 +00:00

- Update to 0.18

PR:		ports/75435
Submitted by:	maintainer
This commit is contained in:
Sergey Matveychuk 2004-12-25 22:53:00 +00:00
parent fdae77ad9d
commit 135c4b9591
Notes: svn2git 2021-03-31 03:12:20 +00:00
svn path=/head/; revision=125184
8 changed files with 117 additions and 457 deletions

View File

@ -6,8 +6,7 @@
#
PORTNAME= torsmo
PORTVERSION= 0.17
PORTREVISION= 2
PORTVERSION= 0.18
CATEGORIES= sysutils
MASTER_SITES= ${MASTER_SITE_SOURCEFORGE}
MASTER_SITE_SUBDIR= ${PORTNAME}
@ -15,8 +14,7 @@ MASTER_SITE_SUBDIR= ${PORTNAME}
MAINTAINER= bogorodskiy@inbox.ru
COMMENT= System monitor that renders text on desktop
USE_AUTOCONF_VER=259
USE_AUTOMAKE_VER=14
GNU_CONFIGURE= yes
USE_X_PREFIX= yes
MAN1= torsmo.1
@ -27,9 +25,6 @@ PORTDOCS= AUTHORS ChangeLog NEWS README
.include <bsd.port.pre.mk>
post-extract:
@${CP} ${FILESDIR}/freebsd.c ${WRKSRC}
post-install:
.if !defined(NOPORTDOCS)
@${MKDIR} ${DOCSDIR}

View File

@ -1,2 +1,2 @@
MD5 (torsmo-0.17.tar.gz) = 8c82134cd78f9d4a7b6f6721ee2c16f9
SIZE (torsmo-0.17.tar.gz) = 80286
MD5 (torsmo-0.18.tar.gz) = 88bd8f627637d785a1d681f4f15f00b6
SIZE (torsmo-0.18.tar.gz) = 84020

View File

@ -1,351 +0,0 @@
/*
* 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/types.h>
#include <sys/time.h>
#include <sys/resource.h>
#include <sys/sysctl.h>
#include <sys/vmmeter.h>
#include <sys/dkstat.h>
#include <unistd.h>
#include <sys/user.h>
#include <sys/socket.h>
#include <net/if.h>
#include <net/if_mib.h>
#include <sys/socket.h>
#include <ifaddrs.h>
#define GETSYSCTL(name, var) getsysctl(name, &(var), sizeof(var))
#define KELVTOC(x) ((x - 2732) / 10.0)
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;
size_t 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 update_net_stats() {
struct net_stat *ns;
double delta;
long long r, t, last_recv, last_trans;
struct ifaddrs *ifap, *ifa;
struct if_data *ifd;
/* get delta */
delta = current_update_time - last_update_time;
if (delta <= 0.0001)
return;
if (getifaddrs(&ifap) < 0)
return;
for (ifa = ifap; ifa; ifa = ifa->ifa_next) {
ns = get_net_stat((const char *)ifa->ifa_name);
if (ifa->ifa_flags & IFF_UP) {
last_recv = ns->recv;
last_trans = ns->trans;
if (ifa->ifa_addr->sa_family != AF_LINK)
continue;
ifd = (struct if_data *)ifa->ifa_data;
r = ifd->ifi_ibytes;
t = ifd->ifi_obytes;
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;
}
}
freeifaddrs(ifap);
}
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 __FreeBSD__ < 5
if (p[i].kp_proc.p_stat == SRUN)
#else
if (p[i].ki_stat == SRUN)
#endif
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) {
int temp;
if (GETSYSCTL("hw.acpi.thermal.tz0.temperature", temp)) {
(void)fprintf(stderr, "Cannot read sysctl \"hw.acpi.thermal.tz0.temperature\"\n");
temp = -1.0;
}
return KELVTOC(temp);
}
void get_battery_stuff(char *buf, unsigned int n, int b) {
int battime;
if (GETSYSCTL("hw.acpi.battery.time", battime))
(void)fprintf(stderr, "Cannot read sysctl \"hw.acpi.battery.time\"\n");
if (battime != -1)
snprintf(buf, n, "Discharging, remaining %d:%2.2d", battime / 60, battime % 60);
else
snprintf(buf, n, "Battery is charging");
}
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)
{
int state;
char *acstate = (char*)malloc(100);
if (GETSYSCTL("hw.acpi.acline", state)) {
(void)fprintf(stderr, "Cannot read sysctl \"hw.acpi.acline\"\n");
return "n\\a";
}
if (state)
strcpy(acstate,"Running on AC Power");
else
strcpy(acstate, "Running on battery");
return acstate;
}
char* get_acpi_fan() {
return "";
}

View File

@ -1,15 +0,0 @@
--- 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)

View File

@ -1,35 +0,0 @@
--- 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)

View File

@ -0,0 +1,103 @@
--- freebsd.c.orig Wed Dec 22 20:52:33 2004
+++ freebsd.c Wed Dec 22 21:34:40 2004
@@ -4,14 +4,12 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <time.h>
-#include <sys/time.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/resource.h>
+#include <sys/sysctl.h>
#include <sys/vmmeter.h>
#include <sys/dkstat.h>
#include <unistd.h>
@@ -19,11 +17,48 @@
#include <sys/socket.h>
#include <net/if.h>
#include <net/if_mib.h>
+#include <sys/socket.h>
#include <ifaddrs.h>
#define GETSYSCTL(name, var) getsysctl(name, &(var), sizeof(var))
#define KELVTOC(x) ((x - 2732) / 10.0)
+static unsigned int get_timer();
+static unsigned int get_cpu_speed(void);
+static inline unsigned long long int rdtsc( void );
+
+/* cpu frequency detection code based on mplayer's one */
+
+static unsigned int get_timer() {
+ struct timeval tv;
+ struct timezone tz;
+ gettimeofday(&tv,&tz);
+
+ return (tv.tv_sec*1000000+tv.tv_usec);
+}
+
+static inline unsigned long long int rdtsc( void )
+{
+ unsigned long long int retval;
+ __asm __volatile ("rdtsc":"=A"(retval)::"memory");
+ return retval;
+}
+
+static unsigned int get_cpu_speed(void)
+{
+ unsigned long long int tscstart, tscstop;
+ unsigned int start, stop;
+
+ tscstart = rdtsc();
+ start = get_timer();
+ usleep(50000);
+ stop = get_timer();
+ tscstop = rdtsc();
+
+ return((tscstop-tscstart)/((stop-start)/1000.0));
+}
+
+
static int getsysctl(char *name, void *ptr, size_t len)
{
size_t nlen = len;
@@ -344,4 +379,34 @@
char* get_acpi_fan() {
return "";
+}
+
+char* get_adt746x_cpu() {
+ return "";
+}
+
+char* get_adt746x_fan() {
+ return "";
+}
+
+char* get_freq() {
+ int i;
+ char *cpuspeed;
+
+ if ((cpuspeed = (char *)malloc(16)) == NULL)
+ exit(1);
+
+ i = 0;
+ if ((i = get_cpu_speed()) > 0) {
+ if (i < 1000000) {
+ i += 50; /* for rounding */
+ snprintf(cpuspeed, 15, "%d.%d MHz", i/1000, (i/100)%10);
+ } else {
+ snprintf(cpuspeed, 15, "%d MHz", i/1000);
+ }
+ } else {
+ cpuspeed = "";
+ }
+
+ return cpuspeed;
}

View File

@ -1,37 +0,0 @@
--- fs.c.orig Thu Aug 5 19:59:50 2004
+++ fs.c Thu Aug 5 20:01:50 2004
@@ -3,10 +3,12 @@
#include <stdlib.h>
#include <string.h>
#include <errno.h>
-#include <sys/statvfs.h>
#include <sys/types.h>
#include <fcntl.h>
+#include <sys/param.h>
+#include <sys/mount.h>
+
/* TODO: benchmark which is faster, fstatvfs() or pre-opened fd and
* statvfs() (fstatvfs() would handle mounts I think...) */
@@ -15,16 +17,16 @@
void update_fs_stats() {
unsigned int i;
- struct statvfs s;
+ struct statfs s;
for (i=0; i<16; i++) {
if (fs_stats[i].fd <= 0)
break;
- fstatvfs(fs_stats[i].fd, &s);
+ fstatfs(fs_stats[i].fd, &s);
- fs_stats[i].size = (long long) s.f_blocks * s.f_frsize;
+ fs_stats[i].size = (long long) s.f_blocks * s.f_bsize;
/* bfree (root) or bavail (non-roots) ? */
- fs_stats[i].avail = (long long) s.f_bavail * s.f_frsize;
+ fs_stats[i].avail = (long long) s.f_bavail * s.f_bsize;
}
}

View File

@ -1,6 +1,6 @@
--- torsmo.c.orig Wed Oct 13 17:31:57 2004
+++ torsmo.c Wed Oct 13 17:35:45 2004
@@ -376,7 +376,7 @@
--- torsmo.c.orig Wed Dec 22 01:14:46 2004
+++ torsmo.c Wed Dec 22 21:49:27 2004
@@ -272,7 +272,7 @@
snprintf(buf, 255, "%.1fM", m);
}
else if (a >= 1024)
@ -9,33 +9,33 @@
else
snprintf(buf, 255, "%Ld", a);
}
@@ -998,7 +998,7 @@
@@ -883,7 +883,7 @@
}
OBJ(acpitemp) {
/* does anyone have decimals in acpi temperature? */
- snprintf(p, n, "%d", (int) get_acpi_temperature(obj->data.i));
+ snprintf(p, n, "%0.1f", (float)get_acpi_temperature(obj->data.i));
}
OBJ(acpifan) {
snprintf(p, n, "%s", get_acpi_fan());
@@ -2248,8 +2248,8 @@
OBJ(freq) {
snprintf(p, n, "%s", get_freq());
@@ -2223,8 +2223,8 @@
/* handle other command line arguments */
- optind = 0;
-
+ optind = optreset = 1;
+ optind = optreset = 1;
+
while (1) {
int c = getopt(argc, argv, getopt_string);
if(c == -1) break;
@@ -2353,8 +2353,7 @@
@@ -2319,8 +2319,7 @@
default:
fprintf(stderr, "torsmo: forked to background, pid is %d\n", ret);
- exit(0);
- break;
+ return 0;
+ return 0;
}
}