]> git.proxmox.com Git - pve-container.git/commitdiff
fix bug #827: Setup: don't replace fqdn with searchdomain in /etc/hosts
authorWolfgang Bumiller <w.bumiller@proxmox.com>
Fri, 27 Nov 2015 11:24:03 +0000 (12:24 +0100)
committerDietmar Maurer <dietmar@proxmox.com>
Fri, 27 Nov 2015 16:22:24 +0000 (17:22 +0100)
debian/changelog
src/PVE/LXC/Setup/Base.pm
src/test/test-debian-004/config
src/test/test-debian-004/etc/hosts.exp

index 758a2f7e14ff7029051b61857e89f39ef93922b0..0f53beaf7d7ef779a7f24ad034354b87f6e0e1c0 100644 (file)
@@ -1,5 +1,7 @@
 pve-container (1.0-27) unstable; urgency=medium
 
+  * fix bug #827: Setup: don't replace fqdn with searchdomain in /etc/hosts
+
   * add support for Fedora 22
   
   * add/restore firewall config with vzdump
index 0d50583acce24d6b3d29ed8271458b3e58bc033f..65f7bdd7e50bc5d845cd615aa31eafb976114227 100644 (file)
@@ -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);
 }
 
index 763cd431b83f81c8a0a310ec051580126166230e..bdd25d7df86e69d9342111473325eeda3f9d0680 100644 (file)
@@ -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
index dab599cd427cff939cdf6042738e7f9bad0dad4c..988a1e7c0ef84db5c944962b6f6dc4bb1f93138c 100644 (file)
@@ -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