never executed always true always false
1 {-# LANGUAGE CPP #-}
2 module GHCi.Signals (installSignalHandlers) where
3
4 import Prelude -- See note [Why do we import Prelude here?]
5 import Control.Concurrent
6 import Control.Exception
7 import System.Mem.Weak ( deRefWeak )
8
9 #if !defined(mingw32_HOST_OS)
10 import System.Posix.Signals
11 #endif
12
13 #if defined(mingw32_HOST_OS)
14 import GHC.ConsoleHandler
15 #endif
16
17 -- | Install standard signal handlers for catching ^C, which just throw an
18 -- exception in the target thread. The current target thread is the
19 -- thread at the head of the list in the MVar passed to
20 -- installSignalHandlers.
21 installSignalHandlers :: IO ()
22 installSignalHandlers = do
23 main_thread <- myThreadId
24 wtid <- mkWeakThreadId main_thread
25
26 let interrupt = do
27 r <- deRefWeak wtid
28 case r of
29 Nothing -> return ()
30 Just t -> throwTo t UserInterrupt
31
32 #if !defined(mingw32_HOST_OS)
33 _ <- installHandler sigQUIT (Catch interrupt) Nothing
34 _ <- installHandler sigINT (Catch interrupt) Nothing
35 #else
36 -- GHC 6.3+ has support for console events on Windows
37 -- NOTE: running GHCi under a bash shell for some reason requires
38 -- you to press Ctrl-Break rather than Ctrl-C to provoke
39 -- an interrupt. Ctrl-C is getting blocked somewhere, I don't know
40 -- why --SDM 17/12/2004
41 let sig_handler ControlC = interrupt
42 sig_handler Break = interrupt
43 sig_handler _ = return ()
44
45 _ <- installHandler (Catch sig_handler)
46 #endif
47 return ()