aboutsummaryrefslogtreecommitdiff
path: root/Assistant.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2014-06-17 19:10:51 -0400
committerGravatar Joey Hess <joey@kitenet.net>2014-06-17 19:27:54 -0400
commit89c188fac37c20c40b0a9dabeb35403cfa4e4f52 (patch)
tree667d76e0d072dcee754f5f61eed5c6bcade232ce /Assistant.hs
parent613725496fd5da37109c4a345077058ebe6955c1 (diff)
Windows: Assistant now logs to daemon.log.
Yes, this means that git annex webapp on windows execs git-annex, which execs itself to set env, and the execs itself again to redirect logs. This is disgusting. This is Windows(TM).
Diffstat (limited to 'Assistant.hs')
-rw-r--r--Assistant.hs42
1 files changed, 32 insertions, 10 deletions
diff --git a/Assistant.hs b/Assistant.hs
index 5dd6a7ece..03864c420 100644
--- a/Assistant.hs
+++ b/Assistant.hs
@@ -52,9 +52,12 @@ import qualified Utility.Daemon
import Utility.ThreadScheduler
import Utility.HumanTime
import qualified Build.SysConfig as SysConfig
-#ifndef mingw32_HOST_OS
-import Utility.LogFile
import Annex.Perms
+import Utility.LogFile
+#ifdef mingw32_HOST_OS
+import Utility.Env
+import Config.Files
+import System.Environment (getArgs)
#endif
import System.Log.Logger
@@ -72,10 +75,10 @@ startDaemon :: Bool -> Bool -> Maybe Duration -> Maybe String -> Maybe HostName
startDaemon assistant foreground startdelay cannotrun listenhost startbrowser = do
Annex.changeState $ \s -> s { Annex.daemon = True }
pidfile <- fromRepo gitAnnexPidFile
-#ifndef mingw32_HOST_OS
logfile <- fromRepo gitAnnexLogFile
+#ifndef mingw32_HOST_OS
createAnnexDirectory (parentDir logfile)
- logfd <- liftIO $ openLog logfile
+ logfd <- liftIO $ handleToFd =<< openLog logfile
if foreground
then do
origout <- liftIO $ catchMaybeIO $
@@ -92,13 +95,32 @@ startDaemon assistant foreground startdelay cannotrun listenhost startbrowser =
else
start (Utility.Daemon.daemonize logfd (Just pidfile) False) Nothing
#else
- -- Windows is always foreground, and has no log file.
+ -- Windows doesn't daemonize, but does redirect output to the
+ -- log file. The only way to do so is to restart the program.
when (foreground || not foreground) $ do
- liftIO $ Utility.Daemon.lockPidFile pidfile
- start id $ do
- case startbrowser of
- Nothing -> Nothing
- Just a -> Just $ a Nothing Nothing
+ let flag = "GIT_ANNEX_OUTPUT_REDIR"
+ createAnnexDirectory (parentDir logfile)
+ ifM (liftIO $ isNothing <$> getEnv flag)
+ ( liftIO $ withFile devNull WriteMode $ \nullh -> do
+ Utility.Daemon.lockPidFile pidfile
+ when (not foreground) $
+ debugM desc $ "logging to " ++ logfile
+ loghandle <- openLog logfile
+ e <- getEnvironment
+ cmd <- readProgramFile
+ ps <- getArgs
+ (_, _, _, pid) <- createProcess (proc cmd ps)
+ { env = Just (addEntry flag "1" e)
+ , std_in = UseHandle nullh
+ , std_out = UseHandle loghandle
+ , std_err = UseHandle loghandle
+ }
+ exitWith =<< waitForProcess pid
+ , start id $ do
+ case startbrowser of
+ Nothing -> Nothing
+ Just a -> Just $ a Nothing Nothing
+ )
#endif
where
desc