Changeset 5730

Show
Ignore:
Timestamp:
06/05/09 17:17:29 (4 years ago)
Author:
khali
Message:

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.

Location:
lm-sensors/trunk
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • lm-sensors/trunk/CHANGES

    r5726 r5730  
    55  isadump: Use geteuid instead of getuid so that setuid bit works 
    66  isaset: Use geteuid instead of getuid so that setuid bit works 
     7  libsensors: Don't rely on dirent->dt_type being set 
    78  Makefile: Include generated source files in dependency checking 
    89            Make it possible to skip building of the static library 
  • lm-sensors/trunk/lib/init.c

    r5665 r5730  
    2424 
    2525#include <sys/types.h> 
     26#include <sys/stat.h> 
    2627#include <locale.h> 
    2728#include <stdlib.h> 
     
    3031#include <errno.h> 
    3132#include <dirent.h> 
     33#include <unistd.h> 
    3234#include "sensors.h" 
    3335#include "data.h" 
     
    121123static int config_file_filter(const struct dirent *entry) 
    122124{ 
    123         return (entry->d_type == DT_REG || entry->d_type == DT_LNK) 
    124             && entry->d_name[0] != '.';         /* Skip hidden files */ 
     125        return entry->d_name[0] != '.';         /* Skip hidden files */ 
    125126} 
    126127 
     
    144145                char path[PATH_MAX]; 
    145146                FILE *input; 
     147                struct stat st; 
    146148 
    147149                len = snprintf(path, sizeof(path), "%s/%s", dir, 
     
    151153                        continue; 
    152154                } 
     155 
     156                /* Only accept regular files */ 
     157                if (stat(path, &st) < 0 || !S_ISREG(st.st_mode)) 
     158                        continue; 
    153159 
    154160                input = fopen(path, "r");