From c50fb6ef15830a01de0a02e2148176a361f47d5e Mon Sep 17 00:00:00 2001 From: Dusty Mabe Date: Mon, 3 May 2021 14:58:39 -0400 Subject: [PATCH] More places where we can not pass file descriptors. This is a follow up to 2615783. We can also use `:close_others` in the reverse mounting case. Caught this because running the test from test/misc/README.txt turned up a leaked process. --- lib/vagrant-sshfs/cap/guest/linux/sshfs_forward_mount.rb | 4 ++-- lib/vagrant-sshfs/cap/host/darwin/sshfs_reverse_mount.rb | 2 +- lib/vagrant-sshfs/cap/host/linux/sshfs_reverse_mount.rb | 2 +- test/misc/README.txt | 2 +- 4 files changed, 5 insertions(+), 5 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 215f5f5..3dbc804 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, :close_others=>true) - p2 = spawn(ssh_cmd, :out => w1, :in => r2, :err => f2, :pgroup => true, :close_others=>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/lib/vagrant-sshfs/cap/host/darwin/sshfs_reverse_mount.rb b/lib/vagrant-sshfs/cap/host/darwin/sshfs_reverse_mount.rb index afe1cb9..cfcdf93 100644 --- a/lib/vagrant-sshfs/cap/host/darwin/sshfs_reverse_mount.rb +++ b/lib/vagrant-sshfs/cap/host/darwin/sshfs_reverse_mount.rb @@ -120,7 +120,7 @@ def self.sshfs_mount(machine, opts) :thread_inherit => true, :startup_info => {:stdin => w2, :stdout => r1, :stderr => f1}) else - p1 = spawn(sshfs_cmd, :out => f1, :err => f1, :pgroup => true) + p1 = spawn(sshfs_cmd, :out => f1, :err => f1, :pgroup => true, :close_others => true) Process.detach(p1) # Detach so process will keep running end diff --git a/lib/vagrant-sshfs/cap/host/linux/sshfs_reverse_mount.rb b/lib/vagrant-sshfs/cap/host/linux/sshfs_reverse_mount.rb index 8d2cddf..5296409 100644 --- a/lib/vagrant-sshfs/cap/host/linux/sshfs_reverse_mount.rb +++ b/lib/vagrant-sshfs/cap/host/linux/sshfs_reverse_mount.rb @@ -117,7 +117,7 @@ def self.sshfs_mount(machine, opts) :thread_inherit => true, :startup_info => {:stdin => w2, :stdout => r1, :stderr => f1}) else - p1 = spawn(sshfs_cmd, :out => f1, :err => f1, :pgroup => true) + p1 = spawn(sshfs_cmd, :out => f1, :err => f1, :pgroup => true, :close_others => true) Process.detach(p1) # Detach so process will keep running end diff --git a/test/misc/README.txt b/test/misc/README.txt index a0ac7b2..6c8c2d6 100644 --- a/test/misc/README.txt +++ b/test/misc/README.txt @@ -42,6 +42,6 @@ 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 +if lsof -wn -d $extra_fd | grep "$tmpfile"; then echo "Failure: there are processes running that hold an inherited file descriptor" fi