Added proper signal handling support

This commit is contained in:
Abhinav Sarkar 2014-05-11 19:08:43 +05:30
parent 8cf2872432
commit d952869ba2
4 changed files with 44 additions and 16 deletions

View File

@ -5,10 +5,12 @@ module Main (main) where
import qualified Data.Configurator as CF
import ClassyPrelude hiding (try, getArgs)
import Control.Exception
import Control.Concurrent.Lifted
import Control.Exception.Lifted
import Data.Configurator.Types
import System.Environment
import System.Exit
import System.Posix.Signals
import Network.IRC.Types (BotConfig(BotConfig))
import Network.IRC.Client
@ -26,6 +28,10 @@ main = do
putStrLn $ "Usage: " ++ pack prog ++ " <config file path>"
exitFailure
mainThreadId <- myThreadId
installHandler sigINT (Catch $ throwTo mainThreadId UserInterrupt) Nothing
installHandler sigTERM (Catch $ throwTo mainThreadId UserInterrupt) Nothing
let configFile = headEx args
loadBotConfig configFile >>= run

View File

@ -33,8 +33,8 @@ sendCommand Bot { .. } reply = do
TF.hprint socket "{}\r\n" $ TF.Only line
TF.print "[{}] > {}\n" $ TF.buildParams (formatTime defaultTimeLocale "%F %T" time, line)
listen :: IRC ()
listen = do
listenerLoop :: IRC ()
listenerLoop = do
status <- get
bot@Bot { .. } <- ask
let nick = botNick botConfig
@ -73,7 +73,7 @@ listen = do
return nStatus
put nStatus
when (nStatus /= Disconnected) listen
when (nStatus /= Disconnected) listenerLoop
loadMsgHandlers :: BotConfig -> IO MsgHandlerStates
loadMsgHandlers botConfig@BotConfig { .. } =
@ -142,4 +142,4 @@ run botConfig' = withSocketsDo $ do
go bot = do
sendCommand bot NickCmd
sendCommand bot UserCmd
runIRC bot Connected listen
runIRC bot Connected listenerLoop

View File

@ -5,7 +5,7 @@ module Network.IRC.Handlers.SongSearch (getMsgHandler) where
import qualified Data.Configurator as CF
import ClassyPrelude hiding (try)
import Control.Exception
import Control.Exception.Lifted
import Control.Monad.Reader
import Data.Aeson
import Data.Aeson.Types (emptyArray)

View File

@ -49,11 +49,22 @@ build-type: Simple
cabal-version: >=1.10
library
build-depends: base >=4.5 && <4.7, text >=0.11 && <0.12, mtl >=2.1 && <2.2,
network >=2.3 && <2.5, configurator >= 0.2, time >=1.4.0,
curl-aeson ==0.0.3, aeson >=0.6.0.0, HTTP, transformers >=0.3,
classy-prelude ==0.9.1, text-format >= 0.3.1, filepath >=1.3, directory >=1.2,
lifted-base >=0.2
build-depends: base >=4.5 && <4.7,
text >=0.11 && <0.12,
mtl >=2.1 && <2.2,
network >=2.3 && <2.5,
configurator >= 0.2,
time >=1.4.0,
curl-aeson ==0.0.3,
aeson >=0.6.0.0,
HTTP >=4000,
transformers >=0.3,
classy-prelude ==0.9.1,
text-format >= 0.3.1,
filepath >=1.3,
directory >=1.2,
lifted-base >=0.2,
unix >=2.7
exposed-modules: Network.IRC.Types, Network.IRC.Protocol,
Network.IRC.Handlers, Network.IRC.Client
@ -74,11 +85,22 @@ executable hask-irc
other-extensions: RecordWildCards, OverloadedStrings, ScopedTypeVariables, OverlappingInstances
-- Other library packages from which modules are imported.
build-depends: base >=4.5 && <4.7, text >=0.11 && <0.12, mtl >=2.1 && <2.2,
network >=2.3 && <2.5, configurator >= 0.2, time >=1.4.0,
curl-aeson ==0.0.3, aeson >=0.6.0.0, HTTP, transformers >=0.3,
classy-prelude ==0.9.1, text-format >= 0.3.1, filepath >=1.3, directory >=1.2,
lifted-base >=0.2
build-depends: base >=4.5 && <4.7,
text >=0.11 && <0.12,
mtl >=2.1 && <2.2,
network >=2.3 && <2.5,
configurator >= 0.2,
time >=1.4.0,
curl-aeson ==0.0.3,
aeson >=0.6.0.0,
HTTP >=4000,
transformers >=0.3,
classy-prelude ==0.9.1,
text-format >= 0.3.1,
filepath >=1.3,
directory >=1.2,
lifted-base >=0.2,
unix >=2.7
-- Directories containing source files.
-- hs-source-dirs: