Skip to content

Commit

Permalink
Fix #120: do not pass our file descriptors to spawned children
Browse files Browse the repository at this point in the history
  • Loading branch information
Ian2020 committed Dec 2, 2020
1 parent dbcf14d commit 2615783
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/vagrant-sshfs/cap/guest/linux/sshfs_forward_mount.rb
Original file line number Diff line number Diff line change
Expand Up @@ -288,8 +288,8 @@ def self.sshfs_slave_mount(machine, opts, hostpath, expanded_guest_path)
:thread_inherit => true,
:startup_info => {:stdin => w1, :stdout => r2, :stderr => f2})
else
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)
p1 = spawn(sftp_server_cmd, :out => w2, :in => r1, :err => f1, :pgroup => true, :close_others=>true)
p2 = spawn(ssh_cmd, :out => w1, :in => r2, :err => f2, :pgroup => true, :close_others=>true)

# Detach from the processes so they will keep running
Process.detach(p1)
Expand Down
11 changes: 11 additions & 0 deletions test/misc/README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ export THIRD_PARTY_HOST='192.168.121.73'
export THIRD_PARTY_HOST_USER='vagrant'
export THIRD_PARTY_HOST_PASS='vagrant'

# Open an extra file descriptor to test it is not passed onto child processes
# https://github.com/dustymabe/vagrant-sshfs/issues/120
tmpfile=$(mktemp)
exec {extra_fd}<> "$tmpfile"

# Next vagrant up - will do 4 mounts
# - slave
# - slave with sym link
Expand All @@ -34,3 +39,9 @@ Testing reverse mount!
# We are printing out the machine-id under each mount. The first two
should be the same, because they are from the same machine. The last
two should be different.

# Close our file descriptor. No other process should be using it
exec {extra_fd}>&-
if sudo lsof -wn -d $extra_fd | grep -q "$tmpfile"; then
echo "Failure: there are processes running that hold an inherited file descriptor"
fi

0 comments on commit 2615783

Please sign in to comment.