summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRyan Cragun <me@ryan.ec>2014-10-31 09:12:18 -0700
committerRyan Cragun <me@ryan.ec>2014-10-31 09:12:18 -0700
commit477495f2c8960aa2bf4527b16968a907e2aeec19 (patch)
tree0fc1833cf021efb8f0a52206419006caec874fea
parenta04ce6db22edf0575c50e18ae2db09adced7dedc (diff)
downloadmixlib-shellout-477495f2c8960aa2bf4527b16968a907e2aeec19.tar.gz
Add buffering to the process status pipe
-rw-r--r--lib/mixlib/shellout.rb2
-rw-r--r--lib/mixlib/shellout/unix.rb23
2 files changed, 17 insertions, 8 deletions
diff --git a/lib/mixlib/shellout.rb b/lib/mixlib/shellout.rb
index e4e0435..3750cc4 100644
--- a/lib/mixlib/shellout.rb
+++ b/lib/mixlib/shellout.rb
@@ -146,7 +146,7 @@ module Mixlib
# cmd = Mixlib::ShellOut.new("apachectl", "start", :user => 'www', :env => nil, :cwd => '/tmp')
# cmd.run_command # etc.
def initialize(*command_args)
- @stdout, @stderr = '', ''
+ @stdout, @stderr, @process_status = '', '', ''
@live_stream = nil
@input = nil
@log_level = :debug
diff --git a/lib/mixlib/shellout/unix.rb b/lib/mixlib/shellout/unix.rb
index 03f619b..b03e0e3 100644
--- a/lib/mixlib/shellout/unix.rb
+++ b/lib/mixlib/shellout/unix.rb
@@ -254,7 +254,7 @@ module Mixlib
# Some patch levels of ruby in wide use (in particular the ruby 1.8.6 on OSX)
# segfault when you IO.select a pipe that's reached eof. Weak sauce.
def open_pipes
- @open_pipes ||= [child_stdout, child_stderr]
+ @open_pipes ||= [child_stdout, child_stderr, child_process_status]
end
# Keep this unbuffered for now
@@ -266,11 +266,10 @@ module Mixlib
def attempt_buffer_read
ready = IO.select(open_pipes, nil, nil, READ_WAIT_TIME)
- if ready && ready.first.include?(child_stdout)
- read_stdout_to_buffer
- end
- if ready && ready.first.include?(child_stderr)
- read_stderr_to_buffer
+ if ready
+ read_stdout_to_buffer if ready.first.include?(child_stdout)
+ read_stderr_to_buffer if ready.first.include?(child_stderr)
+ read_process_status_to_buffer if ready.first.include?(child_process_status)
end
ready
end
@@ -294,6 +293,15 @@ module Mixlib
open_pipes.delete(child_stderr)
end
+ def read_process_status_to_buffer
+ while chunk = child_process_status.read_nonblock(READ_SIZE)
+ @process_status << chunk
+ end
+ rescue Errno::EAGAIN
+ rescue EOFError
+ open_pipes.delete(child_process_status)
+ end
+
def fork_subprocess
initialize_ipc
@@ -334,7 +342,8 @@ module Mixlib
# assume everything went well.
def propagate_pre_exec_failure
begin
- e = Marshal.load child_process_status
+ attempt_buffer_read
+ e = Marshal.load(@process_status)
raise(Exception === e ? e : "unknown failure: #{e.inspect}")
rescue EOFError # If we get an EOF error, then the exec was successful
true