Merge branch 'storageareas' of github.com:ConnorTechnology/ZoneMinder into storageareas
This commit is contained in:
commit
b166579f4b
|
@ -45,6 +45,7 @@ connect to the server and pass instructions to it.
|
||||||
|
|
||||||
=cut
|
=cut
|
||||||
use strict;
|
use strict;
|
||||||
|
use warnings;
|
||||||
use bytes;
|
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 POSIX;
|
||||||
use Socket;
|
use Socket;
|
||||||
use IO::Handle;
|
use IO::Handle;
|
||||||
|
use Time::HiRes qw(usleep);
|
||||||
use autouse 'Pod::Usage'=>qw(pod2usage);
|
use autouse 'Pod::Usage'=>qw(pod2usage);
|
||||||
#use Data::Dumper;
|
#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 $saddr = sockaddr_un( SOCK_FILE );
|
||||||
my $server_up = connect( CLIENT, $saddr );
|
my $server_up = connect( CLIENT, $saddr );
|
||||||
if ( ! $server_up ) {
|
if ( ! $server_up ) {
|
||||||
|
# Server is not up. Some commands can still be handled
|
||||||
if ( $command eq 'logrot' ) {
|
if ( $command eq 'logrot' ) {
|
||||||
|
# If server is not running, then logrotate doesn't need to do anything.
|
||||||
exit();
|
exit();
|
||||||
}
|
}
|
||||||
if ( $command eq 'check' ) {
|
if ( $command eq 'check' ) {
|
||||||
|
@ -153,27 +159,32 @@ if ( !$server_up ) {
|
||||||
print( "Unable to connect to server using socket at " . SOCK_FILE . "\n" );
|
print( "Unable to connect to server using socket at " . SOCK_FILE . "\n" );
|
||||||
exit( -1 );
|
exit( -1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
# The server isn't there
|
# The server isn't there
|
||||||
print( "Starting server\n" );
|
print( "Starting server\n" );
|
||||||
close( CLIENT );
|
close( CLIENT );
|
||||||
|
|
||||||
if ( my $cpid = fork() ) {
|
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();
|
logInit();
|
||||||
|
|
||||||
# Parent process just sleep and fall through
|
|
||||||
socket( CLIENT, PF_UNIX, SOCK_STREAM, 0 ) or Fatal( "Can't open socket: $!" );
|
socket( CLIENT, PF_UNIX, SOCK_STREAM, 0 ) or Fatal( "Can't open socket: $!" );
|
||||||
my $attempts = 0;
|
my $attempts = 0;
|
||||||
while( !connect( CLIENT, $saddr ) ) {
|
while( !connect( CLIENT, $saddr ) ) {
|
||||||
$attempts++;
|
$attempts++;
|
||||||
|
Error("Waiting for zmdc.pl server process, attempt $attempts" );
|
||||||
Fatal( "Can't connect: $!" ) if ($attempts > MAX_CONNECT_DELAY);
|
Fatal( "Can't connect: $!" ) if ($attempts > MAX_CONNECT_DELAY);
|
||||||
sleep(1);
|
usleep(100);
|
||||||
}
|
} # end while
|
||||||
} elsif ( defined($cpid) ) {
|
} elsif ( defined($cpid) ) {
|
||||||
ZMServer::run();
|
ZMServer::run();
|
||||||
} else {
|
} else {
|
||||||
Fatal( "Can't fork: $!" );
|
Fatal( "Can't fork: $!" );
|
||||||
}
|
}
|
||||||
}
|
} # end if ! server is up
|
||||||
|
|
||||||
if ( $command eq 'check' && ! $daemon ) {
|
if ( $command eq 'check' && ! $daemon ) {
|
||||||
print( "running\n" );
|
print( "running\n" );
|
||||||
exit();
|
exit();
|
||||||
|
@ -181,12 +192,11 @@ if ( $command eq 'check' && !$daemon ) {
|
||||||
# Our work here is done
|
# Our work here is done
|
||||||
exit() if ( !$server_up );
|
exit() if ( !$server_up );
|
||||||
}
|
}
|
||||||
|
|
||||||
# The server is there, connect to it
|
# The server is there, connect to it
|
||||||
#print( "Writing commands\n" );
|
#print( "Writing commands\n" );
|
||||||
CLIENT->autoflush();
|
CLIENT->autoflush();
|
||||||
my $message = "$command";
|
my $message = join(';', $command, ( $daemon ? $daemon : () ), @args );
|
||||||
$message .= ";$daemon" if ( $daemon );
|
|
||||||
$message .= ";".join( ';', @args ) if ( @args );
|
|
||||||
print( CLIENT $message );
|
print( CLIENT $message );
|
||||||
shutdown( CLIENT, 1 );
|
shutdown( CLIENT, 1 );
|
||||||
while( my $line = <CLIENT> ) {
|
while( my $line = <CLIENT> ) {
|
||||||
|
@ -202,6 +212,7 @@ exit;
|
||||||
package ZMServer;
|
package ZMServer;
|
||||||
|
|
||||||
use strict;
|
use strict;
|
||||||
|
use warnings;
|
||||||
use bytes;
|
use bytes;
|
||||||
|
|
||||||
@EXTRA_PERL_LIB@
|
@EXTRA_PERL_LIB@
|
||||||
|
@ -474,7 +485,7 @@ sub kill_until_dead {
|
||||||
}
|
}
|
||||||
|
|
||||||
sigprocmask(SIG_UNBLOCK, $blockset) or die "dying at unblock...\n";
|
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";
|
sigprocmask(SIG_BLOCK, $blockset, $sigset ) or die "dying at block...\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -637,7 +648,9 @@ sub shutdownAll {
|
||||||
delete( $cmd_hash{$$process{command}} );
|
delete( $cmd_hash{$$process{command}} );
|
||||||
delete( $pid_hash{$pid} );
|
delete( $pid_hash{$pid} );
|
||||||
}
|
}
|
||||||
|
if ( 0 ) {
|
||||||
killAll( 5 );
|
killAll( 5 );
|
||||||
|
}
|
||||||
dPrint( ZoneMinder::Logger::INFO, "Server shutdown at "
|
dPrint( ZoneMinder::Logger::INFO, "Server shutdown at "
|
||||||
.strftime( '%y/%m/%d %H:%M:%S', localtime() )
|
.strftime( '%y/%m/%d %H:%M:%S', localtime() )
|
||||||
."\n"
|
."\n"
|
||||||
|
@ -653,8 +666,7 @@ sub check {
|
||||||
my $daemon = shift;
|
my $daemon = shift;
|
||||||
my @args = @_;
|
my @args = @_;
|
||||||
|
|
||||||
my $command = $daemon;
|
my $command = join( ' ', $daemon, @args );
|
||||||
$command .= ' '.join( ' ', ( @args ) ) if ( @args );
|
|
||||||
my $process = $cmd_hash{$command};
|
my $process = $cmd_hash{$command};
|
||||||
if ( !$process ) {
|
if ( !$process ) {
|
||||||
cPrint( "unknown\n" );
|
cPrint( "unknown\n" );
|
||||||
|
@ -675,8 +687,7 @@ sub status {
|
||||||
my @args = @_;
|
my @args = @_;
|
||||||
|
|
||||||
if ( defined($daemon) ) {
|
if ( defined($daemon) ) {
|
||||||
my $command = $daemon;
|
my $command = join( ' ', $daemon, @args );
|
||||||
$command .= ' '.join( ' ', ( @args ) ) if ( @args );
|
|
||||||
my $process = $cmd_hash{$command};
|
my $process = $cmd_hash{$command};
|
||||||
if ( ! $process ) {
|
if ( ! $process ) {
|
||||||
dPrint( ZoneMinder::Logger::DEBUG, "'$command' not running\n" );
|
dPrint( ZoneMinder::Logger::DEBUG, "'$command' not running\n" );
|
||||||
|
@ -716,7 +727,7 @@ sub status {
|
||||||
."\n"
|
."\n"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
} # end foreach process
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -74,8 +74,7 @@ static deinterlace_4field_fptr_t fptr_deinterlace_4field_gray8;
|
||||||
/* Pointer to image buffer memory copy function */
|
/* Pointer to image buffer memory copy function */
|
||||||
imgbufcpy_fptr_t fptr_imgbufcpy;
|
imgbufcpy_fptr_t fptr_imgbufcpy;
|
||||||
|
|
||||||
Image::Image()
|
Image::Image() {
|
||||||
{
|
|
||||||
if ( !initialised )
|
if ( !initialised )
|
||||||
Initialise();
|
Initialise();
|
||||||
width = 0;
|
width = 0;
|
||||||
|
@ -91,8 +90,7 @@ Image::Image()
|
||||||
text[0] = '\0';
|
text[0] = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
Image::Image( const char *filename )
|
Image::Image( const char *filename ) {
|
||||||
{
|
|
||||||
if ( !initialised )
|
if ( !initialised )
|
||||||
Initialise();
|
Initialise();
|
||||||
width = 0;
|
width = 0;
|
||||||
|
@ -946,8 +944,7 @@ bool Image::WriteJpeg( const char *filename, int quality_override, struct timeva
|
||||||
cinfo->dct_method = JDCT_FASTEST;
|
cinfo->dct_method = JDCT_FASTEST;
|
||||||
|
|
||||||
jpeg_start_compress( cinfo, TRUE );
|
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) );
|
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
|
// 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 EXIFTIMES_LEN 0x13 // = 19
|
||||||
#define EXIF_CODE 0xE1
|
#define EXIF_CODE 0xE1
|
||||||
|
|
||||||
|
// This is a lot of stuff to allocate on the stack. Recommend char *timebuf[64];
|
||||||
char timebuf[64], msbuf[64];
|
char timebuf[64], msbuf[64];
|
||||||
strftime(timebuf, sizeof timebuf, "%Y:%m:%d %H:%M:%S", localtime(&(timestamp.tv_sec)));
|
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
|
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];
|
char time_text[64];
|
||||||
strftime( time_text, sizeof(time_text), "%y/%m/%d %H:%M:%S", localtime( &when ) );
|
strftime( time_text, sizeof(time_text), "%y/%m/%d %H:%M:%S", localtime( &when ) );
|
||||||
char text[64];
|
char text[64];
|
||||||
if ( label )
|
if ( label ) {
|
||||||
{
|
|
||||||
snprintf( text, sizeof(text), "%s - %s", label, time_text );
|
snprintf( text, sizeof(text), "%s - %s", label, time_text );
|
||||||
Annotate( text, coord, size );
|
Annotate( text, coord, size );
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
Annotate( time_text, coord, size );
|
Annotate( time_text, coord, size );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue