Fixing bug #13: multiple fetch-ip but introducing a multiple ip bug

git-svn-id: svn+ssh://svn.code.sf.net/p/ddclient/code/trunk@121 3873ddee-7413-0410-b6c4-c2c57c1ab35a
This commit is contained in:
wimpunk 2010-10-13 20:29:16 +00:00
parent 4edbb7a3e9
commit e406318257

View file

@ -740,47 +740,58 @@ sub runpostscript {
## update_nics
######################################################################
sub update_nics {
my %examined = ();
my %examined = ();
my %iplist = ();
foreach my $s (sort keys %services) {
my (@hosts, %ips) = ();
my $updateable = $services{$s}{'updateable'};
my $update = $services{$s}{'update'};
foreach my $s (sort keys %services) {
my (@hosts, %ips) = ();
my $updateable = $services{$s}{'updateable'};
my $update = $services{$s}{'update'};
foreach my $h (sort keys %config) {
next if $config{$h}{'protocol'} ne lc($s);
$examined{$h} = 1;
my $use = $config{$h}{'use'} || opt('use');
local $opt{$use} = $config{$h}{$use} if $config{$h}{$use};
# bug #13: we should only do this once
# use isn't enough, we have to save the origin to.
# this will break the multiple ip stuff if use has
# been used twice for the same device.
my $ip = "";
if (defined $iplist{$use}) {
$ip = $iplist{$use};
} else {
$ip = get_ip($use, $h);
if (!defined $ip || !$ip) {
warning("unable to determine IP address")
if !$daemon || opt('verbose');
next;
}
if ($ip !~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
warning("malformed IP address (%s)", $ip);
next;
}
$iplist{$use} = $ip;
}
$config{$h}{'wantip'} = $ip;
next if !nic_updateable($h, $updateable);
push @hosts, $h;
$ips{$ip} = $h;
}
if (@hosts) {
$0 = sprintf("%s - updating %s", $program, join(',', @hosts));
&$update(@hosts);
runpostscript(join ' ', keys %ips);
}
}
foreach my $h (sort keys %config) {
next if $config{$h}{'protocol'} ne lc($s);
$examined{$h} = 1;
my $use = $config{$h}{'use'} || opt('use');
local $opt{$use} = $config{$h}{$use} if $config{$h}{$use};
my $ip = get_ip($use, $h);
if (!defined $ip || !$ip) {
warning("unable to determine IP address")
if !$daemon || opt('verbose');
next;
}
if ($ip !~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
warning("malformed IP address (%s)", $ip);
next;
}
$config{$h}{'wantip'} = $ip;
next if !nic_updateable($h, $updateable);
push @hosts, $h;
$ips{$ip} = $h;
if (!exists $examined{$h}) {
failed("%s was not updated because protocol %s is not supported.",
$h, define($config{$h}{'protocol'}, '<undefined>')
);
}
}
if (@hosts) {
$0 = sprintf("%s - updating %s", $program, join(',', @hosts));
&$update(@hosts);
runpostscript(join ' ', keys %ips);
}
}
foreach my $h (sort keys %config) {
if (!exists $examined{$h}) {
failed("%s was not updated because protocol %s is not supported.",
$h, define($config{$h}{'protocol'}, '<undefined>')
);
}
}
write_cache(opt('cache'));
write_cache(opt('cache'));
}
######################################################################
## unlink_pid()