From 2abc9a8a162de028ec2c0d616182d0c34a54414c Mon Sep 17 00:00:00 2001 From: bobtwinkles Date: Mon, 29 Oct 2018 21:32:27 -0400 Subject: Allow recovery from missing thermal zones Sometimes the kernel takes some time to populate /sys/class/thermal/ * after resuming from suspend. Previously, this would result in the thermal plugin dying permanantly. With this patch, we show "0" until the kernel gets around to populating the sysfs nodes we need. --- src/Plugins/Monitors/ThermalZone.hs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/Plugins/Monitors/ThermalZone.hs b/src/Plugins/Monitors/ThermalZone.hs index d692191..838a7f5 100644 --- a/src/Plugins/Monitors/ThermalZone.hs +++ b/src/Plugins/Monitors/ThermalZone.hs @@ -20,6 +20,7 @@ module Plugins.Monitors.ThermalZone (thermalZoneConfig, runThermalZone) where import Plugins.Monitors.Common import System.Posix.Files (fileExist) +import Control.Exception (IOException, catch) import qualified Data.ByteString.Char8 as B -- | Default thermal configuration. @@ -33,10 +34,12 @@ runThermalZone :: [String] -> Monitor String runThermalZone args = do let zone = head args file = "/sys/class/thermal/thermal_zone" ++ zone ++ "/temp" + handleIOError :: IOException -> IO B.ByteString + handleIOError _ = return (B.pack "-1") parse = return . (read :: String -> Int) . B.unpack exists <- io $ fileExist file if exists - then do mdegrees <- io $ B.readFile file >>= parse + then do mdegrees <- io $ catch ( B.readFile file) handleIOError >>= parse temp <- showWithColors show (mdegrees `quot` 1000) parseTemplate [ temp ] else getConfigValue naString -- cgit v1.2.3