summaryrefslogtreecommitdiff
path: root/Utility
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2014-08-20 11:25:07 -0400
committerGravatar Joey Hess <joey@kitenet.net>2014-08-20 11:37:02 -0400
commitb44e74ace2d74954c503930b9edb75d0aa9d7b52 (patch)
treef07fa949063d3e93987dad89e3348e6d8b692b76 /Utility
parent5fda2e3cb3f93771fb70a3ccbf88eeaf4e7f924a (diff)
Ensure that all lock fds are close-on-exec, fixing various problems with them being inherited by child processes such as git commands.
(With the exception of daemon pid locking.) This fixes at part of #758630. I reproduced the assistant locking eg, a removable drive's annex journal lock file and forking a long-running git-cat-file process that inherited that lock. This did not affect Windows. Considered doing a portable Utility.LockFile layer, but git-annex uses posix locks in several special ways that have no direct Windows equivilant, and it seems like it would mostly be a complication. This commit was sponsored by Protonet.
Diffstat (limited to 'Utility')
-rw-r--r--Utility/WinLock.hs7
1 files changed, 6 insertions, 1 deletions
diff --git a/Utility/WinLock.hs b/Utility/WinLock.hs
index 369da6782..fc7c8a8a9 100644
--- a/Utility/WinLock.hs
+++ b/Utility/WinLock.hs
@@ -44,15 +44,20 @@ lockExclusive = openLock fILE_SHARE_NONE
- Note that createFile busy-waits to try to avoid failing when some other
- process briefly has a file open. But that would make checking locks
- much more expensive, so is not done here. Thus, the use of c_CreateFile.
+ -
+ - Also, passing Nothing for SECURITY_ATTRIBUTES ensures that the lock file
+ - is not inheerited by any child process.
-}
openLock :: ShareMode -> LockFile -> IO (Maybe LockHandle)
openLock sharemode f = do
h <- withTString f $ \c_f ->
- c_CreateFile c_f gENERIC_READ sharemode (maybePtr Nothing)
+ c_CreateFile c_f gENERIC_READ sharemode security_attributes
oPEN_ALWAYS fILE_ATTRIBUTE_NORMAL (maybePtr Nothing)
return $ if h == iNVALID_HANDLE_VALUE
then Nothing
else Just h
+ where
+ security_attributes = maybePtr Nothing
dropLock :: LockHandle -> IO ()
dropLock = closeHandle