LGTM, thanks.

On Thu, Mar 6, 2014 at 4:21 PM, Klaus Aehlig <[email protected]> wrote:

> On Thu, Mar 06, 2014 at 03:56:45PM +0100, Petr Pudlák wrote:
> > If an attempt to lock a file fails, the descriptor doesn't get closed.
> I'd
> > suggest to use bracket, something like
> >
> > bracket (openFile ... >>= handleToFd) closeFd (setLock ...)
> >
> > Perhaps also use openFd instead of openFile so that we don't need to
> > convert to a Handle and that we use just one type handling files here.
>
> Interdiff (before rebasing to the beginning of the patch series).
>
> commit 5e7342d9a3526d97b334164cef82c2214a68bd7a
> Author: Klaus Aehlig <[email protected]>
> Date:   Thu Mar 6 16:13:49 2014 +0100
>
>     Interdiff [PATCH master 01/14] Add a function to detect death of a job
>
> diff --git a/src/Ganeti/WConfd/DeathDetection.hs
> b/src/Ganeti/WConfd/DeathDetection.hs
> index 2c7ecec..5c2d6f1 100644
> --- a/src/Ganeti/WConfd/DeathDetection.hs
> +++ b/src/Ganeti/WConfd/DeathDetection.hs
> @@ -36,6 +36,7 @@ module Ganeti.WConfd.DeathDetection
>    ) where
>
>  import Control.Concurrent (threadDelay)
> +import Control.Exception (bracket)
>  import Control.Monad
>  import System.Directory
>  import System.IO
> @@ -55,11 +56,9 @@ import Ganeti.WConfd.Monad
>  isDead :: FilePath -> IO Bool
>  isDead fpath = fmap (isOk :: Result () -> Bool) . runResultT . liftIO $ do
>    filepresent <- doesFileExist fpath
> -  when filepresent $ do
> -    handle <- openFile fpath ReadMode
> -    fd <- handleToFd handle
> -    setLock fd (ReadLock, AbsoluteSeek, 0, 0)
> -    closeFd fd
> +  when filepresent
> +    $ bracket (openFd fpath ReadOnly Nothing defaultFileFlags) closeFd
> +              (`setLock` (ReadLock, AbsoluteSeek, 0, 0))
>
>  -- | Interval to run clean-up tasks in microseconds
>  cleanupInterval :: Int
>
>
>
> --
> Klaus Aehlig
> Google Germany GmbH, Dienerstr. 12, 80331 Muenchen
> Registergericht und -nummer: Hamburg, HRB 86891
> Sitz der Gesellschaft: Hamburg
> Geschaeftsfuehrer: Graham Law, Christine Elizabeth Flores
>

Reply via email to