From c76907971ec5a7bf4a3fcff794cf243d06423b4e Mon Sep 17 00:00:00 2001 From: Jean Delvare Date: Tue, 8 Sep 2009 16:52:29 +0000 Subject: [PATCH] Check that all referenced sysfs files exist before starting. If not, quilt immediately. Better no fan control than fan control using an out-of-sync configuration file. git-svn-id: http://lm-sensors.org/svn/lm-sensors/trunk@5765 7894878c-1315-0410-8ee3-d5d059ff63e0 --- CHANGES | 1 + prog/pwm/fancontrol | 54 +++++++++++++++++++++++++++++++++++++++++++ prog/pwm/fancontrol.8 | 6 ++++- 3 files changed, 60 insertions(+), 1 deletion(-) diff --git a/CHANGES b/CHANGES index a85f6809..489aeb82 100644 --- a/CHANGES +++ b/CHANGES @@ -3,6 +3,7 @@ lm-sensors CHANGES file SVN-HEAD libsensors: Support upcoming sysfs path to i2c adapters + fancontrol: Check that all referenced sysfs files exist pwmconfig: Exit immediately if not root sensors.conf.default: Encourage user to not modify this file sensors-detect: Refer to tmp401 driver if TMP411 is detected diff --git a/prog/pwm/fancontrol b/prog/pwm/fancontrol index 07b43e5f..5353678d 100755 --- a/prog/pwm/fancontrol +++ b/prog/pwm/fancontrol @@ -152,6 +152,58 @@ function LoadConfig { echo } +# Check that all referenced sysfs files exist +function CheckFiles { + local outdated=0 + + let fcvcount=0 + while (( $fcvcount < ${#AFCPWM[@]} )) # go through all pwm outputs + do + pwmo=${AFCPWM[$fcvcount]} + if [ ! -w $pwmo ] + then + echo "Error: file $pwmo doesn't exist" + outdated=1 + fi + let fcvcount=$fcvcount+1 + done + + let fcvcount=0 + while (( $fcvcount < ${#AFCTEMP[@]} )) # go through all temp inputs + do + tsen=${AFCTEMP[$fcvcount]} + if [ ! -r $tsen ] + then + echo "Error: file $tsen doesn't exist" + outdated=1 + fi + let fcvcount=$fcvcount+1 + done + + let fcvcount=0 + while (( $fcvcount < ${#AFCFAN[@]} )) # go through all fan inputs + do + fan=${AFCFAN[$fcvcount]} + if [ ! -r $fan ] + then + echo "Error: file $fan doesn't exist" + outdated=1 + fi + let fcvcount=$fcvcount+1 + done + + if [ $outdated -eq 1 ] + then + echo + echo "At least one referenced file is missing. Either some" + echo "required kernel modules haven't been loaded, or your" + echo "configuration file is outdated. In the latter case," + echo "you should run pwmconfig again." + fi + + return $outdated +} + if [ -f "$1" ] then LoadConfig $1 @@ -181,6 +233,8 @@ then fi cd $DIR +CheckFiles || exit 1 + if [ -f "$PIDFILE" ] then echo "File $PIDFILE exists, is fancontrol already running?" diff --git a/prog/pwm/fancontrol.8 b/prog/pwm/fancontrol.8 index c4574444..106b44a4 100644 --- a/prog/pwm/fancontrol.8 +++ b/prog/pwm/fancontrol.8 @@ -1,4 +1,4 @@ -.TH FANCONTROL 8 "January 2009" "lm-sensors 3" +.TH FANCONTROL 8 "September 2009" "lm-sensors 3" .SH NAME fancontrol \- automated software based fan speed regulation @@ -92,6 +92,10 @@ You have to play with the temperature values a bit to get happy. For initial setup I recommend using the \fBpwmconfig\fP script. Small changes can be made by editing the config file directly following the rules above. +Upon starting, fancontrol will make sure that all referenced sysfs files +do exist. If not, it will quit immediately, upon the assumption that the +configuration file may be out-of-sync with the loaded kernel drivers. + .SH THE ALGORITHM \fBfancontrol\fP first reads its configuration, writes it to arrays and loops its