Merge pull request #7802 from chrisroberts/safe_exec/windows

[windows] Use subprocess for safe_exec on windows
This commit is contained in:
Chris Roberts 2016-09-30 14:42:40 -07:00 committed by GitHub
commit c3eb1e355b
1 changed files with 24 additions and 4 deletions

View File

@ -7,6 +7,9 @@ module Vagrant
# thread. In that case, `safe_exec` automatically falls back to # thread. In that case, `safe_exec` automatically falls back to
# forking. # forking.
class SafeExec class SafeExec
@@logger = Log4r::Logger.new("vagrant::util::safe_exec")
def self.exec(command, *args) def self.exec(command, *args)
# Create a list of things to rescue from. Since this is OS # Create a list of things to rescue from. Since this is OS
# specific, we need to do some defined? checks here to make # specific, we need to do some defined? checks here to make
@ -18,10 +21,27 @@ module Vagrant
fork_instead = false fork_instead = false
begin begin
pid = nil if fork_instead
pid = fork if fork_instead if Vagrant::Util::Platform.windows?
Kernel.exec(command, *args) if pid.nil? @@logger.debug("Using subprocess because windows platform")
Process.wait(pid) if pid args = args.dup << {notify: [:stdout, :stderr]}
result = Vagrant::Util::Subprocess.execute(command, *args) do |type, data|
case type
when :stdout
@@logger.info(data, new_line: false)
when :stderr
@@logger.info(data, new_line: false)
end
end
Kernel.exit(result.exit_code)
else
pid = fork
Kernel.exec(command, *args)
Process.wait(pid)
end
else
Kernel.exec(command, *args)
end
rescue *rescue_from rescue *rescue_from
# We retried already, raise the issue and be done # We retried already, raise the issue and be done
raise if fork_instead raise if fork_instead