summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/chef/run_lock.rb3
-rw-r--r--spec/functional/run_lock_spec.rb5
-rw-r--r--spec/spec_helper.rb1
-rw-r--r--spec/support/platform_helpers.rb6
4 files changed, 14 insertions, 1 deletions
diff --git a/lib/chef/run_lock.rb b/lib/chef/run_lock.rb
index 50371d93a1..7f0863e2ee 100644
--- a/lib/chef/run_lock.rb
+++ b/lib/chef/run_lock.rb
@@ -57,8 +57,9 @@ class Chef
create_path(File.dirname(runlock_file))
@runlock = File.open(runlock_file,'w+')
# if we support FD_CLOEXEC (linux, !windows), then use it.
+ # NB: ruby-2.0.0-p195 sets FD_CLOEXEC by default, but not ruby-1.8.7/1.9.3
if Fcntl.const_defined?('F_SETFD') && Fcntl.const_defined?('FD_CLOEXEC')
- @runlock.fcntl(Fcntl::F_SETFD, Fcntl::FD_CLOEXEC)
+ runlock.fcntl(Fcntl::F_SETFD, runlock.fcntl(Fcntl::F_GETFD, 0) | Fcntl::FD_CLOEXEC)
end
unless runlock.flock(File::LOCK_EX|File::LOCK_NB)
# Another chef client running...
diff --git a/spec/functional/run_lock_spec.rb b/spec/functional/run_lock_spec.rb
index 5e64e42a0b..7dc23d41fd 100644
--- a/spec/functional/run_lock_spec.rb
+++ b/spec/functional/run_lock_spec.rb
@@ -168,6 +168,11 @@ describe Chef::RunLock do
File.should exist(lockfile)
end
+ it "sets FD_CLOEXEC on the lockfile", :supports_cloexec => true do
+ run_lock.acquire
+ (run_lock.runlock.fcntl(Fcntl::F_GETFD, 0) & Fcntl::FD_CLOEXEC).should == Fcntl::FD_CLOEXEC
+ end
+
it "allows only one chef client run per lockfile" do
# First process, gets the lock and keeps it.
p1 = fork do
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index 23d10b2bba..c3619dd773 100644
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -94,6 +94,7 @@ RSpec.configure do |config|
config.filter_run_excluding :windows32_only => true unless windows32?
config.filter_run_excluding :system_windows_service_gem_only => true unless system_windows_service_gem?
config.filter_run_excluding :unix_only => true unless unix?
+ config.filter_run_excluding :supports_cloexec => true unless supports_cloexec?
config.filter_run_excluding :selinux_only => true unless selinux_enabled?
config.filter_run_excluding :ruby_18_only => true unless ruby_18?
config.filter_run_excluding :ruby_19_only => true unless ruby_19?
diff --git a/spec/support/platform_helpers.rb b/spec/support/platform_helpers.rb
index f9d2338bf4..92f03ac996 100644
--- a/spec/support/platform_helpers.rb
+++ b/spec/support/platform_helpers.rb
@@ -1,3 +1,5 @@
+require 'fcntl'
+
def ruby_19?
!!(RUBY_VERSION =~ /^1.9/)
end
@@ -46,6 +48,10 @@ def freebsd?
!!(RUBY_PLATFORM =~ /freebsd/)
end
+def supports_cloexec?
+ Fcntl.const_defined?('F_SETFD') && Fcntl.const_defined?('FD_CLOEXEC')
+end
+
DEV_NULL = windows? ? 'NUL' : '/dev/null'
def selinux_enabled?