diff options
author | Eugeni Dodonov <eugeni@mandriva.org> | 2009-11-19 17:54:31 +0000 |
---|---|---|
committer | Eugeni Dodonov <eugeni@mandriva.org> | 2009-11-19 17:54:31 +0000 |
commit | fe92e227468d712c8307368d0c41b9af4a45977a (patch) | |
tree | 0a22901e5a4e6298cb211e548bcf9cece7ef7ac5 | |
parent | d4ea677403a9e75794eca517ca3f9928d404a164 (diff) | |
download | drakx-net-fe92e227468d712c8307368d0c41b9af4a45977a.tar drakx-net-fe92e227468d712c8307368d0c41b9af4a45977a.tar.gz drakx-net-fe92e227468d712c8307368d0c41b9af4a45977a.tar.bz2 drakx-net-fe92e227468d712c8307368d0c41b9af4a45977a.tar.xz drakx-net-fe92e227468d712c8307368d0c41b9af4a45977a.zip |
Do not mess up /etc/hosts file when there are multiple aliases for same
IP, use similar procedure as drakhosts instead (#30168)
-rw-r--r-- | lib/network/network.pm | 19 |
1 files changed, 13 insertions, 6 deletions
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! |