diff options
author | khali <khali@7894878c-1315-0410-8ee3-d5d059ff63e0> | 2009-06-05 15:17:29 +0000 |
---|---|---|
committer | khali <khali@7894878c-1315-0410-8ee3-d5d059ff63e0> | 2009-06-05 15:17:29 +0000 |
commit | e411f259d9dfc2e9f4490573018df357113ae6ca (patch) | |
tree | f63d948dcef2bc7285deba17789b69e60ccac5d6 /lib/init.c | |
parent | fd3a302653b51ecc58bfb9f3dcb25e5ecbd8c236 (diff) | |
download | lm-sensors-e411f259d9dfc2e9f4490573018df357113ae6ca.tar.gz |
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
Diffstat (limited to 'lib/init.c')
-rw-r--r-- | lib/init.c | 10 |
1 files changed, 8 insertions, 2 deletions
@@ -23,12 +23,14 @@ #define _BSD_SOURCE #include <sys/types.h> +#include <sys/stat.h> #include <locale.h> #include <stdlib.h> #include <stdio.h> #include <string.h> #include <errno.h> #include <dirent.h> +#include <unistd.h> #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); |