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

This commit is contained in:
Isaac Connor 2017-04-28 10:36:04 -04:00
commit b166579f4b
2 changed files with 1587 additions and 1582 deletions

View File

@ -45,6 +45,7 @@ connect to the server and pass instructions to it.
=cut
use strict;
use warnings;
use bytes;
# ==========================================================================
@ -53,7 +54,9 @@ use bytes;
#
# ==========================================================================
use constant MAX_CONNECT_DELAY => 10;
# in useconds, not seconds.
use constant MAX_CONNECT_DELAY => 10*1000*1000;
use constant KILL_DELAY => 10*1000; # 1/10th of a second
# ==========================================================================
#
@ -66,6 +69,7 @@ use ZoneMinder;
use POSIX;
use Socket;
use IO::Handle;
use Time::HiRes qw(usleep);
use autouse 'Pod::Usage'=>qw(pod2usage);
#use Data::Dumper;
@ -143,7 +147,9 @@ socket( CLIENT, PF_UNIX, SOCK_STREAM, 0 ) or Fatal( "Can't open socket: $!" );
my $saddr = sockaddr_un( SOCK_FILE );
my $server_up = connect( CLIENT, $saddr );
if ( ! $server_up ) {
# Server is not up. Some commands can still be handled
if ( $command eq 'logrot' ) {
# If server is not running, then logrotate doesn't need to do anything.
exit();
}
if ( $command eq 'check' ) {
@ -153,27 +159,32 @@ if ( !$server_up ) {
print( "Unable to connect to server using socket at " . SOCK_FILE . "\n" );
exit( -1 );
}
# The server isn't there
print( "Starting server\n" );
close( CLIENT );
if ( my $cpid = fork() ) {
# Parent process just sleep and fall through
# I'm still not sure why we need to re-init the logs
logInit();
# Parent process just sleep and fall through
socket( CLIENT, PF_UNIX, SOCK_STREAM, 0 ) or Fatal( "Can't open socket: $!" );
my $attempts = 0;
while( !connect( CLIENT, $saddr ) ) {
$attempts++;
Error("Waiting for zmdc.pl server process, attempt $attempts" );
Fatal( "Can't connect: $!" ) if ($attempts > MAX_CONNECT_DELAY);
sleep(1);
}
usleep(100);
} # end while
} elsif ( defined($cpid) ) {
ZMServer::run();
} else {
Fatal( "Can't fork: $!" );
}
}
} # end if ! server is up
if ( $command eq 'check' && ! $daemon ) {
print( "running\n" );
exit();
@ -181,12 +192,11 @@ if ( $command eq 'check' && !$daemon ) {
# Our work here is done
exit() if ( !$server_up );
}
# The server is there, connect to it
#print( "Writing commands\n" );
CLIENT->autoflush();
my $message = "$command";
$message .= ";$daemon" if ( $daemon );
$message .= ";".join( ';', @args ) if ( @args );
my $message = join(';', $command, ( $daemon ? $daemon : () ), @args );
print( CLIENT $message );
shutdown( CLIENT, 1 );
while( my $line = <CLIENT> ) {
@ -202,6 +212,7 @@ exit;
package ZMServer;
use strict;
use warnings;
use bytes;
@EXTRA_PERL_LIB@
@ -474,7 +485,7 @@ sub kill_until_dead {
}
sigprocmask(SIG_UNBLOCK, $blockset) or die "dying at unblock...\n";
usleep( 100 );
usleep( KILL_DELAY );
sigprocmask(SIG_BLOCK, $blockset, $sigset ) or die "dying at block...\n";
}
}
@ -637,7 +648,9 @@ sub shutdownAll {
delete( $cmd_hash{$$process{command}} );
delete( $pid_hash{$pid} );
}
if ( 0 ) {
killAll( 5 );
}
dPrint( ZoneMinder::Logger::INFO, "Server shutdown at "
.strftime( '%y/%m/%d %H:%M:%S', localtime() )
."\n"
@ -653,8 +666,7 @@ sub check {
my $daemon = shift;
my @args = @_;
my $command = $daemon;
$command .= ' '.join( ' ', ( @args ) ) if ( @args );
my $command = join( ' ', $daemon, @args );
my $process = $cmd_hash{$command};
if ( !$process ) {
cPrint( "unknown\n" );
@ -675,8 +687,7 @@ sub status {
my @args = @_;
if ( defined($daemon) ) {
my $command = $daemon;
$command .= ' '.join( ' ', ( @args ) ) if ( @args );
my $command = join( ' ', $daemon, @args );
my $process = $cmd_hash{$command};
if ( ! $process ) {
dPrint( ZoneMinder::Logger::DEBUG, "'$command' not running\n" );
@ -716,7 +727,7 @@ sub status {
."\n"
);
}
}
} # end foreach process
}
}

View File

@ -74,8 +74,7 @@ static deinterlace_4field_fptr_t fptr_deinterlace_4field_gray8;
/* Pointer to image buffer memory copy function */
imgbufcpy_fptr_t fptr_imgbufcpy;
Image::Image()
{
Image::Image() {
if ( !initialised )
Initialise();
width = 0;
@ -91,8 +90,7 @@ Image::Image()
text[0] = '\0';
}
Image::Image( const char *filename )
{
Image::Image( const char *filename ) {
if ( !initialised )
Initialise();
width = 0;
@ -946,8 +944,7 @@ bool Image::WriteJpeg( const char *filename, int quality_override, struct timeva
cinfo->dct_method = JDCT_FASTEST;
jpeg_start_compress( cinfo, TRUE );
if ( config.add_jpeg_comments && text[0] )
{
if ( config.add_jpeg_comments && text[0] ) {
jpeg_write_marker( cinfo, JPEG_COM, (const JOCTET *)text, strlen(text) );
}
// If we have a non-zero time (meaning a parameter was passed in), then form a simple exif segment with that time as DateTimeOriginal and SubsecTimeOriginal
@ -960,6 +957,7 @@ bool Image::WriteJpeg( const char *filename, int quality_override, struct timeva
#define EXIFTIMES_LEN 0x13 // = 19
#define EXIF_CODE 0xE1
// This is a lot of stuff to allocate on the stack. Recommend char *timebuf[64];
char timebuf[64], msbuf[64];
strftime(timebuf, sizeof timebuf, "%Y:%m:%d %H:%M:%S", localtime(&(timestamp.tv_sec)));
snprintf(msbuf, sizeof msbuf, "%06d",(int)(timestamp.tv_usec)); // we only use milliseconds because that's all defined in exif, but this is the whole microseconds because we have it
@ -2007,18 +2005,14 @@ void Image::Annotate( const char *p_text, const Coord &coord, const unsigned int
}
}
void Image::Timestamp( const char *label, const time_t when, const Coord &coord, const int size )
{
void Image::Timestamp( const char *label, const time_t when, const Coord &coord, const int size ) {
char time_text[64];
strftime( time_text, sizeof(time_text), "%y/%m/%d %H:%M:%S", localtime( &when ) );
char text[64];
if ( label )
{
if ( label ) {
snprintf( text, sizeof(text), "%s - %s", label, time_text );
Annotate( text, coord, size );
}
else
{
} else {
Annotate( time_text, coord, size );
}
}