From 5872611d59bd2b0a18b613ef2374b8d8dbe02c70 Mon Sep 17 00:00:00 2001 From: Chris Roberts Date: Thu, 15 Sep 2016 13:08:58 -0700 Subject: [PATCH 1/2] [windows] Use subprocess for safe_exec on windows --- lib/vagrant/util/safe_exec.rb | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/lib/vagrant/util/safe_exec.rb b/lib/vagrant/util/safe_exec.rb index d49a58a56..98875ac3b 100644 --- a/lib/vagrant/util/safe_exec.rb +++ b/lib/vagrant/util/safe_exec.rb @@ -7,6 +7,9 @@ module Vagrant # thread. In that case, `safe_exec` automatically falls back to # forking. class SafeExec + + @@logger = Log4r::Logger.new("vagrant::util::safe_exec") + def self.exec(command, *args) # Create a list of things to rescue from. Since this is OS # specific, we need to do some defined? checks here to make @@ -18,10 +21,26 @@ module Vagrant fork_instead = false begin - pid = nil - pid = fork if fork_instead - Kernel.exec(command, *args) if pid.nil? - Process.wait(pid) if pid + if fork_instead + if Vagrant::Util::Platform.windows? + 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 # We retried already, raise the issue and be done raise if fork_instead From 977733790a5f73a3c17af23030f07efe51a6218d Mon Sep 17 00:00:00 2001 From: Chris Roberts Date: Fri, 30 Sep 2016 12:16:53 -0700 Subject: [PATCH 2/2] Include debug notification when using subprocess --- lib/vagrant/util/safe_exec.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/vagrant/util/safe_exec.rb b/lib/vagrant/util/safe_exec.rb index 98875ac3b..37e6a38c3 100644 --- a/lib/vagrant/util/safe_exec.rb +++ b/lib/vagrant/util/safe_exec.rb @@ -23,6 +23,7 @@ module Vagrant begin if fork_instead if Vagrant::Util::Platform.windows? + @@logger.debug("Using subprocess because windows platform") args = args.dup << {notify: [:stdout, :stderr]} result = Vagrant::Util::Subprocess.execute(command, *args) do |type, data| case type