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

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

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • 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