{-# 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
(old_action, old_handler) <-
case Handler
handler of
Handler
Ignore -> do
old_action <- CInt -> CInt -> Ptr CSigset -> IO CInt
stg_sig_install CInt
sig STG_SIG_IGN nullPtr
old_handler <- setHandler sig Nothing
return (old_action, old_handler)
Handler
Default -> do
old_action <- CInt -> CInt -> Ptr CSigset -> IO CInt
stg_sig_install CInt
sig STG_SIG_DFL nullPtr
old_handler <- setHandler sig Nothing
return (old_action, old_handler)
Handler
_some_kind_of_catch -> do
let dyn :: Dynamic
dyn = Handler -> Dynamic
forall a. Typeable a => a -> Dynamic
toDyn Handler
handler
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 = 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" #-}
old_action <- stg_sig_install sig action nullPtr
return (old_action, old_handler)
case (old_handler,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
si <- ForeignPtr Word8 -> IO SignalInfo
unmarshalSigInfo ForeignPtr Word8
fp_info
handler 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
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
return
SignalInfo {
siginfoSignal = sig,
siginfoError = Errno errno,
siginfoSpecific = 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
r <- CUInt -> IO CUInt
c_alarm (Int -> CUInt
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
secs)
return (fromIntegral 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
rc <- Ptr Int -> IO Int
forall a. Storable a => Ptr a -> IO a
peek Ptr Int
nocldstop
poke nocldstop $ fromEnum (not b)
return (rc == (0::Int))
queryStoppedChildFlag :: IO Bool
queryStoppedChildFlag :: IO Bool
queryStoppedChildFlag = do
rc <- Ptr Int -> IO Int
forall a. Storable a => Ptr a -> IO a
peek Ptr Int
nocldstop
return (rc == (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
fp <- Int -> IO (ForeignPtr CSigset)
forall a. Int -> IO (ForeignPtr a)
mallocForeignPtrBytes Int
sizeof_sigset_t
throwErrnoIfMinus1_ "emptySignalSet" (withForeignPtr fp $ c_sigemptyset)
return (SignalSet 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
fp <- Int -> IO (ForeignPtr CSigset)
forall a. Int -> IO (ForeignPtr a)
mallocForeignPtrBytes Int
sizeof_sigset_t
throwErrnoIfMinus1_ "fullSignalSet" (withForeignPtr fp $ c_sigfillset)
return (SignalSet 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
fp2 <- Int -> IO (ForeignPtr CSigset)
forall a. Int -> IO (ForeignPtr a)
mallocForeignPtrBytes Int
sizeof_sigset_t
withForeignPtr fp1 $ \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)
return (SignalSet 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
fp2 <- Int -> IO (ForeignPtr CSigset)
forall a. Int -> IO (ForeignPtr a)
mallocForeignPtrBytes Int
sizeof_sigset_t
withForeignPtr fp1 $ \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)
return (SignalSet 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
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)
return (r /= 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
fp <- Int -> IO (ForeignPtr CSigset)
forall a. Int -> IO (ForeignPtr a)
mallocForeignPtrBytes Int
sizeof_sigset_t
withForeignPtr fp $ \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)
return (SignalSet 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
fp <- Int -> IO (ForeignPtr CSigset)
forall a. Int -> IO (ForeignPtr a)
mallocForeignPtrBytes Int
sizeof_sigset_t
withForeignPtr fp $ \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)
return (SignalSet fp)
awaitSignal :: Maybe SignalSet -> IO ()
awaitSignal :: Maybe SignalSet -> IO ()
awaitSignal Maybe SignalSet
maybe_sigset = do
fp <- case Maybe SignalSet
maybe_sigset of
Maybe SignalSet
Nothing -> do SignalSet fp <- IO SignalSet
getSignalMask; return 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
withForeignPtr fp $ \Ptr CSigset
p -> do
_ <- Ptr CSigset -> IO CInt
c_sigsuspend Ptr CSigset
p
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" #-}