summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordanielsdeleo <dan@opscode.com>2013-06-26 17:50:34 -0700
committerdanielsdeleo <dan@opscode.com>2013-06-26 17:50:34 -0700
commit9cb0f3ce719001956d7875ead3666f6ec0861dd7 (patch)
treefd3516148ffe5b44100c0fd815f5079e5a7e7911
parent4028eb336612d410d9cc5ff4c666b428bd3ff684 (diff)
parent96cc792d77b5d03808a65ca7e94501a3d6c3d980 (diff)
downloadohai-9cb0f3ce719001956d7875ead3666f6ec0861dd7.tar.gz
Merge branch 'OHAI-455'
-rw-r--r--lib/ohai/mixin/command.rb4
-rw-r--r--spec/unit/mixin/command_spec.rb22
2 files changed, 26 insertions, 0 deletions
diff --git a/lib/ohai/mixin/command.rb b/lib/ohai/mixin/command.rb
index 4487e3bf..a719e274 100644
--- a/lib/ohai/mixin/command.rb
+++ b/lib/ohai/mixin/command.rb
@@ -224,6 +224,10 @@ module Ohai
begin
e = Marshal.load ps.first
+ pw.last.close
+ pr.first.close
+ pe.first.close
+ Process.wait(cid)
raise(Exception === e ? e : "unknown failure!")
rescue EOFError # If we get an EOF error, then the exec was successful
42
diff --git a/spec/unit/mixin/command_spec.rb b/spec/unit/mixin/command_spec.rb
index 0faa1df3..9e454117 100644
--- a/spec/unit/mixin/command_spec.rb
+++ b/spec/unit/mixin/command_spec.rb
@@ -44,4 +44,26 @@ describe Ohai::Mixin::Command, "popen4" do
end
end
+ it "reaps zombie processes after exec fails [OHAI-455]" do
+ # NOTE: depending on ulimit settings, GC, etc., before the OHAI-455 patch,
+ # ohai could also exhaust the available file descriptors when creating this
+ # many zombie processes. A regression _could_ cause Errno::EMFILE but this
+ # probably won't be consistent on different environments.
+ created_procs = 0
+ 100.times do
+ begin
+ Ohai::Mixin::Command.popen4("/bin/this-is-not-a-real-command") {|p,i,o,e| nil }
+ rescue Ohai::Exceptions::Exec
+ created_procs += 1
+ end
+ end
+ created_procs.should == 100
+ reaped_procs = 0
+ begin
+ loop { Process.wait(-1); reaped_procs += 1 }
+ rescue Errno::ECHILD
+ end
+ reaped_procs.should == 0
+ end
+
end