diff options
| author | bobtwinkles <srkoser+github@gmail.com> | 2018-10-29 21:32:27 -0400 | 
|---|---|---|
| committer | bobtwinkles <srkoser+github@gmail.com> | 2018-10-29 21:36:31 -0400 | 
| commit | 2abc9a8a162de028ec2c0d616182d0c34a54414c (patch) | |
| tree | addfc604cb66b00ae27f9be4288146614d88bfdf /src/Plugins | |
| parent | 719cc5375972fdab189bc1672dfa062e1734f75a (diff) | |
| download | xmobar-2abc9a8a162de028ec2c0d616182d0c34a54414c.tar.gz xmobar-2abc9a8a162de028ec2c0d616182d0c34a54414c.tar.bz2 | |
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.
Diffstat (limited to 'src/Plugins')
| -rw-r--r-- | src/Plugins/Monitors/ThermalZone.hs | 5 | 
1 files changed, 4 insertions, 1 deletions
| 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 | 
