summaryrefslogtreecommitdiff
path: root/Utility/Daemon.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2013-01-15 13:34:59 -0400
committerGravatar Joey Hess <joey@kitenet.net>2013-01-15 13:34:59 -0400
commitb236c46dbb20cfbb42201b7cccdaa153b7bd2ed1 (patch)
tree59915ff94b6cb0bb1df8858f30e06b5408af8b44 /Utility/Daemon.hs
parentfd9d5f0d9c3de99c53ba12c85e6c985baeb38901 (diff)
webapp: Now always logs to .git/annex/daemon.log
It used to not log to daemon.log when a repository was first created, and when starting the webapp. Now both do. Redirecting stdout and stderr to the log is tricky when starting the webapp, because the web browser may want to communicate with the user. (Either a console web browser, or web.browser = echo) This is handled by restoring the original fds when running the browser.
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. -}