Changeset 5770

Show
Ignore:
Timestamp:
09/16/09 17:57:53 (5 years ago)
Author:
khali
Message:

Save hwmon device paths and names in configuration file, and check them
before starting any fan control operation.

Location:
lm-sensors/trunk
Files:
4 modified

Legend:

Unmodified
Added
Removed
  • lm-sensors/trunk/CHANGES

    r5769 r5770  
    55  libsensors: Support upcoming sysfs path to i2c adapters 
    66  fancontrol: Check that all referenced sysfs files exist 
     7              Check that all devices match the configuration file 
    78  pwmconfig: Exit immediately if not root 
     9             Save device paths and names in configuration file 
    810  sensors.conf.default: Encourage user to not modify this file 
    911  sensors-detect: Refer to tmp401 driver if TMP411 is detected 
  • lm-sensors/trunk/prog/pwm/fancontrol

    r5766 r5770  
    44# Supported Linux kernel versions: 2.6.5 and later 
    55# 
    6 # Version 0.69 
     6# Version 0.70 
    77# 
    88# Usage: fancontrol [CONFIGFILE] 
    99# 
    1010# Dependencies: 
    11 #   bash, egrep, sed, cut, sleep, lm_sensors :) 
     11#   bash, egrep, sed, cut, sleep, readlink, lm_sensors :) 
    1212# 
    1313# Please send any questions, comments or success stories to 
     
    5656        # grep configuration from file 
    5757        INTERVAL=`egrep '^INTERVAL=.*$' $1 | sed -e 's/INTERVAL=//g'` 
     58        DEVPATH=`egrep '^DEVPATH=.*$' $1 | sed -e 's/DEVPATH= *//g'` 
     59        DEVNAME=`egrep '^DEVNAME=.*$' $1 | sed -e 's/DEVNAME= *//g'` 
    5860        FCTEMPS=`egrep '^FCTEMPS=.*$' $1 | sed -e 's/FCTEMPS=//g'` 
    5961        MINTEMP=`egrep '^MINTEMP=.*$' $1 | sed -e 's/MINTEMP=//g'` 
     
    153155} 
    154156 
     157function DevicePath() 
     158{ 
     159        if [ -h "$1/device" ] 
     160        then 
     161                readlink -f "$1/device" | sed -e 's/^\/sys\///' 
     162        fi 
     163} 
     164 
     165function DeviceName() 
     166{ 
     167        if [ -r "$1/name" ] 
     168        then 
     169                cat "$1/name" | sed -e 's/[[:space:]=]/_/g' 
     170        elif [ -r "$1/device/name" ] 
     171        then 
     172                cat "$1/device/name" | sed -e 's/[[:space:]=]/_/g' 
     173        fi 
     174} 
     175 
     176function ValidateDevices() 
     177{ 
     178        local OLD_DEVPATH="$1" OLD_DEVNAME="$2" outdated=0 
     179        local entry device name path 
     180 
     181        for entry in $OLD_DEVPATH 
     182        do 
     183                device=`echo "$entry" | sed -e 's/=[^=]*$//'` 
     184                path=`echo "$entry" | sed -e 's/^[^=]*=//'` 
     185 
     186                if [ "`DevicePath "$device"`" != "$path" ] 
     187                then 
     188                        echo "Device path of $device has changed" 
     189                        outdated=1 
     190                fi 
     191        done 
     192 
     193        for entry in $OLD_DEVNAME 
     194        do 
     195                device=`echo "$entry" | sed -e 's/=[^=]*$//'` 
     196                name=`echo "$entry" | sed -e 's/^[^=]*=//'` 
     197 
     198                if [ "`DeviceName "$device"`" != "$name" ] 
     199                then 
     200                        echo "Device name of $device has changed" 
     201                        outdated=1 
     202                fi 
     203        done 
     204 
     205        return $outdated 
     206} 
     207 
    155208# Check that all referenced sysfs files exist 
    156209function CheckFiles { 
     
    233286cd $DIR 
    234287 
     288# Check for configuration change 
     289if [ -z "$DEVPATH" -o -z "$DEVNAME" ] 
     290then 
     291        echo "Configuration is too old, please run pwmconfig again" 
     292        exit 1 
     293fi 
     294if ! ValidateDevices "$DEVPATH" "$DEVNAME" 
     295then 
     296        echo "Configuration appears to be outdated, please run pwmconfig again" 
     297        exit 1 
     298fi 
    235299CheckFiles || exit 1 
    236300 
  • lm-sensors/trunk/prog/pwm/fancontrol.8

    r5765 r5770  
    3939\fBfancontrol\fP will be executed 
    4040.TP 
     41.B DEVPATH 
     42Maps hwmon class devices to physical devices. This lets \fBfancontrol\fP 
     43check that the configuration file is still up-to-date. 
     44.TP 
     45.B DEVNAME 
     46Records hwmon class device names. This lets \fBfancontrol\fP check that 
     47the configuration file is still up-to-date. 
     48.TP 
    4149.B FCTEMPS 
    4250Maps PWM outputs to temperature sensors so \fBfancontrol\fP knows which 
     
    4553.TP 
    4654.B FCFANS 
    47 FCFANS records the association between a PWM and a fan. 
     55Records the association between a PWM output and a fan input. 
    4856Then \fBfancontrol\fP can check the fan speed and restart it if it 
    4957stops unexpectedly. 
     
    93101editing the config file directly following the rules above. 
    94102 
    95 Upon starting, fancontrol will make sure that all referenced sysfs files 
    96 do exist. If not, it will quit immediately, upon the assumption that the 
    97 configuration file may be out-of-sync with the loaded kernel drivers. 
     103Upon starting, fancontrol will make sure that all referenced devices 
     104do exist and match what they were at configuration time, and that all 
     105referenced sysfs files do exist. If not, it will quit immediately, upon 
     106the assumption that the configuration file may be out-of-sync with the 
     107loaded kernel drivers. 
    98108 
    99109.SH THE ALGORITHM 
  • lm-sensors/trunk/prog/pwm/pwmconfig

    r5767 r5770  
    540540fi 
    541541 
     542function DevicePath() 
     543{ 
     544        if [ -h "$1/device" ] 
     545        then 
     546                readlink -f "$1/device" | sed -e 's/^\/sys\///' 
     547        fi 
     548} 
     549 
     550function DeviceName() 
     551{ 
     552        if [ -r "$1/name" ] 
     553        then 
     554                cat "$1/name" | sed -e 's/[[:space:]=]/_/g' 
     555        elif [ -r "$1/device/name" ] 
     556        then 
     557                cat "$1/device/name" | sed -e 's/[[:space:]=]/_/g' 
     558        fi 
     559} 
     560 
     561function ValidateDevices() 
     562{ 
     563        local OLD_DEVPATH="$1" OLD_DEVNAME="$2" outdated=0 
     564        local entry device name path 
     565 
     566        for entry in $OLD_DEVPATH 
     567        do 
     568                device=`echo "$entry" | sed -e 's/=[^=]*$//'` 
     569                path=`echo "$entry" | sed -e 's/^[^=]*=//'` 
     570 
     571                if [ "`DevicePath "$device"`" != "$path" ] 
     572                then 
     573                        echo "Device path of $device has changed" 
     574                        outdated=1 
     575                fi 
     576        done 
     577 
     578        for entry in $OLD_DEVNAME 
     579        do 
     580                device=`echo "$entry" | sed -e 's/=[^=]*$//'` 
     581                name=`echo "$entry" | sed -e 's/^[^=]*=//'` 
     582 
     583                if [ "`DeviceName "$device"`" != "$name" ] 
     584                then 
     585                        echo "Device name of $device has changed" 
     586                        outdated=1 
     587                fi 
     588        done 
     589 
     590        return $outdated 
     591} 
     592 
    542593function AskPath() 
    543594{ 
     
    567618function LoadConfig() 
    568619{ 
     620        local OLD_DEVPATH OLD_DEVNAME 
     621 
    569622        # Nothing to do 
    570623        if [ ! -f "$1" ] 
     
    576629        echo "Loading configuration from $1 ..." 
    577630        INTERVAL=`egrep '^INTERVAL=.*$' $1 | sed -e 's/INTERVAL= *//g'` 
     631        OLD_DEVPATH=`egrep '^DEVPATH=.*$' $1 | sed -e 's/DEVPATH= *//g'` 
     632        OLD_DEVNAME=`egrep '^DEVNAME=.*$' $1 | sed -e 's/DEVNAME= *//g'` 
    578633        FCTEMPS=`egrep '^FCTEMPS=.*$' $1 | sed -e 's/FCTEMPS= *//g'` 
    579634        FCFANS=`egrep '^FCFANS=.*$' $1 | sed -e 's/FCFANS= *//g'` 
     
    586641 
    587642        # Check for configuration change 
    588         local item 
    589         for item in $FCFANS 
    590         do 
    591                 if [ ! -f "`echo $item | sed -e 's/=.*$//'`" ] 
    592                 then 
    593                         echo "Configuration appears to be outdated, discarded" 
    594                         ClearConfig 
    595                         return 0 
    596                 fi 
    597         done 
     643        if ! ValidateDevices "$OLD_DEVPATH" "$OLD_DEVNAME" 
     644        then 
     645                echo "Configuration appears to be outdated, discarded" 
     646                ClearConfig 
     647                return 0 
     648        fi 
    598649} 
    599650 
     
    676727} 
    677728 
     729# Remember the path and name of each device with at least one 
     730# reference (pwm, temp or fan) in the configuration file. 
     731# This function sets globals DEVPATH and DEVNAME as a side effect. 
     732function RememberDevices() 
     733{ 
     734        local used entry device name path tempfandev pwmdev 
     735        DEVPATH="" 
     736        DEVNAME="" 
     737 
     738        for device in $DEVICES 
     739        do 
     740                device=`echo "$device" | sed -e 's/\/.*$//'` 
     741 
     742                used=0 
     743                for entry in $1 $2 
     744                do 
     745                        pwmdev=`echo "$entry" | sed -e 's/\/.*$//'` 
     746                        tempfandev=`echo "$entry" | sed -e 's/^[^=]*=//' -e 's/\/.*$//'` 
     747 
     748                        if [ "$device" = "$pwmdev" -o "$device" = "$tempfandev" ] 
     749                        then 
     750                                used=1 
     751                        fi 
     752                done 
     753                if [ "$used" -eq 0 ] 
     754                then 
     755                        continue 
     756                fi 
     757 
     758                # Record the device path and name. This lets the fancontrol 
     759                # script check that they didn't change. If they did, then the 
     760                # configuration file can no longer be trusted. 
     761                path=`DevicePath "$device"` 
     762                if [ -z "$DEVPATH" ] 
     763                then 
     764                        DEVPATH="$device=$path" 
     765                else 
     766                        DEVPATH="$DEVPATH $device=$path" 
     767                fi 
     768 
     769                name=`DeviceName "$device"` 
     770                if [ -z "$DEVNAME" ] 
     771                then 
     772                        DEVNAME="$device=$name" 
     773                else 
     774                        DEVNAME="$DEVNAME $device=$name" 
     775                fi 
     776        done 
     777} 
     778 
    678779function SaveConfig() 
    679780{ 
     781        RememberDevices "$FCTEMPS" "$FCFANS" 
     782 
    680783        echo 
    681784        echo "Saving configuration to $FCCONFIG..." 
     
    684787        echo "# Configuration file generated by pwmconfig, changes will be lost" >$tmpfile 
    685788        echo "INTERVAL=$INTERVAL" >>$tmpfile 
     789        echo "DEVPATH=$DEVPATH" >>$tmpfile 
     790        echo "DEVNAME=$DEVNAME" >>$tmpfile 
    686791        echo "FCTEMPS=$FCTEMPS" >>$tmpfile 
    687792        echo "FCFANS=$FCFANS" >>$tmpfile