mirror of
https://github.com/lm-sensors/lm-sensors.git
synced 2026-10-01 05:52:41 +07:00
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.
This commit is contained in:
committed by
Michal Suchánek
parent
66c2951a47
commit
639e040445
+16
-4
@@ -570,13 +570,25 @@ static int sensors_read_dynamic_chip(sensors_chip_features *chip,
|
|||||||
|
|
||||||
while ((ent = readdir(dir))) {
|
while ((ent = readdir(dir))) {
|
||||||
char *name;
|
char *name;
|
||||||
int nr;
|
int nr, type;
|
||||||
|
struct stat st;
|
||||||
|
|
||||||
/* Skip directories and symlinks */
|
/* Skip directories and special files */
|
||||||
if (ent->d_type != DT_REG)
|
if (ent->d_type == DT_DIR)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
name = ent->d_name;
|
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);
|
sftype = sensors_subfeature_get_type(name, &nr);
|
||||||
if (sftype == SENSORS_SUBFEATURE_UNKNOWN)
|
if (sftype == SENSORS_SUBFEATURE_UNKNOWN)
|
||||||
|
|||||||
Reference in New Issue
Block a user