summaryrefslogtreecommitdiffstats
path: root/main/xfce4-battery-plugin/sysfs-temp.patch
blob: d20680ed8d90f25c2ddff1869b457c7f9fa7c40e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
From e33899de3205edfc0b2c330f43da6a4bc8141b85 Mon Sep 17 00:00:00 2001
From: Florian Rivoal <frivoal@xfce.org>
Date: Sat, 26 Feb 2011 13:53:09 +0000
Subject: 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.
---
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];
--
cgit v0.8.3.4