From 639e040445d41c9ccafede429f46c3543d293b48 Mon Sep 17 00:00:00 2001 From: Michal Suchanek Date: Mon, 27 Apr 2026 09:38:21 +0200 Subject: [PATCH] sysfs: Allow file symlinks To test behavior on read error the test file can be linked to something like /proc/self/mem that does not support read() but currently all symlinks are skipped. Use fstatat instead of the directory entry type to determine file type. --- lib/sysfs.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/lib/sysfs.c b/lib/sysfs.c index 4450b00e..0aaee87e 100644 --- a/lib/sysfs.c +++ b/lib/sysfs.c @@ -570,13 +570,25 @@ static int sensors_read_dynamic_chip(sensors_chip_features *chip, while ((ent = readdir(dir))) { char *name; - int nr; + int nr, type; + struct stat st; - /* Skip directories and symlinks */ - if (ent->d_type != DT_REG) + /* Skip directories and special files */ + if (ent->d_type == DT_DIR) continue; - name = ent->d_name; + if (fstatat(dirfd(dir), name, &st, 0)) { + fprintf(stderr, "%s/%s: %s.\n", dev_path, name, sensors_strerror(errno)); + continue; + } + type = (st.st_mode & S_IFMT); + switch (type) { + case S_IFREG: break; + default: + fprintf(stderr, "%s/%s: Not a regular file.\n", dev_path, name); + /* fallthrough */ + case S_IFDIR: continue; + } sftype = sensors_subfeature_get_type(name, &nr); if (sftype == SENSORS_SUBFEATURE_UNKNOWN)