summaryrefslogtreecommitdiffabout
authorSergey Poznyakoff <gray@gnu.org.ua>2019-08-20 15:29:33 (GMT)
committer Sergey Poznyakoff <gray@gnu.org.ua>2019-08-20 15:29:33 (GMT)
commit9aa788734ab432ef374e88cf550cb8577bdfbfc2 (patch) (side-by-side diff)
treee9eab8bce1cf9482415ad2a3cf445c014f872311
parent64c398c8dd1bf734fdc9cc8e9638cd039d353b89 (diff)
downloaddnstools-9aa788734ab432ef374e88cf550cb8577bdfbfc2.tar.gz
dnstools-9aa788734ab432ef374e88cf550cb8577bdfbfc2.tar.bz2
Fix silly bugs in dgd
Diffstat (more/less context) (ignore whitespace changes)
-rwxr-xr-xdgd/dgd31
1 files changed, 19 insertions, 12 deletions
diff --git a/dgd/dgd b/dgd/dgd
index f809cc8..1b37c3a 100755
--- a/dgd/dgd
+++ b/dgd/dgd
@@ -185,8 +185,8 @@ sub check_mandatory {
my $err = 0;
while (my ($k, $d) = each %{$kw}) {
if (ref($d) eq 'HASH'
- and $d->{mandatory}
- and !exists($section->{$k})) {
+ && $d->{mandatory}
+ && !exists($section->{$k})) {
if (exists($d->{section})) {
if ($s) {
error("$loc: mandatory section [$k] not present");
@@ -247,7 +247,7 @@ sub readconfig {
if (ref($param{kw}) eq 'HASH') {
if (defined($rootname)) {
if (ref($param{kw}{$rootname}) eq 'HASH'
- and exists($param{kw}{$rootname}{section})) {
+ && exists($param{kw}{$rootname}{section})) {
$kw = $param{kw}{$rootname}{section};
} else {
error("$file:$line: unknown section");
@@ -293,7 +293,7 @@ sub readconfig {
next;
}
if (exists($x->{check})
- and !&{$x->{check}}($v, "$file:$line")) {
+ && !&{$x->{check}}($v, "$file:$line")) {
++$err;
next;
}
@@ -302,7 +302,7 @@ sub readconfig {
++$err;
next;
}
- } elsif (!exists($x->{var}) and !exists($x->{mandatory})) {
+ } elsif (!exists($x->{var}) && !exists($x->{mandatory})) {
error("$file:$line: unknown keyword $k");
++$err;
next;
@@ -318,7 +318,7 @@ sub readconfig {
}
}
close $fd;
- # if (defined($param{kw}) and !$param{include}) {
+ # if (defined($param{kw}) && !$param{include}) {
# $err += check_mandatory($conf, $param{kw}, "$file:$line", 1);
# }
return $err;
@@ -434,18 +434,25 @@ sub link_is_alive {
sub check_links {
my $link;
foreach $link (@links) {
+ $link->{prevstate} = link_is_alive($link);
$link->{alive} = 0;
}
- debug(1, "checking links ".($#links+1).", probes $config{core}{probes}");
+ debug(2, "checking links ".($#links+1).", probes $config{core}{probes}");
for (my $i = 0; $i < $config{core}{probes}; $i++) {
foreach $link (@links) {
next if link_is_alive($link);
- debug(3, "ping $link->{name}");
+ debug(3, "ping $link->{name} $link->{gw} $link->{if}");
my $p = Net::Ping->new("icmp", $config{core}{timeout}, undef,
$link->{if});
++$link->{alive} if $p->ping($link->{gw});
- $p->close();
- debug(3, "$link->{name} " . ($link->{alive} ? "alive" : "dead"));
+ }
+ }
+ if ($debug) {
+ foreach $link (@links) {
+ if ($link->{prevstate} != link_is_alive($link)) {
+ debug(1, "$link->{name} state changed to " . (link_is_alive($link) ? "alive" : "dead"));
+ }
+# print "Link $link->{name} is ".(link_is_alive($link)?"up":"down")."\n";
}
}
if (!defined($active_link)) {
@@ -575,7 +582,7 @@ $SIG{HUP} = sub {
}
};
-$use_syslog = defined $config{syslog}{facility};
+$use_syslog = defined $config{syslog}{facility} && !$foreground;
while (1) {
if (check_links()) {
@@ -583,7 +590,7 @@ while (1) {
} elsif ($active_link > 0) {
for (my $i = 0; $i < $active_link; $i++) {
if (link_is_alive($i)
- and $links[$i]->{priority} < $links[$active_link]->{priority}) {
+ && $links[$i]->{priority} < $links[$active_link]->{priority}) {
diag('info', "switching to higher priority link $links[$i]->{name}");
updown('down', $links[$active_link]->{name});

Return to:

Send suggestions and report system problems to the System administrator.