mirror of
https://github.com/xmonad/xmonad-contrib.git
synced 2025-08-15 12:13:57 -07:00
Use doubleFork instead of manual double fork, or buggy single fork.
This fixes showWName because Timer was leaking zombie processes. You should update xmonad, since doubleFork was not exported.
This commit is contained in:
@@ -29,11 +29,9 @@ module XMonad.Util.Run (
|
|||||||
) where
|
) where
|
||||||
|
|
||||||
import System.Posix.IO
|
import System.Posix.IO
|
||||||
import System.Posix.Process (createSession, forkProcess, executeFile,
|
import System.Posix.Process (executeFile)
|
||||||
getProcessStatus)
|
|
||||||
import Control.Concurrent (threadDelay)
|
import Control.Concurrent (threadDelay)
|
||||||
import Control.Exception (try)
|
import Control.Exception (try)
|
||||||
import System.Exit (ExitCode(ExitSuccess), exitWith)
|
|
||||||
import System.IO
|
import System.IO
|
||||||
import System.Process (runInteractiveProcess, waitForProcess)
|
import System.Process (runInteractiveProcess, waitForProcess)
|
||||||
import XMonad
|
import XMonad
|
||||||
@@ -67,9 +65,7 @@ runProcessWithInput cmd args input = do
|
|||||||
-- | Wait is in us
|
-- | Wait is in us
|
||||||
runProcessWithInputAndWait :: FilePath -> [String] -> String -> Int -> IO ()
|
runProcessWithInputAndWait :: FilePath -> [String] -> String -> Int -> IO ()
|
||||||
runProcessWithInputAndWait cmd args input timeout = do
|
runProcessWithInputAndWait cmd args input timeout = do
|
||||||
pid <- forkProcess $ do
|
doubleFork $ do
|
||||||
forkProcess $ do -- double fork it over to init
|
|
||||||
createSession
|
|
||||||
(pin, pout, perr, ph) <- runInteractiveProcess cmd args Nothing Nothing
|
(pin, pout, perr, ph) <- runInteractiveProcess cmd args Nothing Nothing
|
||||||
hPutStr pin input
|
hPutStr pin input
|
||||||
hFlush pin
|
hFlush pin
|
||||||
@@ -79,10 +75,6 @@ runProcessWithInputAndWait cmd args input timeout = do
|
|||||||
hClose perr
|
hClose perr
|
||||||
waitForProcess ph
|
waitForProcess ph
|
||||||
return ()
|
return ()
|
||||||
exitWith ExitSuccess
|
|
||||||
return ()
|
|
||||||
getProcessStatus True False pid
|
|
||||||
return ()
|
|
||||||
|
|
||||||
-- | Multiplies by ONE MILLION, for use with
|
-- | Multiplies by ONE MILLION, for use with
|
||||||
-- 'runProcessWithInputAndWait'.
|
-- 'runProcessWithInputAndWait'.
|
||||||
@@ -113,7 +105,7 @@ seconds = fromEnum . (* 1000000)
|
|||||||
-- interpolation, whereas the safeSpawn example can be safe because
|
-- interpolation, whereas the safeSpawn example can be safe because
|
||||||
-- Firefox doesn't need any arguments if it is just being started.
|
-- Firefox doesn't need any arguments if it is just being started.
|
||||||
safeSpawn :: MonadIO m => FilePath -> String -> m ()
|
safeSpawn :: MonadIO m => FilePath -> String -> m ()
|
||||||
safeSpawn prog arg = liftIO (try (forkProcess $ executeFile prog True [arg] Nothing) >> return ())
|
safeSpawn prog arg = liftIO (try (doubleFork $ executeFile prog True [arg] Nothing) >> return ())
|
||||||
|
|
||||||
unsafeSpawn :: MonadIO m => String -> m ()
|
unsafeSpawn :: MonadIO m => String -> m ()
|
||||||
unsafeSpawn = spawn
|
unsafeSpawn = spawn
|
||||||
@@ -134,11 +126,7 @@ spawnPipe x = do
|
|||||||
setFdOption wr CloseOnExec True
|
setFdOption wr CloseOnExec True
|
||||||
h <- fdToHandle wr
|
h <- fdToHandle wr
|
||||||
hSetBuffering h LineBuffering
|
hSetBuffering h LineBuffering
|
||||||
pid <- forkProcess $ do
|
doubleFork $ do
|
||||||
forkProcess $ do
|
|
||||||
dupTo rd stdInput
|
dupTo rd stdInput
|
||||||
createSession
|
|
||||||
executeFile "/bin/sh" False ["-c", x] Nothing
|
executeFile "/bin/sh" False ["-c", x] Nothing
|
||||||
exitWith ExitSuccess
|
|
||||||
getProcessStatus True False pid
|
|
||||||
return h
|
return h
|
||||||
|
@@ -24,7 +24,6 @@ import Control.Applicative
|
|||||||
import Control.Concurrent
|
import Control.Concurrent
|
||||||
import Data.Unique
|
import Data.Unique
|
||||||
import System.Environment
|
import System.Environment
|
||||||
import System.Posix.Process
|
|
||||||
|
|
||||||
-- $usage
|
-- $usage
|
||||||
-- This module can be used to setup a timer to handle deferred events.
|
-- This module can be used to setup a timer to handle deferred events.
|
||||||
@@ -40,7 +39,7 @@ startTimer s = io $ do
|
|||||||
d <- openDisplay dpy
|
d <- openDisplay dpy
|
||||||
rw <- rootWindow d $ defaultScreen d
|
rw <- rootWindow d $ defaultScreen d
|
||||||
u <- hashUnique <$> newUnique
|
u <- hashUnique <$> newUnique
|
||||||
forkProcess $ do
|
doubleFork $ do
|
||||||
threadDelay (fromEnum $ s * 1000000)
|
threadDelay (fromEnum $ s * 1000000)
|
||||||
a <- internAtom d "XMONAD_TIMER" False
|
a <- internAtom d "XMONAD_TIMER" False
|
||||||
allocaXEvent $ \e -> do
|
allocaXEvent $ \e -> do
|
||||||
|
Reference in New Issue
Block a user