|
21 | 21 | require 'tmpdir' |
22 | 22 | require 'fcntl' |
23 | 23 | require 'etc' |
| 24 | +require 'io/wait' |
24 | 25 |
|
25 | 26 | class Chef |
26 | 27 | module Mixin |
@@ -112,44 +113,34 @@ def run_command(args={}) |
112 | 113 | exec_processing_block = lambda do |pid, stdin, stdout, stderr| |
113 | 114 | stdin.close |
114 | 115 |
|
115 | | - begin |
116 | | - Timeout.timeout(Chef::Config[:run_command_stdout_timeout]) do |
117 | | - while stdout.ready? == nil |
118 | | - Chef::Log.debug("Waiting for STDOUT to be ready..") |
119 | | - sleep 1 |
120 | | - end |
121 | | - end |
122 | | - rescue Timeout::Error => e |
123 | | - Chef::Log.error("#{args[:command]} timed out reading STDOUT") |
124 | | - else |
| 116 | + stdout.sync = true |
| 117 | + stderr.sync = true |
| 118 | + |
| 119 | + stdout.wait(Chef::Config[:run_command_stdout_timeout]) |
| 120 | + if stdout.ready? |
125 | 121 | stdout_string = stdout.gets(nil) |
126 | 122 | if stdout_string |
127 | 123 | command_stdout = stdout_string |
128 | 124 | Chef::Log.debug("---- Begin #{args[:command]} STDOUT ----") |
129 | 125 | Chef::Log.debug(stdout_string.strip) |
130 | 126 | Chef::Log.debug("---- End #{args[:command]} STDOUT ----") |
131 | 127 | end |
| 128 | + else |
| 129 | + Chef::Log.debug("Nothing to read on '#{args[:command]}' STDOUT, or #{Chef::Config[:run_command_stdout_timeout]} seconds exceeded.") |
132 | 130 | end |
133 | 131 |
|
134 | | - begin |
135 | | - Timeout.timeout(Chef::Config[:run_command_stderr_timeout]) do |
136 | | - while stderr.ready? == nil |
137 | | - Chef::Log.debug("Waiting for STDERR to be ready..") |
138 | | - sleep 1 |
139 | | - end |
140 | | - end |
141 | | - rescue Timeout::Error => e |
142 | | - Chef::Log.error("#{args[:command]} timed out reading STDERR") |
143 | | - else |
| 132 | + stderr.wait(Chef::Config[:run_command_stdout_timeout]) |
| 133 | + if stderr.ready? |
144 | 134 | stderr_string = stderr.gets(nil) |
145 | 135 | if stderr_string |
146 | 136 | command_stderr = stderr_string |
147 | 137 | Chef::Log.debug("---- Begin #{args[:command]} STDERR ----") |
148 | 138 | Chef::Log.debug(stderr_string.strip) |
149 | 139 | Chef::Log.debug("---- End #{args[:command]} STDERR ----") |
150 | 140 | end |
| 141 | + else |
| 142 | + Chef::Log.debug("Nothing to read on '#{args[:command]}' STDERR, or #{Chef::Config[:run_command_stderr_timeout]} seconds exceeded.") |
151 | 143 | end |
152 | | - |
153 | 144 | end |
154 | 145 |
|
155 | 146 | args[:cwd] ||= Dir.tmpdir |
|
0 commit comments