Skip to content
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

networking: Workaround 2693 by ignoring resolv.conf entries starting with dot #2694

Merged
merged 1 commit into from
Oct 8, 2024
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions lib/facter/resolvers/hostname.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ def hostname_and_no_domain?(hostname, domain)

def read_domain
file_content = Facter::Util::FileHelper.safe_read('/etc/resolv.conf')
if file_content =~ /^domain\s+(\S+)/
if file_content =~ /^domain\s+([^.]\S+)/
Regexp.last_match(1)
elsif file_content =~ /^search\s+(\S+)/
elsif file_content =~ /^search\s+([^.]\S+)/
Regexp.last_match(1)
end
end
Expand Down
4 changes: 2 additions & 2 deletions lib/facter/resolvers/linux/hostname.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,9 @@ def hostname_and_no_domain?(hostname, domain)

def read_domain
file_content = Facter::Util::FileHelper.safe_read('/etc/resolv.conf')
if file_content =~ /^domain\s+(\S+)/
if file_content =~ /^domain\s+([^.]\S+)/
Regexp.last_match(1)
elsif file_content =~ /^search\s+(\S+)/
elsif file_content =~ /^search\s+([^.]\S+)/
AriaXLi marked this conversation as resolved.
Show resolved Hide resolved
Regexp.last_match(1)
end
end
Expand Down
24 changes: 24 additions & 0 deletions spec/facter/resolvers/linux/hostname_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,30 @@

it_behaves_like 'detects values'
end

context 'when /etc/resolv.conf has "search ."' do
let(:resolv_conf) { "search .\n" }
let(:domain) { nil }
let(:fqdn) { hostname }

it_behaves_like 'detects values'
end

context 'when /etc/resolv.conf has "search ." with multiple entires' do
let(:resolv_conf) { 'search . foo.bar' }
let(:domain) { nil }
let(:fqdn) { hostname }

it_behaves_like 'detects values'
end

context 'when /etc/resolv.conf has "search" with multiple entires' do
let(:resolv_conf) { 'search foo.bar example.com' }
let(:domain) { 'foo.bar' }
let(:fqdn) { "#{hostname}.#{domain}" }

it_behaves_like 'detects values'
end
end

context 'when FFI is not installed' do
Expand Down
Loading