diff --git a/src/cpu.c b/src/cpu.c index de1cace..92e448e 100644 --- a/src/cpu.c +++ b/src/cpu.c @@ -19,10 +19,7 @@ void cpu_detect(struct cpu_sensors_t *t, const char *pci_dev) { return; } - char buf[128]; - char *nt = stpncpy(buf, t->hwmon, sizeof(buf)); // nt is a pointer to the null terminator of the copied string - stpcpy(nt, "/in1_input"); // write at the null terminator address - t->module = file_exists(buf) ? zenpower : k10temp; // idk if this is reliable, we're trying to avoid just reading the name + t->module = read_file(t->hwmon, "/in1_input", NULL, 0) ? zenpower : k10temp; // if we can read zenpower file then zenpower. idk if this is reliable, we're trying to avoid just reading the name applog(LOG_INF, "Detected %d cores, module enum #%d in path %s", t->num_cores, t->module, t->hwmon); } diff --git a/src/gpu.c b/src/gpu.c index a9ae503..1329941 100644 --- a/src/gpu.c +++ b/src/gpu.c @@ -2,7 +2,6 @@ #include "gpu_metrics.h" #include -#include #include "log.h" #include "utils.h" @@ -19,17 +18,13 @@ void gpu_detect(struct gpu_sensors_t *t, const char *pci) { return; } - char buf[128]; - char *nt = stpncpy(buf, t->hwmon, sizeof(buf)); - stpcpy(nt, rel_metrics_path); // write at the null terminator address - if (file_exists(buf)) { - char raw_metrics[max_metrics_length]; - if (!read_file(buf, raw_metrics, sizeof(raw_metrics))) - return; - const struct metrics_table_header *header = (struct metrics_table_header *)raw_metrics; - applog(LOG_INF, "Found gpu_metrics_v%d_%d", header->format_revision, header->content_revision); - t->has_gpu_metrics = true; - } + t->has_gpu_metrics = false; + char raw_metrics[max_metrics_length]; + if (!read_file(t->hwmon, rel_metrics_path, raw_metrics, sizeof(raw_metrics))) + return; + const struct metrics_table_header *header = (struct metrics_table_header *)raw_metrics; + applog(LOG_INF, "Found gpu_metrics_v%d_%d", header->format_revision, header->content_revision); + t->has_gpu_metrics = true; } /* some metrics are missing in gpu_metrics, we always fill them from fs, unused metrics are commented out */ @@ -55,12 +50,9 @@ void update_from_fs(struct gpu_sensors_t *g) { } void update_from_metrics(struct gpu_sensors_t *g) { - char buf[128]; char raw_metrics[max_metrics_length]; - char *nt = stpncpy(buf, g->hwmon, sizeof(buf)); - stpcpy(nt, rel_metrics_path); // write at the null terminator address - if (!read_file(buf, raw_metrics, sizeof(raw_metrics))) + if (!read_file(g->hwmon, rel_metrics_path, raw_metrics, sizeof(raw_metrics))) return; const struct metrics_table_header *header = (struct metrics_table_header *)raw_metrics;