{-
-Copyright (C) 2011 Google Inc.
+Copyright (C) 2011, 2012 Google Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
) where
import Control.Concurrent
+import Control.Exception
import Control.Monad (forever)
import qualified Data.ByteString as B
import Data.IORef
import Data.List
import qualified Data.Map as M
import qualified Network.Socket as S
+import Prelude hiding (catch)
import System.Posix.Files
import System.Posix.Types
import System.Time
buildResponse _ (ConfdRequest { confdRqType = ReqNodePipByInstPip }) =
return queryArgumentError
+buildResponse cdata req@(ConfdRequest { confdRqType = ReqNodeDrbd }) = do
+ let cfg = fst cdata
+ node_name <- case confdRqQuery req of
+ PlainQuery str -> return str
+ _ -> fail $ "Invalid query type " ++ show (confdRqQuery req)
+ node <- getNode cfg node_name
+ let minors = concatMap (getInstMinorsForNode (nodeName node)) .
+ M.elems . configInstances $ cfg
+ encoded = [J.JSArray [J.showJSON a, J.showJSON b, J.showJSON c,
+ J.showJSON d, J.showJSON e, J.showJSON f] |
+ (a, b, c, d, e, f) <- minors]
+ return (ReplyStatusOk, J.showJSON encoded)
+
-- | Parses a signed request.
parseRequest :: HashKey -> String -> Result (String, String, ConfdRequest)
parseRequest key str = do
updateConfig path cref
return (nt', ConfigReloaded)
) (\e -> do
- let msg = "Failure during configuration update: " ++ show e
+ let msg = "Failure during configuration update: " ++
+ show (e::IOError)
writeIORef cref (Bad msg)
return (nullFStat, ConfigIOError)
)
addNotifier inotify path cref mstate = do
catch (addWatch inotify [CloseWrite] path
(onInotify inotify path cref mstate) >> return True)
- (const $ return False)
+ (\e -> const (return False) (e::IOError))
-- | Inotify event handler.
onInotify :: INotify -> String -> CRef -> MVar ServerState -> Event -> IO ()
-- | Main function.
main :: DaemonOptions -> IO ()
main opts = do
- s <- S.socket S.AF_INET S.Datagram S.defaultProtocol
- let port = maybe C.defaultConfdPort fromIntegral $ optPort opts
- S.bindSocket s (S.SockAddrInet (fromIntegral port) S.iNADDR_ANY)
+ parseresult <- parseAddress opts C.defaultConfdPort
+ (af_family, bindaddr) <- exitIfBad "parsing bind address" parseresult
+ s <- S.socket af_family S.Datagram S.defaultProtocol
+ S.bindSocket s bindaddr
cref <- newIORef (Bad "Configuration not yet loaded")
statemvar <- newMVar initialState
hmac <- getClusterHmac