Bug 357 - Changed most die calls to Fatal

git-svn-id: http://svn.zoneminder.com/svn/zm/trunk@2023 e3e1d417-86f3-4887-817a-d78f3d33393f
This commit is contained in:
stan 2006-10-20 09:31:40 +00:00
parent e0df6cac9d
commit 1598f4c066
2 changed files with 38 additions and 16 deletions

View File

@ -74,11 +74,31 @@ my @daemons = (
'zmtrack.pl'
);
sub Usage
{
print( "
Usage: zmdc.pl <command> [daemon [options]]
Parameters are :-
<command> - One of 'startup|shutdown|status|check|logrot' or
'start|stop|restart|reload'.
[daemon [options]] - Daemon name and options, required for second group of commands
");
exit( -1 );
}
my $command = shift @ARGV;
die( "No command given" ) unless( $command );
if( !$command )
{
print( STDERR "No command given\n" );
Usage();
}
my $needs_daemon = $command !~ /(?:startup|shutdown|status|check|logrot)/;
my $daemon = shift( @ARGV );
die( "No daemon given" ) unless( !$needs_daemon || $daemon );
if( $needs_daemon && !$daemon )
{
print( STDERR "No daemon given\n" );
Usage();
}
my @args;
my $daemon_patt = '('.join( '|', @daemons ).')';
@ -90,7 +110,8 @@ if ( $needs_daemon )
}
else
{
die( "Invalid daemon '$daemon' specified" );
print( STDERR "Invalid daemon '$daemon' specified" );
Usage();
}
}
@ -104,11 +125,12 @@ foreach my $arg ( @ARGV )
}
else
{
die( "Bogus argument '$arg' found" );
print( STDERR "Bogus argument '$arg' found" );
exit( -1 );
}
}
socket( CLIENT, PF_UNIX, SOCK_STREAM, 0 ) or die( "Can't open socket: $!" );
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 );
@ -137,7 +159,7 @@ if ( !$server_up )
zmDbgInit( DBG_ID, level=>DBG_LEVEL );
# 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 Fatal( "Can't open socket: $!" );
my $attempts = 0;
while (!connect( CLIENT, $saddr ))
{

View File

@ -66,8 +66,8 @@ if ( !$command || $command !~ /^(?:start|stop|restart|status|logrot)$/ )
{
# Check to see if it's a valid run state
my $sql = "select * from States where Name = '$command'";
my $sth = $dbh->prepare_cached( $sql ) or die( "Can't prepare '$sql': ".$dbh->errstr() );
my $res = $sth->execute() or die( "Can't execute: ".$sth->errstr() );
my $sth = $dbh->prepare_cached( $sql ) or Fatal( "Can't prepare '$sql': ".$dbh->errstr() );
my $res = $sth->execute() or Fatal( "Can't execute: ".$sth->errstr() );
if ( $state = $sth->fetchrow_hashref() )
{
$state->{Name} = $command;
@ -92,7 +92,7 @@ if ( !$command || $command !~ /^(?:start|stop|restart|status|logrot)$/ )
}
# Move to the right place
chdir( ZM_PATH_WEB ) or die( "Can't chdir to '".ZM_PATH_WEB."': $!" );
chdir( ZM_PATH_WEB ) or Fatal( "Can't chdir to '".ZM_PATH_WEB."': $!" );
my $dbg_id = "";
@ -108,8 +108,8 @@ if ( $command eq "state" )
{
Info( "Updating DB: $state->{Name}\n" );
my $sql = "select * from Monitors order by Id asc";
my $sth = $dbh->prepare_cached( $sql ) or die( "Can't prepare '$sql': ".$dbh->errstr() );
my $res = $sth->execute() or die( "Can't execute: ".$sth->errstr() );
my $sth = $dbh->prepare_cached( $sql ) or Fatal( "Can't prepare '$sql': ".$dbh->errstr() );
my $res = $sth->execute() or Fatal( "Can't execute: ".$sth->errstr() );
while( my $monitor = $sth->fetchrow_hashref() )
{
foreach my $definition ( @{$state->{Definitions}} )
@ -126,8 +126,8 @@ if ( $command eq "state" )
if ( $monitor->{Function} ne $monitor->{NewFunction} || $monitor->{Enabled} ne $monitor->{NewEnabled} )
{
my $sql = "update Monitors set Function = ?, Enabled = ? where Id = ?";
my $sth = $dbh->prepare_cached( $sql ) or die( "Can't prepare '$sql': ".$dbh->errstr() );
my $res = $sth->execute( $monitor->{NewFunction}, $monitor->{NewEnabled}, $monitor->{Id} ) or die( "Can't execute: ".$sth->errstr() );
my $sth = $dbh->prepare_cached( $sql ) or Fatal( "Can't prepare '$sql': ".$dbh->errstr() );
my $res = $sth->execute( $monitor->{NewFunction}, $monitor->{NewEnabled}, $monitor->{Id} ) or Fatal( "Can't execute: ".$sth->errstr() );
}
}
$sth->finish();
@ -161,8 +161,8 @@ if ( $command =~ /^(?:start|restart)$/ )
runCommand( "zmdc.pl startup" );
my $sql = "select * from Monitors";
my $sth = $dbh->prepare_cached( $sql ) or die( "Can't prepare '$sql': ".$dbh->errstr() );
my $res = $sth->execute() or die( "Can't execute: ".$sth->errstr() );
my $sth = $dbh->prepare_cached( $sql ) or Fatal( "Can't prepare '$sql': ".$dbh->errstr() );
my $res = $sth->execute() or Fatal( "Can't execute: ".$sth->errstr() );
while( my $monitor = $sth->fetchrow_hashref() )
{
if ( $monitor->{Function} ne 'None' )
@ -311,7 +311,7 @@ sub removeShm
# Find ZoneMinder shared memory
my $command = "ipcs -m | grep '^".substr( sprintf( "0x%x", hex(ZM_SHM_KEY) ), 0, -2 )."'";
Debug( "Checking for shared memory with '$command'\n" );
open( CMD, "$command |" ) or die( "Can't execute '$command': $!" );
open( CMD, "$command |" ) or Fatal( "Can't execute '$command': $!" );
while( <CMD> )
{
chomp;