Package: fancontrol
Version: 1:3.3.5-2
Severity: normal
Tags: patch

Now and again, Jessie detects the sensors on my mainboard (Asus M5A99FX-Pro
R2.0) in a different order. This change in order requires that /etc/fancontrol
be editted to account for the change before the fans can be controlled.

To fix it, I added var DEVMAP to the config in the form "DEVMAP=CPU=k10temp
MBOARD=it8721", and changed all instances of 'hwmon0' to MBOARD and all
instances of hwmon1 to CPU. Then I hacked /usr/sbin/fancontrol to add edit the
config vars to remove this layer of abstraction. The mapping is not performed
if DEVMAP is not defined in--or is commented out of--the config file. DEVMAP
need contain only those sensors that need to be dynamically mapped.

The result is that fancontrol now dynamically determines which hwmonN goes with
which sensor; detection order no longer matters. It also removes a lot of the
confusion from the config file, provided good pseudonames are used.

Note that this depends on the existence of /sys/class/hwmon/hwmon*/device/name;
thus it may not be a universal solution. I assumed that the .../device/name
files always exist for the CPU and the mainboard.

I did not address /usr/sbin/pwmconfig.

Aside, I think--but am not certain--that the failure of fancontrol to start is
not detected/reported at startup; the failure doesn't seem to be reported
anywhere in /var/log/.



-- System Information:
Debian Release: 8.2
  APT prefers stable
  APT policy: (500, 'stable')
Architecture: amd64 (x86_64)
Foreign Architectures: i386

Kernel: Linux 3.16.0-4-amd64 (SMP w/8 CPU cores)
Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/bash
Init: sysvinit (via /sbin/init)

Versions of packages fancontrol depends on:
ii  init-system-helpers  1.22
ii  lsb-base             4.1+Debian13+nmu1

fancontrol recommends no packages.

fancontrol suggests no packages.

-- no debconf information
# Configuration file generated by pwmconfig, changes will be lost
INTERVAL=.2
DEVMAP=CPU=k10temp MBOARD=it8721
DEVNAME=CPU=k10temp MBOARD=it8721
DEVPATH=CPU=devices/pci0000:00/0000:00:18.3 MBOARD=devices/platform/it87.656
FCTEMPS=MBOARD/device/pwm3=MBOARD/device/temp1_input 
MBOARD/device/pwm1=CPU/device/temp1_input
FCFANS=MBOARD/device/pwm3=MBOARD/device/fan2_input 
MBOARD/device/pwm1=MBOARD/device/fan1_input
MINTEMP=MBOARD/device/pwm3=35 MBOARD/device/pwm1=30
MAXTEMP=MBOARD/device/pwm3=55 MBOARD/device/pwm1=55
MINSTART=MBOARD/device/pwm3=90 MBOARD/device/pwm1=0
MINSTOP=MBOARD/device/pwm3=50 MBOARD/device/pwm1=0
MINPWM=MBOARD/device/pwm3=0 MBOARD/device/pwm1=0
MAXPWM=MBOARD/device/pwm3=255 MBOARD/device/pwm1=255
--- /usr/sbin/fancontrol-	2015-12-17 02:44:00.000000000 -0500
+++ /usr/sbin/fancontrol	2016-01-12 00:43:44.000000000 -0500
@@ -55,6 +55,7 @@
 	fi
 
 	# grep configuration from file
+	DEVMAP=`egrep '^DEVMAP=.*$' $1 | sed -e 's/DEVMAP= *//g'`
 	INTERVAL=`egrep '^INTERVAL=.*$' $1 | sed -e 's/INTERVAL=//g'`
 	DEVPATH=`egrep '^DEVPATH=.*$' $1 | sed -e 's/DEVPATH= *//g'`
 	DEVNAME=`egrep '^DEVNAME=.*$' $1 | sed -e 's/DEVNAME= *//g'`
@@ -68,6 +69,39 @@
 	MINPWM=`egrep '^MINPWM=.*$' $1 | sed -e 's/MINPWM=//g'`
 	MAXPWM=`egrep '^MAXPWM=.*$' $1 | sed -e 's/MAXPWM=//g'`
 
+	# if DEVMAP is non-null, map the pseudonames in DEVMAP to the real names
+	if [ ! -z "$DEVMAP" ]; then
+		declare -A MONMAP
+		pushd /sys/class/hwmon
+		for mondev in *; do
+			if [ -e "$mondev/device/name" ]; then
+				for monnam in $DEVMAP; do
+					OIFS=$IFS; IFS="="
+					set $monnam
+					IFS=$OIFS
+					if [ "$2" == `cat "$mondev/device/name"` ]; then
+						MONMAP[$1]=$mondev
+						break;
+					fi
+				done
+			fi
+		done
+		# edit the config VARs
+		for pname in ${!MONMAP[@]}; do
+			DEVNAME=${DEVNAME//$pname/${MONMAP[$pname]}}
+			DEVPATH=${DEVPATH//$pname/${MONMAP[$pname]}}
+			FCTEMPS=${FCTEMPS//$pname/${MONMAP[$pname]}}
+			FCFANS=${FCFANS//$pname/${MONMAP[$pname]}}
+			MINTEMP=${MINTEMP//$pname/${MONMAP[$pname]}}
+			MAXTEMP=${MAXTEMP//$pname/${MONMAP[$pname]}}
+			MINSTART=${MINSTART//$pname/${MONMAP[$pname]}}
+			MINSTOP=${MINSTOP//$pname/${MONMAP[$pname]}}
+			MINPWM=${MINPWM//$pname/${MONMAP[$pname]}}
+			MAXPWM=${MAXPWM//$pname/${MONMAP[$pname]}}
+		done
+		popd
+	fi
+
 	# Check whether all mandatory settings are set
 	if [[ -z ${INTERVAL} || -z ${FCTEMPS} || -z ${MINTEMP} || -z ${MAXTEMP} || -z ${MINSTART} || -z ${MINSTOP} ]]
 	then

Reply via email to