aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org>2015-05-20 08:04:56 +0300
committerSergey Poznyakoff <gray@gnu.org>2015-05-20 08:08:37 +0300
commit1866566b9abb7ee4d3cd4f04fe9a88959db8fc4e (patch)
tree7761d3029ccfbda3dad6824820e176642bafbfd6
parent20fed8167852cf54fc89322bb5f5cb1e16653b3d (diff)
downloaddnstools-1866566b9abb7ee4d3cd4f04fe9a88959db8fc4e.tar.gz
dnstools-1866566b9abb7ee4d3cd4f04fe9a88959db8fc4e.tar.bz2
Fix reconfiguration on SIGNUP
* dgd/dgd (defconfig): New variable. (readconfig): Remove calls to check_mandatory (temporarly) (scan_links): Filter off incomplete link definitions. Don't panic if core.active points to an undefined link. (main): Initialize %config. (SIGHUP): Initialize %t.
-rwxr-xr-xdgd/dgd36
1 files changed, 20 insertions, 16 deletions
diff --git a/dgd/dgd b/dgd/dgd
index 4aa7f02..1aeac04 100755
--- a/dgd/dgd
+++ b/dgd/dgd
@@ -36,7 +36,7 @@ my $use_syslog;
36my @links; 36my @links;
37my $active_link; 37my $active_link;
38 38
39my %config = ( 39my %defconfig = (
40 core => { 40 core => {
41 interval => 60, 41 interval => 60,
42 timeout => 3, 42 timeout => 3,
@@ -44,6 +44,7 @@ my %config = (
44 tolerance => 2 44 tolerance => 2
45 } 45 }
46); 46);
47my %config;
47 48
48my $rxip = '\d{1,3}\.\d{1,3}.\d{1,3}.\d{1,3}'; 49my $rxip = '\d{1,3}\.\d{1,3}.\d{1,3}.\d{1,3}';
49 50
@@ -235,9 +236,6 @@ sub readconfig {
235 next if ($_ eq ""); 236 next if ($_ eq "");
236 237
237 if (/^\[(.+?)\]$/) { 238 if (/^\[(.+?)\]$/) {
238 $err += check_mandatory($section, $kw, "$file:$line")
239 if defined $kw;
240
241 $include = 0; 239 $include = 0;
242 my $arg = $1; 240 my $arg = $1;
243 $arg =~ s/^\s+//; 241 $arg =~ s/^\s+//;
@@ -320,9 +318,9 @@ sub readconfig {
320 } 318 }
321 } 319 }
322 close $fd; 320 close $fd;
323 if (defined($param{kw}) and !$param{include}) { 321 # if (defined($param{kw}) and !$param{include}) {
324 $err += check_mandatory($conf, $param{kw}, "$file:$line", 1); 322 # $err += check_mandatory($conf, $param{kw}, "$file:$line", 1);
325 } 323 # }
326 return $err; 324 return $err;
327} 325}
328 326
@@ -342,9 +340,13 @@ sub get_default_gw {
342 340
343sub scan_links { 341sub scan_links {
344 @links = sort { $a->{priority} <=> $b->{priority} } 342 @links = sort { $a->{priority} <=> $b->{priority} }
345 map { $_->{priority} = 100 unless exists $_->{priority}; 343 map { if (defined($_->{name})) {
346 debug(1, "registered link $_->{name} via $_->{if}"); 344 $_->{priority} = 100 unless exists $_->{priority};
347 $_ 345 debug(1, "registered link $_->{name} via $_->{if}");
346 $_
347 } else {
348 ()
349 }
348 } values %{$config{link}}; 350 } values %{$config{link}};
349 351
350 abend(EX_CONFIG, "no links configured") 352 abend(EX_CONFIG, "no links configured")
@@ -354,11 +356,12 @@ sub scan_links {
354 for ($active_link = 0; $active_link <= $#links; ++$active_link) { 356 for ($active_link = 0; $active_link <= $#links; ++$active_link) {
355 last if $links[$active_link]->{name} eq $config{core}{active}; 357 last if $links[$active_link]->{name} eq $config{core}{active};
356 } 358 }
359 error("no link corresponding to the active one");
360 $active_link = undef;
361 delete $config{core}{active};
362 }
357 363
358 abend(EX_CONFIG, 364 unless (defined($active_link)) {
359 "no link corresponding to the active one")
360 if ($active_link > $#links);
361 } else {
362 my $gw = get_default_gw(); 365 my $gw = get_default_gw();
363 if (defined($gw)) { 366 if (defined($gw)) {
364 debug(1, "default gw $gw"); 367 debug(1, "default gw $gw");
@@ -481,6 +484,7 @@ GetOptions("h" => sub {
481 "foreground|f" => \$foreground, 484 "foreground|f" => \$foreground,
482 "config|c=s" => \$conffile) or exit(1); 485 "config|c=s" => \$conffile) or exit(1);
483 486
487%config = %defconfig;
484if (readconfig($conffile, \%config, kw => \%kw)) { 488if (readconfig($conffile, \%config, kw => \%kw)) {
485 exit(EX_CONFIG); 489 exit(EX_CONFIG);
486} 490}
@@ -524,9 +528,9 @@ unless ($foreground) {
524} 528}
525 529
526$SIG{HUP} = sub { 530$SIG{HUP} = sub {
527 my %t; 531 my %t = %defconfig;
528 diag('info', "re-reading configuration file"); 532 diag('info', "re-reading configuration file");
529 if (readconfig($conffile, \%t)) { 533 if (readconfig($conffile, \%t) == 0) {
530 %config = %t; 534 %config = %t;
531 @links = (); 535 @links = ();
532 scan_links; 536 scan_links;

Return to:

Send suggestions and report system problems to the System administrator.