make it take size after all

This commit is contained in:
2026-05-11 11:01:37 +00:00
parent c26ccba813
commit 574f59b8f5
5 changed files with 8 additions and 8 deletions

View File

@@ -12,7 +12,7 @@ void cpu_detect(struct cpu_sensors_t *t, const char *pci_dev) {
t->num_cores = sysconf(_SC_NPROCESSORS_ONLN);
snprintf(t->hwmon, sizeof(t->hwmon), "/sys/bus/pci/devices/%s/hwmon", pci_dev);
const int ret = get_hwmon_dir(t->hwmon);
const int ret = get_hwmon_dir(t->hwmon, sizeof(t->hwmon));
if (ret != 0) {
t->hwmon[0] = '\0';
applog(LOG_WRN, "Detected %d cores, module enum #%d. Can't get hwmon path, skipping", t->num_cores, t->module);

View File

@@ -12,7 +12,7 @@ const uint16_t max_metrics_length = 512; // length of the metrics buffer
void gpu_detect(struct gpu_sensors_t *t, const char *pci) {
snprintf(t->hwmon, sizeof(t->hwmon), "/sys/bus/pci/devices/%s/hwmon", pci);
const int ret = get_hwmon_dir(t->hwmon);
const int ret = get_hwmon_dir(t->hwmon, sizeof(t->hwmon));
if (ret != 0) {
t->hwmon[0] = '\0';
applog(LOG_WRN, "Detected GPU hwmon");

View File

@@ -71,7 +71,7 @@ void sys_get_network(struct network_t *network) {
void sys_detect(struct syssensors_t *s, const char *platform) {
snprintf(s->hwmon, sizeof(s->hwmon), "/sys/devices/platform/%s/hwmon", platform);
const int ret = get_hwmon_dir(s->hwmon);
const int ret = get_hwmon_dir(s->hwmon, sizeof(s->hwmon));
if (ret != 0) {
s->hwmon[0] = '\0';
applog(LOG_WRN, "Can't open system hwmon. Kernel params added? Module loaded? See README");

View File

@@ -55,12 +55,12 @@ inline bool file_exists(const char *path) {
}
/* path has to have at least 8 free chars at the end for glob */
int get_hwmon_dir(char *path) {
int get_hwmon_dir(char *path, const size_t bufsz) {
glob_t g;
strncat(path, "/hwmon*", 10);
if (glob(path, 0, NULL, &g) == 0) {
strncpy(path, g.gl_pathv[0], 128); // bug prone, careful
strncpy(path, g.gl_pathv[0], bufsz); // same size as hwmon length, careful
globfree(&g);
return 0;
}