summaryrefslogtreecommitdiff
path: root/Utility/Daemon.hs
diff options
context:
space:
mode:
Diffstat (limited to 'Utility/Daemon.hs')
-rw-r--r--Utility/Daemon.hs18
1 files changed, 12 insertions, 6 deletions
diff --git a/Utility/Daemon.hs b/Utility/Daemon.hs
index 16245268e..185ea3e68 100644
--- a/Utility/Daemon.hs
+++ b/Utility/Daemon.hs
@@ -34,16 +34,22 @@ daemonize logfd pidfile changedirectory a = do
when changedirectory $
setCurrentDirectory "/"
nullfd <- openFd "/dev/null" ReadOnly Nothing defaultFileFlags
- _ <- redir nullfd stdInput
- mapM_ (redir logfd) [stdOutput, stdError]
- closeFd logfd
+ redir nullfd stdInput
+ redirLog logfd
a
out
- redir newh h = do
- closeFd h
- dupTo newh h
out = exitImmediately ExitSuccess
+redirLog :: Fd -> IO ()
+redirLog logfd = do
+ mapM_ (redir logfd) [stdOutput, stdError]
+ closeFd logfd
+
+redir :: Fd -> Fd -> IO ()
+redir newh h = do
+ closeFd h
+ void $ dupTo newh h
+
{- Locks the pid file, with an exclusive, non-blocking lock.
- Writes the pid to the file, fully atomically.
- Fails if the pid file is already locked by another process. -}