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).
This commit is contained in:
Joey Hess 2014-06-17 19:10:51 -04:00
parent 8eb45f674f
commit 9fb8038166
5 changed files with 36 additions and 21 deletions

View file

@ -52,9 +52,12 @@ import qualified Utility.Daemon
import Utility.ThreadScheduler import Utility.ThreadScheduler
import Utility.HumanTime import Utility.HumanTime
import qualified Build.SysConfig as SysConfig import qualified Build.SysConfig as SysConfig
#ifndef mingw32_HOST_OS
import Utility.LogFile
import Annex.Perms import Annex.Perms
import Utility.LogFile
#ifdef mingw32_HOST_OS
import Utility.Env
import Config.Files
import System.Environment (getArgs)
#endif #endif
import System.Log.Logger 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 startDaemon assistant foreground startdelay cannotrun listenhost startbrowser = do
Annex.changeState $ \s -> s { Annex.daemon = True } Annex.changeState $ \s -> s { Annex.daemon = True }
pidfile <- fromRepo gitAnnexPidFile pidfile <- fromRepo gitAnnexPidFile
#ifndef mingw32_HOST_OS
logfile <- fromRepo gitAnnexLogFile logfile <- fromRepo gitAnnexLogFile
#ifndef mingw32_HOST_OS
createAnnexDirectory (parentDir logfile) createAnnexDirectory (parentDir logfile)
logfd <- liftIO $ openLog logfile logfd <- liftIO $ handleToFd =<< openLog logfile
if foreground if foreground
then do then do
origout <- liftIO $ catchMaybeIO $ origout <- liftIO $ catchMaybeIO $
@ -92,13 +95,32 @@ startDaemon assistant foreground startdelay cannotrun listenhost startbrowser =
else else
start (Utility.Daemon.daemonize logfd (Just pidfile) False) Nothing start (Utility.Daemon.daemonize logfd (Just pidfile) False) Nothing
#else #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 when (foreground || not foreground) $ do
liftIO $ Utility.Daemon.lockPidFile pidfile let flag = "GIT_ANNEX_OUTPUT_REDIR"
start id $ do createAnnexDirectory (parentDir logfile)
case startbrowser of ifM (liftIO $ isNothing <$> getEnv flag)
Nothing -> Nothing ( liftIO $ withFile devNull WriteMode $ \nullh -> do
Just a -> Just $ a Nothing Nothing 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 #endif
where where
desc desc

View file

@ -224,7 +224,7 @@ checkLogSize n = do
totalsize <- liftIO $ sum <$> mapM filesize logs totalsize <- liftIO $ sum <$> mapM filesize logs
when (totalsize > 2 * oneMegabyte) $ do when (totalsize > 2 * oneMegabyte) $ do
notice ["Rotated logs due to size:", show totalsize] notice ["Rotated logs due to size:", show totalsize]
liftIO $ openLog f >>= redirLog liftIO $ openLog f >>= handleToFd >>= redirLog
when (n < maxLogs + 1) $ do when (n < maxLogs + 1) $ do
df <- liftIO $ getDiskFree $ takeDirectory f df <- liftIO $ getDiskFree $ takeDirectory f
case df of case df of

View file

@ -15,13 +15,10 @@ import Common
import System.Posix.Types import System.Posix.Types
#endif #endif
#ifndef mingw32_HOST_OS openLog :: FilePath -> IO Handle
openLog :: FilePath -> IO Fd
openLog logfile = do openLog logfile = do
rotateLog logfile rotateLog logfile
openFd logfile WriteOnly (Just stdFileMode) openFile logfile AppendMode
defaultFileFlags { append = True }
#endif
rotateLog :: FilePath -> IO () rotateLog :: FilePath -> IO ()
rotateLog logfile = go 0 rotateLog logfile = go 0

1
debian/changelog vendored
View file

@ -6,6 +6,7 @@ git-annex (5.20140614) UNRELEASED; urgency=medium
on login. on login.
* Windows: Fix opening file browser from webapp when repo is in a * Windows: Fix opening file browser from webapp when repo is in a
directory with spaces. directory with spaces.
* Windows: Assistant now logs to daemon.log.
-- Joey Hess <joeyh@debian.org> Mon, 16 Jun 2014 11:28:42 -0400 -- Joey Hess <joeyh@debian.org> Mon, 16 Jun 2014 11:28:42 -0400

View file

@ -5,11 +5,6 @@ usable!
* XMPP library not yet built. (See below.) * XMPP library not yet built. (See below.)
* View debug log is empty in windows -- all logs go to console.
This messes up a few parts of UI that direct user to the debug log.
To fix, redirect output to some file when running git-annex via the
VBScript hack.
* Local pairing seems to fail, after acking on Linux box, it stalls. * Local pairing seems to fail, after acking on Linux box, it stalls.
(Also, of course, the Windows box is unlikely to have a ssh server, (Also, of course, the Windows box is unlikely to have a ssh server,
so only pairing with a !Windows box will work.) so only pairing with a !Windows box will work.)