diff --git a/CHANGES b/CHANGES index aa4f26f7..f457672e 100644 --- a/CHANGES +++ b/CHANGES @@ -2,6 +2,7 @@ lm-sensors CHANGES file ----------------------- SVN HEAD + libsensors: Add a default configuration file sensord: Reload config on SIGHUP rather than automatically sensors: Fix file handle leak on library initialization error Handle the case where voltage measurements aren't available diff --git a/Makefile b/Makefile index c49fe9a2..02d0b9ea 100644 --- a/Makefile +++ b/Makefile @@ -144,9 +144,9 @@ ALL_CFLAGS += $(CFLAGS) PROGCPPFLAGS := -DETCDIR="\"$(ETCDIR)\"" $(ALL_CPPFLAGS) PROGCFLAGS := $(ALL_CFLAGS) -ARCPPFLAGS := $(ALL_CPPFLAGS) +ARCPPFLAGS := -DETCDIR="\"$(ETCDIR)\"" $(ALL_CPPFLAGS) ARCFLAGS := $(ALL_CFLAGS) -LIBCPPFLAGS := $(ALL_CPPFLAGS) +LIBCPPFLAGS := -DETCDIR="\"$(ETCDIR)\"" $(ALL_CPPFLAGS) LIBCFLAGS := -fpic -D_REENTRANT $(ALL_CFLAGS) .PHONY: all user clean install user_install uninstall user_uninstall diff --git a/lib/init.c b/lib/init.c index 5f80a274..15ad3a5a 100644 --- a/lib/init.c +++ b/lib/init.c @@ -29,6 +29,8 @@ #include "scanner.h" #include "init.h" +#define DEFAULT_CONFIG_FILE ETCDIR "/sensors.conf" + int sensors_init(FILE *input) { int res; @@ -38,10 +40,24 @@ int sensors_init(FILE *input) if ((res = sensors_read_sysfs_bus()) || (res = sensors_read_sysfs_chips())) return res; - if ((res = sensors_scanner_init(input))) - return -SENSORS_ERR_PARSE; - if ((res = sensors_yyparse())) - return -SENSORS_ERR_PARSE; + + if (input) { + if (sensors_scanner_init(input) || + sensors_yyparse()) + return -SENSORS_ERR_PARSE; + } else { + /* No configuration provided, use default */ + input = fopen(DEFAULT_CONFIG_FILE, "r"); + if (!input) + return -SENSORS_ERR_PARSE; + if (sensors_scanner_init(input) || + sensors_yyparse()) { + fclose(input); + return -SENSORS_ERR_PARSE; + } + fclose(input); + } + if ((res = sensors_substitute_busses())) return res; return 0; diff --git a/lib/libsensors.3 b/lib/libsensors.3 index 43d3cc6c..a80abc1e 100644 --- a/lib/libsensors.3 +++ b/lib/libsensors.3 @@ -24,7 +24,7 @@ .\" .\" References consulted: .\" libsensors source code -.TH libsensors 3 "June 2007" "lm-sensors 3" "Linux Programmer's Manual" +.TH libsensors 3 "October 2007" "lm-sensors 3" "Linux Programmer's Manual" .SH NAME libsensors \- publicly accessible functions provided by the sensors library .SH SYNOPSIS @@ -57,6 +57,9 @@ value unequal to zero, you are in trouble; you can not assume anything will be initialized properly. If you want to reload the configuration file, call sensors_cleanup() below before calling sensors_init() again. +If FILE is NULL, the default configuration file is used (see the FILES +section below). Most applications will want to do that. + .B void sensors_cleanup(void); .br Clean-up function: You can't access anything after this, until the next sensors_init() call! @@ -168,6 +171,13 @@ data structures. .br A string representing the version of libsensors. +.SH FILES +.I /etc/sensors.conf +.RS +The system-wide +.BR libsensors (3) +configuration file. + .SH SEE ALSO sensors.conf(5)