Handle interrupts well with VirtualBox.

This commit is contained in:
Mitchell Hashimoto 2011-12-26 17:00:41 -08:00
parent dd8a6b9a42
commit bfc85d7f14
3 changed files with 22 additions and 2 deletions

View File

@ -28,6 +28,7 @@
run. [GH-598]
- `vagrant ssh -c` will now send stderr to stderr and stdout to stdout
on the host machine, instead of all output to stdout.
- Vagrant can now be interrupted during the "importing" step.
## 0.8.10 (December 10, 2011)

View File

@ -21,6 +21,10 @@ module Vagrant
# immediately.
env[:ui].clear_line
# If we got interrupted, then the import could have been
# interrupted and its not a big deal. Just return out.
return if env[:interrupted]
# Flag as erroneous and return if import failed
raise Errors::VMImportFailure if !env[:vm].uuid

View File

@ -1,4 +1,5 @@
require 'log4r'
require 'vagrant/util/busy'
require 'vagrant/util/subprocess'
module Vagrant
@ -22,6 +23,9 @@ module Vagrant
@logger = Log4r::Logger.new("vagrant::driver::virtualbox")
@uuid = uuid
# This flag is used to keep track of interrupted state (SIGINT)
@interrupted = false
if @uuid
# Verify the VM exists, and if it doesn't, then don't worry
# about it (mark the UUID as nil)
@ -415,7 +419,11 @@ module Vagrant
# If the command was a failure, then raise an exception that is
# nicely handled by Vagrant.
if r.exit_code != 0
raise Errors::VBoxManageError, :command => command.inspect
if @interrupted
@logger.info("Exit code != 0, but interrupted. Ignoring.")
else
raise Errors::VBoxManageError, :command => command.inspect
end
end
# Return the output
@ -424,7 +432,14 @@ module Vagrant
# Executes a command and returns the raw result object.
def raw(*command, &block)
Subprocess.execute("VBoxManage", *command, &block)
int_callback = lambda do
@interrupted = true
@logger.info("Interrupted.")
end
Util::Busy.busy(int_callback) do
Subprocess.execute("VBoxManage", *command, &block)
end
end
end
end