summaryrefslogtreecommitdiff
path: root/src/Job.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Job.hs')
-rw-r--r--src/Job.hs15
1 files changed, 10 insertions, 5 deletions
diff --git a/src/Job.hs b/src/Job.hs
index 45cc827..b40f450 100644
--- a/src/Job.hs
+++ b/src/Job.hs
@@ -48,6 +48,7 @@ import System.Exit
import System.FilePath
import System.FilePath.Glob
import System.IO
+import System.IO.Error
import System.IO.Temp
import System.Posix.Signals
import System.Process
@@ -529,20 +530,24 @@ runJob job uses checkoutPath jdir = do
Right script -> do
sh <- fromMaybe "/bin/sh" <$> liftIO (lookupEnv "SHELL")
return ( proc sh [], script )
- (Just hin, _, _, hp) <- liftIO $ createProcess_ "" p
+ ( Just hin, _, _, hp ) <- liftIO $ createProcess_ "" p
{ cwd = Just checkoutPath
, std_in = CreatePipe
, std_out = UseHandle logs
, std_err = UseHandle logs
+ , create_group = True
}
+ Just pid <- liftIO $ getPid hp
liftIO $ void $ forkIO $ do
T.hPutStr hin input
hClose hin
- liftIO (waitForProcess hp) >>= \case
+ let killCreatedProcessGroup = do
+ handleJust (\case e | isDoesNotExistError e -> Just (); _ -> Nothing) return $ do
+ signalProcessGroup sigKILL pid
+ waitForProcess hp
+ liftIO (waitForProcess hp `finally` killCreatedProcessGroup) >>= \case
ExitSuccess -> return ()
- ExitFailure n
- | fromIntegral n == -sigINT -> throwError JobCancelled
- | otherwise -> throwError JobFailed
+ ExitFailure _ -> throwError JobFailed
artifacts <- forM (jobArtifacts job) $ \( name@(ArtifactName tname), pathPattern ) -> do
let adir = jdir </> "artifacts" </> T.unpack tname