Commit 2bb2ed24 authored by Klaus Aehlig's avatar Klaus Aehlig

Add a foreign function call to fsync(2)

The function fsync(2) is not packaged in any package we currently
depend on, but we need it nevertheless. For a single function, however,
it is easier, also for people trying to build Ganeti, to just do the
foreign function call ourselves, instead of depending on yet another
package.
Signed-off-by: default avatarKlaus Aehlig <aehlig@google.com>
Reviewed-by: default avatarPetr Pudlak <pudlak@google.com>
parent b79a89e7
......@@ -870,6 +870,7 @@ HS_LIB_SRCS = \
src/Ganeti/Utils/MVarLock.hs \
src/Ganeti/Utils/Random.hs \
src/Ganeti/Utils/Statistics.hs \
src/Ganeti/Utils/UniStd.hs \
src/Ganeti/Utils/Validate.hs \
src/Ganeti/VCluster.hs \
src/Ganeti/WConfd/ConfigState.hs \
......
{-# LANGUAGE ForeignFunctionInterface #-}
{-| Necessary foreign function calls
...with foreign functions declared in unistd.h
-}
{-
Copyright (C) 2014 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
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
-}
module Ganeti.Utils.UniStd
( hCloseAndFsync
) where
import Foreign.C
import System.IO
import System.IO.Error
import System.Posix.IO
import System.Posix.Types
foreign import ccall "fsync" fsync :: CInt -> IO CInt
-- | Flush, close and fsync(2) a file handle.
hCloseAndFsync :: Handle -> IO ()
hCloseAndFsync handle = do
Fd fd <- handleToFd handle -- side effect of closing the handle and flushing
-- its write buffer, if necessary.
_ <- fsync fd
_ <- tryIOError $ closeFd (Fd fd)
return ()
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment