Skip to contentSkip to conversation

pwmconfig: Deal gracefully with unreadable fan inputs

PATCH New Jean Delvare 1 participant 1 message Feb 11, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 pwmconfig: Deal gracefully with unreadable fan inputs

If a hwmon driver exposes an unreadable fan input, let the user know and skip that input. Otherwise we hit syntax errors later on.

---
 prog/pwm/pwmconfig |    7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
prog/pwm/pwmconfig +5 -2
@@ -283,8 +283,11 @@ sleep $DELAY
 echo 'Found the following fan sensors:'
 for i in $FAN
 do
-	S=$(cat $i)
-	if [ "$S" = "0" -o "$S" = "-1" ]
+	S=$(cat $i 2> /dev/null)
+	if [ $? -ne 0 ]
+	then
+		echo "   $i     current speed: can't read ... skipping!"
+	elif [ "$S" = "0" -o "$S" = "-1" ]
 	then
 		echo "   $i     current speed: 0 ... skipping!"
 	else
Signature · 2 lines
Jean Delvare
SUSE L3 Support