Merge branch 'storageareas' of github.com:connortechnology/ZoneMinder into storageareas

This commit is contained in:
Isaac Connor 2018-04-25 10:31:47 -07:00
commit dd6683f0be
11 changed files with 210 additions and 186 deletions

View File

@ -54,7 +54,7 @@ Depends: ${shlibs:Depends}, ${misc:Depends}, ${perl:Depends}
,liburi-encode-perl
,libwww-perl
,libdata-uuid-perl
,libnumber-bytes-human
,libnumber-bytes-human-perl
,libfile-slurp-perl
,mysql-client | virtual-mysql-client
,perl-modules

View File

@ -118,7 +118,7 @@ if ( $command eq 'version' ) {
exit(0);
}
my $needs_daemon = $command !~ /(?:startup|shutdown|status|check|logrot|version)/;
my $daemon = shift( @ARGV );
my $daemon = shift @ARGV;
if ( $needs_daemon && ! $daemon ) {
print(STDERR "No daemon given\n");
pod2usage(-exitstatus => -1);
@ -209,7 +209,6 @@ if ( ($command eq 'check') && !$daemon ) {
}
# The server is there, connect to it
#print( "Writing commands\n" );
CLIENT->autoflush();
my $message = join(';', $command, ( $daemon ? $daemon : () ), @args );
print(CLIENT $message);
@ -218,9 +217,7 @@ while( my $line = <CLIENT> ) {
chomp($line);
print("$line\n");
}
# And we're done!
close(CLIENT);
#print( "Finished writing, bye\n" );
exit;
@ -319,7 +316,7 @@ sub run {
next if !$message;
my ( $command, $daemon, @args ) = split( /;/, $message );
my ( $command, $daemon, @args ) = split(';', $message);
if ( $command eq 'start' ) {
start($daemon, @args);
@ -425,7 +422,7 @@ sub start {
.strftime('%y/%m/%d %H:%M:%S', localtime($process->{started}))
.", pid = $process->{pid}\n"
);
return();
return;
}
my $sigset = POSIX::SigSet->new;
@ -436,7 +433,7 @@ sub start {
$process->{pid} = $cpid;
$process->{started} = time();
delete( $process->{pending} );
delete $process->{pending};
dPrint(ZoneMinder::Logger::INFO, "'$command' starting at "
.strftime('%y/%m/%d %H:%M:%S', localtime($process->{started}))
@ -450,8 +447,7 @@ sub start {
$dbh = zmDbConnect(1);
logReinit();
dPrint( ZoneMinder::Logger::INFO, "'".join( ' ', ( $daemon, @args ) )
."' started at "
dPrint(ZoneMinder::Logger::INFO, "'$command' started at "
.strftime('%y/%m/%d %H:%M:%S', localtime())
."\n"
);
@ -466,7 +462,7 @@ sub start {
foreach my $arg ( @args ) {
# Detaint arguments, if they look ok
if ( $arg =~ /^(-{0,2}[\w\/?&=.-]+)$/ ) {
push( @good_args, $1 );
push @good_args, $1;
} else {
Fatal("Bogus argument '$arg' found");
}
@ -490,7 +486,7 @@ sub start {
} else {
Fatal("Can't fork: $!");
}
}
} # end sub start
# Sends the stop signal, without waiting around to see if the process died.
sub send_stop {
@ -499,7 +495,7 @@ sub send_stop {
my $command = $process->{command};
if ( $process->{pending} ) {
delete( $cmd_hash{$command} );
delete $cmd_hash{$command};
dPrint(ZoneMinder::Logger::INFO, "Command '$command' removed from pending list at "
.strftime('%y/%m/%d %H:%M:%S', localtime())
."\n"
@ -522,7 +518,6 @@ sub send_stop {
$process->{pending} = 0;
$terminating_processes{$command} = $process;
kill('TERM', $pid);
return $pid;
} # end sub send_stop
@ -534,6 +529,7 @@ sub check_for_processes_to_kill {
sigprocmask(SIG_BLOCK, $blockset, $sigset) or die "dying at block...\n";
foreach my $command ( %terminating_processes ) {
my $process = $cmd_hash{$command};
Debug("Have process $command at pid $$process{pid} $$process{term_sent_at}");
if ( $$process{term_sent_at} - time > KILL_DELAY ) {
dPrint(ZoneMinder::Logger::WARNING, "'$$process{command}' has not stopped at "
.strftime('%y/%m/%d %H:%M:%S', localtime())
@ -591,7 +587,7 @@ sub reload {
sub logrot {
logReinit();
foreach my $process ( values(%pid_hash) ) {
foreach my $process ( values %pid_hash ) {
if ( $process->{pid} ) {
# && $process->{command} =~ /^zm.*\.pl/ ) {
kill('HUP', $process->{pid});

View File

@ -834,7 +834,7 @@ double Monitor::GetFPS() const {
Snapshot *snap1 = &image_buffer[index1];
if ( !snap1->timestamp || !snap1->timestamp->tv_sec ) {
// This should be impossible
Warning("Impossible situation. No timestamp on captured image");
Warning("Impossible situation. No timestamp on captured image index was %d, image-buffer_count was (%d)", index1, image_buffer_count);
return 0.0;
}
struct timeval time1 = *snap1->timestamp;

View File

@ -21,6 +21,7 @@
#include "zm_rtsp_auth.h"
#include "zm_mem_utils.h"
#include "zm_signal.h"
#include <sys/types.h>
#include <sys/socket.h>
@ -194,7 +195,7 @@ int RemoteCameraHttp::ReadData( Buffer &buffer, unsigned int bytes_expected ) {
int n_found = select(sd+1, &rfds, NULL, NULL, &temp_timeout);
if( n_found == 0 ) {
Debug( 4, "Select timed out timeout was %d secs %d usecs", temp_timeout.tv_sec, temp_timeout.tv_usec );
Debug( 1, "Select timed out timeout was %d secs %d usecs", temp_timeout.tv_sec, temp_timeout.tv_usec );
int error = 0;
socklen_t len = sizeof (error);
int retval = getsockopt (sd, SOL_SOCKET, SO_ERROR, &error, &len);
@ -206,10 +207,10 @@ int RemoteCameraHttp::ReadData( Buffer &buffer, unsigned int bytes_expected ) {
}
// Why are we disconnecting? It's just a timeout, meaning that data wasn't available.
//Disconnect();
return( 0 );
return 0;
} else if ( n_found < 0) {
Error("Select error: %s", strerror(errno));
return( -1 );
return -1;
}
unsigned int total_bytes_to_read = 0;
@ -309,13 +310,14 @@ int RemoteCameraHttp::GetResponse()
static RegExpr *content_length_expr = 0;
static RegExpr *content_type_expr = 0;
while ( ! ( buffer_len = ReadData( buffer ) ) ) {
while ( !( buffer_len = ReadData(buffer) ) && !zm_terminate ) {
Debug(4, "Timeout waiting for REGEXP HEADER");
}
if ( buffer_len < 0 ) {
Error( "Unable to read header data" );
return( -1 );
}
bytes += buffer_len;
if ( !header_expr )
header_expr = new RegExpr( "^(.+?\r?\n\r?\n)", PCRE_DOTALL );
if ( header_expr->Match( (char*)buffer, buffer.size() ) == 2 )
@ -483,13 +485,14 @@ int RemoteCameraHttp::GetResponse()
else
{
Debug( 3, "Unable to extract subheader from stream, retrying" );
while ( ! ( buffer_len = ReadData( buffer ) ) ) {
while ( !( buffer_len = ReadData(buffer) ) && !zm_terminate ) {
Debug(4, "Timeout waiting to extract subheader");
}
if ( buffer_len < 0 ) {
Error( "Unable to extract subheader data" );
return( -1 );
}
bytes += buffer_len;
}
break;
}
@ -522,13 +525,16 @@ int RemoteCameraHttp::GetResponse()
if ( content_length )
{
while ( (long)buffer.size() < content_length )
while ( ((long)buffer.size() < content_length ) && ! zm_terminate )
{
Debug(3, "Need more data buffer %d < content length %d", buffer.size(), content_length );
if ( ReadData( buffer ) < 0 ) {
int bytes_read = ReadData( buffer );
if ( bytes_read < 0 ) {
Error( "Unable to read content" );
return( -1 );
}
bytes += bytes_read;
}
Debug( 3, "Got end of image by length, content-length = %d", content_length );
}
@ -536,13 +542,14 @@ int RemoteCameraHttp::GetResponse()
{
while ( !content_length )
{
while ( ! ( buffer_len = ReadData( buffer ) ) ) {
while ( !( buffer_len = ReadData(buffer) ) && !zm_terminate ) {
Debug(4, "Timeout waiting for content");
}
if ( buffer_len < 0 ) {
Error( "Unable to read content" );
return( -1 );
}
bytes += buffer_len;
static RegExpr *content_expr = 0;
if ( mode == MULTI_IMAGE )
{
@ -656,13 +663,14 @@ int RemoteCameraHttp::GetResponse()
}
case HEADERCONT :
{
while ( ! ( buffer_len = ReadData( buffer ) ) ) {
while ( !( buffer_len = ReadData(buffer) ) && !zm_terminate ) {
Debug(4, "Timeout waiting for HEADERCONT");
}
if ( buffer_len < 0 ) {
Error( "Unable to read header" );
return( -1 );
}
bytes += buffer_len;
char *crlf = 0;
char *header_ptr = (char *)buffer;
@ -941,13 +949,14 @@ int RemoteCameraHttp::GetResponse()
state = CONTENT;
} else {
Debug( 3, "Unable to extract subheader from stream, retrying" );
while ( ! ( buffer_len = ReadData( buffer ) ) ) {
while ( !( buffer_len = ReadData(buffer) ) &&!zm_terminate ) {
Debug(1, "Timeout waiting to extra subheader non regexp");
}
if ( buffer_len < 0 ) {
Error( "Unable to read subheader" );
return( -1 );
}
bytes += buffer_len;
state = SUBHEADERCONT;
}
break;
@ -980,18 +989,19 @@ int RemoteCameraHttp::GetResponse()
}
if ( content_length ) {
while ( (long)buffer.size() < content_length ) {
//int buffer_len = ReadData( buffer, content_length-buffer.size() );
while ( ( (long)buffer.size() < content_length ) && ! zm_terminate ) {
Debug(4, "getting more data");
if ( ReadData( buffer ) < 0 ) {
int bytes_read = ReadData(buffer);
if ( bytes_read < 0 ) {
Error("Unable to read content");
return( -1 );
return -1;
}
bytes += bytes_read;
}
Debug( 3, "Got end of image by length, content-length = %d", content_length );
} else {
// Read until we find the end of image or the stream closes.
while ( !content_length ) {
while ( !content_length && !zm_terminate ) {
Debug(4, "!content_length, ReadData");
buffer_len = ReadData( buffer );
if ( buffer_len < 0 )
@ -999,6 +1009,7 @@ int RemoteCameraHttp::GetResponse()
Error( "Unable to read content" );
return( -1 );
}
bytes += buffer_len;
int buffer_size = buffer.size();
if ( buffer_len ) {
// Got some data

View File

@ -711,7 +711,7 @@ int VideoStore::writeVideoFramePacket(AVPacket *ipkt) {
opkt.dts = video_next_dts;
opkt.duration = 0;
int duration;
int64_t duration;
if ( !video_last_pts ) {
duration = 0;
} else {
@ -723,7 +723,7 @@ int VideoStore::writeVideoFramePacket(AVPacket *ipkt) {
video_last_pts,
duration);
if (duration < 0) {
duration = ipkt->duration;
duration = ipkt->duration ? ipkt->duration : av_rescale_q(1,video_in_stream->time_base, video_out_stream->time_base);
}
}

View File

@ -228,6 +228,7 @@ int main(int argc, char *argv[]) {
sigset_t block_set;
sigemptyset(&block_set);
sigaddset(&block_set, SIGHUP);
sigaddset(&block_set, SIGUSR1);
sigaddset(&block_set, SIGUSR2);

View File

@ -256,6 +256,9 @@ private $control_fields = array(
public function set($data) {
foreach ($data as $k => $v) {
if ( method_exists($this, $k) ) {
$this->{$k}($v);
} else {
if ( is_array( $v ) ) {
# perhaps should turn into a comma-separated string
$this->{$k} = implode(',',$v);
@ -269,7 +272,8 @@ private $control_fields = array(
Error( "Unknown type $k => $v of var " . gettype( $v ) );
$this->{$k} = $v;
}
}
} # end if method_exists
} # end foreach $data as $k=>$v
}
public static function find_all( $parameters = null, $options = null ) {
$filters = array();
@ -400,10 +404,20 @@ private $control_fields = array(
}
} // end if we are on the recording server
}
public function GroupIds( ) {
public function GroupIds( $new='') {
if ( $new != '' ) {
if(!is_array($new)) {
$this->{'GroupIds'} = array($new);
} else {
$this->{'GroupIds'} = $new;
}
}
if ( !array_key_exists('GroupIds', $this) ) {
if ( array_key_exists('Id', $this) and $this->{'Id'} ) {
$this->{'GroupIds'} = dbFetchAll('SELECT GroupId FROM Groups_Monitors WHERE MonitorId=?', 'GroupId', array($this->{'Id'}) );
if ( ! $this->{'GroupIds'} )
$this->{'GroupIds'} = array();
} else {
$this->{'GroupIds'} = array();
}

View File

@ -565,6 +565,8 @@ if ( canEdit( 'Monitors' ) ) {
return;
}
$restart = true;
} # end if count(changes)
if (
( !isset($_POST['newMonitor']['GroupIds']) )
or
@ -581,8 +583,6 @@ if ( canEdit( 'Monitors' ) ) {
}
}
} // end if there has been a change of groups
$restart = true;
} # end if count(changes)
if ( ZM_OPT_X10 ) {
$x10Changes = getFormChanges( $x10Monitor, $_REQUEST['newX10Monitor'] );

View File

@ -133,10 +133,7 @@ function dbQuery( $sql, $params=NULL ) {
}
} else {
if ( defined('ZM_DB_DEBUG') ) {
if ( $params )
Warning("SQL: $sql" . implode(',',$params) );
else
Warning("SQL: $sql:" );
Logger::Debug("SQL: $sql values:" . $params?implode(',',$params):'' );
}
$result = $dbConn->query($sql);
}
@ -186,7 +183,7 @@ function dbFetchAll( $sql, $col=false, $params=NULL ) {
$dbRows = array();
while( $dbRow = $result->fetch( PDO::FETCH_ASSOC ) )
$dbRows[] = $col?$dbRow[$col]:$dbRow;
return( $dbRows );
return $dbRows;
}
function dbFetchAssoc( $sql, $indexCol, $dataCol=false ) {

View File

@ -486,7 +486,7 @@ function getFormChanges( $values, $newValues, $types=false, $columns=false ) {
$types = array();
foreach( $newValues as $key=>$value ) {
if ( $columns && !$columns[$key] )
if ( $columns && !isset($columns[$key]) )
continue;
if ( !isset($types[$key]) )

View File

@ -62,7 +62,7 @@ if ( ! $monitor ) {
$nextId = getTableAutoInc( 'Monitors' );
if ( isset( $_REQUEST['dupId'] ) ) {
$monitor = new Monitor( $_REQUEST['dupId'] );
$monitor->GroupIds(); // have to lead before we change the Id
$monitor->GroupIds(); // have to load before we change the Id
if ( ZM_OPT_X10 )
$x10Monitor = dbFetchOne( 'SELECT * FROM TriggersX10 WHERE MonitorId = ?', NULL, array($_REQUEST['dupId']) );
$clonedName = $monitor->Name();
@ -534,6 +534,11 @@ if ( $tab != 'general' ) {
<input type="hidden" name="newMonitor[Name]" value="<?php echo validHtmlStr($monitor->Name()) ?>"/>
<input type="hidden" name="newMonitor[ServerId]" value="<?php echo validHtmlStr($monitor->ServerId() ) ?>"/>
<input type="hidden" name="newMonitor[StorageId]" value="<?= validHtmlStr($monitor->StorageId() ) ?>"/>
<?php
foreach ( $monitor->GroupIds() as $group_id ) {
echo '<input type="hidden" name="newMonitor[GroupIds][]" value="'.$group_id.'"/>';
}
?>
<input type="hidden" name="newMonitor[Type]" value="<?php echo validHtmlStr($monitor->Type()) ?>"/>
<input type="hidden" name="newMonitor[Function]" value="<?php echo validHtmlStr($monitor->Function()) ?>"/>
<input type="hidden" name="newMonitor[Enabled]" value="<?php echo validHtmlStr($monitor->Enabled()) ?>"/>