Commit 7bf8736c authored by Mac Newbold's avatar Mac Newbold
Browse files

Fix sig handling per Rob's instructions so we don't reenter the elvin

code when taking a signal.
parent cbfd8776
...@@ -191,6 +191,8 @@ if ($debug) { qshow(); } ...@@ -191,6 +191,8 @@ if ($debug) { qshow(); }
# Gets set if a reload of state from the database should happen. # Gets set if a reload of state from the database should happen.
my $do_reload = 0; my $do_reload = 0;
my $sigrestart= 0;
my $sigcleanup= 0;
# Make the daemon reload database state on a sighup - but I'm worried # Make the daemon reload database state on a sighup - but I'm worried
# about what would happen if we tried to do this mid-loop. So, we'll # about what would happen if we tried to do this mid-loop. So, we'll
...@@ -198,13 +200,13 @@ my $do_reload = 0; ...@@ -198,13 +200,13 @@ my $do_reload = 0;
$SIG{HUP} = sub { info("SIGHUP - Reloading DB state\n"); $do_reload = 1; }; $SIG{HUP} = sub { info("SIGHUP - Reloading DB state\n"); $do_reload = 1; };
# Set up other signals. # Set up other signals.
$SIG{USR1} = \&restart; $SIG{USR1} = \&restart_wrap;
$SIG{USR2} = \&cleanup; $SIG{USR2} = \&cleanup_wrap;
$SIG{INT} = \&cleanup; $SIG{INT} = \&cleanup_wrap;
$SIG{QUIT} = \&cleanup; $SIG{QUIT} = \&cleanup_wrap;
$SIG{ABRT} = \&cleanup; $SIG{ABRT} = \&cleanup_wrap;
$SIG{TERM} = \&cleanup; $SIG{TERM} = \&cleanup_wrap;
$SIG{KILL} = \&cleanup; $SIG{KILL} = \&cleanup_wrap;
# Track if I handled an event or not # Track if I handled an event or not
my $event_count = 0; my $event_count = 0;
...@@ -312,6 +314,9 @@ while (1) { ...@@ -312,6 +314,9 @@ while (1) {
# Send any messages in the queue if it is time # Send any messages in the queue if it is time
notify("",1); notify("",1);
if ($sigrestart) { restart(); }
if ($sigcleanup) { cleanup(); }
#sleep(1); #sleep(1);
} }
...@@ -1084,10 +1089,10 @@ sub info($;$) { ...@@ -1084,10 +1089,10 @@ sub info($;$) {
syslog($prio,$message) || notify("syslog failed: $? $!\n"); syslog($prio,$message) || notify("syslog failed: $? $!\n");
} }
sub restart_wrap { $sigrestart=1; }
# This gets called if we catch a signal USR1 # This gets called if we catch a signal USR1
sub restart { sub restart {
info("SIGUSER1 received: Performing final event poll before restarting\n");
process_event_queue;
my $params = join(" ",@args); my $params = join(" ",@args);
my $prog = ""; my $prog = "";
# If we're started from an abosolute path, use that. # If we're started from an abosolute path, use that.
...@@ -1096,6 +1101,9 @@ sub restart { ...@@ -1096,6 +1101,9 @@ sub restart {
} else { } else {
$prog = "$TB/sbin/stated"; $prog = "$TB/sbin/stated";
} }
info("SIGUSER1 received: Performing final event poll before restarting\n");
$blockwait=0;
process_event_queue;
info("Restarting from '$prog".($params ne "" ? " $params" : "")."'\n"); info("Restarting from '$prog".($params ne "" ? " $params" : "")."'\n");
if ($handle && event_unregister($handle) == 0) { if ($handle && event_unregister($handle) == 0) {
warn "Unable to unregister with event system\n"; warn "Unable to unregister with event system\n";
...@@ -1117,6 +1125,8 @@ sub restart { ...@@ -1117,6 +1125,8 @@ sub restart {
}; };
} }
sub cleanup_wrap { $sigcleanup=1; }
# This gets called if we catch a signal (TERM, etc.) # This gets called if we catch a signal (TERM, etc.)
sub cleanup { sub cleanup {
notify("Signal received, exiting\n"); notify("Signal received, exiting\n");
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment