summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorJose Antonio Ortega Ruiz <jao@gnu.org>2012-06-04 01:55:46 +0200
committerJose Antonio Ortega Ruiz <jao@gnu.org>2012-06-04 01:55:46 +0200
commitc87df01f1d1eef7ccd5fb1d03282c6cdb341ce5b (patch)
tree1dcb679ccbe9ab0315db2a5ce80f6e8638e7c4f4
parentfae4472f5fedcfd23522b53cba0f5a7f146afed2 (diff)
downloadxmobar-c87df01f1d1eef7ccd5fb1d03282c6cdb341ce5b.tar.gz
xmobar-c87df01f1d1eef7ccd5fb1d03282c6cdb341ce5b.tar.bz2
Mostly failed attempt to robustify disk usage monitor
Since a kernel upgrade about two months ago, DiskU just blows up my xmobar apparently at random.
-rw-r--r--src/Plugins/Monitors/Disk.hs13
1 files changed, 8 insertions, 5 deletions
diff --git a/src/Plugins/Monitors/Disk.hs b/src/Plugins/Monitors/Disk.hs
index dca268d..725fe29 100644
--- a/src/Plugins/Monitors/Disk.hs
+++ b/src/Plugins/Monitors/Disk.hs
@@ -19,6 +19,7 @@ import StatFS
import Data.IORef (IORef, newIORef, readIORef, writeIORef)
+import Control.Exception (SomeException, handle)
import Control.Monad (zipWithM)
import qualified Data.ByteString.Lazy.Char8 as B
import Data.List (isPrefixOf, find)
@@ -80,10 +81,10 @@ fsStats :: String -> IO [Integer]
fsStats path = do
stats <- getFileSystemStats path
case stats of
- Nothing -> return [-1, -1, -1]
+ Nothing -> return [0, 0, 0]
Just f -> let tot = fsStatByteCount f
free = fsStatBytesAvailable f
- in return [tot, free, (tot - free)]
+ in return [tot, free, tot - free]
speedToStr :: Float -> String
speedToStr = showWithUnits 2 1
@@ -133,15 +134,17 @@ startDiskIO disks args rate cb = do
runDiskU' :: String -> String -> Monitor String
runDiskU' tmp path = do
setConfigValue tmp template
- fstats <- io $ fsStats path
- let strs = map sizeToStr fstats
- freep = (fstats !! 1) * 100 `div` head fstats
+ [total, free, diff] <- io (handle ign $ fsStats path)
+ let strs = map sizeToStr [total, free, diff]
+ freep = if total > 0 then free * 100 `div` total else 0
fr = fromIntegral freep / 100
s <- zipWithM showWithColors' strs [100, freep, 100 - freep]
sp <- showPercentsWithColors [fr, 1 - fr]
fb <- showPercentBar (fromIntegral freep) fr
ub <- showPercentBar (fromIntegral $ 100 - freep) (1 - fr)
parseTemplate $ s ++ sp ++ [fb, ub]
+ where ign = const (return [0, 0, 0]) :: SomeException -> IO [Integer]
+
runDiskU :: [(String, String)] -> [String] -> Monitor String
runDiskU disks _ = do