From 55f91677bbcaa4b29a09dfb5cfc0efe7d5e1ac5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roman=20Smr=C5=BE?= Date: Fri, 20 Nov 2026 11:41:39 +0100 Subject: Spawn processes directly instead of via shell Changelog: Test tool is now spawned directly without shell wrapper. --- src/Process.hs | 29 +++++++++++++---------------- src/Run.hs | 10 ++++++---- 2 files changed, 19 insertions(+), 20 deletions(-) diff --git a/src/Process.hs b/src/Process.hs index 1c2dbe5..6d1f20a 100644 --- a/src/Process.hs +++ b/src/Process.hs @@ -141,18 +141,15 @@ startProcessIOLoops process@Process {..} hout herr = do | Right (Just _) <- regexMatch re line = True | otherwise = False -spawnOn :: Either Network Node -> ProcName -> Maybe Signal -> String -> TestRun Process -spawnOn target procName procKillWith cmd = do +spawnOn :: Either Network Node -> ProcName -> Maybe Signal -> String -> [ String ] -> TestRun Process +spawnOn target procName procKillWith cmd args = do -- When executing command given with relative path, turn it to absolute one, - -- because working directory will be changed for the shell wrapper. - cmd' <- liftIO $ do - case span (/= ' ') cmd of - ( path, rest ) - | any isPathSeparator path && isRelative path - -> do - path' <- makeAbsolute path - return (path' ++ rest) - _ -> return cmd + -- because working directory will be changed for the process. + cmd' <- if + | any isPathSeparator cmd && isRelative cmd + -> liftIO $ makeAbsolute cmd + | otherwise + -> return cmd procId <- case procName of ProcNameTcpdump -> return $ ProcessId (-1) @@ -162,8 +159,8 @@ spawnOn target procName procKillWith cmd = do let netns = either getNetns getNetns target currentEnv <- liftIO $ getEnvironment - (Just procStdin, Just hout, Just herr, handle) <- liftIO $ do - runInNetworkNamespace netns $ createProcess (shell cmd') + ( Just procStdin, Just hout, Just herr, handle ) <- liftIO $ do + runInNetworkNamespace netns $ createProcess (proc cmd' args) { std_in = CreatePipe, std_out = CreatePipe, std_err = CreatePipe , cwd = Just (either netDir nodeDir target) , env = Just $ ( "EREBOS_DIR", "." ) : currentEnv @@ -222,11 +219,11 @@ closeTestProcess process = do timeout <- getCurrentTimeout closeProcess timeout process -withProcess :: Either Network Node -> ProcName -> Maybe Signal -> String -> (Process -> TestRun a) -> TestRun a -withProcess target pname killWith cmd inner = do +withProcess :: Either Network Node -> ProcName -> Maybe Signal -> String -> [ String ] -> (Process -> TestRun a) -> TestRun a +withProcess target pname killWith cmd args inner = do procVar <- asks $ teProcesses . fst - process <- spawnOn target pname killWith cmd + process <- spawnOn target pname killWith cmd args liftIO $ modifyMVar_ procVar $ return . (process:) inner process `finally` do diff --git a/src/Run.hs b/src/Run.hs index 33c4109..b6613b4 100644 --- a/src/Run.hs +++ b/src/Run.hs @@ -367,11 +367,13 @@ runStep = \case go node = do env <- asks fst let pname = ProcName tname - tool = fromMaybe (teDefaultTool env) (lookup pname $ teProcTools env) - cmd = T.unwords $ T.pack tool : map escape args + ( tool, cargs ) = fromMaybe ( "", [] ) $ uncons $ words $ + fromMaybe (teDefaultTool env) (lookup pname $ teProcTools env) + args' = cargs ++ map T.unpack args + cmd = T.unwords $ T.pack tool : map escape (map T.pack args') escape = ("'" <>) . (<> "'") . T.replace "'" "'\\''" outProcName OutputChildExec pname cmd - withProcess (Right node) pname killWith (T.unpack cmd) $ runStep . inner + withProcess (Right node) pname killWith tool args' $ runStep . inner SpawnShell mbname node script inner -> do let tname | Just (TypedVarName (VarName name)) <- mbname = name @@ -429,7 +431,7 @@ withNetwork :: Network -> (Network -> TestRun a) -> TestRun a withNetwork net inner = do tcpdump <- asks (optTcpdump . teOptions . fst) >>= return . \case Just path -> withProcess (Left net) ProcNameTcpdump (Just (Signal softwareTermination)) - (path ++ " -i br0 -w './br0.pcap' -U -Z root") . const + path [ "-i", "br0", "-w", "./br0.pcap", "-U", "-Z", "root" ] . const Nothing -> id tcpdump $ inner net -- cgit v1.2.3