From ce289e3c6e7c5bc59c41b5fa3abfd667a96fa684 Mon Sep 17 00:00:00 2001 From: Wolfgang Bumiller Date: Fri, 27 Nov 2015 12:24:03 +0100 Subject: [PATCH] fix bug #827: Setup: don't replace fqdn with searchdomain in /etc/hosts --- debian/changelog | 2 ++ src/PVE/LXC/Setup/Base.pm | 20 +++++++++++++------- src/test/test-debian-004/config | 2 +- src/test/test-debian-004/etc/hosts.exp | 2 +- 4 files changed, 17 insertions(+), 9 deletions(-) diff --git a/debian/changelog b/debian/changelog index 758a2f7..0f53bea 100644 --- a/debian/changelog +++ b/debian/changelog @@ -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 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.39.2