From e3650fa208a29186feaaf9b70ea43786dadf872d Mon Sep 17 00:00:00 2001 From: Spencer Janssen Date: Wed, 23 Dec 2009 07:16:23 +0100 Subject: Add xfork: a forkProcess that works around process global state Ignore-this: 3f968260d8c1b6710c82566520c47c43 darcs-hash:20091223061623-25a6b-3b3cc5f1a12543336e5b8581f9798989c4d848ac --- XMonad/Core.hs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'XMonad/Core.hs') diff --git a/XMonad/Core.hs b/XMonad/Core.hs index 0961235..b0713d7 100644 --- a/XMonad/Core.hs +++ b/XMonad/Core.hs @@ -27,7 +27,7 @@ module XMonad.Core ( StateExtension(..), ExtensionClass(..), runX, catchX, userCode, userCodeDef, io, catchIO, installSignalHandlers, uninstallSignalHandlers, withDisplay, withWindowSet, isRoot, runOnWorkspaces, - getAtom, spawn, spawnPID, getXMonadDir, recompile, trace, whenJust, whenX, + getAtom, spawn, spawnPID, xfork, getXMonadDir, recompile, trace, whenJust, whenX, atom_WM_STATE, atom_WM_PROTOCOLS, atom_WM_DELETE_WINDOW, ManageHook, Query(..), runQuery ) where @@ -395,10 +395,14 @@ spawn x = spawnPID x >> return () -- | Like 'spawn', but returns the 'ProcessID' of the launched application spawnPID :: MonadIO m => String -> m ProcessID -spawnPID x = io . forkProcess . finally nullStdin $ do +spawnPID x = xfork $ executeFile "/bin/sh" False ["-c", x] Nothing + +-- | A replacement for 'forkProcess' which resets default signal handlers. +xfork :: MonadIO m => IO () -> m ProcessID +xfork x = io . forkProcess . finally nullStdin $ do uninstallSignalHandlers createSession - executeFile "/bin/sh" False ["-c", x] Nothing + x where nullStdin = do fd <- openFd "/dev/null" ReadOnly Nothing defaultFileFlags -- cgit v1.2.3