Handle OSError when 'temp' file is not readable

Sometimes reading 'temp' generates an error message 'No data available'. Wrapping it in a try/catch allows other temp zone to work as expected. I also modified it to use the with statement to ensure files are always closed - even when an exception occurs.

Example where reading zone3 raises an error:

$ sudo cat /sys/class/thermal/thermal_zone3/temp
cat: /sys/class/thermal/thermal_zone3/temp: No data available
$ echo $?
1

Within the code, it raises this stack trace:

# time, sensor, value
Traceback (most recent call last):
  File "/usr/sbin/ntplogtemp", line 315, in <module>
    log_data()
  File "/usr/sbin/ntplogtemp", line 300, in log_data
    logData(Logger, zone.get_data())
                    ^^^^^^^^^^^^^^^
  File "/usr/sbin/ntplogtemp", line 211, in get_data
    for line in _zone_data:
OSError: [Errno 61] No data available

This bug was reported at https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1098368

Merge request reports

Loading