remotedaemon: Fork to background by default. Added --foreground switch to enable old behavior.

Groundwork for tor hidden services, which the remotedaemon will serve.
This commit is contained in:
Joey Hess 2016-11-20 14:39:26 -04:00
parent d50b0f3bb3
commit a101b8de37
No known key found for this signature in database
GPG key ID: C910D9222512E3C7
8 changed files with 97 additions and 36 deletions

View file

@ -1,11 +1,11 @@
{- git-remote-daemon core
-
- Copyright 2014 Joey Hess <id@joeyh.name>
- Copyright 2014-2016 Joey Hess <id@joeyh.name>
-
- Licensed under the GNU GPL version 3 or higher.
-}
module RemoteDaemon.Core (runForeground) where
module RemoteDaemon.Core (runInteractive, runNonInteractive) where
import qualified Annex
import Common
@ -17,6 +17,7 @@ import qualified Git
import qualified Git.Types as Git
import qualified Git.CurrentRepo
import Utility.SimpleProtocol
import Utility.ThreadScheduler
import Config
import Annex.Ssh
@ -26,8 +27,8 @@ import Control.Concurrent.STM
import Network.URI
import qualified Data.Map as M
runForeground :: IO ()
runForeground = do
runInteractive :: IO ()
runInteractive = do
(readh, writeh) <- dupIoHandles
ichan <- newTChanIO :: IO (TChan Consumed)
ochan <- newTChanIO :: IO (TChan Emitted)
@ -44,8 +45,21 @@ runForeground = do
let controller = runController ichan ochan
-- If any thread fails, the rest will be killed.
void $ tryIO $
reader `concurrently` writer `concurrently` controller
void $ tryIO $ reader `concurrently` writer `concurrently` controller
runNonInteractive :: IO ()
runNonInteractive = do
ichan <- newTChanIO :: IO (TChan Consumed)
ochan <- newTChanIO :: IO (TChan Emitted)
let reader = forever $ do
threadDelaySeconds (Seconds (60*60))
atomically $ writeTChan ichan RELOAD
let writer = forever $
void $ atomically $ readTChan ochan
let controller = runController ichan ochan
void $ tryIO $ reader `concurrently` writer `concurrently` controller
type RemoteMap = M.Map Git.Repo (IO (), TChan Consumed)