Changeset 5647

Show
Ignore:
Timestamp:
02/15/09 18:22:38 (4 years ago)
Author:
khali
Message:

Read extra configuration files from /etc/sensors.d.

Location:
lm-sensors/trunk
Files:
4 modified

Legend:

Unmodified
Added
Removed
  • lm-sensors/trunk/CHANGES

    r5645 r5647  
    1313              Exit the configuration file parser sooner 
    1414              Free bus statements from the configuration file sooner 
     15              Read extra configuration files from /etc/sensors.d 
    1516  lm_sensors.init: Support new format of /etc/sysconfig/lm_sensors (#2246) 
    1617                   Drop support for kernels 2.4 and earlier 
  • lm-sensors/trunk/lib/init.c

    r5646 r5647  
    22    init.c - Part of libsensors, a Linux library for reading sensor data. 
    33    Copyright (c) 1998, 1999  Frodo Looijaard <frodol@dds.nl> 
    4     Copyright (C) 2007        Jean Delvare <khali@linux-fr.org> 
     4    Copyright (C) 2007, 2009  Jean Delvare <khali@linux-fr.org> 
    55 
    66    This program is free software; you can redistribute it and/or modify 
     
    2020*/ 
    2121 
     22/* Needed for scandir() and alphasort() */ 
     23#define _BSD_SOURCE 
     24 
     25#include <sys/types.h> 
    2226#include <locale.h> 
    2327#include <stdlib.h> 
     
    2529#include <string.h> 
    2630#include <errno.h> 
     31#include <dirent.h> 
    2732#include "sensors.h" 
    2833#include "data.h" 
     
    3641#define DEFAULT_CONFIG_FILE     ETCDIR "/sensors3.conf" 
    3742#define ALT_CONFIG_FILE         ETCDIR "/sensors.conf" 
     43#define DEFAULT_CONFIG_DIR      ETCDIR "/sensors.d" 
    3844 
    3945/* Wrapper around sensors_yyparse(), which clears the locale so that 
     
    98104        free_config_busses(); 
    99105        return err; 
     106} 
     107 
     108static int config_file_filter(const struct dirent *entry) 
     109{ 
     110        return (entry->d_type == DT_REG || entry->d_type == DT_LNK) 
     111            && entry->d_name[0] != '.';         /* Skip hidden files */ 
     112} 
     113 
     114static int add_config_from_dir(const char *dir) 
     115{ 
     116        int count, res, i; 
     117        struct dirent **namelist; 
     118 
     119        count = scandir(dir, &namelist, config_file_filter, alphasort); 
     120        if (count < 0) { 
     121                sensors_parse_error(strerror(errno), 0); 
     122                return -SENSORS_ERR_PARSE; 
     123        } 
     124 
     125        for (res = 0, i = 0; !res && i < count; i++) { 
     126                int len; 
     127                char path[PATH_MAX]; 
     128                FILE *input; 
     129 
     130                len = snprintf(path, sizeof(path), "%s/%s", dir, 
     131                               namelist[i]->d_name); 
     132                if (len < 0 || len >= (int)sizeof(path)) { 
     133                        res = -SENSORS_ERR_PARSE; 
     134                        continue; 
     135                } 
     136 
     137                input = fopen(path, "r"); 
     138                if (input) { 
     139                        res = parse_config(input); 
     140                        fclose(input); 
     141                } else { 
     142                        res = -SENSORS_ERR_PARSE; 
     143                        sensors_parse_error(strerror(errno), 0); 
     144                } 
     145        } 
     146 
     147        /* Free memory allocated by scandir() */ 
     148        for (i = 0; i < count; i++) 
     149                free(namelist[i]); 
     150        free(namelist); 
     151 
     152        return res; 
    100153} 
    101154 
     
    130183                        goto exit_cleanup; 
    131184                } 
     185 
     186                /* Also check for files in default directory */ 
     187                res = add_config_from_dir(DEFAULT_CONFIG_DIR); 
     188                if (res) 
     189                        goto exit_cleanup; 
    132190        } 
    133191 
  • lm-sensors/trunk/lib/libsensors.3

    r4990 r5647  
    1 .\" Copyright 1998, 1999 Adrian Baugh <adrian.baugh@keble.ox.ac.uk> 
     1.\" Copyright (C) 1998, 1999  Adrian Baugh <adrian.baugh@keble.ox.ac.uk> 
     2.\" Copyright (C) 2007, 2009  Jean Delvare <khali@linux-fr.org> 
    23.\" based on sensors.h, part of libsensors by Frodo Looijaard 
    34.\" libsensors is distributed under the GPL 
     
    2526.\" References consulted: 
    2627.\"     libsensors source code 
    27 .TH libsensors 3  "October 2007" "lm-sensors 3" "Linux Programmer's Manual" 
     28.TH libsensors 3  "February 2009" "lm-sensors 3" "Linux Programmer's Manual" 
    2829.SH NAME 
    2930libsensors \- publicly accessible functions provided by the sensors library 
     
    5859sensors_cleanup() below before calling sensors_init() again. 
    5960 
    60 If FILE is NULL, the default configuration file is used (see the FILES 
     61If FILE is NULL, the default configuration files are used (see the FILES 
    6162section below). Most applications will want to do that. 
    6263 
     
    181182configuration file. /etc/sensors3.conf is tried first, and if it doesn't exist, 
    182183/etc/sensors.conf is used instead. 
     184.RE 
     185 
     186.I /etc/sensors.d 
     187.RS 
     188A directory where you can put additional libsensors configuration files. 
     189Files found in this directory will be processed in alphabetical order after 
     190the default configuration file. Files with names that start with a dot are 
     191ignored. 
     192.RE 
    183193 
    184194.SH SEE ALSO 
  • lm-sensors/trunk/lib/sensors.conf.5

    r5536 r5647  
    11.\" Copyright (C) 1998, 1999 Adrian Baugh <adrian.baugh@keble.ox.ac.uk> and 
    22.\"                          Frodo Looijaard <frodol@dds.nl> 
    3 .\" Copyright (C) 2008      Jean Delvare <khali@linux-fr.org> 
     3.\" Copyright (C) 2008, 2009 Jean Delvare <khali@linux-fr.org> 
    44.\" 
    55.\" Permission is granted to make and distribute verbatim copies of this 
     
    2222.\" References consulted: 
    2323.\"     sensors.conf.eg by Frodo Looijaard 
    24 .TH sensors.conf 5  "December 2008" "lm-sensors 3" "Linux User's Manual" 
     24.TH sensors.conf 5  "February 2009" "lm-sensors 3" "Linux User's Manual" 
    2525.SH NAME 
    2626sensors.conf \- libsensors configuration file 
     
    275275will generate these lines for you. 
    276276 
     277In the case where multiple configuration files are used, the scope 
     278of each 
     279.I bus 
     280statement is the configuration file it was defined in. This makes it 
     281possible to have bus statements in all configuration files which will 
     282not unexpectedly interfere with each other. 
     283 
    277284.SS STATEMENT ORDER 
    278285 
     
    534541configuration file. /etc/sensors3.conf is tried first, and if it doesn't exist, 
    535542/etc/sensors.conf is used instead. 
     543.RE 
     544 
     545.I /etc/sensors.d 
     546.RS 
     547A directory where you can put additional libsensors configuration files. 
     548Files found in this directory will be processed in alphabetical order after 
     549the default configuration file. Files with names that start with a dot are 
     550ignored. 
     551.RE 
    536552 
    537553.SH SEE ALSO