#983808 fancontrol: pwmconfig should validate permissions before reading.

#983808#5
Date:
2021-03-01 22:02:21 UTC
From:
To:
When running pwmconfig on a Dell Precision 5530, it fails to read
/sys/class/hwmon/hwmon6/pwm1_enable. Indeed, this file is write only
(--w-------). Therefore the script it throwing an error:

Found the following PWM controls:
   hwmon6/pwm1           current value: 128
cat: hwmon6/pwm1_enable: Permission non accordée

cat: hwmon6/pwm1_enable: Permission non accordée
/usr/sbin/pwmconfig: ligne 164 : [:  : nombre entier attendu comme expression
cat: hwmon6/pwm1_enable: Permission non accordée
/usr/sbin/pwmconfig: ligne 187 : [:  : nombre entier attendu comme expression
cat: hwmon6/pwm1_enable: Permission non accordée
/usr/sbin/pwmconfig: ligne 195 : [:  : nombre entier attendu comme expression
hwmon6/pwm1 stuck to 128
Manual control mode not supported, skipping hwmon6/pwm1.
   hwmon6/pwm2           current value: 128

Giving the fans some time to reach full speed...
Found the following fan sensors:
   hwmon6/fan1_input     current speed: 5126 RPM
   hwmon6/fan2_input     current speed: 5086 RPM



The resulting /etc/fancontrol file is almost empty:
# cat /etc/fancontrol
# Configuration file generated by pwmconfig, changes will be lost
INTERVAL=10
DEVPATH=
DEVNAME=
FCTEMPS=
FCFANS=
MINTEMP=
MAXTEMP=
MINSTART=
MINSTOP=


And then the service fails to restart:
mar 01 16:50:45 precision5530 systemd[1]: Starting Cleanup of Temporary
Directories...
░░ Subject: L'unité (unit) systemd-tmpfiles-clean.service a commencé à démarrer
░░ Defined-By: systemd
░░ Support: https://www.debian.org/support
░░
░░ L'unité (unit) systemd-tmpfiles-clean.service a commencé à démarrer.
mar 01 16:50:45 precision5530 su[2434]: (to root) jmspaggi on pts/0
mar 01 16:50:45 precision5530 su[2434]: pam_unix(su:session): session opened
for user root(uid=0) by (uid=0)
mar 01 16:50:45 precision5530 systemd[1]: systemd-tmpfiles-clean.service:
Succeeded.
░░ Subject: Unit succeeded
░░ Defined-By: systemd
░░ Support: https://www.debian.org/support
░░
░░ The unit systemd-tmpfiles-clean.service has successfully entered the 'dead'
state.
mar 01 16:50:45 precision5530 systemd[1]: Finished Cleanup of Temporary
Directories.
░░ Subject: L'unité (unit) systemd-tmpfiles-clean.service a terminé son
démarrage
░░ Defined-By: systemd
░░ Support: https://www.debian.org/support
░░
░░ L'unité (unit) systemd-tmpfiles-clean.service a terminé son démarrage, avec
le résultat done.
mar 01 16:54:25 precision5530 wpa_supplicant[776]: wlp59s0: CTRL-EVENT-SIGNAL-
CHANGE above=1 signal=-49 noise=-96 txrate=175500
mar 01 16:58:10 precision5530 systemd[1]: Starting fan speed regulator...
░░ Subject: L'unité (unit) fancontrol.service a commencé à démarrer
░░ Defined-By: systemd
░░ Support: https://www.debian.org/support
░░
░░ L'unité (unit) fancontrol.service a commencé à démarrer.
mar 01 16:58:10 precision5530 fancontrol[2697]: Loading configuration from
/etc/fancontrol ...
mar 01 16:58:10 precision5530 fancontrol[2697]: Some mandatory settings
missing, please check your config file!
mar 01 16:58:10 precision5530 systemd[1]: fancontrol.service: Control process
exited, code=exited, status=1/FAILURE
░░ Subject: Unit process exited
░░ Defined-By: systemd
░░ Support: https://www.debian.org/support
░░
░░ An ExecStartPre= process belonging to unit fancontrol.service has exited.
░░
░░ The process' exit code is 'exited' and its exit status is 1.
mar 01 16:58:10 precision5530 systemd[1]: fancontrol.service: Failed with
result 'exit-code'.
░░ Subject: Unit failed
░░ Defined-By: systemd
░░ Support: https://www.debian.org/support
░░
░░ The unit fancontrol.service has entered the 'failed' state with result
'exit-code'.
mar 01 16:58:10 precision5530 systemd[1]: Failed to start fan speed regulator.
░░ Subject: L'unité (unit) fancontrol.service a échoué
░░ Defined-By: systemd
░░ Support: https://www.debian.org/support
░░
░░ L'unité (unit) fancontrol.service a échoué, avec le résultat failed.



Before trying to read the file, the script should check for the permissions,
and if not allowed, should take the right decision.