Revision 79ac58fa htools/Ganeti/Daemon.hs
b/htools/Ganeti/Daemon.hs | ||
---|---|---|
41 | 41 |
, genericMain |
42 | 42 |
) where |
43 | 43 |
|
44 |
import Control.Exception |
|
44 | 45 |
import Control.Monad |
45 | 46 |
import qualified Data.Version |
46 | 47 |
import Data.Word |
47 | 48 |
import qualified Network.Socket as Socket |
49 |
import Prelude hiding (catch) |
|
48 | 50 |
import System.Console.GetOpt |
49 | 51 |
import System.Exit |
50 | 52 |
import System.Environment |
... | ... | |
199 | 201 |
_ <- fdWrite fd (show my_pid ++ "\n") |
200 | 202 |
return fd |
201 | 203 |
|
204 |
-- | Helper to format an IOError. |
|
205 |
formatIOError :: String -> IOError -> String |
|
206 |
formatIOError msg err = msg ++ ": " ++ show err |
|
207 |
|
|
202 | 208 |
-- | Wrapper over '_writePidFile' that transforms IO exceptions into a |
203 | 209 |
-- 'Bad' value. |
204 | 210 |
writePidFile :: FilePath -> IO (Result Fd) |
205 | 211 |
writePidFile path = do |
206 |
catch (fmap Ok $ _writePidFile path) (return . Bad . show) |
|
212 |
catch (fmap Ok $ _writePidFile path) |
|
213 |
(return . Bad . formatIOError "Failure during writing of the pid file") |
|
207 | 214 |
|
208 | 215 |
-- | Sets up a daemon's environment. |
209 | 216 |
setupDaemonEnv :: FilePath -> FileMode -> IO () |
Also available in: Unified diff