diff options
author | Greg Lewis <glewis@FreeBSD.org> | 2004-08-06 18:00:53 +0000 |
---|---|---|
committer | Greg Lewis <glewis@FreeBSD.org> | 2004-08-06 18:00:53 +0000 |
commit | 3d2373ec2c1a9ce549a39ee3df01d26df1289936 (patch) | |
tree | dae87855c5d1076a88cb850a4868f8bdae46e90a /sysutils/torsmo | |
parent | 3122f31a466a1b65ca61ba6c8529259b7269a7d9 (diff) | |
download | ports-3d2373ec2c1a9ce549a39ee3df01d26df1289936.tar.gz ports-3d2373ec2c1a9ce549a39ee3df01d26df1289936.zip |
Notes
Diffstat (limited to 'sysutils/torsmo')
-rw-r--r-- | sysutils/torsmo/Makefile | 4 | ||||
-rw-r--r-- | sysutils/torsmo/files/freebsd.c | 53 | ||||
-rw-r--r-- | sysutils/torsmo/files/patch-fs.c | 37 | ||||
-rw-r--r-- | sysutils/torsmo/files/patch-torsmo.c | 11 |
4 files changed, 91 insertions, 14 deletions
diff --git a/sysutils/torsmo/Makefile b/sysutils/torsmo/Makefile index 060988df4a71..434f4342cafc 100644 --- a/sysutils/torsmo/Makefile +++ b/sysutils/torsmo/Makefile @@ -26,10 +26,6 @@ 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} diff --git a/sysutils/torsmo/files/freebsd.c b/sysutils/torsmo/files/freebsd.c index d8d65ef73f81..b973050d6b97 100644 --- a/sysutils/torsmo/files/freebsd.c +++ b/sysutils/torsmo/files/freebsd.c @@ -11,11 +11,12 @@ #include <stdlib.h> #include <string.h> #include <kvm.h> +#include <sys/dkstat.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 <unistd.h> #include <sys/user.h> @@ -28,6 +29,7 @@ void net_init(); #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) { @@ -144,15 +146,15 @@ 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; - struct ifaddrs *ifap, *ifa; - struct if_data *ifd; - if (getifaddrs(&ifap) < 0) return; @@ -237,7 +239,11 @@ int get_running_processes() { 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 @@ -291,14 +297,27 @@ void get_load_average(double v[3]) { } double get_acpi_temperature(int fd) { - double temp; + double temp; - temp = 0; - - return 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) @@ -312,9 +331,23 @@ int open_acpi_temperature(const char *name) { char* get_acpi_ac_adapter(void) { - return "blah"; + 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 ""; } diff --git a/sysutils/torsmo/files/patch-fs.c b/sysutils/torsmo/files/patch-fs.c new file mode 100644 index 000000000000..206307a97006 --- /dev/null +++ b/sysutils/torsmo/files/patch-fs.c @@ -0,0 +1,37 @@ +--- 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; + } + } + diff --git a/sysutils/torsmo/files/patch-torsmo.c b/sysutils/torsmo/files/patch-torsmo.c new file mode 100644 index 000000000000..c32c6aa662a3 --- /dev/null +++ b/sysutils/torsmo/files/patch-torsmo.c @@ -0,0 +1,11 @@ +--- torsmo.c.orig Thu Aug 5 19:39:06 2004 ++++ torsmo.c Thu Aug 5 19:39:20 2004 +@@ -998,7 +998,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", (int) get_acpi_temperature(obj->data.i)); + } + OBJ(acpifan) { + snprintf(p, n, "%s", get_acpi_fan()); |