[Xfce4-commits] <xfce4-battery-plugin:master> Add support for getting the temperature from sysfs

Florian Rivoal noreply at xfce.org
Sat Feb 26 15:14:03 CET 2011


Updating branch refs/heads/master
         to e33899de3205edfc0b2c330f43da6a4bc8141b85 (commit)
       from 686cf28fc98ac8596714b1dd9317c16de1b3f34e (commit)

commit e33899de3205edfc0b2c330f43da6a4bc8141b85
Author: Florian Rivoal <frivoal at xfce.org>
Date:   Sat Feb 26 22:53:09 2011 +0900

    Add support for getting the temperature from sysfs
    
    Up to the linux kernel version 2.6.37, this information was available in
    the proc file system, but after that, it is only available from the sys
    file system.
    
    This fixes bug #7339.

 panel-plugin/libacpi.c |   42 ++++++++++++++++++++++++++++++------------
 1 files changed, 30 insertions(+), 12 deletions(-)

diff --git a/panel-plugin/libacpi.c b/panel-plugin/libacpi.c
index 838a760..0e368f4 100644
--- a/panel-plugin/libacpi.c
+++ b/panel-plugin/libacpi.c
@@ -1002,18 +1002,36 @@ const char *get_temperature(void)
 #ifdef __linux__
   FILE *fp;
   char *proc_temperature="/proc/acpi/thermal_zone/*/temperature";
-  static char *p,line[256];
-
-  if ( (fp=fopen_glob(proc_temperature, "r")) == NULL) return NULL;
-  fgets(line,255,fp);
-  fclose(fp);
-  p=strtok(line," ");
-  if (!p) return NULL;
-  p=p+strlen(p)+1;
-  while (p && *p ==' ') p++;
-  if (*p==0) return NULL;
-  if (strchr(p,'\n')) p=strtok(p,"\n");
-  return (const char *)p;
+  char *sys_temperature="/sys/class/thermal/thermal_zone*/temp";
+  static char *p,*p2,line[256];
+
+  if ( (fp=fopen_glob(proc_temperature, "r")) != NULL )
+  {
+    fgets(line,255,fp);
+    fclose(fp);
+    p=strtok(line," ");
+    if (!p) return NULL;
+    p=p+strlen(p)+1;
+    while (p && *p ==' ') p++;
+    if (*p==0) return NULL;
+    if (strchr(p,'\n')) p=strtok(p,"\n");
+    return (const char *)p;
+  }
+  else if ( (fp=fopen_glob(sys_temperature, "r")) != NULL )
+  {
+    fgets(line,255,fp);
+    fclose(fp);
+    p = line;
+    if (strchr(p,'\n')) *strchr(p,'\n') = 0;
+    if (strlen(p) <= 3) return NULL;
+    p2 = p + strlen(p) - 3;
+    strcpy(p2, " C");
+    return (const char *)p;
+  }
+  else
+  {
+    return NULL;
+  }
 #else
 #ifdef HAVE_SYSCTL
   static char buf[BUFSIZ];



More information about the Xfce4-commits mailing list