Skip to content
Snippets Groups Projects
Commit 0d0ac025 authored by Iustin Pop's avatar Iustin Pop
Browse files

Cleanup query socket before attempting to bind


This patch adds a simple function to ensure a socket doesn't exist
before binding to it. Additionally, we cleanup the exports of
Queryd.hs.

Signed-off-by: default avatarIustin Pop <iustin@google.com>
Reviewed-by: default avatarAgata Murawska <agatamurawska@google.com>
parent a2160e57
No related branches found
No related tags found
No related merge requests found
......@@ -37,6 +37,7 @@ module Ganeti.Daemon
, oSyslogUsage
, parseArgs
, parseAddress
, cleanupSocket
, writePidFile
, genericMain
) where
......@@ -54,6 +55,7 @@ import System.Exit
import System.Environment
import System.Info
import System.IO
import System.IO.Error (isDoesNotExistError)
import System.Posix.Directory
import System.Posix.Files
import System.Posix.IO
......@@ -221,6 +223,13 @@ writePidFile path = do
catch (fmap Ok $ _writePidFile path)
(return . Bad . formatIOError "Failure during writing of the pid file")
-- | Helper function to ensure a socket doesn't exist. Should only be
-- called once we have locked the pid file successfully.
cleanupSocket :: FilePath -> IO ()
cleanupSocket socketPath = do
catchJust (guard . isDoesNotExistError) (removeLink socketPath)
(const $ return ())
-- | Sets up a daemon's environment.
setupDaemonEnv :: FilePath -> FileMode -> IO ()
setupDaemonEnv cwd umask = do
......
......@@ -26,8 +26,9 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
-}
module Ganeti.Queryd
where
( ConfigReader
, runQueryD
) where
import Control.Applicative
import Control.Concurrent
......@@ -41,6 +42,7 @@ import Text.JSON.Pretty (pp_value)
import System.Info (arch)
import qualified Ganeti.Constants as C
import Ganeti.Daemon
import Ganeti.Objects
import qualified Ganeti.Config as Config
import Ganeti.BasicTypes
......@@ -183,6 +185,7 @@ mainLoop creader socket = do
runQueryD :: Maybe FilePath -> ConfigReader -> IO ()
runQueryD fpath creader = do
let socket_path = fromMaybe C.querySocket fpath
cleanupSocket socket_path
bracket
(getServer socket_path)
(closeServer socket_path)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment