[pve-devel] [PATCH pve-container 2/2] Setup: don't replace fqdn with searchdomain in /etc/hosts

Wolfgang Bumiller w.bumiller at proxmox.com
Fri Nov 27 12:24:03 CET 2015


Fixes #827
---
 src/PVE/LXC/Setup/Base.pm              | 20 +++++++++++++-------
 src/test/test-debian-004/config        |  2 +-
 src/test/test-debian-004/etc/hosts.exp |  2 +-
 3 files changed, 15 insertions(+), 9 deletions(-)

diff --git a/src/PVE/LXC/Setup/Base.pm b/src/PVE/LXC/Setup/Base.pm
index 0d50583..65f7bdd 100644
--- a/src/PVE/LXC/Setup/Base.pm
+++ b/src/PVE/LXC/Setup/Base.pm
@@ -60,10 +60,16 @@ sub update_etc_hosts {
 
     my @lines;
 
+    my $namepart = ($newname =~ s/\..*$//r);
+
     my $extra_names = '';
-    foreach my $domain (PVE::Tools::split_list($searchdomains)) {
-	$extra_names .= ' ' if $extra_names;
-	$extra_names .= "$newname.$domain";
+    if ($newname =~ /\./) {
+	$extra_names .= $namepart;
+    } else {
+	foreach my $domain (PVE::Tools::split_list($searchdomains)) {
+	    $extra_names .= ' ' if $extra_names;
+	    $extra_names .= "$newname.$domain";
+	}
     }
     
     foreach my $line (split(/\n/, $etc_hosts_data)) {
@@ -93,7 +99,7 @@ sub update_etc_hosts {
 		if (defined($hostip)) {
 		    push @lines, "$hostip $extra_names $newname";
 		} else {
-		    push @lines, "127.0.1.1 $newname";
+		    push @lines, "127.0.1.1 $namepart";
 		}
 		$done = 1;
 	    }
@@ -107,7 +113,7 @@ sub update_etc_hosts {
 	if (defined($hostip)) {
 	    push @lines, "$hostip $extra_names $newname";
 	} else {
-	    push @lines, "127.0.1.1 $newname";
+	    push @lines, "127.0.1.1 $namepart";
 	}	
     }
 
@@ -156,7 +162,7 @@ sub set_hostname {
     
     my $hostname = $conf->{hostname} || 'localhost';
 
-    $hostname =~ s/\..*$//;
+    my $namepart = ($hostname =~ s/\..*$//r);
 
     my $hostname_fn = "/etc/hostname";
     
@@ -177,7 +183,7 @@ sub set_hostname {
     $etc_hosts_data = update_etc_hosts($etc_hosts_data, $hostip, $oldname, 
 				       $hostname, $searchdomains);
     
-    $self->ct_file_set_contents($hostname_fn, "$hostname\n");
+    $self->ct_file_set_contents($hostname_fn, "$namepart\n");
     $self->ct_file_set_contents($hosts_fn, $etc_hosts_data);
 }
 
diff --git a/src/test/test-debian-004/config b/src/test/test-debian-004/config
index 763cd43..bdd25d7 100644
--- a/src/test/test-debian-004/config
+++ b/src/test/test-debian-004/config
@@ -1,5 +1,5 @@
 arch: i386
 memory: 512
 ostype: debian
-hostname: test3
+hostname: test3.use-fqdn.com
 net0: bridge=vmbr0,name=eth0,hwaddr=26:2B:CC:E5:7F:F9,ip=1.2.3.2/24,gw=1.2.3.1
diff --git a/src/test/test-debian-004/etc/hosts.exp b/src/test/test-debian-004/etc/hosts.exp
index dab599c..988a1e7 100644
--- a/src/test/test-debian-004/etc/hosts.exp
+++ b/src/test/test-debian-004/etc/hosts.exp
@@ -1,2 +1,2 @@
 127.0.0.1 localhost.localnet localhost
-1.2.3.2 test3.proxmox.com test3
+1.2.3.2 test3 test3.use-fqdn.com
-- 
2.1.4





More information about the pve-devel mailing list