Skip to content

Commit

Permalink
sshfs_mount: redirect STDERR streams to predictable files
Browse files Browse the repository at this point in the history
This will allow us to print the error logs on failure. Also fixes #29.
  • Loading branch information
dustymabe committed Jul 28, 2016
1 parent 7f7d7b7 commit b7ac26c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 13 deletions.
25 changes: 15 additions & 10 deletions lib/vagrant-sshfs/cap/linux/sshfs_mount.rb
Original file line number Diff line number Diff line change
Expand Up @@ -149,11 +149,13 @@ def self.sshfs_slave_mount(machine, opts, hostpath, expanded_guest_path)
r1, w1 = IO.pipe # reader/writer from pipe1
r2, w2 = IO.pipe # reader/writer from pipe2

# 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')
t2 = Tempfile.new('vagrant_sshfs_ssh_stderr')
# Log STDERR to predictable files so that we can inspect them
# later in case things go wrong. We'll use the machines data
# directory (i.e. .vagrant/machines/default/virtualbox/) for this
f1path = machine.data_dir.join('vagrant_sshfs_sftp_server_stderr.txt')
f2path = machine.data_dir.join('vagrant_sshfs_ssh_stderr.txt')
f1 = File.new(f1path, 'w+')
f2 = File.new(f2path, 'w+')

# 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 @@ -177,16 +179,16 @@ def self.sshfs_slave_mount(machine, opts, hostpath, expanded_guest_path)
:creation_flags => Process::DETACHED_PROCESS,
:process_inherit => false,
:thread_inherit => true,
:startup_info => {:stdin => w2, :stdout => r1, :stderr => t1})
:startup_info => {:stdin => w2, :stdout => r1, :stderr => f1})

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})
:startup_info => {:stdin => w1, :stdout => r2, :stderr => f2})
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)
p1 = spawn(sftp_server_cmd, :out => w2, :in => r1, :err => f1, :pgroup => true)
p2 = spawn(ssh_cmd, :out => w1, :in => r2, :err => f2, :pgroup => true)

# Detach from the processes so they will keep running
Process.detach(p1)
Expand All @@ -204,7 +206,10 @@ def self.sshfs_slave_mount(machine, opts, hostpath, expanded_guest_path)
sleep(2)
end
if !mounted
raise VagrantPlugins::SyncedFolderSSHFS::Errors::SSHFSSlaveMountFailed
f1.rewind # Seek to beginning of the file
f2.rewind # Seek to beginning of the file
error_class = VagrantPlugins::SyncedFolderSSHFS::Errors::SSHFSSlaveMountFailed
raise error_class, sftp_stderr: f1.read, ssh_stderr: f2.read
end
machine.ui.info("Folder Successfully Mounted!")
end
Expand Down
13 changes: 10 additions & 3 deletions locales/synced_folder_sshfs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,16 @@ en:
%{stderr}
slave_mount_failed: |-
Mounting SSHFS shared via slave SSHFS mount failed. Please look at your
terminal scrollback to look for any error messages from the processes that
were run.
Mounting SSHFS shared folder via slave SSHFS mount failed. Please
look at the below STDERR output from the processes that were run.
SSH command:
%{ssh_stderr}
SFTP command:
%{sftp_stderr}
unmount_failed: |-
Unmount the SSHFS mount failed.
Expand Down

0 comments on commit b7ac26c

Please sign in to comment.