Skip to content

Commit

Permalink
Issue #27 Switching to win32-process for creating sub processes on Wi…
Browse files Browse the repository at this point in the history
…ndows
  • Loading branch information
hferentschik committed Jun 21, 2016
1 parent 2a118f6 commit 3b81711
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 11 deletions.
11 changes: 11 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Build artifacts
pkg

# Ruby / Bundler
Gemfile.lock
.ruby-gemset
.ruby-version

# IDE config files
.idea
*.iml
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ group :development do
# We depend on Vagrant for development, but we don't add it as a
# gem dependency because we expect to be installed within the
# Vagrant environment itself using `vagrant plugin`.
gem "vagrant", :git => "https://github.com/mitchellh/vagrant.git"
gem "vagrant", :git => "https://github.com/mitchellh/vagrant.git", :ref => 'v1.8.4'
end

group :plugins do
Expand Down
6 changes: 6 additions & 0 deletions lib/vagrant-sshfs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@
raise "The Vagrant sshfs plugin must be run within Vagrant"
end

# Only load the gem on Windows since it replaces some methods in Ruby's Process class
# Also load before Process.uid is called the first time by Vagrant
if Vagrant::Util::Platform.windows?
require 'win32/process'
end

require "vagrant-sshfs/errors"
require "vagrant-sshfs/version"
require "vagrant-sshfs/plugin"
Expand Down
33 changes: 24 additions & 9 deletions lib/vagrant-sshfs/cap/linux/sshfs_mount.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
require "log4r"

require "vagrant/util/retryable"
require "tempfile"

Expand Down Expand Up @@ -146,8 +145,8 @@ def self.sshfs_slave_mount(machine, opts, hostpath, expanded_guest_path)
# For issue #27 we'll need to create a tmp files for STDERR
# Can't send to /dev/null. Doesn't work on Windows.
# Can't close FD with :close. Doesn't work on Windows.
t1 = Tempfile.new('vagrant_sshfs_sftp_server_stderr').path()
t2 = Tempfile.new('vagrant_sshfs_ssh_stderr').path()
t1 = Tempfile.new('vagrant_sshfs_sftp_server_stderr')
t2 = Tempfile.new('vagrant_sshfs_ssh_stderr')

# The way this works is by hooking up the stdin+stdout of the
# sftp-server process to the stdin+stdout of the sshfs process
Expand All @@ -164,8 +163,28 @@ def self.sshfs_slave_mount(machine, opts, hostpath, expanded_guest_path)
# stdin <= r2 pipe2 w2 <= stdout
#
# Wire up things appropriately and start up the processes
p1 = spawn(sftp_server_cmd, :out => w2, :in => r1, :err => t1)
p2 = spawn(ssh_cmd, :out => w1, :in => r2, :err => t2)
if Vagrant::Util::Platform.windows?
# Need to handle Windows differently. Kernel.spawn fails to work, if the shell creating the process is closed.
# See https://github.com/dustymabe/vagrant-sshfs/issues/31
Process.create(:command_line => sftp_server_cmd,
:creation_flags => Process::DETACHED_PROCESS,
:process_inherit => false,
:thread_inherit => true,
:startup_info => {:stdin => w2, :stdout => r1, :stderr => t1})

Process.create(:command_line => ssh_cmd,
:creation_flags => Process::DETACHED_PROCESS,
:process_inherit => false,
:thread_inherit => true,
:startup_info => {:stdin => w1, :stdout => r2, :stderr => t2})
else
p1 = spawn(sftp_server_cmd, :out => w2, :in => r1, :err => t1, :pgroup => true)
p2 = spawn(ssh_cmd, :out => w1, :in => r2, :err => t2, :pgroup => true)

# Detach from the processes so they will keep running
Process.detach(p1)
Process.detach(p2)
end

# Check that the mount made it
mounted = false
Expand All @@ -181,10 +200,6 @@ def self.sshfs_slave_mount(machine, opts, hostpath, expanded_guest_path)
raise VagrantPlugins::SyncedFolderSSHFS::Errors::SSHFSSlaveMountFailed
end
machine.ui.info("Folder Successfully Mounted!")

# Detach from the processes so they will keep running
Process.detach(p1)
Process.detach(p2)
end

# Do a normal sshfs mount in which we will ssh into the guest
Expand Down
2 changes: 1 addition & 1 deletion lib/vagrant-sshfs/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module VagrantPlugins
module SyncedFolderSSHFS
VERSION = "1.1.0"
VERSION = "1.1.0.dev"
end
end
2 changes: 2 additions & 0 deletions vagrant-sshfs.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ Gem::Specification.new do |spec|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
spec.require_paths = ["lib"]

spec.add_dependency 'win32-process'

spec.add_development_dependency "bundler", "~> 1.7"
spec.add_development_dependency "rake", "~> 10.0"
end

0 comments on commit 3b81711

Please sign in to comment.