[pve-devel] [PATCH common v2 2/2] Fix #1234: allows multiple search domains to be set

Emmanuel Kasper e.kasper at proxmox.com
Tue Apr 4 15:26:24 CEST 2017


---
 src/PVE/INotify.pm | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/src/PVE/INotify.pm b/src/PVE/INotify.pm
index 074f8b3..5f08439 100644
--- a/src/PVE/INotify.pm
+++ b/src/PVE/INotify.pm
@@ -539,11 +539,16 @@ sub read_etc_resolv_conf {
     my $nscount = 0;
     while (my $line = <$fh>) {
 	chomp $line;
-	# resolv.conf should *either* have a search or domain, else behaviour is undefined
-	# see res_init.c in libc, havesearch is set to 0 when a domain entry is found
-	if ($line =~ m/^(search|domain)\s+(\S+)\s*/) {
-	    $res->{search} = $2;
-	} elsif ($line =~ m/^\s*nameserver\s+($PVE::Tools::IPRE)\s*/) {
+	# resolv.conf should *either* have a search or domain, else
+	# last one found wins, see resolv.conf(5)
+	if ($line =~ m/^domain\s+(\S+)\s*$/) {
+	    $res->{search} = $1;
+	}
+	elsif ($line =~ m/^search\s+((?:\S+\s*)*)$/) {
+	    (my $domains = $1) =~ s/\s+$//;
+	    $res->{search} = $domains;
+	}
+	elsif ($line =~ m/^\s*nameserver\s+($PVE::Tools::IPRE)\s*/) {
 	    $nscount++;
 	    if ($nscount <= 3) {
 		$res->{"dns$nscount"} = $1;
-- 
2.1.4





More information about the pve-devel mailing list