From b87ed38376361259fb1aa8cef7fd9c34414b98ee Mon Sep 17 00:00:00 2001 From: Reto Hablützel Date: Sun, 9 Mar 2014 11:05:37 +0100 Subject: Handle inexistent devices If a device is unplugged without prior unmounting, it still appears in the /etc/mtab file, which is used for this monitor. The problem is that this monitor canonicalized every path regardless of whether it actually existed or not. I basically added the 'only canonicalize if file exists'. --- src/Plugins/Monitors/Disk.hs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/Plugins/Monitors/Disk.hs b/src/Plugins/Monitors/Disk.hs index 73bd5b7..cf4fa00 100644 --- a/src/Plugins/Monitors/Disk.hs +++ b/src/Plugins/Monitors/Disk.hs @@ -23,7 +23,8 @@ import Control.Exception (SomeException, handle) import Control.Monad (zipWithM) import qualified Data.ByteString.Lazy.Char8 as B import Data.List (isPrefixOf, find) -import System.Directory (canonicalizePath) +import Data.Maybe (catMaybes) +import System.Directory (canonicalizePath, doesFileExist) diskIOConfig :: IO MConfig diskIOConfig = mkMConfig "" ["total", "read", "write", @@ -40,11 +41,15 @@ type DevDataRef = IORef [(DevName, [Float])] mountedDevices :: [String] -> IO [(DevName, Path)] mountedDevices req = do s <- B.readFile "/etc/mtab" - parse `fmap` mapM canon (devs s) + parse `fmap` mapM mbcanon (devs s) where + mbcanon (d, p) = doesFileExist d >>= \e -> + if e + then Just `fmap` canon (d,p) + else return Nothing canon (d, p) = do {d' <- canonicalizePath d; return (d', p)} devs = filter isDev . map (firstTwo . B.words) . B.lines - parse = map undev . filter isReq + parse = map undev . filter isReq . catMaybes firstTwo (a:b:_) = (B.unpack a, B.unpack b) firstTwo _ = ("", "") isDev (d, _) = "/dev/" `isPrefixOf` d -- cgit v1.2.3