From bd60d6b283eca5a54aaff18a602a585eded6c854 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Thu, 21 Mar 2013 21:43:50 -0700 Subject: [PATCH] Lock around chdir in Subprocess for thread safety --- lib/vagrant/util/subprocess.rb | 10 ++++++++-- plugins/providers/virtualbox/action/import.rb | 1 + 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/vagrant/util/subprocess.rb b/lib/vagrant/util/subprocess.rb index a9c7fcb4a..20d103738 100644 --- a/lib/vagrant/util/subprocess.rb +++ b/lib/vagrant/util/subprocess.rb @@ -1,3 +1,5 @@ +require 'thread' + require 'childprocess' require 'log4r' @@ -12,6 +14,8 @@ module Vagrant # from the subprocess in real time, by simply passing a block to # the execute method. class Subprocess + @@chdir_lock = Mutex.new + # The chunk size for reading from subprocess IO. READ_CHUNK_SIZE = 4096 @@ -72,8 +76,10 @@ module Vagrant # Start the process begin - Dir.chdir(workdir) do - process.start + @@chdir_lock.synchronize do + Dir.chdir(workdir) do + process.start + end end rescue ChildProcess::LaunchError => ex # Raise our own version of the error so that users of the class diff --git a/plugins/providers/virtualbox/action/import.rb b/plugins/providers/virtualbox/action/import.rb index 14ac2b0bb..9fe93f820 100644 --- a/plugins/providers/virtualbox/action/import.rb +++ b/plugins/providers/virtualbox/action/import.rb @@ -7,6 +7,7 @@ module VagrantPlugins end def call(env) + raise "foo" env[:ui].info I18n.t("vagrant.actions.vm.import.importing", :name => env[:machine].box.name)