generalize withNullHandle to MonadIO

This commit is contained in:
Joey Hess 2020-06-03 15:18:48 -04:00
parent e683207123
commit 31d53587d5
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
3 changed files with 13 additions and 8 deletions

View file

@ -100,18 +100,20 @@ startDaemon assistant foreground startdelay cannotrun listenhost startbrowser =
let flag = "GIT_ANNEX_OUTPUT_REDIR"
createAnnexDirectory (parentDir logfile)
ifM (liftIO $ isNothing <$> getEnv flag)
( liftIO $ withFile devNull WriteMode $ \nullh -> do
( liftIO $ withNullHandle $ \nullh -> do
loghandle <- openLog logfile
e <- getEnvironment
cmd <- programPath
ps <- getArgs
(_, _, _, pid) <- createProcess (proc cmd ps)
let p = (proc cmd ps)
{ env = Just (addEntry flag "1" e)
, std_in = UseHandle nullh
, std_out = UseHandle loghandle
, std_err = UseHandle loghandle
}
exitWith =<< waitForProcess pid
exitcode <- withCreateProcess p $ \_ _ _ pid ->
waitForProcess pid
exitWith exitcode
, start (Utility.Daemon.foreground (Just pidfile)) $
case startbrowser of
Nothing -> Nothing