blob: 0bd99aef122223b9632b1442fab2c744cae4112a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
{-# LANGUAGE CApiFFI #-}
{-# LANGUAGE Trustworthy #-}
module System.Posix.Process.Internals (
pPrPr_disableITimers, c_execvpe,
decipherWaitStatus, ProcessStatus(..) ) where
import Foreign
import Foreign.C
import System.Exit
import System.IO.Error
import GHC.Conc (Signal)
-- | The exit status of a process
data ProcessStatus
= Exited ExitCode -- ^ the process exited by calling
-- @exit()@ or returning from @main@
| Terminated Signal Bool -- ^ the process was terminated by a
-- signal, the @Bool@ is @True@ if a core
-- dump was produced
--
-- /Since: 2.7.0.0/
| Stopped Signal -- ^ the process was stopped by a signal
deriving (Eq, Ord, Show)
-- this function disables the itimer, which would otherwise cause confusing
-- signals to be sent to the new process.
foreign import capi unsafe "Rts.h stopTimer"
pPrPr_disableITimers :: IO ()
foreign import ccall unsafe "__hsunix_execvpe"
c_execvpe :: CString -> Ptr CString -> Ptr CString -> IO CInt
decipherWaitStatus :: CInt -> IO ProcessStatus
decipherWaitStatus wstat =
if c_WIFEXITED wstat /= 0
then do
let exitstatus = c_WEXITSTATUS wstat
if exitstatus == 0
then return (Exited ExitSuccess)
else return (Exited (ExitFailure (fromIntegral exitstatus)))
else do
if c_WIFSIGNALED wstat /= 0
then do
let termsig = c_WTERMSIG wstat
let coredumped = c_WCOREDUMP wstat /= 0
return (Terminated termsig coredumped)
else do
if c_WIFSTOPPED wstat /= 0
then do
let stopsig = c_WSTOPSIG wstat
return (Stopped stopsig)
else do
ioError (mkIOError illegalOperationErrorType
"waitStatus" Nothing Nothing)
foreign import capi unsafe "HsUnix.h WIFEXITED"
c_WIFEXITED :: CInt -> CInt
foreign import capi unsafe "HsUnix.h WEXITSTATUS"
c_WEXITSTATUS :: CInt -> CInt
foreign import capi unsafe "HsUnix.h WIFSIGNALED"
c_WIFSIGNALED :: CInt -> CInt
foreign import capi unsafe "HsUnix.h WTERMSIG"
c_WTERMSIG :: CInt -> CInt
foreign import capi unsafe "HsUnix.h WIFSTOPPED"
c_WIFSTOPPED :: CInt -> CInt
foreign import capi unsafe "HsUnix.h WSTOPSIG"
c_WSTOPSIG :: CInt -> CInt
foreign import capi unsafe "HsUnix.h WCOREDUMP"
c_WCOREDUMP :: CInt -> CInt
|