Prevent zmtrigger from crashing when memory handles change

This commit is contained in:
Andy Bauer 2016-02-21 17:55:04 -06:00
parent b653f74b09
commit a2e06ed70c
1 changed files with 49 additions and 43 deletions

View File

@ -197,6 +197,7 @@ my %spawned_connections;
my %monitors;
my $monitor_reload_time = 0;
my $needsReload = 0;
$! = undef;
my $rin = '';
@ -217,7 +218,7 @@ while( 1 )
if ( $nfound > 0 )
{
Debug( "Got input from $nfound connections\n" );
foreach my $connection ( @in_select_connections )
foreach my $connection ( @in_select_connections ) {
{
if ( vec( $rout, $connection->fileno(), 1 ) )
{
@ -310,8 +311,15 @@ while( 1 )
# Check for alarms that might have happened
my @out_messages;
foreach my $monitor ( values(%monitors) )
{
foreach my $monitor ( values(%monitors) ) {
my $memVerified = 1;
if ( !zmMemRead($monitor, "shared_data:valid") ) {
zmMemInvalidate($monitor);
$memVerified = zmMemVerify($monitor);
}
if ($memVerified) {
my ( $state, $last_event )
= zmMemRead( $monitor,
[ "shared_data:state",
@ -323,39 +331,36 @@ while( 1 )
#print( "$monitor->{Id}: mS:$monitor->{LastState}, mLE:$monitor->{LastEvent}\n" );
if ( $state == STATE_ALARM
|| $state == STATE_ALERT
) # In alarm state
{
) { # In alarm state
if ( !defined($monitor->{LastEvent})
|| ($last_event != $monitor->{LastEvent})
) # A new event
{
) { # A new event
push( @out_messages, $monitor->{Id}."|on|".time()."|".$last_event );
}
else # The same one as last time, so ignore it
{
} else { # The same one as last time, so ignore it
# Do nothing
}
}
elsif ( ($state == STATE_IDLE
} elsif ( ($state == STATE_IDLE
&& $monitor->{LastState} != STATE_IDLE
)
|| ($state == STATE_TAPE
&& $monitor->{LastState} != STATE_TAPE
)
) # Out of alarm state
{
) { # Out of alarm state
push( @out_messages, $monitor->{Id}."|off|".time()."|".$last_event );
}
elsif ( defined($monitor->{LastEvent})
&& ($last_event != $monitor->{LastEvent})
) # We've missed a whole event
{
) { # We've missed a whole event
push( @out_messages, $monitor->{Id}."|on|".time()."|".$last_event );
push( @out_messages, $monitor->{Id}."|off|".time()."|".$last_event );
}
$monitor->{LastState} = $state;
$monitor->{LastEvent} = $last_event;
} else { # Our attempt to verify the memory handle failed. We should reload the monitors.
$needsReload = 1;
}
}
foreach my $connection ( @out_connections )
{
if ( $connection->canWrite() )
@ -412,7 +417,7 @@ while( 1 )
}
# If necessary reload monitors
if ( (time() - $monitor_reload_time) > MONITOR_RELOAD_INTERVAL )
if ( $needsReload || ((time() - $monitor_reload_time) > MONITOR_RELOAD_INTERVAL ))
{
foreach my $monitor ( values(%monitors) )
{
@ -420,6 +425,7 @@ while( 1 )
zmMemInvalidate( $monitor );
}
loadMonitors();
$needsReload = 0;
}
}
Info( "Trigger daemon exiting\n" );