Revision 5b11f8db htools/Ganeti/Daemon.hs

b/htools/Ganeti/Daemon.hs
105 105
instance StandardOptions DaemonOptions where
106 106
  helpRequested = optShowHelp
107 107
  verRequested  = optShowVer
108
  requestHelp   = \opts -> opts { optShowHelp = True }
109
  requestVer    = \opts -> opts { optShowVer  = True }
108
  requestHelp o = o { optShowHelp = True }
109
  requestVer  o = o { optShowVer  = True }
110 110

  
111 111
-- | Abrreviation for the option type.
112 112
type OptType = GenericOptType DaemonOptions
......
176 176
-- | Wrapper over '_writePidFile' that transforms IO exceptions into a
177 177
-- 'Bad' value.
178 178
writePidFile :: FilePath -> IO (Result Fd)
179
writePidFile path = do
179
writePidFile path =
180 180
  catch (fmap Ok $ _writePidFile path)
181 181
    (return . Bad . formatIOError "Failure during writing of the pid file")
182 182

  
183 183
-- | Helper function to ensure a socket doesn't exist. Should only be
184 184
-- called once we have locked the pid file successfully.
185 185
cleanupSocket :: FilePath -> IO ()
186
cleanupSocket socketPath = do
186
cleanupSocket socketPath =
187 187
  catchJust (guard . isDoesNotExistError) (removeLink socketPath)
188 188
            (const $ return ())
189 189

  
......
217 217
                -> Socket.Family        -- ^ The cluster IP family
218 218
                -> Result (Socket.Family, Socket.SockAddr)
219 219
defaultBindAddr port Socket.AF_INET =
220
  Ok $ (Socket.AF_INET,
221
        Socket.SockAddrInet (fromIntegral port) Socket.iNADDR_ANY)
220
  Ok (Socket.AF_INET,
221
      Socket.SockAddrInet (fromIntegral port) Socket.iNADDR_ANY)
222 222
defaultBindAddr port Socket.AF_INET6 =
223
  Ok $ (Socket.AF_INET6,
224
        Socket.SockAddrInet6 (fromIntegral port) 0 Socket.iN6ADDR_ANY 0)
223
  Ok (Socket.AF_INET6,
224
      Socket.SockAddrInet6 (fromIntegral port) 0 Socket.iN6ADDR_ANY 0)
225 225
defaultBindAddr _ fam = Bad $ "Unsupported address family: " ++ show fam
226 226

  
227 227
-- | Default hints for the resolver
......
236 236
  resolved <- Socket.getAddrInfo resolveAddrHints (Just str) (Just (show port))
237 237
  return $ case resolved of
238 238
             [] -> Bad "Invalid results from lookup?"
239
             best:_ -> Ok $ (Socket.addrFamily best, Socket.addrAddress best)
239
             best:_ -> Ok (Socket.addrFamily best, Socket.addrAddress best)
240 240

  
241 241
-- | Based on the options, compute the socket address to use for the
242 242
-- daemon.
......
246 246
parseAddress opts defport = do
247 247
  let port = maybe defport fromIntegral $ optPort opts
248 248
  def_family <- Ssconf.getPrimaryIPFamily Nothing
249
  ainfo <- case optBindAddress opts of
250
             Nothing -> return (def_family >>= defaultBindAddr port)
251
             Just saddr -> catch (resolveAddr port saddr)
252
                           (annotateIOError $ "Invalid address " ++ saddr)
253
  return ainfo
249
  case optBindAddress opts of
250
    Nothing -> return (def_family >>= defaultBindAddr port)
251
    Just saddr -> catch (resolveAddr port saddr)
252
                  (annotateIOError $ "Invalid address " ++ saddr)
254 253

  
255 254
-- | Run an I/O action as a daemon.
256 255
--

Also available in: Unified diff