diff --git a/Git/LockFile.hs b/Git/LockFile.hs index 70d8e5bb54..9d9042f453 100644 --- a/Git/LockFile.hs +++ b/Git/LockFile.hs @@ -53,8 +53,12 @@ openLock' lck = do #ifndef mingw32_HOST_OS -- On unix, git simply uses O_EXCL h <- openFdWithMode (fromOsPath lck) ReadWrite (Just 0O666) +#if MIN_VERSION_unix(2,8,0) + (defaultFileFlags { exclusive = True, cloexec = True }) +#else (defaultFileFlags { exclusive = True }) setFdOption h CloseOnExec True +#endif #else -- It's not entirely clear how git manages locking on Windows, -- since it's buried in the portability layer, and different diff --git a/Utility/LockFile/Posix.hs b/Utility/LockFile/Posix.hs index f74e3691a7..3ad3554a8b 100644 --- a/Utility/LockFile/Posix.hs +++ b/Utility/LockFile/Posix.hs @@ -5,6 +5,8 @@ - License: BSD-2-clause -} +{-# LANGUAGE CPP #-} + module Utility.LockFile.Posix ( LockHandle, lockShared, @@ -76,8 +78,13 @@ tryLock lockreq mode lockfile = uninterruptibleMask_ $ do openLockFile :: LockRequest -> Maybe ModeSetter -> LockFile -> IO Fd openLockFile lockreq filemode lockfile = do l <- applyModeSetter filemode lockfile $ \filemode' -> - openFdWithMode (fromOsPath lockfile) openfor filemode' defaultFileFlags + openFdWithMode (fromOsPath lockfile) openfor filemode' $ +#if MIN_VERSION_unix(2,8,0) + defaultFileFlags { cloexec = True } +#else + defaultFileFlags setFdOption l CloseOnExec True +#endif return l where openfor = case lockreq of