Skip to content

Instantly share code, notes, and snippets.

@danielsdeleo
Created October 23, 2009 19:21
Show Gist options
  • Select an option

  • Save danielsdeleo/217109 to your computer and use it in GitHub Desktop.

Select an option

Save danielsdeleo/217109 to your computer and use it in GitHub Desktop.
diff --git a/chef/lib/chef/mixin/command.rb b/chef/lib/chef/mixin/command.rb
index 946c16d..606d52d 100644
--- a/chef/lib/chef/mixin/command.rb
+++ b/chef/lib/chef/mixin/command.rb
@@ -341,8 +341,10 @@ class Chef
channels_to_watch << stderr if !stderr_finished
ready = IO.select(channels_to_watch, nil, nil, 1.0)
rescue Errno::EAGAIN
+ ensure
results = Process.waitpid2(cid, Process::WNOHANG)
if results
+ results = results.last
stdout_finished = true
stderr_finished = true
end
#!/usr/bin/env ruby
# Sample "evil" init script that doesn't close STDIN like it should
# In the shell, it returns immediately, but continues printing crap
# in popen4, it hangs until the 2nd fork finishes
parent = Process.pid
puts "evilinit starting: #{parent}"
exit if fork
child = Process.pid
puts "evilinit, first fork: #{child}"
exit if fork
10.times do |i|
sleep 2;
puts "evilinit, 2nd fork: #{Process.pid}"
end
puts "finally done"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment