aboutsummaryrefslogtreecommitdiff
path: root/Utility/Lsof.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2012-12-13 00:24:19 -0400
committerGravatar Joey Hess <joey@kitenet.net>2012-12-13 00:24:19 -0400
commit94554782894ec6c26da3b46312d5d1d16d596458 (patch)
tree78746106bfb153945ccbfd2bbae536081c005e91 /Utility/Lsof.hs
parent55bd61d8c42aaf36a3c57f8444c493f6b045f4cd (diff)
finished where indentation changes
Diffstat (limited to 'Utility/Lsof.hs')
-rw-r--r--Utility/Lsof.hs72
1 files changed, 35 insertions, 37 deletions
diff --git a/Utility/Lsof.hs b/Utility/Lsof.hs
index ce6a16283..72f3e5815 100644
--- a/Utility/Lsof.hs
+++ b/Utility/Lsof.hs
@@ -36,8 +36,8 @@ query :: [String] -> IO [(FilePath, LsofOpenMode, ProcessInfo)]
query opts =
withHandle StdoutHandle (createProcessChecked checkSuccessProcess) p $ \h -> do
parse <$> hGetContentsStrict h
- where
- p = proc "lsof" ("-F0can" : opts)
+ where
+ p = proc "lsof" ("-F0can" : opts)
{- Parsing null-delimited output like:
-
@@ -51,38 +51,36 @@ query opts =
-}
parse :: String -> [(FilePath, LsofOpenMode, ProcessInfo)]
parse s = bundle $ go [] $ lines s
- where
- bundle = concatMap (\(fs, p) -> map (\(f, m) -> (f, m, p)) fs)
-
- go c [] = c
- go c ((t:r):ls)
- | t == 'p' =
- let (fs, ls') = parsefiles [] ls
- in go ((fs, parseprocess r):c) ls'
- | otherwise = parsefail
- go _ _ = parsefail
-
- parseprocess l =
- case splitnull l of
- [pid, 'c':cmdline, ""] ->
- case readish pid of
- (Just n) -> ProcessInfo n cmdline
- Nothing -> parsefail
- _ -> parsefail
-
- parsefiles c [] = (c, [])
- parsefiles c (l:ls) =
- case splitnull l of
- ['a':mode, 'n':file, ""] ->
- parsefiles ((file, parsemode mode):c) ls
- (('p':_):_) -> (c, l:ls)
- _ -> parsefail
-
- parsemode ('r':_) = OpenReadOnly
- parsemode ('w':_) = OpenWriteOnly
- parsemode ('u':_) = OpenReadWrite
- parsemode _ = OpenUnknown
-
- splitnull = split "\0"
-
- parsefail = error $ "failed to parse lsof output: " ++ show s
+ where
+ bundle = concatMap (\(fs, p) -> map (\(f, m) -> (f, m, p)) fs)
+
+ go c [] = c
+ go c ((t:r):ls)
+ | t == 'p' =
+ let (fs, ls') = parsefiles [] ls
+ in go ((fs, parseprocess r):c) ls'
+ | otherwise = parsefail
+ go _ _ = parsefail
+
+ parseprocess l = case splitnull l of
+ [pid, 'c':cmdline, ""] ->
+ case readish pid of
+ (Just n) -> ProcessInfo n cmdline
+ Nothing -> parsefail
+ _ -> parsefail
+
+ parsefiles c [] = (c, [])
+ parsefiles c (l:ls) = case splitnull l of
+ ['a':mode, 'n':file, ""] ->
+ parsefiles ((file, parsemode mode):c) ls
+ (('p':_):_) -> (c, l:ls)
+ _ -> parsefail
+
+ parsemode ('r':_) = OpenReadOnly
+ parsemode ('w':_) = OpenWriteOnly
+ parsemode ('u':_) = OpenReadWrite
+ parsemode _ = OpenUnknown
+
+ splitnull = split "\0"
+
+ parsefail = error $ "failed to parse lsof output: " ++ show s