summaryrefslogtreecommitdiffstats
path: root/perl-install
diff options
context:
space:
mode:
authorPascal Rigaux <pixel@mandriva.com>2002-11-06 22:14:12 +0000
committerPascal Rigaux <pixel@mandriva.com>2002-11-06 22:14:12 +0000
commitd3271db5a1609ee14b6f3a57aed7925644a5dabe (patch)
tree7c38191e6074d6bf7f28d8d2d7dd96e879eea009 /perl-install
parent9281bc5381cfb7a11cc6470de4a4766c4ff8f771 (diff)
downloaddrakx-backup-do-not-use-d3271db5a1609ee14b6f3a57aed7925644a5dabe.tar
drakx-backup-do-not-use-d3271db5a1609ee14b6f3a57aed7925644a5dabe.tar.gz
drakx-backup-do-not-use-d3271db5a1609ee14b6f3a57aed7925644a5dabe.tar.bz2
drakx-backup-do-not-use-d3271db5a1609ee14b6f3a57aed7925644a5dabe.tar.xz
drakx-backup-do-not-use-d3271db5a1609ee14b6f3a57aed7925644a5dabe.zip
(write_resolv_conf): much cleanup (originally it was meant to introduce
cat_ and output, but it ended up with a complete rewrite :)
Diffstat (limited to 'perl-install')
-rw-r--r--perl-install/network/network.pm71
1 files changed, 37 insertions, 34 deletions
diff --git a/perl-install/network/network.pm b/perl-install/network/network.pm
index ed5c7f0f5..ceb9f4314 100644
--- a/perl-install/network/network.pm
+++ b/perl-install/network/network.pm
@@ -81,43 +81,46 @@ sub write_conf {
sub write_resolv_conf {
my ($file, $netc) = @_;
- #- get the list of used dns.
- my %used_dns; @used_dns{$netc->{dnsServer}, $netc->{dnsServer2}, $netc->{dnsServer3}} = (1, 2, 3);
-
- if (!$netc->{DOMAINNAME} && !$netc->{DOMAINNAME2} && !%used_dns) {
- unlink($file);
- log::l("neither domain name nor dns server are configured");
- return 0;
+ my %new = (
+ search => [ grep { $_ } uniq(@$netc{'DOMAINNAME', 'DOMAINNAME2'}) ],
+ nameserver => [ grep { $_ } uniq(@$netc{'dnsServer', 'dnsServer2', 'dnsServer3'}) ],
+ );
+
+ my (%prev, @unknown);
+ foreach (cat_($file)) {
+ s/\s+$//;
+ s/^[#\s]*//;
+
+ if (my ($key, $val) = /^(search|nameserver)\s+(.*)$/) {
+ push @{$prev{$key}}, $val;
+ } elsif (/^ppp temp entry$/) {
+ } elsif (/\S/) {
+ push @unknown, $_;
+ }
}
+ unlink $file; #- workaround situation when /etc/resolv.conf is an absolute link to /etc/ppp/resolv.conf or whatever
- my (%search, %dns, @unknown);
- local *F; open F, $file;
- local $_;
-#- my $options;
- while (<F>) {
-#- if (/^[\s]*(options\s+[^#]*).*$/) { $options = $1; $options =~ s/timeout:\d+/timeout:1/; next }
- /^[#\s]*search\s+(.*?)\s*$/ and $search{$1} = $., next;
- /^[#\s]*nameserver\s+(.*?)\s*$/ and $dns{$1} = $., next;
- /^.*# ppp temp entry\s*$/ and next;
- /^[#\s]*(\S.*?)\s*$/ and push @unknown, $1;
+ if (@{$new{search}} || @{$new{nameserver}}) {
+ $prev{$_} = [ difference2($prev{$_} || [], $new{$_}) ] foreach keys %new;
+
+ my @search = do {
+ my @new = if_(@{$new{search}}, "search " . join(' ', @{$new{search}}) . "\n");
+ my @old = if_(@{$prev{search}}, "# search " . join(' ', @{$prev{search}}) . "\n");
+ @new, @old;
+ };
+ my @nameserver = do {
+ my @new = map { "nameserver $_\n" } @{$new{nameserver}};
+ my @old = map { "# nameserver $_\n" } @{$prev{nameserver}};
+ @new, @old;
+ };
+ output($file, @search, @nameserver, (map { "# $_\n" } @unknown), "\n# ppp temp entry\n");
+
+ #-res_init(); # reinit the resolver so DNS changes take affect
+ 1;
+ } else {
+ log::l("neither domain name nor dns server are configured");
+ 0;
}
-#- $options ||= "options timeout:1";
-
- close F;
- unlink $file; #- workaround situation when /etc/resolv.conf is an absolute link to /etc/ppp/resolv.conf or whatever
- open F, ">$file" or die "cannot write $file: $!";
- print F "# search $_\n" foreach grep { $_ ne "$netc->{DOMAINNAME} $netc->{DOMAINNAME2}" } sort { $search{$a} <=> $search{$b} } keys %search;
- print F "search $netc->{DOMAINNAME} $netc->{DOMAINNAME2}\n" if $netc->{DOMAINNAME} || $netc->{DOMAINNAME2};
-#- print F "$options\n\n";
- print F "# nameserver $_\n" foreach grep { ! exists $used_dns{$_} } sort { $dns{$a} <=> $dns{$b} } keys %dns;
- print F "nameserver $_\n" foreach sort { $used_dns{$a} <=> $used_dns{$b} } grep { $_ } keys %used_dns;
- print F "\n";
- print F "# $_\n" foreach @unknown;
- print F "\n";
- print F "# ppp temp entry\n";
-
- #-res_init(); # reinit the resolver so DNS changes take affect
- 1;
}
sub write_interface_conf {