Hashell-0.15: Hashell/Signals.hs
{-
Signals handlers routines.
Copyright (C) 2005, 2008 Luis Francisco Araujo
-}
module Signals
where
import System.IO (hPutStrLn, stderr)
import System.Exit -- (ExitFailure, exitFailure)
import Control.Exception -- (ExitException, handle)
import System.Posix.Signals -- (Handler(), installHandler, sigINT, Catch())
----------------------------------------------------------------------------------
{- | Set the signal-handler in the program.
It is used for catching the SIGINT signal
and preserves the shell running. -}
setSignalHandler :: IO Handler
setSignalHandler = installHandler sigINT (Catch signalHandler) Nothing
signalHandler :: IO ()
signalHandler = return $ throw (ExitException (ExitFailure 2))
handler :: IO a -> IO a
handler = handle (\e -> do hPutStrLn stderr (show e)
exitFailure)