Skip to content

Avoid closing directory we're iterating #9546

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions lib/puppet/util.rb
Original file line number Diff line number Diff line change
Expand Up @@ -478,13 +478,15 @@ def safe_posix_fork(stdin = $stdin, stdout = $stdout, stderr = $stderr, &block)
$stderr = STDERR

begin
Dir.foreach('/proc/self/fd') do |f|
if f != '.' && f != '..' && f.to_i >= 3
begin
IO.new(f.to_i).close
rescue
nil
end
d = Dir.new('/proc/self/fd')
ignore_fds = ['.', '..', d.fileno.to_s]
d.each_child do |f|
next if ignore_fds.include?(f) || f.to_i < 3

begin
IO.new(f.to_i).close
rescue
nil
end
end
rescue Errno::ENOENT, Errno::ENOTDIR # /proc/self/fd not found, /proc/self not a dir
Expand Down
Loading