aboutsummaryrefslogtreecommitdiffstats
path: root/Library
diff options
context:
space:
mode:
authorJack Nagel2013-07-27 23:53:53 -0500
committerJack Nagel2013-07-27 23:57:35 -0500
commit5f6f8bc1c1946d8bc7ee179de8e412c6c0eb58af (patch)
treee3f745157b3e1a033815b6dafe38eed025d04639 /Library
parent04e04869f395e70079ce1cfc33940d36ab44d5c9 (diff)
downloadhomebrew-5f6f8bc1c1946d8bc7ee179de8e412c6c0eb58af.tar.bz2
Set close-on-exec on lock file descriptors
The formula locks used by the installer and commands like link and unlink are backed by open files and flock(). The open file descriptors are thus leaked to any subprocesses. This can result in weird behavior in programs spawned from formula that do not expect to inherit these descriptors. Fix this by setting close-on-exec on the lock file descriptors. Fixes #21486.
Diffstat (limited to 'Library')
-rw-r--r--Library/Homebrew/formula_lock.rb6
1 files changed, 5 insertions, 1 deletions
diff --git a/Library/Homebrew/formula_lock.rb b/Library/Homebrew/formula_lock.rb
index 3b3807fd8..0eeb27c84 100644
--- a/Library/Homebrew/formula_lock.rb
+++ b/Library/Homebrew/formula_lock.rb
@@ -1,3 +1,5 @@
+require 'fcntl'
+
class FormulaLock
LOCKDIR = HOMEBREW_CACHE_FORMULA
@@ -33,7 +35,9 @@ class FormulaLock
def get_or_create_lockfile
if @lockfile.nil? || @lockfile.closed?
- @path.open(File::RDWR | File::CREAT)
+ @lockfile = @path.open(File::RDWR | File::CREAT)
+ @lockfile.fcntl(Fcntl::F_SETFD, Fcntl::FD_CLOEXEC)
+ @lockfile
else
@lockfile
end