From 26157837ddf41cacfbc319888500daddf8b50db4 Mon Sep 17 00:00:00 2001 From: Ian2020 Date: Wed, 2 Dec 2020 13:04:12 +0000 Subject: [PATCH] Fix #120: do not pass our file descriptors to spawned children --- .../cap/guest/linux/sshfs_forward_mount.rb | 4 ++-- test/misc/README.txt | 11 +++++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/lib/vagrant-sshfs/cap/guest/linux/sshfs_forward_mount.rb b/lib/vagrant-sshfs/cap/guest/linux/sshfs_forward_mount.rb index 83ee384..215f5f5 100644 --- a/lib/vagrant-sshfs/cap/guest/linux/sshfs_forward_mount.rb +++ b/lib/vagrant-sshfs/cap/guest/linux/sshfs_forward_mount.rb @@ -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) diff --git a/test/misc/README.txt b/test/misc/README.txt index 3821de8..a0ac7b2 100644 --- a/test/misc/README.txt +++ b/test/misc/README.txt @@ -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 @@ -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