Skip to content

Instantly share code, notes, and snippets.

@mitsuji
Created July 17, 2011 05:54
Show Gist options
  • Save mitsuji/1087250 to your computer and use it in GitHub Desktop.
Save mitsuji/1087250 to your computer and use it in GitHub Desktop.
module HDaemon.Daemon where
import Control.Concurrent
import System.Environment
import System.Posix.Signals
import Foreign
import HDaemon.Server
termHandler :: MVar Bool -> SHandle -> IO()
termHandler continue handle = do
stop handle
modifyMVar_ continue (\_ -> return(False))
hupHandler :: IO()
hupHandler = return()
foreignMain :: IO()
foreignMain = do
confPath <- getConfPath
handle <- start confPath
continue <- newMVar True
installHandler sigTERM (Catch $ termHandler continue handle ) Nothing
installHandler sigHUP (Catch hupHandler) Nothing
wait continue
where
wait :: MVar Bool -> IO()
wait continue = do
continue' <- readMVar continue
if continue'
then do
threadDelay $ 100 * 1000
wait continue
else do
return()
getConfPath :: IO(String)
getConfPath = do
args <- getArgs
return(args !! 0)
foreign export ccall foreignMain :: IO ()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment