Add a note about why we will always leak RDP tmpfiles
This commit is contained in:
parent
ca337122dc
commit
982af05178
|
@ -9,7 +9,18 @@ module VagrantPlugins
|
|||
class RDP
|
||||
def self.rdp_client(env, rdp_info)
|
||||
config_path = self.generate_config_file(rdp_info)
|
||||
Vagrant::Util::Subprocess.execute("open", config_path.to_s)
|
||||
begin
|
||||
Vagrant::Util::Subprocess.execute("open", config_path.to_s)
|
||||
ensure
|
||||
# Note: this technically will never get run; neither would an
|
||||
# at_exit call. The reason is that `exec` replaces this process,
|
||||
# effectively the same as `kill -9`. This is solely here to prove
|
||||
# that and so that future developers do not waste a ton of time
|
||||
# try to identify why Vagrant is leaking RDP connection files.
|
||||
# There is a catch-22 here in that we can't delete the file before
|
||||
# we exec, and we can't delete the file after we exec :(.
|
||||
File.unlink(config_path) if File.file?(config_path)
|
||||
end
|
||||
end
|
||||
|
||||
protected
|
||||
|
@ -25,21 +36,24 @@ module VagrantPlugins
|
|||
}
|
||||
|
||||
# Create the ".rdp" file
|
||||
config_path = Pathname.new(Dir.tmpdir).join(
|
||||
"vagrant-rdp-#{Time.now.to_i}-#{rand(10000)}.rdp")
|
||||
config_path.open("w+") do |f|
|
||||
t = ::Tempfile.new(["vagrant-rdp", ".rdp"]).tap do |f|
|
||||
f.binmode
|
||||
|
||||
opts.each do |k, v|
|
||||
f.puts("#{k}:#{v}")
|
||||
f.write("#{k}:#{v}")
|
||||
end
|
||||
|
||||
if rdp_info[:extra_args]
|
||||
rdp_info[:extra_args].each do |arg|
|
||||
f.puts("#{arg}")
|
||||
f.write("#{arg}")
|
||||
end
|
||||
end
|
||||
|
||||
f.fsync
|
||||
f.close
|
||||
end
|
||||
|
||||
return config_path
|
||||
return t.path
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue