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
This commit is contained in:
Joey Hess 2012-06-15 22:34:42 -04:00
parent 3dac81d345
commit bb6074dfea

View file

@ -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