{-# LINE 1 "libraries/unix/System/Posix/Signals.hsc" #-}
{-# LANGUAGE CApiFFI, CPP, DeriveDataTypeable, NondecreasingIndentation #-}
{-# OPTIONS_GHC -fno-cse #-}
{-# LANGUAGE Trustworthy #-}
#include "HsUnixConfig.h"
{-# LINE 22 "libraries/unix/System/Posix/Signals.hsc" #-}
{-# LINE 24 "libraries/unix/System/Posix/Signals.hsc" #-}
module System.Posix.Signals (
Signal,
nullSignal,
internalAbort, sigABRT,
realTimeAlarm, sigALRM,
busError, sigBUS,
processStatusChanged, sigCHLD,
continueProcess, sigCONT,
floatingPointException, sigFPE,
lostConnection, sigHUP,
illegalInstruction, sigILL,
keyboardSignal, sigINT,
killProcess, sigKILL,
openEndedPipe, sigPIPE,
keyboardTermination, sigQUIT,
segmentationViolation, sigSEGV,
softwareStop, sigSTOP,
softwareTermination, sigTERM,
keyboardStop, sigTSTP,
backgroundRead, sigTTIN,
backgroundWrite, sigTTOU,
userDefinedSignal1, sigUSR1,
userDefinedSignal2, sigUSR2,
{-# LINE 52 "libraries/unix/System/Posix/Signals.hsc" #-}
pollableEvent, sigPOLL,
{-# LINE 54 "libraries/unix/System/Posix/Signals.hsc" #-}
profilingTimerExpired, sigPROF,
badSystemCall, sigSYS,
breakpointTrap, sigTRAP,
urgentDataAvailable, sigURG,
virtualTimerExpired, sigVTALRM,
cpuTimeLimitExceeded, sigXCPU,
fileSizeLimitExceeded, sigXFSZ,
raiseSignal,
signalProcess,
signalProcessGroup,
Handler(Default,Ignore,Catch,CatchOnce,CatchInfo,CatchInfoOnce),
SignalInfo(..), SignalSpecificInfo(..),
installHandler,
SignalSet,
emptySignalSet, fullSignalSet, reservedSignals,
addSignal, deleteSignal, inSignalSet,
getSignalMask, setSignalMask, blockSignals, unblockSignals,
scheduleAlarm,
getPendingSignals,
awaitSignal,
setStoppedChildFlag, queryStoppedChildFlag,
) where
import Data.Word
import Foreign.C
import Foreign.ForeignPtr
import Foreign.Marshal
import Foreign.Ptr
import Foreign.Storable
{-# LINE 108 "libraries/unix/System/Posix/Signals.hsc" #-}
import System.IO.Unsafe (unsafePerformIO)
import System.Posix.Types
import System.Posix.Internals
import System.Posix.Process
import System.Posix.Process.Internals
import Data.Dynamic
{-# LINE 124 "libraries/unix/System/Posix/Signals.hsc" #-}
#include "rts/Signals.h"
{-# LINE 126 "libraries/unix/System/Posix/Signals.hsc" #-}
import GHC.Conc hiding (Signal)
{-# LINE 132 "libraries/unix/System/Posix/Signals.hsc" #-}
nullSignal :: Signal
nullSignal :: CInt
nullSignal = CInt
0
sigABRT :: CInt
sigABRT :: CInt
sigABRT = CONST_SIGABRT
sigALRM :: CInt
sigALRM :: CInt
sigALRM = CONST_SIGALRM
sigBUS :: CInt
sigBUS :: CInt
sigBUS = CONST_SIGBUS
sigCHLD :: CInt
sigCHLD :: CInt
sigCHLD = CONST_SIGCHLD
sigCONT :: CInt
sigCONT :: CInt
sigCONT = CONST_SIGCONT
sigFPE :: CInt
sigFPE :: CInt
sigFPE = CONST_SIGFPE
sigHUP :: CInt
sigHUP :: CInt
sigHUP = CONST_SIGHUP
sigILL :: CInt
sigILL :: CInt
sigILL = CONST_SIGILL
sigINT :: CInt
sigINT :: CInt
sigINT = CONST_SIGINT
sigKILL :: CInt
sigKILL :: CInt
sigKILL = CONST_SIGKILL
sigPIPE :: CInt
sigPIPE :: CInt
sigPIPE = CONST_SIGPIPE
sigQUIT :: CInt
sigQUIT :: CInt
sigQUIT = CONST_SIGQUIT
sigSEGV :: CInt
sigSEGV :: CInt
sigSEGV = CONST_SIGSEGV
sigSTOP :: CInt
sigSTOP :: CInt
sigSTOP = CONST_SIGSTOP
sigTERM :: CInt
sigTERM :: CInt
sigTERM = CONST_SIGTERM
sigTSTP :: CInt
sigTSTP :: CInt
sigTSTP = CONST_SIGTSTP
sigTTIN :: CInt
sigTTIN :: CInt
sigTTIN = CONST_SIGTTIN
sigTTOU :: CInt
sigTTOU :: CInt
sigTTOU = CONST_SIGTTOU
sigUSR1 :: CInt
sigUSR1 :: CInt
sigUSR1 = CONST_SIGUSR1
sigUSR2 :: CInt
sigUSR2 :: CInt
sigUSR2 = CONST_SIGUSR2
{-# LINE 220 "libraries/unix/System/Posix/Signals.hsc" #-}
sigPOLL :: CInt
sigPOLL :: CInt
sigPOLL = CONST_SIGPOLL
{-# LINE 224 "libraries/unix/System/Posix/Signals.hsc" #-}
sigPROF :: CInt
sigPROF :: CInt
sigPROF = CONST_SIGPROF
sigSYS :: CInt
sigSYS :: CInt
sigSYS = CONST_SIGSYS
sigTRAP :: CInt
sigTRAP :: CInt
sigTRAP = CONST_SIGTRAP
sigURG :: CInt
sigURG :: CInt
sigURG = CONST_SIGURG
sigVTALRM :: CInt
sigVTALRM :: CInt
sigVTALRM = CONST_SIGVTALRM
sigXCPU :: CInt
sigXCPU :: CInt
sigXCPU = CONST_SIGXCPU
sigXFSZ :: CInt
sigXFSZ :: CInt
sigXFSZ = CONST_SIGXFSZ
internalAbort ::Signal
internalAbort :: CInt
internalAbort = CInt
sigABRT
realTimeAlarm :: Signal
realTimeAlarm :: CInt
realTimeAlarm = CInt
sigALRM
busError :: Signal
busError :: CInt
busError = CInt
sigBUS
processStatusChanged :: Signal
processStatusChanged :: CInt
processStatusChanged = CInt
sigCHLD
continueProcess :: Signal
continueProcess :: CInt
continueProcess = CInt
sigCONT
floatingPointException :: Signal
floatingPointException :: CInt
floatingPointException = CInt
sigFPE
lostConnection :: Signal
lostConnection :: CInt
lostConnection = CInt
sigHUP
illegalInstruction :: Signal
illegalInstruction :: CInt
illegalInstruction = CInt
sigILL
keyboardSignal :: Signal
keyboardSignal :: CInt
keyboardSignal = CInt
sigINT
killProcess :: Signal
killProcess :: CInt
killProcess = CInt
sigKILL
openEndedPipe :: Signal
openEndedPipe :: CInt
openEndedPipe = CInt
sigPIPE
keyboardTermination :: Signal
keyboardTermination :: CInt
keyboardTermination = CInt
sigQUIT
segmentationViolation :: Signal
segmentationViolation :: CInt
segmentationViolation = CInt
sigSEGV
softwareStop :: Signal
softwareStop :: CInt
softwareStop = CInt
sigSTOP
softwareTermination :: Signal
softwareTermination :: CInt
softwareTermination = CInt
sigTERM
keyboardStop :: Signal
keyboardStop :: CInt
keyboardStop = CInt
sigTSTP
backgroundRead :: Signal
backgroundRead :: CInt
backgroundRead = CInt
sigTTIN
backgroundWrite :: Signal
backgroundWrite :: CInt
backgroundWrite = CInt
sigTTOU
userDefinedSignal1 :: Signal
userDefinedSignal1 :: CInt
userDefinedSignal1 = CInt
sigUSR1
userDefinedSignal2 :: Signal
userDefinedSignal2 :: CInt
userDefinedSignal2 = CInt
sigUSR2
{-# LINE 334 "libraries/unix/System/Posix/Signals.hsc" #-}
pollableEvent :: Signal
pollableEvent :: CInt
pollableEvent = CInt
sigPOLL
{-# LINE 338 "libraries/unix/System/Posix/Signals.hsc" #-}
profilingTimerExpired :: Signal
profilingTimerExpired :: CInt
profilingTimerExpired = CInt
sigPROF
badSystemCall :: Signal
badSystemCall :: CInt
badSystemCall = CInt
sigSYS
breakpointTrap :: Signal
breakpointTrap :: CInt
breakpointTrap = CInt
sigTRAP
urgentDataAvailable :: Signal
urgentDataAvailable :: CInt
urgentDataAvailable = CInt
sigURG
virtualTimerExpired :: Signal
virtualTimerExpired :: CInt
virtualTimerExpired = CInt
sigVTALRM
cpuTimeLimitExceeded :: Signal
cpuTimeLimitExceeded :: CInt
cpuTimeLimitExceeded = CInt
sigXCPU
fileSizeLimitExceeded :: Signal
fileSizeLimitExceeded :: CInt
fileSizeLimitExceeded = CInt
sigXFSZ
signalProcess :: Signal -> ProcessID -> IO ()
{-# LINE 380 "libraries/unix/System/Posix/Signals.hsc" #-}
signalProcess :: CInt -> ProcessID -> IO ()
signalProcess CInt
sig ProcessID
pid
= String -> IO CInt -> IO ()
forall a. (Eq a, Num a) => String -> IO a -> IO ()
throwErrnoIfMinus1_ String
"signalProcess" (ProcessID -> CInt -> IO CInt
c_kill ProcessID
pid CInt
sig)
foreign import ccall unsafe "kill"
c_kill :: CPid -> CInt -> IO CInt
{-# LINE 388 "libraries/unix/System/Posix/Signals.hsc" #-}
signalProcessGroup :: Signal -> ProcessGroupID -> IO ()
{-# LINE 400 "libraries/unix/System/Posix/Signals.hsc" #-}
signalProcessGroup :: CInt -> ProcessID -> IO ()
signalProcessGroup CInt
sig ProcessID
pgid
= String -> IO CInt -> IO ()
forall a. (Eq a, Num a) => String -> IO a -> IO ()
throwErrnoIfMinus1_ String
"signalProcessGroup" (ProcessID -> CInt -> IO CInt
c_killpg ProcessID
pgid CInt
sig)
foreign import ccall unsafe "killpg"
c_killpg :: CPid -> CInt -> IO CInt
{-# LINE 408 "libraries/unix/System/Posix/Signals.hsc" #-}
raiseSignal :: Signal -> IO ()
{-# LINE 419 "libraries/unix/System/Posix/Signals.hsc" #-}
raiseSignal :: CInt -> IO ()
raiseSignal CInt
sig = String -> IO CInt -> IO ()
forall a. (Eq a, Num a) => String -> IO a -> IO ()
throwErrnoIfMinus1_ String
"raiseSignal" (CInt -> IO CInt
c_raise CInt
sig)
{-# LINE 429 "libraries/unix/System/Posix/Signals.hsc" #-}
foreign import ccall unsafe "raise"
c_raise :: CInt -> IO CInt
{-# LINE 432 "libraries/unix/System/Posix/Signals.hsc" #-}
{-# LINE 434 "libraries/unix/System/Posix/Signals.hsc" #-}
type Signal = CInt
data Handler = Default
| Ignore
| Catch (IO ())
| CatchOnce (IO ())
| CatchInfo (SignalInfo -> IO ())
| CatchInfoOnce (SignalInfo -> IO ())
deriving (Typeable)
data SignalInfo = SignalInfo {
SignalInfo -> CInt
siginfoSignal :: Signal,
SignalInfo -> Errno
siginfoError :: Errno,
SignalInfo -> SignalSpecificInfo
siginfoSpecific :: SignalSpecificInfo
}
data SignalSpecificInfo
= NoSignalSpecificInfo
| SigChldInfo {
SignalSpecificInfo -> ProcessID
siginfoPid :: ProcessID,
SignalSpecificInfo -> UserID
siginfoUid :: UserID,
SignalSpecificInfo -> ProcessStatus
siginfoStatus :: ProcessStatus
}
installHandler :: Signal
-> Handler
-> Maybe SignalSet
-> IO Handler
{-# LINE 506 "libraries/unix/System/Posix/Signals.hsc" #-}
installHandler :: CInt -> Handler -> Maybe SignalSet -> IO Handler
installHandler CInt
sig Handler
handler Maybe SignalSet
_maybe_mask = do
IO ()
ensureIOManagerIsRunning
(CInt
old_action, Maybe (HandlerFun, Dynamic)
old_handler) <-
case Handler
handler of
Handler
Ignore -> do
CInt
old_action <- CInt -> CInt -> Ptr CSigset -> IO CInt
stg_sig_install CInt
sig STG_SIG_IGN nullPtr
Maybe (HandlerFun, Dynamic)
old_handler <- CInt
-> Maybe (HandlerFun, Dynamic) -> IO (Maybe (HandlerFun, Dynamic))
setHandler CInt
sig Maybe (HandlerFun, Dynamic)
forall a. Maybe a
Nothing
(CInt, Maybe (HandlerFun, Dynamic))
-> IO (CInt, Maybe (HandlerFun, Dynamic))
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (CInt
old_action, Maybe (HandlerFun, Dynamic)
old_handler)
Handler
Default -> do
CInt
old_action <- CInt -> CInt -> Ptr CSigset -> IO CInt
stg_sig_install CInt
sig STG_SIG_DFL nullPtr
Maybe (HandlerFun, Dynamic)
old_handler <- CInt
-> Maybe (HandlerFun, Dynamic) -> IO (Maybe (HandlerFun, Dynamic))
setHandler CInt
sig Maybe (HandlerFun, Dynamic)
forall a. Maybe a
Nothing
(CInt, Maybe (HandlerFun, Dynamic))
-> IO (CInt, Maybe (HandlerFun, Dynamic))
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (CInt
old_action, Maybe (HandlerFun, Dynamic)
old_handler)
Handler
_some_kind_of_catch -> do
let dyn :: Dynamic
dyn = Handler -> Dynamic
forall a. Typeable a => a -> Dynamic
toDyn Handler
handler
Maybe (HandlerFun, Dynamic)
old_handler <- case Handler
handler of
Catch IO ()
action -> CInt
-> Maybe (HandlerFun, Dynamic) -> IO (Maybe (HandlerFun, Dynamic))
setHandler CInt
sig ((HandlerFun, Dynamic) -> Maybe (HandlerFun, Dynamic)
forall a. a -> Maybe a
Just (IO () -> HandlerFun
forall a b. a -> b -> a
const IO ()
action,Dynamic
dyn))
CatchOnce IO ()
action -> CInt
-> Maybe (HandlerFun, Dynamic) -> IO (Maybe (HandlerFun, Dynamic))
setHandler CInt
sig ((HandlerFun, Dynamic) -> Maybe (HandlerFun, Dynamic)
forall a. a -> Maybe a
Just (IO () -> HandlerFun
forall a b. a -> b -> a
const IO ()
action,Dynamic
dyn))
CatchInfo SignalInfo -> IO ()
action -> CInt
-> Maybe (HandlerFun, Dynamic) -> IO (Maybe (HandlerFun, Dynamic))
setHandler CInt
sig ((HandlerFun, Dynamic) -> Maybe (HandlerFun, Dynamic)
forall a. a -> Maybe a
Just ((SignalInfo -> IO ()) -> HandlerFun
getinfo SignalInfo -> IO ()
action,Dynamic
dyn))
CatchInfoOnce SignalInfo -> IO ()
action -> CInt
-> Maybe (HandlerFun, Dynamic) -> IO (Maybe (HandlerFun, Dynamic))
setHandler CInt
sig ((HandlerFun, Dynamic) -> Maybe (HandlerFun, Dynamic)
forall a. a -> Maybe a
Just ((SignalInfo -> IO ()) -> HandlerFun
getinfo SignalInfo -> IO ()
action,Dynamic
dyn))
{-# LINE 539 "libraries/unix/System/Posix/Signals.hsc" #-}
let action :: CInt
action = case Handler
handler of
Catch IO ()
_ -> STG_SIG_HAN
CatchOnce IO ()
_ -> STG_SIG_RST
CatchInfo SignalInfo -> IO ()
_ -> STG_SIG_HAN
CatchInfoOnce SignalInfo -> IO ()
_ -> STG_SIG_RST
{-# LINE 548 "libraries/unix/System/Posix/Signals.hsc" #-}
CInt
old_action <- CInt -> CInt -> Ptr CSigset -> IO CInt
stg_sig_install CInt
sig CInt
action Ptr CSigset
forall a. Ptr a
nullPtr
(CInt, Maybe (HandlerFun, Dynamic))
-> IO (CInt, Maybe (HandlerFun, Dynamic))
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (CInt
old_action, Maybe (HandlerFun, Dynamic)
old_handler)
case (Maybe (HandlerFun, Dynamic)
old_handler,CInt
old_action) of
(Maybe (HandlerFun, Dynamic)
_, STG_SIG_DFL) -> return $ Default
(Maybe (HandlerFun, Dynamic)
_, STG_SIG_IGN) -> return $ Ignore
(Maybe (HandlerFun, Dynamic)
Nothing, CInt
_) -> Handler -> IO Handler
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (Handler -> IO Handler) -> Handler -> IO Handler
forall a b. (a -> b) -> a -> b
$ Handler
Ignore
(Just (HandlerFun
_,Dynamic
dyn), CInt
_)
| Just Handler
h <- Dynamic -> Maybe Handler
forall a. Typeable a => Dynamic -> Maybe a
fromDynamic Dynamic
dyn -> Handler -> IO Handler
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return Handler
h
| Just IO ()
io <- Dynamic -> Maybe (IO ())
forall a. Typeable a => Dynamic -> Maybe a
fromDynamic Dynamic
dyn -> Handler -> IO Handler
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (IO () -> Handler
Catch IO ()
io)
| Bool
otherwise -> Handler -> IO Handler
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return Handler
Default
foreign import ccall unsafe
stg_sig_install
:: CInt
-> CInt
-> Ptr CSigset
-> IO CInt
getinfo :: (SignalInfo -> IO ()) -> ForeignPtr Word8 -> IO ()
getinfo :: (SignalInfo -> IO ()) -> HandlerFun
getinfo SignalInfo -> IO ()
handler ForeignPtr Word8
fp_info = do
SignalInfo
si <- ForeignPtr Word8 -> IO SignalInfo
unmarshalSigInfo ForeignPtr Word8
fp_info
SignalInfo -> IO ()
handler SignalInfo
si
unmarshalSigInfo :: ForeignPtr Word8 -> IO SignalInfo
unmarshalSigInfo :: ForeignPtr Word8 -> IO SignalInfo
unmarshalSigInfo ForeignPtr Word8
fp = do
ForeignPtr Word8 -> (Ptr Word8 -> IO SignalInfo) -> IO SignalInfo
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr ForeignPtr Word8
fp ((Ptr Word8 -> IO SignalInfo) -> IO SignalInfo)
-> (Ptr Word8 -> IO SignalInfo) -> IO SignalInfo
forall a b. (a -> b) -> a -> b
$ \Ptr Word8
p -> do
CInt
sig <- ((\Ptr Word8
hsc_ptr -> Ptr Word8 -> Int -> IO CInt
forall b. Ptr b -> Int -> IO CInt
forall a b. Storable a => Ptr b -> Int -> IO a
peekByteOff Ptr Word8
hsc_ptr Int
0)) Ptr Word8
p
{-# LINE 580 "libraries/unix/System/Posix/Signals.hsc" #-}
errno <- ((\hsc_ptr -> peekByteOff hsc_ptr 4)) p
{-# LINE 581 "libraries/unix/System/Posix/Signals.hsc" #-}
extra <- case sig of
_ | sig == sigCHLD -> do
pid <- ((\hsc_ptr -> peekByteOff hsc_ptr 16)) p
{-# LINE 584 "libraries/unix/System/Posix/Signals.hsc" #-}
uid <- ((\hsc_ptr -> peekByteOff hsc_ptr 20)) p
{-# LINE 585 "libraries/unix/System/Posix/Signals.hsc" #-}
wstat <- ((\hsc_ptr -> peekByteOff hsc_ptr 24)) p
{-# LINE 586 "libraries/unix/System/Posix/Signals.hsc" #-}
pstat <- decipherWaitStatus wstat
return SigChldInfo { siginfoPid = pid,
siginfoUid = uid,
siginfoStatus = pstat }
_ | otherwise ->
return NoSignalSpecificInfo
SignalInfo -> IO SignalInfo
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return
SignalInfo {
siginfoSignal :: CInt
siginfoSignal = CInt
sig,
siginfoError :: Errno
siginfoError = CInt -> Errno
Errno CInt
errno,
siginfoSpecific :: SignalSpecificInfo
siginfoSpecific = SignalSpecificInfo
extra }
{-# LINE 599 "libraries/unix/System/Posix/Signals.hsc" #-}
{-# LINE 608 "libraries/unix/System/Posix/Signals.hsc" #-}
scheduleAlarm :: Int -> IO Int
scheduleAlarm :: Int -> IO Int
scheduleAlarm Int
secs = do
CUInt
r <- CUInt -> IO CUInt
c_alarm (Int -> CUInt
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
secs)
Int -> IO Int
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (CUInt -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral CUInt
r)
foreign import ccall unsafe "alarm"
c_alarm :: CUInt -> IO CUInt
{-# LINE 623 "libraries/unix/System/Posix/Signals.hsc" #-}
{-# LINE 638 "libraries/unix/System/Posix/Signals.hsc" #-}
foreign import ccall "&nocldstop" nocldstop :: Ptr Int
setStoppedChildFlag :: Bool -> IO Bool
setStoppedChildFlag :: Bool -> IO Bool
setStoppedChildFlag Bool
b = do
Int
rc <- Ptr Int -> IO Int
forall a. Storable a => Ptr a -> IO a
peek Ptr Int
nocldstop
Ptr Int -> Int -> IO ()
forall a. Storable a => Ptr a -> a -> IO ()
poke Ptr Int
nocldstop (Int -> IO ()) -> Int -> IO ()
forall a b. (a -> b) -> a -> b
$ Bool -> Int
forall a. Enum a => a -> Int
fromEnum (Bool -> Bool
not Bool
b)
Bool -> IO Bool
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (Int
rc Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== (Int
0::Int))
queryStoppedChildFlag :: IO Bool
queryStoppedChildFlag :: IO Bool
queryStoppedChildFlag = do
Int
rc <- Ptr Int -> IO Int
forall a. Storable a => Ptr a -> IO a
peek Ptr Int
nocldstop
Bool -> IO Bool
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (Int
rc Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== (Int
0::Int))
{-# LINE 656 "libraries/unix/System/Posix/Signals.hsc" #-}
{-# LINE 661 "libraries/unix/System/Posix/Signals.hsc" #-}
newtype SignalSet = SignalSet (ForeignPtr CSigset)
{-# LINE 669 "libraries/unix/System/Posix/Signals.hsc" #-}
{-# LINE 704 "libraries/unix/System/Posix/Signals.hsc" #-}
emptySignalSet :: SignalSet
emptySignalSet :: SignalSet
emptySignalSet = IO SignalSet -> SignalSet
forall a. IO a -> a
unsafePerformIO (IO SignalSet -> SignalSet) -> IO SignalSet -> SignalSet
forall a b. (a -> b) -> a -> b
$ do
ForeignPtr CSigset
fp <- Int -> IO (ForeignPtr CSigset)
forall a. Int -> IO (ForeignPtr a)
mallocForeignPtrBytes Int
sizeof_sigset_t
String -> IO CInt -> IO ()
forall a. (Eq a, Num a) => String -> IO a -> IO ()
throwErrnoIfMinus1_ String
"emptySignalSet" (ForeignPtr CSigset -> (Ptr CSigset -> IO CInt) -> IO CInt
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr ForeignPtr CSigset
fp ((Ptr CSigset -> IO CInt) -> IO CInt)
-> (Ptr CSigset -> IO CInt) -> IO CInt
forall a b. (a -> b) -> a -> b
$ Ptr CSigset -> IO CInt
c_sigemptyset)
SignalSet -> IO SignalSet
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (ForeignPtr CSigset -> SignalSet
SignalSet ForeignPtr CSigset
fp)
fullSignalSet :: SignalSet
fullSignalSet :: SignalSet
fullSignalSet = IO SignalSet -> SignalSet
forall a. IO a -> a
unsafePerformIO (IO SignalSet -> SignalSet) -> IO SignalSet -> SignalSet
forall a b. (a -> b) -> a -> b
$ do
ForeignPtr CSigset
fp <- Int -> IO (ForeignPtr CSigset)
forall a. Int -> IO (ForeignPtr a)
mallocForeignPtrBytes Int
sizeof_sigset_t
String -> IO CInt -> IO ()
forall a. (Eq a, Num a) => String -> IO a -> IO ()
throwErrnoIfMinus1_ String
"fullSignalSet" (ForeignPtr CSigset -> (Ptr CSigset -> IO CInt) -> IO CInt
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr ForeignPtr CSigset
fp ((Ptr CSigset -> IO CInt) -> IO CInt)
-> (Ptr CSigset -> IO CInt) -> IO CInt
forall a b. (a -> b) -> a -> b
$ Ptr CSigset -> IO CInt
c_sigfillset)
SignalSet -> IO SignalSet
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (ForeignPtr CSigset -> SignalSet
SignalSet ForeignPtr CSigset
fp)
reservedSignals :: SignalSet
reservedSignals :: SignalSet
reservedSignals = CInt -> SignalSet -> SignalSet
addSignal CInt
rtsTimerSignal SignalSet
emptySignalSet
foreign import ccall rtsTimerSignal :: CInt
infixr `addSignal`, `deleteSignal`
addSignal :: Signal -> SignalSet -> SignalSet
addSignal :: CInt -> SignalSet -> SignalSet
addSignal CInt
sig (SignalSet ForeignPtr CSigset
fp1) = IO SignalSet -> SignalSet
forall a. IO a -> a
unsafePerformIO (IO SignalSet -> SignalSet) -> IO SignalSet -> SignalSet
forall a b. (a -> b) -> a -> b
$ do
ForeignPtr CSigset
fp2 <- Int -> IO (ForeignPtr CSigset)
forall a. Int -> IO (ForeignPtr a)
mallocForeignPtrBytes Int
sizeof_sigset_t
ForeignPtr CSigset -> (Ptr CSigset -> IO ()) -> IO ()
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr ForeignPtr CSigset
fp1 ((Ptr CSigset -> IO ()) -> IO ())
-> (Ptr CSigset -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \Ptr CSigset
p1 ->
ForeignPtr CSigset -> (Ptr CSigset -> IO ()) -> IO ()
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr ForeignPtr CSigset
fp2 ((Ptr CSigset -> IO ()) -> IO ())
-> (Ptr CSigset -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \Ptr CSigset
p2 -> do
Ptr CSigset -> Ptr CSigset -> Int -> IO ()
forall a. Ptr a -> Ptr a -> Int -> IO ()
copyBytes Ptr CSigset
p2 Ptr CSigset
p1 Int
sizeof_sigset_t
String -> IO CInt -> IO ()
forall a. (Eq a, Num a) => String -> IO a -> IO ()
throwErrnoIfMinus1_ String
"addSignal" (Ptr CSigset -> CInt -> IO CInt
c_sigaddset Ptr CSigset
p2 CInt
sig)
SignalSet -> IO SignalSet
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (ForeignPtr CSigset -> SignalSet
SignalSet ForeignPtr CSigset
fp2)
deleteSignal :: Signal -> SignalSet -> SignalSet
deleteSignal :: CInt -> SignalSet -> SignalSet
deleteSignal CInt
sig (SignalSet ForeignPtr CSigset
fp1) = IO SignalSet -> SignalSet
forall a. IO a -> a
unsafePerformIO (IO SignalSet -> SignalSet) -> IO SignalSet -> SignalSet
forall a b. (a -> b) -> a -> b
$ do
ForeignPtr CSigset
fp2 <- Int -> IO (ForeignPtr CSigset)
forall a. Int -> IO (ForeignPtr a)
mallocForeignPtrBytes Int
sizeof_sigset_t
ForeignPtr CSigset -> (Ptr CSigset -> IO ()) -> IO ()
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr ForeignPtr CSigset
fp1 ((Ptr CSigset -> IO ()) -> IO ())
-> (Ptr CSigset -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \Ptr CSigset
p1 ->
ForeignPtr CSigset -> (Ptr CSigset -> IO ()) -> IO ()
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr ForeignPtr CSigset
fp2 ((Ptr CSigset -> IO ()) -> IO ())
-> (Ptr CSigset -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \Ptr CSigset
p2 -> do
Ptr CSigset -> Ptr CSigset -> Int -> IO ()
forall a. Ptr a -> Ptr a -> Int -> IO ()
copyBytes Ptr CSigset
p2 Ptr CSigset
p1 Int
sizeof_sigset_t
String -> IO CInt -> IO ()
forall a. (Eq a, Num a) => String -> IO a -> IO ()
throwErrnoIfMinus1_ String
"deleteSignal" (Ptr CSigset -> CInt -> IO CInt
c_sigdelset Ptr CSigset
p2 CInt
sig)
SignalSet -> IO SignalSet
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (ForeignPtr CSigset -> SignalSet
SignalSet ForeignPtr CSigset
fp2)
inSignalSet :: Signal -> SignalSet -> Bool
inSignalSet :: CInt -> SignalSet -> Bool
inSignalSet CInt
sig (SignalSet ForeignPtr CSigset
fp) = IO Bool -> Bool
forall a. IO a -> a
unsafePerformIO (IO Bool -> Bool) -> IO Bool -> Bool
forall a b. (a -> b) -> a -> b
$
ForeignPtr CSigset -> (Ptr CSigset -> IO Bool) -> IO Bool
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr ForeignPtr CSigset
fp ((Ptr CSigset -> IO Bool) -> IO Bool)
-> (Ptr CSigset -> IO Bool) -> IO Bool
forall a b. (a -> b) -> a -> b
$ \Ptr CSigset
p -> do
CInt
r <- String -> IO CInt -> IO CInt
forall a. (Eq a, Num a) => String -> IO a -> IO a
throwErrnoIfMinus1 String
"inSignalSet" (Ptr CSigset -> CInt -> IO CInt
c_sigismember Ptr CSigset
p CInt
sig)
Bool -> IO Bool
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (CInt
r CInt -> CInt -> Bool
forall a. Eq a => a -> a -> Bool
/= CInt
0)
{-# LINE 750 "libraries/unix/System/Posix/Signals.hsc" #-}
{-# LINE 774 "libraries/unix/System/Posix/Signals.hsc" #-}
getSignalMask :: IO SignalSet
getSignalMask :: IO SignalSet
getSignalMask = do
ForeignPtr CSigset
fp <- Int -> IO (ForeignPtr CSigset)
forall a. Int -> IO (ForeignPtr a)
mallocForeignPtrBytes Int
sizeof_sigset_t
ForeignPtr CSigset -> (Ptr CSigset -> IO ()) -> IO ()
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr ForeignPtr CSigset
fp ((Ptr CSigset -> IO ()) -> IO ())
-> (Ptr CSigset -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \Ptr CSigset
p ->
String -> IO CInt -> IO ()
forall a. (Eq a, Num a) => String -> IO a -> IO ()
throwErrnoIfMinus1_ String
"getSignalMask" (CInt -> Ptr CSigset -> Ptr CSigset -> IO CInt
c_sigprocmask CInt
0 Ptr CSigset
forall a. Ptr a
nullPtr Ptr CSigset
p)
SignalSet -> IO SignalSet
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (ForeignPtr CSigset -> SignalSet
SignalSet ForeignPtr CSigset
fp)
sigProcMask :: String -> CInt -> SignalSet -> IO ()
sigProcMask :: String -> CInt -> SignalSet -> IO ()
sigProcMask String
fn CInt
how (SignalSet ForeignPtr CSigset
set) =
ForeignPtr CSigset -> (Ptr CSigset -> IO ()) -> IO ()
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr ForeignPtr CSigset
set ((Ptr CSigset -> IO ()) -> IO ())
-> (Ptr CSigset -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \Ptr CSigset
p_set ->
String -> IO CInt -> IO ()
forall a. (Eq a, Num a) => String -> IO a -> IO ()
throwErrnoIfMinus1_ String
fn (CInt -> Ptr CSigset -> Ptr CSigset -> IO CInt
c_sigprocmask CInt
how Ptr CSigset
p_set Ptr CSigset
forall a. Ptr a
nullPtr)
setSignalMask :: SignalSet -> IO ()
setSignalMask :: SignalSet -> IO ()
setSignalMask SignalSet
set = String -> CInt -> SignalSet -> IO ()
sigProcMask String
"setSignalMask" (CONST_SIG_SETMASK :: CInt) set
blockSignals :: SignalSet -> IO ()
blockSignals :: SignalSet -> IO ()
blockSignals SignalSet
set = String -> CInt -> SignalSet -> IO ()
sigProcMask String
"blockSignals" (CONST_SIG_BLOCK :: CInt) set
unblockSignals :: SignalSet -> IO ()
unblockSignals :: SignalSet -> IO ()
unblockSignals SignalSet
set = String -> CInt -> SignalSet -> IO ()
sigProcMask String
"unblockSignals" (CONST_SIG_UNBLOCK :: CInt) set
{-# LINE 807 "libraries/unix/System/Posix/Signals.hsc" #-}
{-# LINE 821 "libraries/unix/System/Posix/Signals.hsc" #-}
getPendingSignals :: IO SignalSet
getPendingSignals :: IO SignalSet
getPendingSignals = do
ForeignPtr CSigset
fp <- Int -> IO (ForeignPtr CSigset)
forall a. Int -> IO (ForeignPtr a)
mallocForeignPtrBytes Int
sizeof_sigset_t
ForeignPtr CSigset -> (Ptr CSigset -> IO ()) -> IO ()
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr ForeignPtr CSigset
fp ((Ptr CSigset -> IO ()) -> IO ())
-> (Ptr CSigset -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \Ptr CSigset
p ->
String -> IO CInt -> IO ()
forall a. (Eq a, Num a) => String -> IO a -> IO ()
throwErrnoIfMinus1_ String
"getPendingSignals" (Ptr CSigset -> IO CInt
c_sigpending Ptr CSigset
p)
SignalSet -> IO SignalSet
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (ForeignPtr CSigset -> SignalSet
SignalSet ForeignPtr CSigset
fp)
awaitSignal :: Maybe SignalSet -> IO ()
awaitSignal :: Maybe SignalSet -> IO ()
awaitSignal Maybe SignalSet
maybe_sigset = do
ForeignPtr CSigset
fp <- case Maybe SignalSet
maybe_sigset of
Maybe SignalSet
Nothing -> do SignalSet ForeignPtr CSigset
fp <- IO SignalSet
getSignalMask; ForeignPtr CSigset -> IO (ForeignPtr CSigset)
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return ForeignPtr CSigset
fp
Just (SignalSet ForeignPtr CSigset
fp) -> ForeignPtr CSigset -> IO (ForeignPtr CSigset)
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return ForeignPtr CSigset
fp
ForeignPtr CSigset -> (Ptr CSigset -> IO ()) -> IO ()
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr ForeignPtr CSigset
fp ((Ptr CSigset -> IO ()) -> IO ())
-> (Ptr CSigset -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \Ptr CSigset
p -> do
CInt
_ <- Ptr CSigset -> IO CInt
c_sigsuspend Ptr CSigset
p
() -> IO ()
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return ()
{-# LINE 858 "libraries/unix/System/Posix/Signals.hsc" #-}
{-# LINE 860 "libraries/unix/System/Posix/Signals.hsc" #-}
foreign import ccall unsafe "sigsuspend"
c_sigsuspend :: Ptr CSigset -> IO CInt
foreign import capi unsafe "signal.h sigdelset"
c_sigdelset :: Ptr CSigset -> CInt -> IO CInt
foreign import capi unsafe "signal.h sigfillset"
c_sigfillset :: Ptr CSigset -> IO CInt
foreign import capi unsafe "signal.h sigismember"
c_sigismember :: Ptr CSigset -> CInt -> IO CInt
foreign import ccall unsafe "sigpending"
c_sigpending :: Ptr CSigset -> IO CInt
{-# LINE 877 "libraries/unix/System/Posix/Signals.hsc" #-}