diff options
Diffstat (limited to 'dgd/dgd')
-rwxr-xr-x | dgd/dgd | 36 |
1 files changed, 20 insertions, 16 deletions
@@ -36,7 +36,7 @@ my $use_syslog; my @links; my $active_link; -my %config = ( +my %defconfig = ( core => { interval => 60, timeout => 3, @@ -44,6 +44,7 @@ my %config = ( tolerance => 2 } ); +my %config; my $rxip = '\d{1,3}\.\d{1,3}.\d{1,3}.\d{1,3}'; @@ -235,9 +236,6 @@ sub readconfig { next if ($_ eq ""); if (/^\[(.+?)\]$/) { - $err += check_mandatory($section, $kw, "$file:$line") - if defined $kw; - $include = 0; my $arg = $1; $arg =~ s/^\s+//; @@ -320,9 +318,9 @@ sub readconfig { } } close $fd; - if (defined($param{kw}) and !$param{include}) { - $err += check_mandatory($conf, $param{kw}, "$file:$line", 1); - } + # if (defined($param{kw}) and !$param{include}) { + # $err += check_mandatory($conf, $param{kw}, "$file:$line", 1); + # } return $err; } @@ -342,9 +340,13 @@ sub get_default_gw { sub scan_links { @links = sort { $a->{priority} <=> $b->{priority} } - map { $_->{priority} = 100 unless exists $_->{priority}; - debug(1, "registered link $_->{name} via $_->{if}"); - $_ + map { if (defined($_->{name})) { + $_->{priority} = 100 unless exists $_->{priority}; + debug(1, "registered link $_->{name} via $_->{if}"); + $_ + } else { + () + } } values %{$config{link}}; abend(EX_CONFIG, "no links configured") @@ -354,11 +356,12 @@ sub scan_links { for ($active_link = 0; $active_link <= $#links; ++$active_link) { last if $links[$active_link]->{name} eq $config{core}{active}; } + error("no link corresponding to the active one"); + $active_link = undef; + delete $config{core}{active}; + } - abend(EX_CONFIG, - "no link corresponding to the active one") - if ($active_link > $#links); - } else { + unless (defined($active_link)) { my $gw = get_default_gw(); if (defined($gw)) { debug(1, "default gw $gw"); @@ -481,6 +484,7 @@ GetOptions("h" => sub { "foreground|f" => \$foreground, "config|c=s" => \$conffile) or exit(1); +%config = %defconfig; if (readconfig($conffile, \%config, kw => \%kw)) { exit(EX_CONFIG); } @@ -524,9 +528,9 @@ unless ($foreground) { } $SIG{HUP} = sub { - my %t; + my %t = %defconfig; diag('info', "re-reading configuration file"); - if (readconfig($conffile, \%t)) { + if (readconfig($conffile, \%t) == 0) { %config = %t; @links = (); scan_links; |