{-# LINE 1 "System/Posix/Process/ByteString.hsc" #-}
{-# LANGUAGE Safe #-}
module System.Posix.Process.ByteString (
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 System.Posix.Process.Internals
import System.Posix.Process.Common
import Foreign.C hiding (
throwErrnoPath,
throwErrnoPathIf,
throwErrnoPathIf_,
throwErrnoPathIfNull,
throwErrnoPathIfMinus1,
throwErrnoPathIfMinus1_ )
import Data.ByteString (ByteString)
import qualified Data.ByteString.Char8 as BC
import System.Posix.ByteString.FilePath
{-# LINE 91 "System/Posix/Process/ByteString.hsc" #-}
executeFile :: RawFilePath
-> Bool
-> [ByteString]
-> Maybe [(ByteString, ByteString)]
-> IO a
{-# LINE 112 "System/Posix/Process/ByteString.hsc" #-}
executeFile :: forall a.
RawFilePath
-> Bool
-> [RawFilePath]
-> Maybe [(RawFilePath, RawFilePath)]
-> IO a
executeFile RawFilePath
path Bool
search [RawFilePath]
args Maybe [(RawFilePath, RawFilePath)]
Nothing = do
forall a. RawFilePath -> (Ptr CChar -> IO a) -> IO a
withFilePath RawFilePath
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. RawFilePath -> (Ptr CChar -> IO a) -> IO a
withFilePath (RawFilePath
pathforall a. a -> [a] -> [a]
:[RawFilePath]
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) => String -> RawFilePath -> IO a -> IO ()
throwErrnoPathIfMinus1_ String
"executeFile" RawFilePath
path (Ptr CChar -> Ptr (Ptr CChar) -> IO CInt
c_execvp Ptr CChar
s Ptr (Ptr CChar)
arr)
else forall a. (Eq a, Num a) => String -> RawFilePath -> IO a -> IO ()
throwErrnoPathIfMinus1_ String
"executeFile" RawFilePath
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 RawFilePath
path Bool
search [RawFilePath]
args (Just [(RawFilePath, RawFilePath)]
env) = do
forall a. RawFilePath -> (Ptr CChar -> IO a) -> IO a
withFilePath RawFilePath
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. RawFilePath -> (Ptr CChar -> IO a) -> IO a
withFilePath (RawFilePath
pathforall a. a -> [a] -> [a]
:[RawFilePath]
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' :: [RawFilePath]
env' = forall a b. (a -> b) -> [a] -> [b]
map (\ (RawFilePath
name, RawFilePath
val) -> RawFilePath
name RawFilePath -> RawFilePath -> RawFilePath
`BC.append` (Char
'=' Char -> RawFilePath -> RawFilePath
`BC.cons` RawFilePath
val)) [(RawFilePath, RawFilePath)]
env in
forall a b res.
(a -> (b -> res) -> res) -> [a] -> ([b] -> res) -> res
withMany forall a. RawFilePath -> (Ptr CChar -> IO a) -> IO a
withFilePath [RawFilePath]
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) => String -> RawFilePath -> IO a -> IO ()
throwErrnoPathIfMinus1_ String
"executeFile" RawFilePath
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) => String -> RawFilePath -> IO a -> IO ()
throwErrnoPathIfMinus1_ String
"executeFile" RawFilePath
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 148 "System/Posix/Process/ByteString.hsc" #-}