--- a/src/linux.c 2011-01-18 12:39:23.251000005 +0100 +++ b/src/linux.c 2011-01-18 12:59:51.081000039 +0100 @@ -1421,26 +1421,19 @@ 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)); @@ -1452,6 +1445,9 @@ 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) { @@ -1469,15 +1465,16 @@ /* 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; } }