From ee26e6d2b0333a0b14674fff6d9db088ac46a9c9 Mon Sep 17 00:00:00 2001 From: Jean Delvare Date: Fri, 5 Jun 2009 15:17:29 +0000 Subject: [PATCH] From Yuriy Kaminskiy: Most filesystems (in particular - reiserfs, jfs, xfs, nfs); maybe, some legacy installation of ext2/3 too) always return dirent->dt_type = DT_UNKNOWN, so libsensors fails to parse /etc/sensors.d. Also, symlink (DT_LNK) can point to directory, or FIFO/socket/device (very bad!) - current check insufficient anyways. Fixed by always using stat() to check what each entry is, rather than relying on dirent->dt_type. git-svn-id: http://lm-sensors.org/svn/lm-sensors/trunk@5730 7894878c-1315-0410-8ee3-d5d059ff63e0 --- CHANGES | 1 + lib/init.c | 10 ++++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/CHANGES b/CHANGES index cae42f8f..75d123a7 100644 --- a/CHANGES +++ b/CHANGES @@ -4,6 +4,7 @@ lm-sensors CHANGES file SVN-HEAD isadump: Use geteuid instead of getuid so that setuid bit works isaset: Use geteuid instead of getuid so that setuid bit works + libsensors: Don't rely on dirent->dt_type being set Makefile: Include generated source files in dependency checking Make it possible to skip building of the static library fancontrol: Add support for absolute path to hwmon devices diff --git a/lib/init.c b/lib/init.c index e97f6882..f15ec6cc 100644 --- a/lib/init.c +++ b/lib/init.c @@ -23,12 +23,14 @@ #define _BSD_SOURCE #include +#include #include #include #include #include #include #include +#include #include "sensors.h" #include "data.h" #include "error.h" @@ -120,8 +122,7 @@ exit_cleanup: static int config_file_filter(const struct dirent *entry) { - return (entry->d_type == DT_REG || entry->d_type == DT_LNK) - && entry->d_name[0] != '.'; /* Skip hidden files */ + return entry->d_name[0] != '.'; /* Skip hidden files */ } static int add_config_from_dir(const char *dir) @@ -143,6 +144,7 @@ static int add_config_from_dir(const char *dir) int len; char path[PATH_MAX]; FILE *input; + struct stat st; len = snprintf(path, sizeof(path), "%s/%s", dir, namelist[i]->d_name); @@ -151,6 +153,10 @@ static int add_config_from_dir(const char *dir) continue; } + /* Only accept regular files */ + if (stat(path, &st) < 0 || !S_ISREG(st.st_mode)) + continue; + input = fopen(path, "r"); if (input) { res = parse_config(input, path);