Changeset 5179

Show
Ignore:
Timestamp:
04/16/08 13:18:36 (5 years ago)
Author:
khali
Message:

Don't create the configuration file before it's needed.
Don't preserve configuration file customizations.
Fix permissions of the configuration file.

Location:
lm-sensors/branches/lm-sensors-3.0.0
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • lm-sensors/branches/lm-sensors-3.0.0/CHANGES

    r5176 r5179  
    77              Late compute statements override early ones 
    88              Support virtual hwmon devices (#2309) 
     9  pwmconfig: Don't create the configuration file before it's needed 
     10             Don't preserve configuration file customizations 
     11             Fix permissions of the configuration file 
    912  sensors-detect: Add SMSC SCH5027D detection 
    1013                  Do not access I/O ports on PPC 
  • lm-sensors/branches/lm-sensors-3.0.0/prog/pwm/pwmconfig

    r5163 r5179  
    1010#    program has exited!!! 
    1111# 
    12 #    Copyright (C) 2007 Jean Delvare <khali@linux-fr.org> 
     12#    Copyright (C) 2007-2008 Jean Delvare <khali@linux-fr.org> 
    1313# 
    1414#    This program is free software; you can redistribute it and/or modify 
     
    502502        echo -n 'What should be the path to your fancontrol config file (/etc/fancontrol)? ' 
    503503 
    504         read X 
    505         if [ "$X" = "y" -o "$X" = "Y" -o "$X" = "" ] 
    506         then 
    507                 X=/etc/fancontrol 
    508         fi 
    509         if [ -f $X ] 
    510         then 
    511                 FCCONFIG=$X 
    512         else 
    513                 echo -n "$X does not exist, shall I create it now (y)? " 
    514                 read Y 
    515                 if [ "$Y" = "y" -o "$Y" = "Y" -o "$Y" = "" ] 
    516                 then 
    517                         touch $X 
    518                         chmod 0660 $X 
    519                         chown root.root $X 
    520                         FCCONFIG=$X 
    521                 else 
    522                         AskPath 
    523                 fi 
     504        read FCCONFIG 
     505        if [ "$FCCONFIG" = "" ] 
     506        then 
     507                FCCONFIG="/etc/fancontrol" 
    524508        fi 
    525509} 
     
    527511AskPath 
    528512 
     513function ClearConfig { 
     514        FCTEMPS="" 
     515        FCFANS="" 
     516        MINTEMP="" 
     517        MAXTEMP="" 
     518        MINSTART="" 
     519        MINSTOP="" 
     520        MINPWM="" 
     521        MAXPWM="" 
     522} 
     523 
    529524function LoadConfig { 
     525        # Nothing to do 
     526        if [ ! -f "$1" ] 
     527        then 
     528                ClearConfig 
     529                return 0 
     530        fi 
     531 
    530532        echo "Loading configuration from $1 ..." 
    531533        INTERVAL=`egrep '^INTERVAL=.*$' $1 | sed -e 's/INTERVAL= *//g'` 
     
    546548                then 
    547549                        echo "Configuration appears to be outdated, discarded" 
    548                         FCTEMPS="" 
    549                         FCFANS="" 
    550                         MINTEMP="" 
    551                         MAXTEMP="" 
    552                         MINSTART="" 
    553                         MINSTOP="" 
    554                         MINPWM="" 
    555                         MAXPWM="" 
     550                        ClearConfig 
    556551                        return 0 
    557552                fi 
     
    612607        tmpfile=`mktemp -t pwmcfg.XXXXXXXXXX` || { echo "$0: Cannot create temporary file" >&2; exit 1;  } 
    613608        trap " [ -f \"$tmpfile\" ] && /bin/rm -f -- \"$tmpfile\"" 0 1 2 3 13 15 
    614         egrep -v '(INTERVAL|FCTEMPS|FCFANS|MAXTEMP|MINTEMP|MINSTART|MINSTOP|MINPWM|MAXPWM)' $FCCONFIG >$tmpfile 
     609        echo "# Configuration file generated by pwmconfig, changes will be lost" >$tmpfile 
    615610        echo -e "INTERVAL=$INTERVAL\nFCTEMPS=$FCTEMPS\nFCFANS=$FCFANS\nMINTEMP=$MINTEMP\nMAXTEMP=$MAXTEMP\nMINSTART=$MINSTART\nMINSTOP=$MINSTOP" >>$tmpfile 
    616611        [ -n "$MINPWM" ] && echo "MINPWM=$MINPWM" >>$tmpfile 
    617612        [ -n "$MAXPWM" ] && echo "MAXPWM=$MAXPWM" >>$tmpfile 
    618613        mv $tmpfile $FCCONFIG 
     614        chmod +r $FCCONFIG 
    619615        #check if file was written correctly 
    620616        echo 'Configuration saved'