Bug 247,248 Debug mods, changed to remove log control from scripts.

git-svn-id: http://svn.zoneminder.com/svn/zm/trunk@1767 e3e1d417-86f3-4887-817a-d78f3d33393f
This commit is contained in:
stan 2006-01-11 23:55:22 +00:00
parent a38532eaa2
commit 3ada3ee967
12 changed files with 339 additions and 161 deletions

View File

@ -42,8 +42,6 @@ use ZoneMinder;
use Getopt::Long; use Getopt::Long;
use Device::SerialPort; use Device::SerialPort;
use constant LOG_FILE => ZM_PATH_LOGS.'/zmcontrol-axis-v2.log';
$| = 1; $| = 1;
$ENV{PATH} = '/bin:/usr/bin'; $ENV{PATH} = '/bin:/usr/bin';
@ -58,7 +56,7 @@ Usage: zmcontrol-axis-v2.pl <various options>
exit( -1 ); exit( -1 );
} }
zmDbgInit( DBG_ID, DBG_LEVEL ); zmDbgInit( DBG_ID, level=>DBG_LEVEL );
my $arg_string = join( " ", @ARGV ); my $arg_string = join( " ", @ARGV );
@ -96,14 +94,6 @@ if ( !$address )
Usage(); Usage();
} }
my $log_file = LOG_FILE;
open( LOG, ">>$log_file" ) or die( "Can't open log file: $!" );
open( STDOUT, ">&LOG" ) || die( "Can't dup stdout: $!" );
select( STDOUT ); $| = 1;
open( STDERR, ">&LOG" ) || die( "Can't dup stderr: $!" );
select( STDERR ); $| = 1;
select( LOG ); $| = 1;
Debug( $arg_string."\n" ); Debug( $arg_string."\n" );
srand( time() ); srand( time() );

293
scripts/zmcontrol-ncs370.pl Normal file
View File

@ -0,0 +1,293 @@
#!/usr/bin/perl -wT
#
# ==========================================================================
#
# ZoneMinder Neu-Fusion Control Script, $Date$, $Revision$
# Copyright (C) 2005 Richard Yeardley
# Portions Copyright (C) 2003, 2004, 2005 Philip Coombes
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
# ==========================================================================
#
# This script continuously monitors the recorded events for the given
# monitor and applies any filters which would delete and/or upload
# matching events
#
use strict;
# ==========================================================================
#
# These are the elements you can edit to suit your installation
#
# ==========================================================================
use constant DBG_ID => "zmctrl-ncs370"; # Tag that appears in debug to identify source
use constant DBG_LEVEL => 0; # 0 is errors, warnings and info only, > 0 for debug
use ZoneMinder;
use Getopt::Long;
use Device::SerialPort;
$| = 1;
$ENV{PATH} = '/bin:/usr/bin';
$ENV{SHELL} = '/bin/sh' if exists $ENV{SHELL};
delete @ENV{qw(IFS CDPATH ENV BASH_ENV)};
sub Usage
{
print( "
Usage: zmcontrol-ncs370.pl <various options>
");
exit( -1 );
}
zmDbgInit( DBG_ID, level=>DBG_LEVEL );
my $arg_string = join( " ", @ARGV );
my $address;
my $command;
my ( $speed, $step );
my ( $xcoord, $ycoord );
my ( $width, $height );
my ( $panspeed, $tiltspeed );
my ( $panstep, $tiltstep );
my $preset;
if ( !GetOptions(
'address=s'=>\$address,
'command=s'=>\$command,
'speed=i'=>\$speed,
'step=i'=>\$step,
'xcoord=i'=>\$xcoord,
'ycoord=i'=>\$ycoord,
'width=i'=>\$width,
'height=i'=>\$height,
'panspeed=i'=>\$panspeed,
'tiltspeed=i'=>\$tiltspeed,
'panstep=i'=>\$panstep,
'tiltstep=i'=>\$tiltstep,
'preset=i'=>\$preset
)
)
{
Usage();
}
if ( !$address )
{
Usage();
}
Debug( $arg_string."\n" );
srand( time() );
sub printMsg
{
my $msg = shift;
my $msg_len = length($msg);
Debug( $msg."[".$msg_len."]\n" );
}
sub sendCmd
{
my $cmd = shift;
my $result = undef;
printMsg( $cmd, "Tx" );
use LWP::UserAgent;
my $ua = LWP::UserAgent->new;
$ua->agent( "ZoneMinder Control Agent/".ZM_VERSION );
my $req = HTTP::Request->new( POST=>"http://$address/PANTILTCONTROL.CGI" );
$req->content($cmd);
my $res = $ua->request($req);
if ( $res->is_success )
{
$result = !undef;
}
else
{
Error( "Error check failed: '".$res->status_line()."'\n" );
}
return( $result );
}
sub cameraReset
{
Debug( "Camera Reset\n" );
my $cmd = "nphRestart?PAGE=Restart&Restart=OK";
sendCmd( $cmd );
}
sub moveUp
{
Debug( "Move Up\n" );
my $cmd = "PanSingleMoveDegree=1\nTiltSingleMoveDegree=1\nPanTiltSingleMove=1";
sendCmd( $cmd );
}
sub moveDown
{
Debug( "Move Down\n" );
my $cmd = "PanSingleMoveDegree=1\nTiltSingleMoveDegree=1\nPanTiltSingleMove=7";
sendCmd( $cmd );
}
sub moveLeft
{
Debug( "Move Left\n" );
my $cmd = "PanSingleMoveDegree=1\nTiltSingleMoveDegree=1\nPanTiltSingleMove=3";
sendCmd( $cmd );
}
sub moveRight
{
Debug( "Move Right\n" );
my $cmd = "PanSingleMoveDegree=1\nTiltSingleMoveDegree=1\nPanTiltSingleMove=5";
sendCmd( $cmd );
}
sub moveUpRight
{
moveUp();
moveRight();
}
sub moveUpLeft
{
moveUp();
moveLeft();
}
sub moveDownRight
{
moveDown();
moveRight();
}
sub moveDownLeft
{
moveDown();
moveLeft();
}
sub moveMap
{
my ( $xcoord, $ycoord, $width, $height ) = @_;
Debug( "Move Map to $xcoord,$ycoord\n" );
my $cmd = "/axis-cgi/com/ptz.cgi?center=$xcoord,$ycoord&imagewidth=$width&imageheight=$height";
sendCmd( $cmd );
}
sub stepUp
{
my $step = shift;
Debug( "Step Up $step\n" );
my $cmd = "PanSingleMoveDegree=1\nTiltSingleMoveDegree=$step\nPanTiltSingleMove=1";
sendCmd( $cmd );
}
sub presetClear
{
my $preset = shift || 1;
Debug( "Clear Preset $preset\n" );
my $cmd = "nphPresetNameCheck?Data=$preset";
sendCmd( $cmd );
}
sub presetSet
{
my $preset = shift || 1;
Debug( "Set Preset $preset\n" );
my $cmd = "/axis-cgi/com/ptz.cgi?setserverpresetno=$preset";
sendCmd( $cmd );
}
sub presetGoto
{
my $preset = shift || 1;
Debug( "Goto Preset $preset\n" );
my $cmd = "PanTiltPresetPositionMove=$preset";
sendCmd( $cmd );
}
sub presetHome
{
Debug( "Home Preset\n" );
my $cmd = "PanSingleMoveDegree=1\nTiltSingleMoveDegree=1\nPanTiltSingleMove=4";
sendCmd( $cmd );
}
if ( $command eq "move_con_up" )
{
moveUp();
}
elsif ( $command eq "move_con_down" )
{
moveDown();
}
elsif ( $command eq "move_con_left" )
{
moveLeft();
}
elsif ( $command eq "move_con_right" )
{
moveRight();
}
elsif ( $command eq "move_con_upleft" )
{
moveUpLeft();
}
elsif ( $command eq "move_con_upright" )
{
moveUpRight();
}
elsif ( $command eq "move_con_downleft" )
{
moveDownLeft();
}
elsif ( $command eq "move_con_downright" )
{
moveDownRight();
}
elsif ( $command eq "move_map" )
{
# moveMap( $xcoord, $ycoord, $width, $height );
}
elsif ( $command eq "preset_home" )
{
presetHome();
}
elsif ( $command eq "preset_set" )
{
# presetSet( $preset );
}
elsif ( $command eq "preset_goto" )
{
presetGoto( $preset );
}
else
{
Error( "Can't handle command $command\n" );
}

View File

@ -42,8 +42,6 @@ use ZoneMinder;
use Getopt::Long; use Getopt::Long;
use Device::SerialPort; use Device::SerialPort;
use constant LOG_FILE => ZM_PATH_LOGS.'/zmcontrol-panasonic-ip.log';
$| = 1; $| = 1;
$ENV{PATH} = '/bin:/usr/bin'; $ENV{PATH} = '/bin:/usr/bin';
@ -58,7 +56,7 @@ Usage: zmcontrol-pansonic-ip.pl <various options>
exit( -1 ); exit( -1 );
} }
zmDbgInit( DBG_ID, DBG_LEVEL ); zmDbgInit( DBG_ID, level=>DBG_LEVEL );
my $arg_string = join( " ", @ARGV ); my $arg_string = join( " ", @ARGV );
@ -96,14 +94,6 @@ if ( !$address )
Usage(); Usage();
} }
my $log_file = LOG_FILE;
open( LOG, ">>$log_file" ) or die( "Can't open log file: $!" );
open( STDOUT, ">&LOG" ) || die( "Can't dup stdout: $!" );
select( STDOUT ); $| = 1;
open( STDERR, ">&LOG" ) || die( "Can't dup stderr: $!" );
select( STDERR ); $| = 1;
select( LOG ); $| = 1;
Debug( $arg_string."\n" ); Debug( $arg_string."\n" );
srand( time() ); srand( time() );

View File

@ -43,8 +43,6 @@ use Getopt::Long;
use Device::SerialPort; use Device::SerialPort;
use Time::HiRes qw( usleep ); use Time::HiRes qw( usleep );
use constant LOG_FILE => ZM_PATH_LOGS.'/zmcontrol-pelco-d.log';
$| = 1; $| = 1;
$ENV{PATH} = '/bin:/usr/bin'; $ENV{PATH} = '/bin:/usr/bin';
@ -59,7 +57,7 @@ Usage: zmcontrol-pelco-d.pl <various options>
exit( -1 ); exit( -1 );
} }
zmDbgInit( DBG_ID, DBG_LEVEL ); zmDbgInit( DBG_ID, level=>DBG_LEVEL );
my $arg_string = join( " ", @ARGV ); my $arg_string = join( " ", @ARGV );
@ -99,14 +97,6 @@ if ( defined($autostop) )
$autostop = int(1000000*$autostop); $autostop = int(1000000*$autostop);
} }
my $log_file = LOG_FILE;
open( LOG, ">>$log_file" ) or die( "Can't open log file: $!" );
open( STDOUT, ">&LOG" ) || die( "Can't dup stdout: $!" );
select( STDOUT ); $| = 1;
open( STDERR, ">&LOG" ) || die( "Can't dup stderr: $!" );
select( STDERR ); $| = 1;
select( LOG ); $| = 1;
Debug( $arg_string."\n" ); Debug( $arg_string."\n" );
srand( time() ); srand( time() );

View File

@ -44,8 +44,6 @@ use Getopt::Long;
use Device::SerialPort; use Device::SerialPort;
use Time::HiRes qw( usleep ); use Time::HiRes qw( usleep );
use constant LOG_FILE => ZM_PATH_LOGS.'/zmcontrol-pelco-p.log';
$| = 1; $| = 1;
$ENV{PATH} = '/bin:/usr/bin'; $ENV{PATH} = '/bin:/usr/bin';
@ -60,7 +58,7 @@ Usage: zmcontrol-pelco-d.pl <various options>
exit( -1 ); exit( -1 );
} }
zmDbgInit( DBG_ID, DBG_LEVEL ); zmDbgInit( DBG_ID, level=>DBG_LEVEL );
my $arg_string = join( " ", @ARGV ); my $arg_string = join( " ", @ARGV );
@ -100,14 +98,6 @@ if ( defined($autostop) )
$autostop = int(1000000*$autostop); $autostop = int(1000000*$autostop);
} }
my $log_file = LOG_FILE;
open( LOG, ">>$log_file" ) or die( "Can't open log file: $!" );
open( STDOUT, ">&LOG" ) || die( "Can't dup stdout: $!" );
select( STDOUT ); $| = 1;
open( STDERR, ">&LOG" ) || die( "Can't dup stderr: $!" );
select( STDERR ); $| = 1;
select( LOG ); $| = 1;
Debug( $arg_string."\n" ); Debug( $arg_string."\n" );
srand( time() ); srand( time() );

View File

@ -42,8 +42,6 @@ use ZoneMinder;
use Getopt::Long; use Getopt::Long;
use Device::SerialPort; use Device::SerialPort;
use constant LOG_FILE => ZM_PATH_LOGS.'/zmcontrol-visca.log';
$| = 1; $| = 1;
$ENV{PATH} = '/bin:/usr/bin'; $ENV{PATH} = '/bin:/usr/bin';
@ -58,7 +56,7 @@ Usage: zmcontrol-visca.pl <various options>
exit( -1 ); exit( -1 );
} }
zmDbgInit( DBG_ID, DBG_LEVEL ); zmDbgInit( DBG_ID, level=>DBG_LEVEL );
my $arg_string = join( " ", @ARGV ); my $arg_string = join( " ", @ARGV );
@ -90,14 +88,6 @@ if ( !GetOptions(
Usage(); Usage();
} }
my $log_file = LOG_FILE;
open( LOG, ">>$log_file" ) or die( "Can't open log file: $!" );
open( STDOUT, ">&LOG" ) || die( "Can't dup stdout: $!" );
select( STDOUT ); $| = 1;
open( STDERR, ">&LOG" ) || die( "Can't dup stderr: $!" );
select( STDERR ); $| = 1;
select( LOG ); $| = 1;
Debug( $arg_string."\n" ); Debug( $arg_string."\n" );
srand( time() ); srand( time() );

View File

@ -53,8 +53,7 @@ use Socket;
use IO::Handle; use IO::Handle;
use Data::Dumper; use Data::Dumper;
use constant DC_SOCK_FILE => ZM_PATH_SOCKS.'/zmdc.sock'; use constant SOCK_FILE => ZM_PATH_SOCKS.'/zmdc.sock';
use constant DC_LOG_FILE => ZM_PATH_LOGS.'/zmdc.log';
$| = 1; $| = 1;
@ -62,9 +61,18 @@ $ENV{PATH} = '/bin:/usr/bin';
$ENV{SHELL} = '/bin/sh' if exists $ENV{SHELL}; $ENV{SHELL} = '/bin/sh' if exists $ENV{SHELL};
delete @ENV{qw(IFS CDPATH ENV BASH_ENV)}; delete @ENV{qw(IFS CDPATH ENV BASH_ENV)};
zmDbgInit( DBG_ID, DBG_LEVEL ); my @daemons = (
'zmc',
my @daemons = ( 'zmc', 'zma', 'zmf', 'zmfilter.pl', 'zmaudit.pl', 'zmtrigger.pl', 'zmx10.pl', 'zmwatch.pl', 'zmupdate.pl', 'zmtrack.pl' ); 'zma',
'zmf',
'zmfilter.pl',
'zmaudit.pl',
'zmtrigger.pl',
'zmx10.pl',
'zmwatch.pl',
'zmupdate.pl',
'zmtrack.pl'
);
my $command = shift @ARGV; my $command = shift @ARGV;
die( "No command given" ) unless( $command ); die( "No command given" ) unless( $command );
@ -102,7 +110,7 @@ foreach my $arg ( @ARGV )
socket( CLIENT, PF_UNIX, SOCK_STREAM, 0 ) or die( "Can't open socket: $!" ); socket( CLIENT, PF_UNIX, SOCK_STREAM, 0 ) or die( "Can't open socket: $!" );
my $saddr = sockaddr_un( DC_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 )
{ {
@ -122,26 +130,26 @@ if ( !$server_up )
if ( my $cpid = fork() ) if ( my $cpid = fork() )
{ {
zmDbgInit( DBG_ID, level=>DBG_LEVEL );
# Parent process just sleep and fall through # Parent process just sleep and fall through
socket( CLIENT, PF_UNIX, SOCK_STREAM, 0 ) or die( "Can't open socket: $!" ); socket( CLIENT, PF_UNIX, SOCK_STREAM, 0 ) or die( "Can't open socket: $!" );
my $attempts = 0; my $attempts = 0;
while (!connect( CLIENT, $saddr )) while (!connect( CLIENT, $saddr ))
{ {
$attempts++; $attempts++;
die( "Can't connect: $!" ) if ($attempts > MAX_CONNECT_DELAY); Fatal( "Can't connect: $!" ) if ($attempts > MAX_CONNECT_DELAY);
sleep(1); sleep(1);
} }
} }
elsif ( defined($cpid) ) elsif ( defined($cpid) )
{ {
close( STDOUT );
close( STDERR );
setpgrp(); setpgrp();
open( LOG, ">>".DC_LOG_FILE ) or die( "Can't open log file: $!" ); zmDbgInit( DBG_ID, level=>DBG_LEVEL );
open(STDOUT, ">&LOG") || die( "Can't dup stdout: $!" );
select( STDOUT ); $| = 1;
open(STDERR, ">&LOG") || die( "Can't dup stderr: $!" );
select( STDERR ); $| = 1;
select( LOG ); $| = 1;
dPrint( DBG_INFO, "Server starting at ".strftime( '%y/%m/%d %H:%M:%S', localtime() )."\n" ); dPrint( DBG_INFO, "Server starting at ".strftime( '%y/%m/%d %H:%M:%S', localtime() )."\n" );
@ -154,7 +162,7 @@ if ( !$server_up )
killAll( 1 ); killAll( 1 );
socket( SERVER, PF_UNIX, SOCK_STREAM, 0 ) or Fatal( "Can't open socket: $!" ); socket( SERVER, PF_UNIX, SOCK_STREAM, 0 ) or Fatal( "Can't open socket: $!" );
unlink( DC_SOCK_FILE ); unlink( SOCK_FILE );
bind( SERVER, $saddr ) or Fatal( "Can't bind: $!" ); bind( SERVER, $saddr ) or Fatal( "Can't bind: $!" );
listen( SERVER, SOMAXCONN ) or Fatal( "Can't listen: $!" ); listen( SERVER, SOMAXCONN ) or Fatal( "Can't listen: $!" );
@ -262,8 +270,7 @@ if ( !$server_up )
} }
} }
dPrint( DBG_INFO, "Server exiting at ".strftime( '%y/%m/%d %H:%M:%S', localtime() )."\n" ); dPrint( DBG_INFO, "Server exiting at ".strftime( '%y/%m/%d %H:%M:%S', localtime() )."\n" );
close( LOG ); unlink( SOCK_FILE );
unlink( DC_SOCK_FILE );
unlink( ZM_PID ); unlink( ZM_PID );
exit(); exit();
@ -338,6 +345,9 @@ if ( !$server_up )
} }
elsif ( defined($cpid ) ) elsif ( defined($cpid ) )
{ {
close( STDOUT );
close( STDERR );
# Child process # Child process
$SIG{CHLD} = 'DEFAULT'; $SIG{CHLD} = 'DEFAULT';
$SIG{INT} = 'DEFAULT'; $SIG{INT} = 'DEFAULT';
@ -548,9 +558,8 @@ if ( !$server_up )
} }
killAll( 5 ); killAll( 5 );
dPrint( DBG_INFO, "Server shutdown at ".strftime( '%y/%m/%d %H:%M:%S', localtime() )."\n" ); dPrint( DBG_INFO, "Server shutdown at ".strftime( '%y/%m/%d %H:%M:%S', localtime() )."\n" );
unlink( DC_SOCK_FILE ); unlink( SOCK_FILE );
unlink( ZM_PID ); unlink( ZM_PID );
close( LOG );
close( CLIENT ); close( CLIENT );
close( SERVER ); close( SERVER );
exit(); exit();
@ -674,11 +683,15 @@ sub killAll
sleep( $delay ); sleep( $delay );
foreach my $daemon ( @daemons ) foreach my $daemon ( @daemons )
{ {
qx( killall --quiet --signal TERM $daemon ); my $cmd = "killall --quiet --signal TERM $daemon";
Debug( $cmd );
qx( $cmd );
} }
sleep( $delay ); sleep( $delay );
foreach my $daemon ( @daemons ) foreach my $daemon ( @daemons )
{ {
qx( killall --quiet --signal KILL $daemon ); my $cmd = "killall --quiet --signal KILL $daemon";
Debug( $cmd );
qx( $cmd );
} }
} }

View File

@ -54,9 +54,8 @@ use Data::Dumper;
use Getopt::Long; use Getopt::Long;
use constant EVENT_PATH => ZM_PATH_WEB.'/'.ZM_DIR_EVENTS; use constant EVENT_PATH => ZM_PATH_WEB.'/'.ZM_DIR_EVENTS;
use constant LOG_FILE => ZM_PATH_LOGS.'/zmfilter.log';
zmDbgInit( DBG_ID, DBG_LEVEL ); zmDbgInit( DBG_ID, level=>DBG_LEVEL );
if ( ZM_OPT_UPLOAD ) if ( ZM_OPT_UPLOAD )
{ {
@ -127,32 +126,6 @@ Parameters are :-
exit( -1 ); exit( -1 );
} }
my $dbg_id = "";
sub dbgInit
{
my $id = shift;
if ( $id )
{
$dbg_id = $id;
my $add_parms = shift;
if ( $add_parms )
{
foreach my $arg ( @ARGV )
{
if ( $arg =~ /^-(.*)$/ )
{
$dbg_id .= "_$1";
}
else
{
$dbg_id .= $arg;
}
}
}
}
}
# #
# More or less replicates the equivalent PHP function # More or less replicates the equivalent PHP function
# #
@ -185,21 +158,11 @@ sub DateTimeToSQL
return( strftime( "%Y-%m-%d %H:%M:%S", localtime( $dt_val ) ) ); return( strftime( "%Y-%m-%d %H:%M:%S", localtime( $dt_val ) ) );
} }
dbgInit( "zmfilter", 1 );
if ( !GetOptions( 'delay=i'=>\$delay ) ) if ( !GetOptions( 'delay=i'=>\$delay ) )
{ {
Usage(); Usage();
} }
my $log_file = LOG_FILE;
open( LOG, ">>$log_file" ) or die( "Can't open log file: $!" );
open( STDOUT, ">&LOG" ) || die( "Can't dup stdout: $!" );
select( STDOUT ); $| = 1;
open( STDERR, ">&LOG" ) || die( "Can't dup stderr: $!" );
select( STDERR ); $| = 1;
select( LOG ); $| = 1;
chdir( EVENT_PATH ); chdir( EVENT_PATH );
my $dbh = DBI->connect( "DBI:mysql:database=".ZM_DB_NAME.";host=".ZM_DB_HOST, ZM_DB_USER, ZM_DB_PASS ); my $dbh = DBI->connect( "DBI:mysql:database=".ZM_DB_NAME.";host=".ZM_DB_HOST, ZM_DB_USER, ZM_DB_PASS );

View File

@ -47,14 +47,12 @@ use DBI;
use POSIX; use POSIX;
use Time::HiRes qw/gettimeofday/; use Time::HiRes qw/gettimeofday/;
use constant LOG_FILE => ZoneMinder::ZM_PATH_LOGS.'/zmpkg.log';
# Detaint our environment # Detaint our environment
$ENV{PATH} = '/bin:/usr/bin'; $ENV{PATH} = '/bin:/usr/bin';
$ENV{SHELL} = '/bin/sh' if exists $ENV{SHELL}; $ENV{SHELL} = '/bin/sh' if exists $ENV{SHELL};
delete @ENV{qw(IFS CDPATH ENV BASH_ENV)}; delete @ENV{qw(IFS CDPATH ENV BASH_ENV)};
zmDbgInit( DBG_ID, DBG_LEVEL ); zmDbgInit( DBG_ID, level=>DBG_LEVEL );
my $command = $ARGV[0]; my $command = $ARGV[0];
@ -98,21 +96,8 @@ chdir( ZM_PATH_WEB ) or die( "Can't chdir to '".ZM_PATH_WEB."': $!" );
my $dbg_id = ""; my $dbg_id = "";
my $log_file = LOG_FILE;
open( LOG, ">>$log_file" ) or die( "Can't open log file: $!" );
open( STDERR, ">&LOG" ) || die( "Can't dup stderr: $!" );
select( STDERR ); $| = 1;
select( LOG ); $| = 1;
Info( "Command: $command\n" ); Info( "Command: $command\n" );
my $web_uid = (getpwnam( ZM_WEB_USER ))[2];
my $web_gid = (getgrnam( ZM_WEB_GROUP ))[2];
if ( $> != $web_uid )
{
chown( $web_uid, $web_gid, $log_file ) or die( "Can't change permissions on log file: $!" )
}
my $retval = 0; my $retval = 0;
# Determine the appropriate syntax for the su command # Determine the appropriate syntax for the su command

View File

@ -51,8 +51,6 @@ use Data::Dumper;
use Getopt::Long; use Getopt::Long;
use Time::HiRes qw( usleep ); use Time::HiRes qw( usleep );
use constant LOG_FILE => ZM_PATH_LOGS.'/zmtrack-%s.log';
$| = 1; $| = 1;
$ENV{PATH} = '/bin:/usr/bin'; $ENV{PATH} = '/bin:/usr/bin';
@ -76,19 +74,11 @@ if ( !GetOptions( 'monitor=s'=>\$mid ) )
Usage(); Usage();
} }
zmDbgInit( DBG_ID, DBG_LEVEL ); zmDbgInit( DBG_ID, level=>DBG_LEVEL );
my ( $detaint_mid ) = $mid =~ /^(\d+)$/; my ( $detaint_mid ) = $mid =~ /^(\d+)$/;
$mid = $detaint_mid; $mid = $detaint_mid;
my $log_file = sprintf( LOG_FILE, $mid );
open( LOG, ">>$log_file" ) or die( "Can't open log file: $!" );
open( STDOUT, ">&LOG" ) || die( "Can't dup stdout: $!" );
select( STDOUT ); $| = 1;
open( STDERR, ">&LOG" ) || die( "Can't dup stderr: $!" );
select( STDERR ); $| = 1;
select( LOG ); $| = 1;
print( "Tracker daemon $mid (experimental) starting at ".strftime( '%y/%m/%d %H:%M:%S', localtime() )."\n" ); print( "Tracker daemon $mid (experimental) starting at ".strftime( '%y/%m/%d %H:%M:%S', localtime() )."\n" );
my $dbh = DBI->connect( "DBI:mysql:database=".ZM_DB_NAME.";host=".ZM_DB_HOST, ZM_DB_USER, ZM_DB_PASS ); my $dbh = DBI->connect( "DBI:mysql:database=".ZM_DB_NAME.";host=".ZM_DB_HOST, ZM_DB_USER, ZM_DB_PASS );
@ -130,7 +120,7 @@ if ( !$monitor->{CanMoveMap} )
} }
Debug( "Found monitor for id '$monitor'\n" ); Debug( "Found monitor for id '$monitor'\n" );
exit( -1 ) if ( !zmShmGet( $monitor ) ); exit( -1 ) if ( !zmShmVerify( $monitor ) );
sub Suspend sub Suspend
{ {

View File

@ -63,22 +63,13 @@ use POSIX;
#use Socket; #use Socket;
use Data::Dumper; use Data::Dumper;
use constant LOG_FILE => ZM_PATH_LOGS.'/zmtrigger.log';
$| = 1; $| = 1;
$ENV{PATH} = '/bin:/usr/bin'; $ENV{PATH} = '/bin:/usr/bin';
$ENV{SHELL} = '/bin/sh' if exists $ENV{SHELL}; $ENV{SHELL} = '/bin/sh' if exists $ENV{SHELL};
delete @ENV{qw(IFS CDPATH ENV BASH_ENV)}; delete @ENV{qw(IFS CDPATH ENV BASH_ENV)};
zmDbgInit( DBG_ID, DBG_LEVEL ); zmDbgInit( DBG_ID, level=>DBG_LEVEL );
open( LOG, ">>".LOG_FILE ) or die( "Can't open log file: $!" );
open(STDOUT, ">&LOG") || die( "Can't dup stdout: $!" );
select( STDOUT ); $| = 1;
open(STDERR, ">&LOG") || die( "Can't dup stderr: $!" );
select( STDERR ); $| = 1;
select( LOG ); $| = 1;
Info( "Trigger daemon starting\n" ); Info( "Trigger daemon starting\n" );
@ -283,7 +274,7 @@ sub loadMonitors
my $res = $sth->execute() or Fatal( "Can't execute: ".$sth->errstr() ); my $res = $sth->execute() or Fatal( "Can't execute: ".$sth->errstr() );
while( my $monitor = $sth->fetchrow_hashref() ) while( my $monitor = $sth->fetchrow_hashref() )
{ {
next if ( !zmShmGet( $monitor ) ); # Check shared memory ok next if ( !zmShmVerify( $monitor ) ); # Check shared memory ok
if ( defined($monitors{$monitor->{Id}}->{LastState}) ) if ( defined($monitors{$monitor->{Id}}->{LastState}) )
{ {
@ -324,7 +315,7 @@ sub handleMessage
} }
Debug( "Found monitor for id '$id'\n" ); Debug( "Found monitor for id '$id'\n" );
next if ( !zmShmGet( $monitor ) ); next if ( !zmShmVerify( $monitor ) );
Debug( "Handling action '$action'\n" ); Debug( "Handling action '$action'\n" );
if ( $action =~ /^(enable|disable)(?:\+(\d+))?$/ ) if ( $action =~ /^(enable|disable)(?:\+(\d+))?$/ )

View File

@ -53,7 +53,6 @@ use Getopt::Long;
use Data::Dumper; use Data::Dumper;
use constant EVENT_PATH => ZM_PATH_WEB.'/'.ZM_DIR_EVENTS; use constant EVENT_PATH => ZM_PATH_WEB.'/'.ZM_DIR_EVENTS;
use constant UPDATE_LOG_FILE => ZM_PATH_LOGS.'/zmupdate.log';
$| = 1; $| = 1;
@ -61,7 +60,7 @@ $ENV{PATH} = '/bin:/usr/bin';
$ENV{SHELL} = '/bin/sh' if exists $ENV{SHELL}; $ENV{SHELL} = '/bin/sh' if exists $ENV{SHELL};
delete @ENV{qw(IFS CDPATH ENV BASH_ENV)}; delete @ENV{qw(IFS CDPATH ENV BASH_ENV)};
zmDbgInit( DBG_ID, DBG_LEVEL ); zmDbgInit( DBG_ID, level=>DBG_LEVEL );
my $check = 0; my $check = 0;
my $freshen = 0; my $freshen = 0;
@ -103,12 +102,6 @@ if ( ($check + $freshen + $rename + $zone_fix + ($version?1:0)) > 1 )
if ( $check ) if ( $check )
{ {
open( LOG, '>>'.UPDATE_LOG_FILE ) or die( "Can't open log file: $!" );
open( STDOUT, ">&LOG" ) || die( "Can't dup stdout: $!" );
select( STDOUT ); $| = 1;
open( STDERR, ">&LOG" ) || die( "Can't dup stderr: $!" );
select( STDERR ); $| = 1;
select( LOG ); $| = 1;
} }
print( "Update agent starting at ".strftime( '%y/%m/%d %H:%M:%S', localtime() )."\n" ); print( "Update agent starting at ".strftime( '%y/%m/%d %H:%M:%S', localtime() )."\n" );