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 12:57:21 -0700
commitaff7ca38002d58d71f47b10c2fa29ed7dbdd3059 (patch)
tree74c3c462488b557e418ef8ceab8919225ca01fa7
parent34c023f17bee57f789bf5e30cdcc3b7d73507cdd (diff)
downloadmixlib-shellout-aff7ca38002d58d71f47b10c2fa29ed7dbdd3059.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 a379ee8..2b53d02 100644
--- a/lib/mixlib/shellout.rb
+++ b/lib/mixlib/shellout.rb
@@ -144,7 +144,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_stdout = @live_stderr = nil
@input = nil
@log_level = :debug
diff --git a/lib/mixlib/shellout/unix.rb b/lib/mixlib/shellout/unix.rb
index 2bde64a..3172f6e 100644
--- a/lib/mixlib/shellout/unix.rb
+++ b/lib/mixlib/shellout/unix.rb
@@ -229,7 +229,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
@@ -241,11 +241,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
@@ -270,6 +269,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
@@ -311,7 +319,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