From 1e2ec7028ec99dd794fd126e8e834cfd59703e41 Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Tue, 12 Jul 2016 14:16:20 -0400 Subject: [PATCH] better debugging. add back deleting of zmswap files. detaint them so that they can be deleted. Use Objects to fix up deleting events --- scripts/ZoneMinder/lib/ZoneMinder/Event.pm | 7 ++-- scripts/zmaudit.pl.in | 40 ++++++++++++++-------- 2 files changed, 30 insertions(+), 17 deletions(-) diff --git a/scripts/ZoneMinder/lib/ZoneMinder/Event.pm b/scripts/ZoneMinder/lib/ZoneMinder/Event.pm index a9dc68967..936070cdb 100644 --- a/scripts/ZoneMinder/lib/ZoneMinder/Event.pm +++ b/scripts/ZoneMinder/lib/ZoneMinder/Event.pm @@ -333,8 +333,11 @@ sub Storage { } sub check_for_in_filesystem { my $path = $_[0]->Path(); - my @files = glob( $path . '/*' ); - return 1 if @files; + if ( $path ) { + my @files = glob( $path . '/*' ); + return 1 if @files; + } + return 0; } 1; diff --git a/scripts/zmaudit.pl.in b/scripts/zmaudit.pl.in index 9032cbc6d..249ba72ec 100644 --- a/scripts/zmaudit.pl.in +++ b/scripts/zmaudit.pl.in @@ -202,7 +202,7 @@ MAIN: while( $loop ) { if ( $Config{ZM_USE_DEEP_STORAGE} ) { foreach my $day_dir ( glob("$monitor_dir/*/*/*") ) { - Debug( "Checking $day_dir" ); + Debug( "Checking day dir $day_dir" ); ( $day_dir ) = ( $day_dir =~ /^(.*)$/ ); # De-taint if ( ! chdir( $day_dir ) ) { Error( "Can't chdir to $$Storage{Path}/$monitor_dir/'$day_dir': $!" ); @@ -238,9 +238,9 @@ MAIN: while( $loop ) { $Event->MonitorId( $monitor_dir ); $Event->StorageId( $Storage->Id() ); if ( $count++ > MAX_AGED_DIRS ) { - $Event->age( -1 ); + $$Event{age} = -1; } else { - $Event->age( (time() - ($^T - ((-M $event_path ) * 24*60*60))) ); + $$Event{age} = (time() - ($^T - ((-M $event_path ) * 24*60*60))); } } # event path exists @@ -266,9 +266,9 @@ MAIN: while( $loop ) { $Event->MonitorId( $monitor_dir ); $Event->StorageId( $Storage->Id() ); if ( $count++ > MAX_AGED_DIRS ) { - $Event->age( -1 ); + $$Event{age} = -1; } else { - $Event->age( (time() - ($^T - ((-M $event ) * 24*60*60))) ); + $$Event{age} = (time() - ($^T - ((-M $event ) * 24*60*60))); } } # end foreach event @@ -344,27 +344,31 @@ MAIN: while( $loop ) { if ( my $fs_events = $fs_monitors->{$db_monitor} ) { next if ! $db_events; - while ( my ( $db_event, $age ) = each(%$db_events ) ) { - if ( !defined($fs_events->{$db_event}) ) { + while ( my ( $db_event, $age ) = each( %$db_events ) ) { + if ( ! defined( $fs_events->{$db_event} ) ) { +Debug("Event $db_event is not in fs."); my $Event = new ZoneMinder::Event( $db_event ); + if ( ! $Event->StartTime() ) { + Debug("Event $$Event{Id} has no start time. deleting it."); + if ( confirm() ) { + $Event->delete(); + $cleaned = 1; + } + next; + } if ( $Event->check_for_in_filesystem() ) { Debug("Database events apparent exists at " . $Event->Path() ); } else { if ( $age > $Config{ZM_AUDIT_MIN_AGE} ) { aud_print( "Database event '$db_monitor/$db_event' does not exist at " . $Event->Path()." in filesystem" ); if ( confirm() ) { - my $res = $deleteEventSth->execute( $db_event ) - or Fatal( "Can't execute: ".$deleteEventSth->errstr() ); - $res = $deleteFramesSth->execute( $db_event ) - or Fatal( "Can't execute: ".$deleteFramesSth->errstr() ); - $res = $deleteStatsSth->execute( $db_event ) - or Fatal( "Can't execute: ".$deleteStatsSth->errstr() ); + $Event->delete(); $cleaned = 1; } } else { my $Storage = $Event->Storage(); - aud_print( "Database event '".$Event->getPath()."/$db_monitor/$db_event' does not exist in filesystem but too young to delete.\n" ); + aud_print( "Database event '".$Event->getPath()." monitor:$db_monitor event:$db_event' does not exist in filesystem but too young to delete age: $age > MIN $Config{ZM_AUDIT_MIN_AGE}.\n" ); } } # end if exists in filesystem } # end if ! in fs_events @@ -632,18 +636,24 @@ sub confirm { sub deleteSwapImage { my $file = $_; + return if $file =~ /^./; + if ( $file !~ /^zmswap-/ ) { + Error( "Trying to delete SwapImage that isnt a swap image $file" ); return; } # Ignore directories if ( -d $file ) { + Error( "Trying to delete a directory instead of a swap image $file" ); return; } if ( -M $file > $max_swap_age ) { + ( $file ) = ( $file =~ /^(.*)$/ ); + Debug( "Deleting $file" ); -#unlink( $file ); + unlink( $file ); } }