From fe92e227468d712c8307368d0c41b9af4a45977a Mon Sep 17 00:00:00 2001 From: Eugeni Dodonov Date: Thu, 19 Nov 2009 17:54:31 +0000 Subject: Do not mess up /etc/hosts file when there are multiple aliases for same IP, use similar procedure as drakhosts instead (#30168) --- lib/network/network.pm | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) (limited to 'lib/network/network.pm') diff --git a/lib/network/network.pm b/lib/network/network.pm index eb88435..fa8df00 100644 --- a/lib/network/network.pm +++ b/lib/network/network.pm @@ -243,16 +243,23 @@ sub add2hosts { my $file = "$::prefix/etc/hosts"; - my %l; + my @l; + push(@l, [$_, $hostname, if_($sub_hostname, $sub_hostname)]) foreach(@ips); foreach (cat_($file)) { + # strip our own comments + next if ($_ =~ /# generated by drak.*/); my ($ip, $aliases) = /^\s*(\S+)\s+(\S+.*)$/ or next; - push @{$l{$ip}}, difference2([ split /\s+/, $aliases ], [ $hostname, $sub_hostname ]); - } cat_($file); - - unshift @{$l{$_}}, $hostname, if_($sub_hostname, $sub_hostname) foreach grep { $_ } @ips; + my @hosts = difference2([ split /\s+/, $aliases ], [ $hostname, $sub_hostname ]); + if (@hosts) { + push (@l, [$ip, @hosts]); + } + }; log::explanations("writing host information to $file"); - output($file, map { "$_\t\t" . join(" ", @{$l{$_}}) . "\n" } keys %l); + output($file, "# generated by drakconnect\n"); + foreach (@l) { + append_to_file($file, join(" ", @{$_}) . "\n"); + } } # The interface/gateway needs to be configured before this will work! -- cgit v1.2.1