{-# LINE 1 "System/Posix/Process.hsc" #-}
{-# LANGUAGE Safe #-}
module System.Posix.Process (
forkProcess,
forkProcessWithUnmask,
executeFile,
exitImmediately,
getProcessID,
getParentProcessID,
getProcessGroupID,
getProcessGroupIDOf,
createProcessGroupFor,
joinProcessGroup,
setProcessGroupIDOf,
createSession,
ProcessTimes(..),
getProcessTimes,
nice,
getProcessPriority,
getProcessGroupPriority,
getUserPriority,
setProcessPriority,
setProcessGroupPriority,
setUserPriority,
ProcessStatus(..),
getProcessStatus,
getAnyProcessStatus,
getGroupProcessStatus,
createProcessGroup,
setProcessGroupID,
) where
import Foreign
import Foreign.C
import System.Posix.Process.Internals
import System.Posix.Process.Common
import System.Posix.Internals ( withFilePath )
{-# LINE 79 "System/Posix/Process.hsc" #-}
executeFile :: FilePath
-> Bool
-> [String]
-> Maybe [(String, String)]
-> IO a
{-# LINE 100 "System/Posix/Process.hsc" #-}
executeFile :: forall a.
FilePath
-> Bool -> [FilePath] -> Maybe [(FilePath, FilePath)] -> IO a
executeFile FilePath
path Bool
search [FilePath]
args Maybe [(FilePath, FilePath)]
Nothing = do
forall a. FilePath -> (Ptr CChar -> IO a) -> IO a
withFilePath FilePath
path forall a b. (a -> b) -> a -> b
$ \Ptr CChar
s ->
forall a b res.
(a -> (b -> res) -> res) -> [a] -> ([b] -> res) -> res
withMany forall a. FilePath -> (Ptr CChar -> IO a) -> IO a
withFilePath (FilePath
pathforall a. a -> [a] -> [a]
:[FilePath]
args) forall a b. (a -> b) -> a -> b
$ \[Ptr CChar]
cstrs ->
forall a b. Storable a => a -> [a] -> (Ptr a -> IO b) -> IO b
withArray0 forall a. Ptr a
nullPtr [Ptr CChar]
cstrs forall a b. (a -> b) -> a -> b
$ \Ptr (Ptr CChar)
arr -> do
IO ()
pPrPr_disableITimers
if Bool
search
then forall a. (Eq a, Num a) => FilePath -> FilePath -> IO a -> IO ()
throwErrnoPathIfMinus1_ FilePath
"executeFile" FilePath
path (Ptr CChar -> Ptr (Ptr CChar) -> IO CInt
c_execvp Ptr CChar
s Ptr (Ptr CChar)
arr)
else forall a. (Eq a, Num a) => FilePath -> FilePath -> IO a -> IO ()
throwErrnoPathIfMinus1_ FilePath
"executeFile" FilePath
path (Ptr CChar -> Ptr (Ptr CChar) -> IO CInt
c_execv Ptr CChar
s Ptr (Ptr CChar)
arr)
forall (m :: * -> *) a. Monad m => a -> m a
return forall a. HasCallStack => a
undefined
executeFile FilePath
path Bool
search [FilePath]
args (Just [(FilePath, FilePath)]
env) = do
forall a. FilePath -> (Ptr CChar -> IO a) -> IO a
withFilePath FilePath
path forall a b. (a -> b) -> a -> b
$ \Ptr CChar
s ->
forall a b res.
(a -> (b -> res) -> res) -> [a] -> ([b] -> res) -> res
withMany forall a. FilePath -> (Ptr CChar -> IO a) -> IO a
withFilePath (FilePath
pathforall a. a -> [a] -> [a]
:[FilePath]
args) forall a b. (a -> b) -> a -> b
$ \[Ptr CChar]
cstrs ->
forall a b. Storable a => a -> [a] -> (Ptr a -> IO b) -> IO b
withArray0 forall a. Ptr a
nullPtr [Ptr CChar]
cstrs forall a b. (a -> b) -> a -> b
$ \Ptr (Ptr CChar)
arg_arr ->
let env' :: [FilePath]
env' = forall a b. (a -> b) -> [a] -> [b]
map (\ (FilePath
name, FilePath
val) -> FilePath
name forall a. [a] -> [a] -> [a]
++ (Char
'=' forall a. a -> [a] -> [a]
: FilePath
val)) [(FilePath, FilePath)]
env in
forall a b res.
(a -> (b -> res) -> res) -> [a] -> ([b] -> res) -> res
withMany forall a. FilePath -> (Ptr CChar -> IO a) -> IO a
withFilePath [FilePath]
env' forall a b. (a -> b) -> a -> b
$ \[Ptr CChar]
cenv ->
forall a b. Storable a => a -> [a] -> (Ptr a -> IO b) -> IO b
withArray0 forall a. Ptr a
nullPtr [Ptr CChar]
cenv forall a b. (a -> b) -> a -> b
$ \Ptr (Ptr CChar)
env_arr -> do
IO ()
pPrPr_disableITimers
if Bool
search
then forall a. (Eq a, Num a) => FilePath -> FilePath -> IO a -> IO ()
throwErrnoPathIfMinus1_ FilePath
"executeFile" FilePath
path
(Ptr CChar -> Ptr (Ptr CChar) -> Ptr (Ptr CChar) -> IO CInt
c_execvpe Ptr CChar
s Ptr (Ptr CChar)
arg_arr Ptr (Ptr CChar)
env_arr)
else forall a. (Eq a, Num a) => FilePath -> FilePath -> IO a -> IO ()
throwErrnoPathIfMinus1_ FilePath
"executeFile" FilePath
path
(Ptr CChar -> Ptr (Ptr CChar) -> Ptr (Ptr CChar) -> IO CInt
c_execve Ptr CChar
s Ptr (Ptr CChar)
arg_arr Ptr (Ptr CChar)
env_arr)
forall (m :: * -> *) a. Monad m => a -> m a
return forall a. HasCallStack => a
undefined
foreign import ccall unsafe "execvp"
c_execvp :: CString -> Ptr CString -> IO CInt
foreign import ccall unsafe "execv"
c_execv :: CString -> Ptr CString -> IO CInt
foreign import ccall unsafe "execve"
c_execve :: CString -> Ptr CString -> Ptr CString -> IO CInt
{-# LINE 136 "System/Posix/Process.hsc" #-}