summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Assistant.hs4
-rw-r--r--Utility/Daemon.hs9
2 files changed, 10 insertions, 3 deletions
diff --git a/Assistant.hs b/Assistant.hs
index b5caceac2..5dd6a7ece 100644
--- a/Assistant.hs
+++ b/Assistant.hs
@@ -84,9 +84,7 @@ startDaemon assistant foreground startdelay cannotrun listenhost startbrowser =
fdToHandle =<< dup stdError
let undaemonize a = do
debugM desc $ "logging to " ++ logfile
- Utility.Daemon.lockPidFile pidfile
- Utility.LogFile.redirLog logfd
- a
+ Utility.Daemon.foreground logfd (Just pidfile) a
start undaemonize $
case startbrowser of
Nothing -> Nothing
diff --git a/Utility/Daemon.hs b/Utility/Daemon.hs
index 2b62382ee..2a2e0e08a 100644
--- a/Utility/Daemon.hs
+++ b/Utility/Daemon.hs
@@ -56,6 +56,15 @@ daemonize logfd pidfile changedirectory a = do
out = exitImmediately ExitSuccess
#endif
+{- To run an action that is normally daemonized in the forground. -}
+foreground :: Fd -> Maybe FilePath -> IO () -> IO ()
+foreground logfd pidfile a = do
+ maybe noop lockPidFile pidfile
+ _ <- createSession
+ redirLog logfd
+ a
+ exitImmediately ExitSuccess
+
{- Locks the pid file, with an exclusive, non-blocking lock,
- and leaves it locked on return.
-