From 2f48f828f3205aac17e716ee5e24a317a0120795 Mon Sep 17 00:00:00 2001 From: Alastair Poole Date: Mon, 5 Oct 2020 14:52:00 +0100 Subject: [PATCH] sensors: sense. --- src/bin/system/machine/sensors.bogox | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/bin/system/machine/sensors.bogox b/src/bin/system/machine/sensors.bogox index fc2b666..eddfa68 100644 --- a/src/bin/system/machine/sensors.bogox +++ b/src/bin/system/machine/sensors.bogox @@ -72,26 +72,26 @@ system_sensors_thermal_get(int *sensor_count) sensor_t *sensor; DIR *dir; struct dirent *dh; - struct dirent **names = NULL; - char *link; char buf[4096]; int seen[128]; - int n, idx; dir = opendir("/sys/class/hwmon"); if (!dir) return NULL; while ((dh = readdir(dir)) != NULL) { + struct dirent **names = NULL; + snprintf(buf, sizeof(buf), "/sys/class/hwmon/%s", dh->d_name); - link = realpath(buf, NULL); + char *link = realpath(buf, NULL); if (!link) continue; - idx = 0; - memset(&seen, 0, sizeof(seen)); - n = scandir(link, &names, 0, alphasort); + int n = scandir(link, &names, 0, alphasort); if (n < 0) continue; + int idx = 0; + memset(&seen, 0, sizeof(seen)); + for (int i = 0; i < n; i++) { if (!strncmp(names[i]->d_name, "temp", 4)) @@ -114,8 +114,9 @@ system_sensors_thermal_get(int *sensor_count) continue; } - sensors = realloc(sensors, (1 + (*sensor_count)) * sizeof(sensor_t *)); - sensors[(*sensor_count)++] = sensor = calloc(1,sizeof(sensor_t)); + void *tmp = realloc(sensors, (1 + (*sensor_count)) * sizeof(sensor_t *)); + sensors = tmp; + sensors[(*sensor_count)++] = sensor = calloc(1, sizeof(sensor_t)); snprintf(buf, sizeof(buf), "%s/name", link); sensor->name = file_contents(buf);