summaryrefslogtreecommitdiff
path: root/app-admin/conky/files/conky-1.8.1-acpitemp.patch
blob: 9632b99ef5abd30610d5569605ef3f4da1fe426a (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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
From 1b90218c339467770254aba03e3f0a3acc4af4b0 Mon Sep 17 00:00:00 2001
From: Nikolas Garofil <nikolas@garofil.be>
Date: Wed, 10 Nov 2010 18:22:22 +0100
Subject: [PATCH] Let $acpitemp use /sys instead of /proc

From the 2.6.36 changelog (http://www.kernel.org/pub/linux/kernel/v2.6/ChangeLog-2.6.36):
Mark the ACPI thermal procfs I/F deprecated, because /sys/class/thermal/ is already available and has been working for years w/o any problem.
The ACPI thermal procfs I/F will be removed in 2.6.37
---
 src/linux.cc |   26 ++++++++++++--------------
 1 files changed, 12 insertions(+), 14 deletions(-)

diff --git a/src/linux.cc b/src/linux.cc
index ae97f48..bfb0063 100644
--- a/src/linux.c
+++ b/src/linux.c
@@ -1449,26 +1449,20 @@ critical (S5):           73 C
 passive:                 73 C: tc1=4 tc2=3 tsp=40 devices=0xcdf6e6c0
 */
 
-#define ACPI_THERMAL_DIR "/proc/acpi/thermal_zone/"
-#define ACPI_THERMAL_FORMAT "/proc/acpi/thermal_zone/%s/temperature"
+#define ACPI_THERMAL_ZONE_DEFAULT "thermal_zone0"
+#define ACPI_THERMAL_FORMAT "/sys/class/thermal/%s/temp"
 
 int open_acpi_temperature(const char *name)
 {
 	char path[256];
-	char buf[256];
 	int fd;
 
 	if (name == NULL || strcmp(name, "*") == 0) {
-		static int rep = 0;
-
-		if (!get_first_file_in_a_directory(ACPI_THERMAL_DIR, buf, &rep)) {
-			return -1;
-		}
-		name = buf;
+		snprintf(path, 255, ACPI_THERMAL_FORMAT, ACPI_THERMAL_ZONE_DEFAULT);
+	} else {
+		snprintf(path, 255, ACPI_THERMAL_FORMAT, name);
 	}
 
-	snprintf(path, 255, ACPI_THERMAL_FORMAT, name);
-
 	fd = open(path, O_RDONLY);
 	if (fd < 0) {
 		NORM_ERR("can't open '%s': %s", path, strerror(errno));
@@ -1480,6 +1474,9 @@ int open_acpi_temperature(const char *name)
 static double last_acpi_temp;
 static double last_acpi_temp_time;
 
+//the maximum length of the string inside a ACPI_THERMAL_FORMAT file including the ending 0
+#define MAXTHERMZONELEN 6
+
 double get_acpi_temperature(int fd)
 {
 	if (fd <= 0) {
@@ -1497,15 +1494,16 @@ double get_acpi_temperature(int fd)
 
 	/* read */
 	{
-		char buf[256];
+		char buf[MAXTHERMZONELEN];
 		int n;
 
-		n = read(fd, buf, 255);
+		n = read(fd, buf, MAXTHERMZONELEN-1);
 		if (n < 0) {
 			NORM_ERR("can't read fd %d: %s", fd, strerror(errno));
 		} else {
 			buf[n] = '\0';
-			sscanf(buf, "temperature: %lf", &last_acpi_temp);
+			sscanf(buf, "%lf", &last_acpi_temp);
+			last_acpi_temp /= 1000;
 		}
 	}
 
-- 
1.7.0.4