From b8f6617db30a9ffb6a4a9779ba683411e12efa2f Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Sun, 9 Sep 2018 12:15:06 -0400 Subject: [PATCH 1/6] fix another instance of find_all --- web/skins/classic/views/storage.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web/skins/classic/views/storage.php b/web/skins/classic/views/storage.php index 0608ef139..dafd7bb67 100644 --- a/web/skins/classic/views/storage.php +++ b/web/skins/classic/views/storage.php @@ -48,7 +48,7 @@ $scheme_options = array( 'Shallow' => translate('Shallow'), ); -$servers = Server::find_all( null, array('order'=>'lower(Name)') ); +$servers = Server::find( null, array('order'=>'lower(Name)') ); $ServersById = array(); foreach ( $servers as $S ) { $ServersById[$S->Id()] = $S; From 9e8a876101940dbe2016ce7694db64013a384985 Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Sun, 9 Sep 2018 13:28:11 -0400 Subject: [PATCH 2/6] Fix finding Storage by ServerId --- scripts/ZoneMinder/lib/ZoneMinder/Storage.pm | 85 ++++++++++---------- 1 file changed, 43 insertions(+), 42 deletions(-) diff --git a/scripts/ZoneMinder/lib/ZoneMinder/Storage.pm b/scripts/ZoneMinder/lib/ZoneMinder/Storage.pm index b6924c4e9..134752594 100644 --- a/scripts/ZoneMinder/lib/ZoneMinder/Storage.pm +++ b/scripts/ZoneMinder/lib/ZoneMinder/Storage.pm @@ -53,64 +53,65 @@ $primary_key = 'Id'; #__PACKAGE__->primary_key('Id'); sub find { - shift if $_[0] eq 'ZoneMinder::Storage'; - my %sql_filters = @_; + shift if $_[0] eq 'ZoneMinder::Storage'; + my %sql_filters = @_; - my $sql = 'SELECT * FROM Storage'; - my @sql_filters; - my @sql_values; + my $sql = 'SELECT * FROM Storage'; + my @sql_filters; + my @sql_values; - if ( exists $sql_filters{Id} ) { - push @sql_filters , ' Id=? '; - push @sql_values, $sql_filters{Id}; - } - if ( exists $sql_filters{Name} ) { - push @sql_filters , ' Name = ? '; - push @sql_values, $sql_filters{Name}; - } - if ( exists $sql_filters{ServerId} ) { - push @sql_filters, ' Id IN ( SELECT StorageId FROM Monitors WHERE ServerId=? )'; - push @sql_values, $sql_filters{ServerId}; - } + if ( exists $sql_filters{Id} ) { + push @sql_filters , ' Id=? '; + push @sql_values, $sql_filters{Id}; + } + if ( exists $sql_filters{Name} ) { + push @sql_filters , ' Name = ? '; + push @sql_values, $sql_filters{Name}; + } + if ( exists $sql_filters{ServerId} ) { + push @sql_filters, ' ServerId = ?'; + push @sql_values, $sql_filters{ServerId}; + } - $sql .= ' WHERE ' . join(' AND ', @sql_filters ) if @sql_filters; - $sql .= ' LIMIT ' . $sql_filters{limit} if $sql_filters{limit}; + $sql .= ' WHERE ' . join(' AND ', @sql_filters) if @sql_filters; + $sql .= ' LIMIT ' . $sql_filters{limit} if $sql_filters{limit}; - my $sth = $ZoneMinder::Database::dbh->prepare_cached( $sql ) - or Fatal( "Can't prepare '$sql': ".$ZoneMinder::Database::dbh->errstr() ); - my $res = $sth->execute( @sql_values ) - or Fatal( "Can't execute '$sql': ".$sth->errstr() ); + my $sth = $ZoneMinder::Database::dbh->prepare_cached( $sql ) + or Fatal( "Can't prepare '$sql': ".$ZoneMinder::Database::dbh->errstr() ); + my $res = $sth->execute( @sql_values ) + or Fatal( "Can't execute '$sql': ".$sth->errstr() ); - my @results; + my @results; - while( my $db_filter = $sth->fetchrow_hashref() ) { - my $filter = new ZoneMinder::Storage( $$db_filter{Id}, $db_filter ); - push @results, $filter; - } # end while - return @results; + while( my $db_filter = $sth->fetchrow_hashref() ) { + my $filter = new ZoneMinder::Storage( $$db_filter{Id}, $db_filter ); + push @results, $filter; + } # end while + Debug("SQL: $sql returned " . @results . ' results'); + return @results; } sub find_one { - my @results = find(@_); - return $results[0] if @results; + my @results = find(@_); + return $results[0] if @results; } sub Path { - if ( @_ > 1 ) { - $_[0]{Path} = $_[1]; - } - if ( ! ( $_[0]{Id} or $_[0]{Path} ) ) { - $_[0]{Path} = ($Config{ZM_DIR_EVENTS}=~/^\//) ? $Config{ZM_DIR_EVENTS} : ($Config{ZM_PATH_WEB}.'/'.$Config{ZM_DIR_EVENTS}) - } - return $_[0]{Path}; + if ( @_ > 1 ) { + $_[0]{Path} = $_[1]; + } + if ( ! ( $_[0]{Id} or $_[0]{Path} ) ) { + $_[0]{Path} = ($Config{ZM_DIR_EVENTS}=~/^\//) ? $Config{ZM_DIR_EVENTS} : ($Config{ZM_PATH_WEB}.'/'.$Config{ZM_DIR_EVENTS}) + } + return $_[0]{Path}; } # end sub Path sub Name { - if ( @_ > 1 ) { - $_[0]{Name} = $_[1]; - } - return $_[0]{Name}; + if ( @_ > 1 ) { + $_[0]{Name} = $_[1]; + } + return $_[0]{Name}; } # end sub Path sub DoDelete { From 882e47c9abd3199acce2e84eb7fb8d586a636dc6 Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Sun, 9 Sep 2018 13:28:24 -0400 Subject: [PATCH 3/6] Fix deleting empty directories --- scripts/zmaudit.pl.in | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/scripts/zmaudit.pl.in b/scripts/zmaudit.pl.in index 28a505801..dbe480d28 100644 --- a/scripts/zmaudit.pl.in +++ b/scripts/zmaudit.pl.in @@ -382,7 +382,7 @@ MAIN: while( $loop ) { } # if USE_DEEP_STORAGE Debug( 'Got '.int(keys(%$fs_events))." filesystem events for monitor $monitor_dir\n" ); - #delete_empty_directories( $monitor_dir ); + delete_empty_directories($monitor_dir); } # end foreach monitor if ( $cleaned ) { @@ -879,26 +879,30 @@ sub deleteSwapImage { sub delete_empty_directories { my $DIR; - Debug("delete_empty_directories $_[0]"); - if ( ! opendir( $DIR, $_[0] ) ) { - Error( "delete_empty_directories: Can't open directory '".getcwd()."/$_[0]': $!" ); + if ( !opendir($DIR, $_[0]) ) { + Error("delete_empty_directories: Can't open directory '".getcwd()."/$_[0]': $!" ); return; } - my @contents = map { $_ eq '.' or $_ eq '..' ? () : $_ } readdir( $DIR ); + my @contents = map { ( $_ eq '.' or $_ eq '..' ) ? () : $_ } readdir( $DIR ); + Debug("delete_empty_directories $_[0] has " . @contents .' entries:' . ( @contents < 2 ? join(',',@contents) : '' )); my @dirs = map { -d $_[0].'/'.$_ ? $_ : () } @contents; if ( @dirs ) { + Debug("Have " . @dirs . " dirs"); foreach ( @dirs ) { delete_empty_directories( $_[0].'/'.$_ ); } #Reload, since we may now be empty rewinddir $DIR; - @contents = map { $_ eq '.' or $_ eq '..' ? () : $_ } readdir( $DIR ); + @contents = map { ($_ eq '.' or $_ eq '..') ? () : $_ } readdir( $DIR ); } + closedir($DIR); if ( ! @contents ) { ( my $dir ) = ( $_[0] =~ /^(.*)$/ ); - unlink $dir; + Debug("Unlinking $dir because it's empty"); + if ( ! rmdir $dir ) { + Error("Unable to unlink $dir: $!"); + } } - closedir( $DIR ); } # end sub delete_empty_directories 1; From b4f80fbe1112ef1437a1be575f792fb1efcd7b43 Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Sun, 9 Sep 2018 13:56:29 -0400 Subject: [PATCH 4/6] Always return an array from find --- web/includes/Server.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/web/includes/Server.php b/web/includes/Server.php index f9a82c9bb..1da08c56a 100644 --- a/web/includes/Server.php +++ b/web/includes/Server.php @@ -98,7 +98,7 @@ class Server { $file = $backTrace[1]['file']; $line = $backTrace[1]['line']; Error("Invalid value for limit($limit) passed to Server::find from $file:$line"); - return; + return array(); } } } @@ -106,6 +106,7 @@ class Server { if ( $results ) { return array_map( function($id){ return new Server($id); }, $results ); } + return array(); } public static function find_one( $parameters = array() ) { From 55dcb161aeb6cac9cbbfa29f4bb34ded7e429851 Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Sun, 9 Sep 2018 13:59:10 -0400 Subject: [PATCH 5/6] find should always return an array --- web/includes/Event.php | 2 +- web/includes/Filter.php | 2 +- web/includes/Group.php | 2 +- web/includes/Monitor.php | 2 +- web/includes/Storage.php | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/web/includes/Event.php b/web/includes/Event.php index 2bb05bf5d..c9b3d0da5 100644 --- a/web/includes/Event.php +++ b/web/includes/Event.php @@ -532,7 +532,7 @@ class Event { $file = $backTrace[1]['file']; $line = $backTrace[1]['line']; Error("Invalid value for limit($limit) passed to Event::find from $file:$line"); - return; + return array(); } } } diff --git a/web/includes/Filter.php b/web/includes/Filter.php index f65399320..099307276 100644 --- a/web/includes/Filter.php +++ b/web/includes/Filter.php @@ -145,7 +145,7 @@ public $defaults = array( $file = $backTrace[1]['file']; $line = $backTrace[1]['line']; Error("Invalid value for limit($limit) passed to Filter::find from $file:$line"); - return; + return array(); } } } diff --git a/web/includes/Group.php b/web/includes/Group.php index 4cbdaa83b..dae1acb6a 100644 --- a/web/includes/Group.php +++ b/web/includes/Group.php @@ -91,7 +91,7 @@ class Group { $file = $backTrace[1]['file']; $line = $backTrace[1]['line']; Error("Invalid value for limit($limit) passed to Group::find from $file:$line"); - return; + return array(); } } } # end if options diff --git a/web/includes/Monitor.php b/web/includes/Monitor.php index 19aaf920b..f6ceca734 100644 --- a/web/includes/Monitor.php +++ b/web/includes/Monitor.php @@ -312,7 +312,7 @@ private $control_fields = array( $file = $backTrace[1]['file']; $line = $backTrace[1]['line']; Error("Invalid value for limit($limit) passed to Control::find from $file:$line"); - return; + return array(); } } } diff --git a/web/includes/Storage.php b/web/includes/Storage.php index bdd4bdf26..c4be3ae7e 100644 --- a/web/includes/Storage.php +++ b/web/includes/Storage.php @@ -117,7 +117,7 @@ class Storage { $file = $backTrace[1]['file']; $line = $backTrace[1]['line']; Error("Invalid value for limit($limit) passed to Control::find from $file:$line"); - return; + return array(); } } # end if limit } # end if options From a296b2b7772f1ba0d4873fa8293f5d16eab710ec Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Sun, 9 Sep 2018 14:01:03 -0400 Subject: [PATCH 6/6] fix crash when savind audio on ffmpeg 2.8 --- src/zm_videostore.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/zm_videostore.cpp b/src/zm_videostore.cpp index 1c3f34cf5..f36ecc72f 100644 --- a/src/zm_videostore.cpp +++ b/src/zm_videostore.cpp @@ -353,6 +353,9 @@ VideoStore::~VideoStore() { // The codec queues data. We need to send a flush command and out // whatever we get. Failures are not fatal. AVPacket pkt; + // Without these we seg fault I don't know why. + pkt.data = NULL; + pkt.size = 0; av_init_packet(&pkt); while (1) {