[pve-devel] [PATCH container] Setup: order fqdn before hostname in /etc/hosts

Wolfgang Bumiller w.bumiller at proxmox.com
Mon Dec 14 14:02:18 CET 2015


Some services seem to require this to lookup the local fqdn.
This only affects /etc/hosts while /etc/hostname still uses
the non-fqdn hostname.

This is also consistent with behavior in 4.0 (before commit
ce289e3c6e).

Fixes #845
---
 src/PVE/LXC/Setup/Base.pm              | 14 ++++++++------
 src/test/test-debian-004/etc/hosts.exp |  2 +-
 2 files changed, 9 insertions(+), 7 deletions(-)

diff --git a/src/PVE/LXC/Setup/Base.pm b/src/PVE/LXC/Setup/Base.pm
index 7627f55..8991b29 100644
--- a/src/PVE/LXC/Setup/Base.pm
+++ b/src/PVE/LXC/Setup/Base.pm
@@ -62,14 +62,16 @@ sub update_etc_hosts {
 
     my $namepart = ($newname =~ s/\..*$//r);
 
-    my $extra_names = '';
+    my $all_names = '';
     if ($newname =~ /\./) {
-	$extra_names .= $namepart;
+	$all_names .= "$newname $namepart";
     } else {
 	foreach my $domain (PVE::Tools::split_list($searchdomains)) {
-	    $extra_names .= ' ' if $extra_names;
-	    $extra_names .= "$newname.$domain";
+	    $all_names .= ' ' if $all_names;
+	    $all_names .= "$newname.$domain";
 	}
+	$all_names .= ' ' if $all_names;
+	$all_names .= $newname;
     }
     
     foreach my $line (split(/\n/, $etc_hosts_data)) {
@@ -97,7 +99,7 @@ sub update_etc_hosts {
 	if ($found) {
 	    if (!$done) {
 		if (defined($hostip)) {
-		    push @lines, "$hostip $extra_names $newname";
+		    push @lines, "$hostip $all_names";
 		} else {
 		    push @lines, "127.0.1.1 $namepart";
 		}
@@ -111,7 +113,7 @@ sub update_etc_hosts {
 
     if (!$done) {
 	if (defined($hostip)) {
-	    push @lines, "$hostip $extra_names $newname";
+	    push @lines, "$hostip $all_names";
 	} else {
 	    push @lines, "127.0.1.1 $namepart";
 	}	
diff --git a/src/test/test-debian-004/etc/hosts.exp b/src/test/test-debian-004/etc/hosts.exp
index 988a1e7..cd65bdf 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 test3.use-fqdn.com
+1.2.3.2 test3.use-fqdn.com test3
-- 
2.1.4





More information about the pve-devel mailing list