Skip to contentSkip to conversation

fix fancontrol to survive a system suspend

PATCH New Maximilian Seesslen 1 participant 1 message Jul 12, 2013

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fix fancontrol to survive a system suspend

Hello,

find attached a patch that fixes fancontrol to survive a system suspend.

If the daemon can not set the pwm values but it did it already in the past successfully, it tries to reenable the pwm output instead of quitting.

Regards,
Max

--
Maximilian Seesslen

pwm/fancontrol +9 -1
Index: prog/pwm/fancontrol
===================================================================
@@ -42,6 +42,7 @@
 
 #DEBUG=1
 MAX=255
+DID_FIRSTRUN=0
 
 function LoadConfig
 {
@@ -490,7 +491,12 @@
 		if [ $? -ne 0 ]
 		then
 			echo "Error writing PWM value to $DIR/$pwmo" >&2
-			restorefans 1
+			[ "$DID_FIRSTRUN" == "0" ] && restorefans 1
+			# Ignoring write error. System probably was syspended and has to reanable pwm.
+			echo "Ignoring, i try reanabling PWM."
+			pwmenable $pwmo
+			# Write values again to keep failure short
+			echo $pwmval > $pwmo # write new value to pwm output
 		fi
 		if [ "$DEBUG" != "" ]
 		then
@@ -498,6 +504,8 @@
 		fi
 		let fcvcount=$fcvcount+1
 	done
+	
+	DID_FIRSTRUN=1
 }
 
 echo 'Enabling PWM on fans...'

From 46940390c8f9fcc4325710867c95b2e28aebaf81 Mon Sep 17 00:00:00 2001
From: Maximilian Seesslen <[email protected]>
Date: Fri, 12 Jul 2013 18:59:49 +0200
Subject: [PATCH] fix fancontrol to survive a system suspend/hibernate

---
 prog/pwm/fancontrol |   10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
prog/pwm/fancontrol +9 -1
index 2771139..3e57901 100755
@@ -42,6 +42,7 @@ PIDFILE="/var/run/fancontrol.pid"
 
 #DEBUG=1
 MAX=255
+DID_FIRSTRUN=0
 
 function LoadConfig
 {
@@ -490,7 +491,12 @@ function UpdateFanSpeeds
 		if [ $? -ne 0 ]
 		then
 			echo "Error writing PWM value to $DIR/$pwmo" >&2
-			restorefans 1
+			[ "$DID_FIRSTRUN" == "0" ] && restorefans 1
+			# Ignoring write error. System probably was syspended and has to reanable pwm.
+			echo "Ignoring, i try reanabling PWM."
+			pwmenable $pwmo
+			# Write values again to keep failure short
+			echo $pwmval > $pwmo # write new value to pwm output
 		fi
 		if [ "$DEBUG" != "" ]
 		then
@@ -498,6 +504,8 @@ function UpdateFanSpeeds
 		fi
 		let fcvcount=$fcvcount+1
 	done
+	
+	DID_FIRSTRUN=1
 }
 
 echo 'Enabling PWM on fans...'
Signature · 1 line
1.7.10.4

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors