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: Klaus Aehlig <[email protected]> --- Makefile.am | 1 + src/Ganeti/Utils/UniStd.hs | 50 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 src/Ganeti/Utils/UniStd.hs diff --git a/Makefile.am b/Makefile.am index 60c04f4..44f88e6 100644 --- a/Makefile.am +++ b/Makefile.am @@ -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 \ diff --git a/src/Ganeti/Utils/UniStd.hs b/src/Ganeti/Utils/UniStd.hs new file mode 100644 index 0000000..ae804ce --- /dev/null +++ b/src/Ganeti/Utils/UniStd.hs @@ -0,0 +1,50 @@ +{-# 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 () -- 2.0.0.526.g5318336
