diff options
author | Roman Smrž <roman.smrz@seznam.cz> | 2025-03-03 19:33:25 +0100 |
---|---|---|
committer | Roman Smrž <roman.smrz@seznam.cz> | 2025-03-03 19:41:37 +0100 |
commit | b7d7ab0c2158886f5dccac91a0377054ba84005a (patch) | |
tree | 33a8a5cfcac50a1aaf7e75ec98bafe0f1d007c0a | |
parent | a7b5aa6325732616fece14f8d392db551d23911c (diff) |
Turn relative command path to absolute before starting subprocess
Changelog: Fix executing test tool given with relative path
-rw-r--r-- | src/Process.hs | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/src/Process.hs b/src/Process.hs index e74d04d..a65fb4a 100644 --- a/src/Process.hs +++ b/src/Process.hs @@ -22,7 +22,9 @@ import Data.Text (Text) import qualified Data.Text as T import qualified Data.Text.IO as T +import System.Directory import System.Exit +import System.FilePath import System.IO import System.IO.Error import System.Posix.Signals @@ -89,9 +91,20 @@ lineReadingLoop process h act = spawnOn :: Either Network Node -> ProcName -> Maybe Signal -> String -> TestRun Process spawnOn target pname killWith cmd = do + -- When executing command given with relative path, turn it to absolute one, + -- because working directory will be changed for the "ip netns exec" wrapper. + cmd' <- liftIO $ do + case span (/= ' ') cmd of + ( path, rest ) + | any isPathSeparator path && isRelative path + -> do + path' <- makeAbsolute path + return (path' ++ rest) + _ -> return cmd + let netns = either getNetns getNetns target let prefix = T.unpack $ "ip netns exec \"" <> textNetnsName netns <> "\" " - (Just hin, Just hout, Just herr, handle) <- liftIO $ createProcess (shell $ prefix ++ cmd) + (Just hin, Just hout, Just herr, handle) <- liftIO $ createProcess (shell $ prefix ++ cmd') { std_in = CreatePipe, std_out = CreatePipe, std_err = CreatePipe , cwd = Just (either netDir nodeDir target) , env = Just [ ( "EREBOS_DIR", "." ) ] |