Skip to content

Commit 5ab43ea

Browse files
authored
Merge pull request #2694 from Geod24/mlang/workaround2693
networking: Workaround 2693 by ignoring resolv.conf entries starting with dot
2 parents 92a6484 + 0181bb7 commit 5ab43ea

File tree

3 files changed

+28
-4
lines changed

3 files changed

+28
-4
lines changed

lib/facter/resolvers/hostname.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,9 @@ def hostname_and_no_domain?(hostname, domain)
6868

6969
def read_domain
7070
file_content = Facter::Util::FileHelper.safe_read('/etc/resolv.conf')
71-
if file_content =~ /^domain\s+(\S+)/
71+
if file_content =~ /^domain\s+([^.]\S+)/
7272
Regexp.last_match(1)
73-
elsif file_content =~ /^search\s+(\S+)/
73+
elsif file_content =~ /^search\s+([^.]\S+)/
7474
Regexp.last_match(1)
7575
end
7676
end

lib/facter/resolvers/linux/hostname.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,9 @@ def hostname_and_no_domain?(hostname, domain)
9696

9797
def read_domain
9898
file_content = Facter::Util::FileHelper.safe_read('/etc/resolv.conf')
99-
if file_content =~ /^domain\s+(\S+)/
99+
if file_content =~ /^domain\s+([^.]\S+)/
100100
Regexp.last_match(1)
101-
elsif file_content =~ /^search\s+(\S+)/
101+
elsif file_content =~ /^search\s+([^.]\S+)/
102102
Regexp.last_match(1)
103103
end
104104
end

spec/facter/resolvers/linux/hostname_spec.rb

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,30 @@
7979

8080
it_behaves_like 'detects values'
8181
end
82+
83+
context 'when /etc/resolv.conf has "search ."' do
84+
let(:resolv_conf) { "search .\n" }
85+
let(:domain) { nil }
86+
let(:fqdn) { hostname }
87+
88+
it_behaves_like 'detects values'
89+
end
90+
91+
context 'when /etc/resolv.conf has "search ." with multiple entires' do
92+
let(:resolv_conf) { 'search . foo.bar' }
93+
let(:domain) { nil }
94+
let(:fqdn) { hostname }
95+
96+
it_behaves_like 'detects values'
97+
end
98+
99+
context 'when /etc/resolv.conf has "search" with multiple entires' do
100+
let(:resolv_conf) { 'search foo.bar example.com' }
101+
let(:domain) { 'foo.bar' }
102+
let(:fqdn) { "#{hostname}.#{domain}" }
103+
104+
it_behaves_like 'detects values'
105+
end
82106
end
83107

84108
context 'when FFI is not installed' do

0 commit comments

Comments
 (0)