summaryrefslogtreecommitdiff
path: root/lib/init.c
diff options
context:
space:
mode:
authorkhali <khali@7894878c-1315-0410-8ee3-d5d059ff63e0>2009-06-05 15:17:29 +0000
committerkhali <khali@7894878c-1315-0410-8ee3-d5d059ff63e0>2009-06-05 15:17:29 +0000
commite411f259d9dfc2e9f4490573018df357113ae6ca (patch)
treef63d948dcef2bc7285deba17789b69e60ccac5d6 /lib/init.c
parentfd3a302653b51ecc58bfb9f3dcb25e5ecbd8c236 (diff)
downloadlm-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.c10
1 files changed, 8 insertions, 2 deletions
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 <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);