[pve-devel] [PATCH] pve-manager: use domain instead of search in /etc/resolv.conf

Damien PIQUET piqudam at gmail.com
Fri Mar 8 16:41:32 CET 2013


Signed-off-by: Damien PIQUET <piqudam at gmail.com>
---
 data/PVE/INotify.pm |   20 +++++++++++++++-----
 1 file changed, 15 insertions(+), 5 deletions(-)

diff --git a/data/PVE/INotify.pm b/data/PVE/INotify.pm
index 850668a..35c71b9 100644
--- a/data/PVE/INotify.pm
+++ b/data/PVE/INotify.pm
@@ -532,13 +532,18 @@ sub read_etc_resolv_conf {
     my ($filename, $fh) = @_;
 
     my $res = {};
+    my $search;
 
     my $nscount = 0;
     while (my $line = <$fh>) {
 	chomp $line;
-	if ($line =~ m/^(search|domain)\s+(\S+)\s*/) {
-	    $res->{search} = $2;
-	} elsif ($line =~ m/^nameserver\s+(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})\s*/) {
+	if ($line =~ m/^search\s+(.+)/) {
+	    $search = $1;
+	}
+	elsif ($line =~ m/^domain\s+(.+)/) {
+	    $res->{search} = $1;
+	}
+	elsif ($line =~ m/^nameserver\s+(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})\s*/) {
 	    $nscount++;
 	    if ($nscount <= 3) {
 		$res->{"dns$nscount"} = $1;
@@ -546,6 +551,11 @@ sub read_etc_resolv_conf {
 	}
     }
 
+    if (!defined $res->{search} && $search) {
+	$search =~ m/(\S+)/;
+	$res->{search} = $1;
+    }
+
     return $res;
 }
 
@@ -554,7 +564,7 @@ sub update_etc_resolv_conf {
 
     my $data = "";
 
-    $data = "search $resolv->{search}\n"
+    $data = "domain $resolv->{search}\n"
 	if $resolv->{search};
 
     my $written = {};
@@ -567,7 +577,7 @@ sub update_etc_resolv_conf {
     }
 
     while (my $line = <$fh>) {
-	next if $line =~ m/^(search|domain|nameserver)\s+/;
+	next if $line =~ m/^(domain|nameserver)\s+/;
 	$data .= $line
     }
     
-- 
1.7.10.4




More information about the pve-devel mailing list