summaryrefslogtreecommitdiff
path: root/Utility/Lsof.hs
diff options
context:
space:
mode:
Diffstat (limited to 'Utility/Lsof.hs')
-rw-r--r--Utility/Lsof.hs13
1 files changed, 13 insertions, 0 deletions
diff --git a/Utility/Lsof.hs b/Utility/Lsof.hs
index 72f3e5815..9a877a3c9 100644
--- a/Utility/Lsof.hs
+++ b/Utility/Lsof.hs
@@ -10,8 +10,10 @@
module Utility.Lsof where
import Common
+import Build.SysConfig as SysConfig
import System.Posix.Types
+import System.Posix.Env
data LsofOpenMode = OpenReadWrite | OpenReadOnly | OpenWriteOnly | OpenUnknown
deriving (Show, Eq)
@@ -21,6 +23,17 @@ type CmdLine = String
data ProcessInfo = ProcessInfo ProcessID CmdLine
deriving (Show)
+{- lsof is not in PATH on all systems, so SysConfig may have the absolute
+ - path where the program was found. Make sure at runtime that lsof is
+ - available, and if it's not in PATH, adjust PATH to contain it. -}
+setupLsof :: IO ()
+setupLsof = do
+ let cmd = fromMaybe "lsof" SysConfig.lsof
+ when (isAbsolute cmd) $ do
+ path <- getSearchPath
+ let path' = takeDirectory cmd : path
+ setEnv "PATH" (join [searchPathSeparator] path') True
+
{- 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)]