X-Git-Url: http://gitweb.michael.orlitzky.com/?a=blobdiff_plain;f=src%2FMain.hs;h=38dd2e5ad5e8af5c4336c667507a6a87b74c0ccd;hb=bb74b494c23a737b9c0355148d25f090545b856b;hp=a06bd2338e62a0371fb90215d43a366478719347;hpb=a4eb5f096c486cb94b1e8a25de7bc16879cab6e5;p=dead%2Fhtsn.git diff --git a/src/Main.hs b/src/Main.hs index a06bd23..38dd2e5 100644 --- a/src/Main.hs +++ b/src/Main.hs @@ -5,7 +5,7 @@ module Main where import Control.Concurrent ( threadDelay ) -import Control.Exception.Base ( bracket ) +import Control.Exception ( bracket, throw ) import Control.Monad ( when ) import Data.List ( isPrefixOf ) import Data.Maybe ( isNothing ) @@ -256,7 +256,7 @@ main = do -- logging before the missing parameter checks below so that we can -- log the errors. let cfg = (def :: Configuration) `merge_optional` opt_config - init_logging (log_file cfg) (log_level cfg) (syslog cfg) + init_logging (log_level cfg) (log_file cfg) (syslog cfg) -- Check the optional config for missing required options. This is -- necessary because if the user specifies an empty list of @@ -296,7 +296,7 @@ main = do -- If we were asked to daemonize, do that; otherwise just run the thing. if (daemonize cfg) - then full_daemonize cfg run_program + then try_daemonize cfg run_program else run_program where @@ -313,3 +313,16 @@ main = do catchIOError (connect_and_parse cfg host) (report_error . show) thread_sleep 5 -- Wait 5s before attempting to reconnect. round_robin cfg $ (feed_host_idx + 1) `mod` (length hosts) + + + -- | A exception handler around full_daemonize. If full_daemonize + -- doesn't work, we report the error and crash. This is fine; we + -- only need the program to be resilient once it actually starts. + -- + try_daemonize :: Configuration -> IO () -> IO () + try_daemonize cfg program = + catchIOError + (full_daemonize cfg program) + (\e -> do + report_error (show e) + throw e)