[Xfce4-commits] <xfce4-battery-plugin:master> Fix fan and temperature detection
Florian Rivoal
noreply at xfce.org
Mon Dec 27 17:14:01 CET 2010
Updating branch refs/heads/master
to a1e45d47f8bf0c09c6965b06c5f12ae3c1751b3d (commit)
from fc035e529ccc6cd5faa3e94eb3257863fc2759df (commit)
commit a1e45d47f8bf0c09c6965b06c5f12ae3c1751b3d
Author: Florian Rivoal <frivoal at xfce.org>
Date: Tue Dec 28 01:13:38 2010 +0900
Fix fan and temperature detection
Applying patch from bug #2884
panel-plugin/libacpi.c | 23 ++++++++++++++++++++---
1 files changed, 20 insertions(+), 3 deletions(-)
diff --git a/panel-plugin/libacpi.c b/panel-plugin/libacpi.c
index af17b09..15050f2 100644
--- a/panel-plugin/libacpi.c
+++ b/panel-plugin/libacpi.c
@@ -28,6 +28,7 @@
#include <stdlib.h>
#include <sys/types.h>
#include <dirent.h>
+#include <glob.h>
#if HAVE_SYSCTL
@@ -246,6 +247,22 @@ int check_acpi_sysfs(void)
}
}
+/* expand file name and fopen first match */
+static FILE *
+fopen_glob(const char *name, const char *mode)
+{
+ glob_t globbuf;
+ FILE *fd;
+
+ if (glob(name, 0, NULL, &globbuf) != 0)
+ return NULL;
+
+ fd = fopen(globbuf.gl_pathv[0], mode);
+ globfree(&globbuf);
+
+ return fd;
+}
+
/* see if we have ACPI support */
int check_acpi(void)
{
@@ -971,7 +988,7 @@ int get_fan_status(void)
else return 0;
}
proc_fan_status="/proc/acpi/fan/*/state";
- if ( (fp=fopen(proc_fan_status, "r")) == NULL ) return 0;
+ if ( (fp=fopen_glob(proc_fan_status, "r")) == NULL ) return 0;
fgets(line,255,fp);
fclose(fp);
@@ -984,10 +1001,10 @@ const char *get_temperature(void)
{
#ifdef __linux__
FILE *fp;
- char *proc_temperature="/proc/acpi/thermal_zone/*0/temperature";
+ char *proc_temperature="/proc/acpi/thermal_zone/*/temperature";
static char *p,line[256];
- if ( (fp=fopen(proc_temperature, "r")) == NULL) return NULL;
+ if ( (fp=fopen_glob(proc_temperature, "r")) == NULL) return NULL;
fgets(line,255,fp);
fclose(fp);
p=strtok(line," ");
More information about the Xfce4-commits
mailing list