summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEugeni Dodonov <eugeni@mandriva.org>2009-11-25 16:47:16 +0000
committerEugeni Dodonov <eugeni@mandriva.org>2009-11-25 16:47:16 +0000
commit7639695c14a74fe53430affb84595df238d5b8fe (patch)
treebe12fe2b9b87a1ec4335806106206bce4e2fabc7
parent7a918b00f35dc9422facdc42a7a0a5f6a94207dc (diff)
downloaddrakx-net-7639695c14a74fe53430affb84595df238d5b8fe.tar
drakx-net-7639695c14a74fe53430affb84595df238d5b8fe.tar.gz
drakx-net-7639695c14a74fe53430affb84595df238d5b8fe.tar.bz2
drakx-net-7639695c14a74fe53430affb84595df238d5b8fe.tar.xz
drakx-net-7639695c14a74fe53430affb84595df238d5b8fe.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.pm19
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!