From 5b047dc74b4105b39cacc675eabb8ed9f033cee3 Mon Sep 17 00:00:00 2001 From: Kaarle Ritvanen Date: Sat, 20 Feb 2016 23:58:07 +0200 Subject: [PATCH 1/3] zm_event: fix overlap in memcpy buffers --- src/zm_event.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/zm_event.cpp b/src/zm_event.cpp index 1f1fb0f0b..a34ce50a0 100644 --- a/src/zm_event.cpp +++ b/src/zm_event.cpp @@ -1121,7 +1121,7 @@ void EventStream::processCommand( const CmdMsg *msg ) DataMsg status_msg; status_msg.msg_type = MSG_DATA_EVENT; - memcpy( &status_msg.msg_data, &status_data, sizeof(status_msg.msg_data) ); + memcpy( &status_msg.msg_data, &status_data, sizeof(status_data) ); if ( sendto( sd, &status_msg, sizeof(status_msg), MSG_DONTWAIT, (sockaddr *)&rem_addr, sizeof(rem_addr) ) < 0 ) { //if ( errno != EAGAIN ) From a2e06ed70c591e5c9d38c4ce0e52c180d9444741 Mon Sep 17 00:00:00 2001 From: Andy Bauer Date: Sun, 21 Feb 2016 17:55:04 -0600 Subject: [PATCH 2/3] Prevent zmtrigger from crashing when memory handles change --- scripts/zmtrigger.pl.in | 92 ++++++++++++++++++++++------------------- 1 file changed, 49 insertions(+), 43 deletions(-) diff --git a/scripts/zmtrigger.pl.in b/scripts/zmtrigger.pl.in index 222e42f79..6111828ba 100644 --- a/scripts/zmtrigger.pl.in +++ b/scripts/zmtrigger.pl.in @@ -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,52 +311,56 @@ while( 1 ) # Check for alarms that might have happened my @out_messages; - foreach my $monitor ( values(%monitors) ) - { - my ( $state, $last_event ) - = zmMemRead( $monitor, - [ "shared_data:state", - "shared_data:last_event" - ] - ); + foreach my $monitor ( values(%monitors) ) { - #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 - ) # In alarm state - { - if ( !defined($monitor->{LastEvent}) - || ($last_event != $monitor->{LastEvent}) - ) # A new event - { + 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", + "shared_data:last_event" + ] + ); + + #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 + ) { # In alarm state + if ( !defined($monitor->{LastEvent}) + || ($last_event != $monitor->{LastEvent}) + ) { # A new event + push( @out_messages, $monitor->{Id}."|on|".time()."|".$last_event ); + } else { # The same one as last time, so ignore it + # Do nothing + } + } elsif ( ($state == STATE_IDLE + && $monitor->{LastState} != STATE_IDLE + ) + || ($state == STATE_TAPE + && $monitor->{LastState} != STATE_TAPE + ) + ) { # 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 push( @out_messages, $monitor->{Id}."|on|".time()."|".$last_event ); + push( @out_messages, $monitor->{Id}."|off|".time()."|".$last_event ); } - else # The same one as last time, so ignore it - { - # Do nothing - } + $monitor->{LastState} = $state; + $monitor->{LastEvent} = $last_event; + } else { # Our attempt to verify the memory handle failed. We should reload the monitors. + $needsReload = 1; } - elsif ( ($state == STATE_IDLE - && $monitor->{LastState} != STATE_IDLE - ) - || ($state == STATE_TAPE - && $monitor->{LastState} != STATE_TAPE - ) - ) # 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 - { - 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; } + 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" ); From 0fce33b2d352debadfef6564941e7707b65c4fa4 Mon Sep 17 00:00:00 2001 From: Andrew Bauer Date: Mon, 22 Feb 2016 06:59:14 -0600 Subject: [PATCH 3/3] one too many curly brackets --- scripts/zmtrigger.pl.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/zmtrigger.pl.in b/scripts/zmtrigger.pl.in index 6111828ba..d7ef79f68 100644 --- a/scripts/zmtrigger.pl.in +++ b/scripts/zmtrigger.pl.in @@ -219,7 +219,7 @@ while( 1 ) { Debug( "Got input from $nfound connections\n" ); foreach my $connection ( @in_select_connections ) { - { + if ( vec( $rout, $connection->fileno(), 1 ) ) { Debug( "Got input from connection "