Skip to content

Commit

Permalink
sshfs_forward_mount: best effort for uninheriting
Browse files Browse the repository at this point in the history
In 6f285cd we made it so that we would uninherit all filehandles by
default on windows. Some users have reported that this operation
is erroring because `The parameter is incorrect.`. See #52

In this commit I am making the uninheriting operation best effort.
The rationale is that if a file handle was not able to be set to
uninheritable then it probably wasn't one that would get inherited
in the first place. The code will now print out a warning, but
continue on.
  • Loading branch information
dustymabe committed Nov 12, 2016
1 parent c0ba07d commit fe4fcd5
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions lib/vagrant-sshfs/cap/guest/linux/sshfs_forward_mount.rb
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def self.sshfs_forward_unmount_folder(machine, opts)

protected

def self.windows_uninherit_handles
def self.windows_uninherit_handles(machine)
# For win32-process Process.create, if we pass any file handles to the
# underlying process for stdin/stdout/stderr then all file handles are
# inherited by default. We'll explicitly go through and set all Handles
Expand All @@ -115,12 +115,27 @@ def self.windows_uninherit_handles
# https://github.com/djberg96/win32-process/blob/6b380f450aebb69d44bb7accd958ecb6b9e1d246/lib/win32/process.rb#L445-L447
# bInheritHandles from https://msdn.microsoft.com/en-us/library/windows/desktop/ms682425(v=vs.85).aspx
#
# In 6f285cd we made it so that we would uninherit all filehandles by
# default on windows. Some users have reported that this operation
# is erroring because `The parameter is incorrect.`. See #52
# We will make the uninheriting operation best effort. The rationale
# is that if a file handle was not able to be set to uninheritable
# then it probably wasn't one that would get inherited in the first place.
#
# For each open IO object
ObjectSpace.each_object(IO) do |io|
if !io.closed?
fileno = io.fileno
@@logger.debug("Setting file handle #{fileno} to not be inherited")
self.windows_uninherit_handle(fileno)
begin
self.windows_uninherit_handle(fileno)
rescue SystemCallError => error
msg = "Warning: couldn't set file handle #{fileno} to not be inherited\n"
msg+= "Message: " + error.message + "\n"
msg+= "Continuing in best effort...."
machine.ui.warn(msg)
@@logger.warn(msg)
end
end
end
end
Expand Down Expand Up @@ -226,7 +241,7 @@ def self.sshfs_slave_mount(machine, opts, hostpath, expanded_guest_path)
# For windows we need to set it so not all file handles are inherited
# by default. See https://github.com/dustymabe/vagrant-sshfs/issues/41
# The r1,r2,w1,w2,f1,f2 we pass below will get set back to be shared
self.windows_uninherit_handles
self.windows_uninherit_handles(machine)
# For windows, we are using win32-process' Process.create because ruby
# doesn't properly detach processes. See https://github.com/dustymabe/vagrant-sshfs/issues/31
Process.create(:command_line => sftp_server_cmd,
Expand Down

0 comments on commit fe4fcd5

Please sign in to comment.