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
This commit is contained in:
Jean Delvare committed 2009-06-05 15:17:29 +00:00
1 parent eb25257655
commit ee26e6d2b0
2 files changed
+9 -2

No files matched your search

+1
View File
@@ -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
+8 -2
View File
@@ -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);