diff options
author | Joey Hess <joey@kitenet.net> | 2012-06-15 22:34:42 -0400 |
---|---|---|
committer | Joey Hess <joey@kitenet.net> | 2012-06-15 22:34:42 -0400 |
commit | bb6074dfea4c87037abe096e3b9a0a6d746f5437 (patch) | |
tree | 8f6653c6c3dc7e4f2fa3bd4f5aa78a1a81b36e93 /Utility/Lsof.hs | |
parent | 3dac81d3450da25581ad8f4bcfb615da5050767d (diff) |
work around a wrinkle in how lsof handles hard links to files that are open elsewhere
+d is probably more expensive, but I need it
Diffstat (limited to 'Utility/Lsof.hs')
-rw-r--r-- | Utility/Lsof.hs | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/Utility/Lsof.hs b/Utility/Lsof.hs index 1c0e934fd..25581cc23 100644 --- a/Utility/Lsof.hs +++ b/Utility/Lsof.hs @@ -21,9 +21,14 @@ type CmdLine = String data ProcessInfo = ProcessInfo ProcessID CmdLine deriving (Show) -query :: FilePath -> IO [(FilePath, LsofOpenMode, ProcessInfo)] -query p = do - (pid, s) <- pipeFrom "lsof" ["-F0can", "--", p] +{- Checks each of the files in a directory to find open files. + - Note that this will find hard links to files elsewhere that are open. -} +queryDir :: FilePath -> IO [(FilePath, LsofOpenMode, ProcessInfo)] +queryDir path = query ["+d", path] + +query :: [String] -> IO [(FilePath, LsofOpenMode, ProcessInfo)] +query opts = do + (pid, s) <- pipeFrom "lsof" ("-F0can" : opts) let !r = parse s -- ignore nonzero exit code; lsof returns that when no files are open void $ getProcessStatus True False $ processID pid |