aboutsummaryrefslogtreecommitdiffstats
path: root/sysutils
diff options
context:
space:
mode:
authorglewis <glewis@FreeBSD.org>2004-08-07 02:00:53 +0800
committerglewis <glewis@FreeBSD.org>2004-08-07 02:00:53 +0800
commitfa5ca9d6025a8ca4acac3c6505539e2737a87c55 (patch)
tree5485d3548e5b487ddda6327be78bcb9418243286 /sysutils
parent4c7f31b870097d8c1d81be2ad18aefbd80a28be2 (diff)
downloadfreebsd-ports-gnome-fa5ca9d6025a8ca4acac3c6505539e2737a87c55.tar.gz
freebsd-ports-gnome-fa5ca9d6025a8ca4acac3c6505539e2737a87c55.tar.zst
freebsd-ports-gnome-fa5ca9d6025a8ca4acac3c6505539e2737a87c55.zip
. Add ACPI support. [1]
. Make this compile on FreeBSD 4.x. I've hacked the version being committed to actually compile on 4.x. The submitted patch only partially fixed 4.x build problems. [2] PR: 70039 [1], 70041 [2] Submitted by: Roman Bogorodskiy <bogorodskiy@inbox.ru> (maintainer)
Diffstat (limited to 'sysutils')
-rw-r--r--sysutils/torsmo/Makefile4
-rw-r--r--sysutils/torsmo/files/freebsd.c53
-rw-r--r--sysutils/torsmo/files/patch-fs.c37
-rw-r--r--sysutils/torsmo/files/patch-torsmo.c11
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());