Skip to content

Commit

Permalink
Move unix_socket file to "<user_home>/.vagrant.d/tmp"
Browse files Browse the repository at this point in the history
Moving them together also helps to implement the NFS support later.
  • Loading branch information
gaozengqi committed Mar 26, 2022
1 parent 39def30 commit dd06c62
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
17 changes: 13 additions & 4 deletions lib/vagrant-qemu/driver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@ class Driver
# @return [String] VM ID
attr_reader :vm_id
attr_reader :data_dir
attr_reader :tmp_dir

def initialize(id, dir)
def initialize(id, dir, tmp)
@vm_id = id
@data_dir = dir
@tmp_dir = tmp.join("vagrant-qemu")
end

def get_current_state
Expand All @@ -32,16 +34,21 @@ def delete
if created?
id_dir = @data_dir.join(@vm_id)
FileUtils.rm_rf(id_dir)
id_tmp_dir = @tmp_dir.join(@vm_id)
FileUtils.rm_rf(id_tmp_dir)
end
end

def start(options)
if !running?
id_dir = @data_dir.join(@vm_id)
image_path = id_dir.join("linked-box.img").to_s
unix_socket_path = id_dir.join("qemu_socket").to_s
pid_file = id_dir.join("qemu.pid").to_s

id_tmp_dir = @tmp_dir.join(@vm_id)
FileUtils.mkdir_p(id_tmp_dir)
unix_socket_path = id_tmp_dir.join("qemu_socket").to_s

cmd = []
cmd += %W(qemu-system-#{options[:arch]})

Expand Down Expand Up @@ -81,8 +88,8 @@ def start(options)

def stop
if running?
id_dir = @data_dir.join(@vm_id)
unix_socket_path = id_dir.join("qemu_socket").to_s
id_tmp_dir = @tmp_dir.join(@vm_id)
unix_socket_path = id_tmp_dir.join("qemu_socket").to_s
sent = false
execute("nc", "-w", "5", "-U", unix_socket_path) do |type, data|
case type
Expand All @@ -102,6 +109,8 @@ def import(options)
# Make dir
id_dir = @data_dir.join(new_id)
FileUtils.mkdir_p(id_dir)
id_tmp_dir = @tmp_dir.join(new_id)
FileUtils.mkdir_p(id_tmp_dir)

# Prepare firmware
execute("cp", options[:qemu_dir].join("edk2-aarch64-code.fd").to_s, id_dir.join("edk2-aarch64-code.fd").to_s)
Expand Down
2 changes: 1 addition & 1 deletion lib/vagrant-qemu/provider.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def action(name)
end

def machine_id_changed
@driver = Driver.new(@machine.id, @machine.data_dir)
@driver = Driver.new(@machine.id, @machine.data_dir, @machine.env.tmp_path)
end

def ssh_info
Expand Down

0 comments on commit dd06c62

Please sign in to comment.