This commit is contained in:
Isaac Connor 2017-01-10 13:53:02 -05:00
parent 66cdcd95fa
commit d2ff6701f4
3 changed files with 13 additions and 3 deletions

View File

@ -246,10 +246,12 @@ sub zmMemInit {
sub zmMemVerify {
my $monitor = shift;
if ( !zmMemAttach( $monitor, $mem_size ) ) {
print "no attach for $$monitor{Id} $mem_size\n";
return( undef );
}
my $mem_key = zmMemKey( $monitor );
print "mem_key for $$monitor{Id} $mem_key\n";
if ( !defined($mem_verified->{$mem_key}) ) {
my $sd_size = zmMemRead( $monitor, "shared_data:size", 1 );
if ( $sd_size != $mem_data->{shared_data}->{size} ) {
@ -365,6 +367,7 @@ sub zmMemRead {
sub zmMemInvalidate {
my $monitor = shift;
my $mem_key = zmMemKey($monitor);
print "zmMemInvalidate $$monitor{Id} $mem_key\n";
if ( $mem_key ) {
delete $mem_verified->{$mem_key};
zmMemDetach( $monitor );

View File

@ -120,6 +120,8 @@ sub zmMemAttach
$monitor->{MMapHandle} = \*MMAP;
$monitor->{MMapAddr} = $mmap_addr;
$monitor->{MMap} = \$mmap;
} else {
print "$$monitor{Id} already defined at $$monitor{MMapAddr}\n";
}
return( !undef );
}

View File

@ -117,7 +117,7 @@ use bytes;
# ==========================================================================
use constant MAX_CONNECT_DELAY => 10;
use constant MONITOR_RELOAD_INTERVAL => 300;
use constant MONITOR_RELOAD_INTERVAL => 30;
use constant SELECT_TIMEOUT => 0.25;
# ==========================================================================
@ -320,7 +320,7 @@ while( 1 )
]
);
#print( "$monitor->{Id}: S:$state, LE:$last_event\n" );
print( "$monitor->{Id}: S:$state, LE:$last_event\n" );
#print( "$monitor->{Id}: mS:$monitor->{LastState}, mLE:$monitor->{LastEvent}\n" );
if ( $state == STATE_ALARM
|| $state == STATE_ALERT
@ -415,8 +415,10 @@ while( 1 )
# If necessary reload monitors
if ( (time() - $monitor_reload_time) > MONITOR_RELOAD_INTERVAL )
{
print "TIme to reload Monitors " . join(',',keys %monitors ). "\n";
foreach my $monitor ( values(%monitors) )
{
print "imvalidating $$monitor{Id}\n";
# Free up any used memory handle
zmMemInvalidate( $monitor );
}
@ -443,7 +445,10 @@ sub loadMonitors
or Fatal( "Can't execute: ".$sth->errstr() );
while( my $monitor = $sth->fetchrow_hashref() )
{
next if ( !zmMemVerify( $monitor ) ); # Check shared memory ok
next
if ( !zmMemVerify( $monitor ) ) {
; # Check shared memory ok
}
if ( defined($monitors{$monitor->{Id}}->{LastState}) )
{