Add “Ignore warning” option to cabal check
[cabal.git] / cabal-install / src / Distribution / Client / Signal.hs
blobc009d805cd44161c0f1a2aa1f1a10726d92b9c2a
1 {-# LANGUAGE CPP #-}
3 module Distribution.Client.Signal
4 ( installTerminationHandler
5 , Terminated (..)
7 where
9 import qualified Control.Exception as Exception
11 #ifndef mingw32_HOST_OS
12 import Control.Concurrent (myThreadId)
13 import Control.Monad (void)
14 import qualified System.Posix.Signals as Signals
15 #endif
17 -- | Terminated is an asynchronous exception, thrown when
18 -- SIGTERM is received. It's to 'kill' what 'UserInterrupt'
19 -- is to Ctrl-C.
20 data Terminated = Terminated
22 instance Exception.Exception Terminated where
23 toException = Exception.asyncExceptionToException
24 fromException = Exception.asyncExceptionFromException
26 instance Show Terminated where
27 show Terminated = "terminated"
29 -- | Install a signal handler that initiates a controlled shutdown on receiving
30 -- SIGTERM by throwing an asynchronous exception at the main thread. Must be
31 -- called from the main thread.
33 -- It is a noop on Windows.
34 installTerminationHandler :: IO ()
36 #ifdef mingw32_HOST_OS
38 installTerminationHandler = return ()
40 #else
42 installTerminationHandler = do
43 mainThreadId <- myThreadId
44 void $ Signals.installHandler
45 Signals.sigTERM
46 (Signals.CatchOnce $ Exception.throwTo mainThreadId Terminated)
47 Nothing
49 #endif