From d453a0add31502345c84d42defbc81d1f98c0e82 Mon Sep 17 00:00:00 2001 From: Spencer Janssen Date: Mon, 19 Nov 2007 04:03:53 +0100 Subject: Factor out doubleFork logic darcs-hash:20071119030353-a5988-935fc83135dc394c1e1a757f0232022b4de96f01 --- XMonad/Core.hs | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) (limited to 'XMonad') diff --git a/XMonad/Core.hs b/XMonad/Core.hs index d533bf6..e873848 100644 --- a/XMonad/Core.hs +++ b/XMonad/Core.hs @@ -270,9 +270,14 @@ catchIO f = liftIO (f `catch` \e -> hPrint stderr e >> hFlush stderr) -- | spawn. Launch an external application spawn :: MonadIO m => String -> m () -spawn x = liftIO $ do +spawn x = doubleFork $ executeFile "/bin/sh" False ["-c", x] Nothing + +-- | Double fork and execute an IO action (usually one of the exec family of +-- functions) +doubleFork :: MonadIO m => IO () -> m () +doubleFork m = liftIO $ do pid <- forkProcess $ do - forkProcess (createSession >> executeFile "/bin/sh" False ["-c", x] Nothing) + forkProcess (createSession >> m) exitWith ExitSuccess getProcessStatus True False pid return () @@ -324,14 +329,7 @@ recompile = do let msg = unlines $ ["Error detected while loading xmonad configuration file: " ++ src] ++ lines ghcErr ++ ["","Please check the file for errors."] - -- usual double fork for async processes, and no zombies. - -- careful to use exec directly, avoiding shell - -- interpreting chars in the command line args - pid <- forkProcess $ do - forkProcess $ createSession >> executeFile "xmessage" True [msg] Nothing - exitWith ExitSuccess - getProcessStatus True False pid - return () + doubleFork $ executeFile "xmessage" True [msg] Nothing -- | Run a side effecting action with the current workspace. Like 'when' but whenJust :: Monad m => Maybe a -> (a -> m ()) -> m () -- cgit v1.2.3