Fix broken legacy status handling

`$config{$h}{'status'}` was always initialized to a non-`undef` value,
so the `//` fallbacks never did anything.  Instead, any protocol that
does not explicitly update the legacy `status` variable (such as
`godaddy`) would always appear to have failed even if it had
succeeded.

Change the `status*` variables to `undef` by default, and only set
them when an attempt is made so that the legacy `//` fallback works as
expected.
This commit is contained in:
Richard Hansen 2024-05-18 03:09:56 -04:00
parent f212613526
commit ba18535c51
2 changed files with 20 additions and 20 deletions

View file

@ -66,6 +66,8 @@ repository history](https://github.com/ddclient/ddclient/commits/master).
[#664](https://github.com/ddclient/ddclient/pull/664)
* Fixed "Scalar value better written as" Perl warning.
[#667](https://github.com/ddclient/ddclient/pull/667)
* Fixed unnecessary repeated updates for some services.
[#670](https://github.com/ddclient/ddclient/pull/670)
## 2023-11-23 v3.11.2

View file

@ -639,9 +639,9 @@ my %variables = (
'wtime' => setv(T_DELAY, 0, 1, 0, interval('30s')),
'mtime' => setv(T_NUMBER,0, 1, 0, undef),
'atime' => setv(T_NUMBER,0, 1, 0, undef),
'status' => setv(T_ANY, 0, 1, '', undef), #TODO remove from cache?
'status-ipv4' => setv(T_ANY, 0, 1, '', undef),
'status-ipv6' => setv(T_ANY, 0, 1, '', undef),
'status' => setv(T_ANY, 0, 1, undef, undef), #TODO remove from cache?
'status-ipv4' => setv(T_ANY, 0, 1, undef, undef),
'status-ipv6' => setv(T_ANY, 0, 1, undef, undef),
'min-interval' => setv(T_DELAY, 0, 0, interval('30s'), 0),
'max-interval' => setv(T_DELAY, 0, 0, interval('25d'), 0),
'min-error-interval' => setv(T_DELAY, 0, 0, interval('5m'), 0),
@ -1452,10 +1452,8 @@ sub update_nics {
# To allow gradual transition, we make sure both the old 'status' and 'ip' are being set
# accordingly to what new providers returned in the new 'status-ipv*' and 'ipv*' fields respectively.
foreach my $h (@hosts) {
$config{$h}{'status'} //= $config{$h}{'status-ipv4'};
$config{$h}{'status'} //= $config{$h}{'status-ipv6'};
$config{$h}{'ip'} //= $config{$h}{'ipv4'};
$config{$h}{'ip'} //= $config{$h}{'ipv6'};
$config{$h}{'status'} //= $config{$h}{'status-ipv4'} // $config{$h}{'status-ipv6'};
$config{$h}{'ip'} //= $config{$h}{'ipv4'} // $config{$h}{'ipv6'};
}
runpostscript(join ' ', keys %ipsv4, keys %ipsv6);
@ -1919,7 +1917,7 @@ sub init_config {
@hosts = split_by_comma($opt{'host'});
}
if (opt('retry')) {
@hosts = map { $_ if $cache{$_}{'status'} ne 'good' } keys %cache;
@hosts = map { $_ if ($cache{$_}{'status'} // '') ne 'good' } keys %cache;
}
## remove any other hosts
@ -3568,7 +3566,7 @@ sub nic_updateable {
} elsif ( ($use ne 'disabled')
&& ((!exists($cache{$host}{'ip'})) || ("$cache{$host}{'ip'}" ne "$ip"))) {
## Check whether to update IP address for the "--use" method"
if (($cache{$host}{'status'} eq 'good') &&
if ((($cache{$host}{'status'} // '') eq 'good') &&
!interval_expired($host, 'mtime', 'min-interval')) {
warning("skipping update of %s from %s to %s.\nlast updated %s.\nWait at least %s between update attempts.",
@ -3582,7 +3580,7 @@ sub nic_updateable {
$cache{$host}{'warned-min-interval'} = $now;
} elsif (($cache{$host}{'status'} ne 'good') &&
} elsif ((($cache{$host}{'status'} // '') ne 'good') &&
!interval_expired($host, 'atime', 'min-error-interval')) {
if ( opt('verbose')
@ -3613,7 +3611,7 @@ sub nic_updateable {
} elsif ( ($usev4 ne 'disabled')
&& ((!exists($cache{$host}{'ipv4'})) || ("$cache{$host}{'ipv4'}" ne "$ipv4"))) {
## Check whether to update IPv4 address for the "--usev4" method"
if (($cache{$host}{'status-ipv4'} eq 'good') &&
if ((($cache{$host}{'status-ipv4'} // '') eq 'good') &&
!interval_expired($host, 'mtime', 'min-interval')) {
warning("skipping update of %s from %s to %s.\nlast updated %s.\nWait at least %s between update attempts.",
@ -3627,7 +3625,7 @@ sub nic_updateable {
$cache{$host}{'warned-min-interval'} = $now;
} elsif (($cache{$host}{'status-ipv4'} ne 'good') &&
} elsif ((($cache{$host}{'status-ipv4'} // '') ne 'good') &&
!interval_expired($host, 'atime', 'min-error-interval')) {
if ( opt('verbose')
@ -3658,7 +3656,7 @@ sub nic_updateable {
} elsif ( ($usev6 ne 'disabled')
&& ((!exists($cache{$host}{'ipv6'})) || ("$cache{$host}{'ipv6'}" ne "$ipv6"))) {
## Check whether to update IPv6 address for the "--usev6" method"
if (($cache{$host}{'status-ipv6'} eq 'good') &&
if ((($cache{$host}{'status-ipv6'} // '') eq 'good') &&
!interval_expired($host, 'mtime', 'min-interval')) {
warning("skipping update of %s from %s to %s.\nlast updated %s.\nWait at least %s between update attempts.",
@ -3672,7 +3670,7 @@ sub nic_updateable {
$cache{$host}{'warned-min-interval'} = $now;
} elsif (($cache{$host}{'status-ipv6'} ne 'good') &&
} elsif ((($cache{$host}{'status-ipv6'} // '') ne 'good') &&
!interval_expired($host, 'atime', 'min-error-interval')) {
if ( opt('verbose')
@ -3727,14 +3725,14 @@ sub nic_updateable {
}
}
$config{$host}{'status'} = $cache{$host}{'status'} // '';
$config{$host}{'status-ipv4'} = $cache{$host}{'status-ipv4'} // '';
$config{$host}{'status-ipv6'} = $cache{$host}{'status-ipv6'} // '';
$config{$host}{'status'} = $cache{$host}{'status'};
$config{$host}{'status-ipv4'} = $cache{$host}{'status-ipv4'};
$config{$host}{'status-ipv6'} = $cache{$host}{'status-ipv6'};
$config{$host}{'update'} = $update;
if ($update) {
$config{$host}{'status'} = 'noconnect';
$config{$host}{'status-ipv4'} = 'noconnect';
$config{$host}{'status-ipv6'} = 'noconnect';
$config{$host}{'status'} = undef;
$config{$host}{'status-ipv4'} = undef;
$config{$host}{'status-ipv6'} = undef;
$config{$host}{'atime'} = $now;
$config{$host}{'wtime'} = 0;
$config{$host}{'warned-min-interval'} = 0;