Don't create the configuration file before it's needed.

Don't preserve configuration file customizations.
Fix permissions of the configuration file.


git-svn-id: http://lm-sensors.org/svn/lm-sensors/branches/lm-sensors-3.0.0@5179 7894878c-1315-0410-8ee3-d5d059ff63e0
This commit is contained in:
Jean Delvare committed 2008-04-16 11:18:36 +00:00
1 parent a16f065eee
commit be4ea8ac3e
2 files changed
+28 -29

No files matched your search

+3
View File
@@ -6,6 +6,9 @@ SVN-HEAD
Parse the configuration file in C locale
Late compute statements override early ones
Support virtual hwmon devices (#2309)
pwmconfig: Don't create the configuration file before it's needed
Don't preserve configuration file customizations
Fix permissions of the configuration file
sensors-detect: Add SMSC SCH5027D detection
Do not access I/O ports on PPC
Move south bridge sensor detection to the right section
+25 -29
View File
@@ -9,7 +9,7 @@
# Verify that all fans are running at normal speed after this
# program has exited!!!
#
# Copyright (C) 2007 Jean Delvare <khali@linux-fr.org>
# Copyright (C) 2007-2008 Jean Delvare <khali@linux-fr.org>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -501,32 +501,34 @@ fi
function AskPath {
echo -n 'What should be the path to your fancontrol config file (/etc/fancontrol)? '
read X
if [ "$X" = "y" -o "$X" = "Y" -o "$X" = "" ]
read FCCONFIG
if [ "$FCCONFIG" = "" ]
then
X=/etc/fancontrol
fi
if [ -f $X ]
then
FCCONFIG=$X
else
echo -n "$X does not exist, shall I create it now (y)? "
read Y
if [ "$Y" = "y" -o "$Y" = "Y" -o "$Y" = "" ]
then
touch $X
chmod 0660 $X
chown root.root $X
FCCONFIG=$X
else
AskPath
fi
FCCONFIG="/etc/fancontrol"
fi
}
AskPath
function ClearConfig {
FCTEMPS=""
FCFANS=""
MINTEMP=""
MAXTEMP=""
MINSTART=""
MINSTOP=""
MINPWM=""
MAXPWM=""
}
function LoadConfig {
# Nothing to do
if [ ! -f "$1" ]
then
ClearConfig
return 0
fi
echo "Loading configuration from $1 ..."
INTERVAL=`egrep '^INTERVAL=.*$' $1 | sed -e 's/INTERVAL= *//g'`
FCTEMPS=`egrep '^FCTEMPS=.*$' $1 | sed -e 's/FCTEMPS= *//g'`
@@ -545,14 +547,7 @@ function LoadConfig {
if [ ! -f "`echo $item | sed -e 's/=.*$//'`" ]
then
echo "Configuration appears to be outdated, discarded"
FCTEMPS=""
FCFANS=""
MINTEMP=""
MAXTEMP=""
MINSTART=""
MINSTOP=""
MINPWM=""
MAXPWM=""
ClearConfig
return 0
fi
done
@@ -611,11 +606,12 @@ function SaveConfig {
echo "Saving configuration to $FCCONFIG..."
tmpfile=`mktemp -t pwmcfg.XXXXXXXXXX` || { echo "$0: Cannot create temporary file" >&2; exit 1; }
trap " [ -f \"$tmpfile\" ] && /bin/rm -f -- \"$tmpfile\"" 0 1 2 3 13 15
egrep -v '(INTERVAL|FCTEMPS|FCFANS|MAXTEMP|MINTEMP|MINSTART|MINSTOP|MINPWM|MAXPWM)' $FCCONFIG >$tmpfile
echo "# Configuration file generated by pwmconfig, changes will be lost" >$tmpfile
echo -e "INTERVAL=$INTERVAL\nFCTEMPS=$FCTEMPS\nFCFANS=$FCFANS\nMINTEMP=$MINTEMP\nMAXTEMP=$MAXTEMP\nMINSTART=$MINSTART\nMINSTOP=$MINSTOP" >>$tmpfile
[ -n "$MINPWM" ] && echo "MINPWM=$MINPWM" >>$tmpfile
[ -n "$MAXPWM" ] && echo "MAXPWM=$MAXPWM" >>$tmpfile
mv $tmpfile $FCCONFIG
chmod +r $FCCONFIG
#check if file was written correctly
echo 'Configuration saved'
}