Permalink
Browse files

Improved handling of missing thermal zone files

Instead of simply displaying zero when reading the thermal zone file fails,
display whatever we would display when provided with a misconfigured thermal
zone.
  • Loading branch information...
bobtwinkles committed Oct 30, 2018
1 parent 2abc9a8 commit 51d5535a9b4c513fb96daa2bd8b1bcb71fdebb2f
Showing with 9 additions and 5 deletions.
  1. +9 −5 src/Plugins/Monitors/ThermalZone.hs
@@ -34,12 +34,16 @@ 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")
handleIOError :: IOException -> IO (Maybe B.ByteString)
handleIOError _ = return Nothing
parse = return . (read :: String -> Int) . B.unpack
exists <- io $ fileExist file
if exists
then do mdegrees <- io $ catch ( B.readFile file) handleIOError >>= parse
temp <- showWithColors show (mdegrees `quot` 1000)
parseTemplate [ temp ]
then do contents <- io $ catch (fmap Just $ B.readFile file) handleIOError
case contents of
Just d -> do
mdegrees <- parse d
temp <- showWithColors show (mdegrees `quot` 1000)
parseTemplate [ temp ]
Nothing -> getConfigValue naString
else getConfigValue naString

0 comments on commit 51d5535

Please sign in to comment.