summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorbobtwinkles <srkoser+github@gmail.com>2018-10-29 21:32:27 -0400
committerbobtwinkles <srkoser+github@gmail.com>2018-10-29 21:36:31 -0400
commit2abc9a8a162de028ec2c0d616182d0c34a54414c (patch)
treeaddfc604cb66b00ae27f9be4288146614d88bfdf
parent719cc5375972fdab189bc1672dfa062e1734f75a (diff)
downloadxmobar-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.
-rw-r--r--src/Plugins/Monitors/ThermalZone.hs5
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