From 1598f4c0665d9668e2bdfd80f4ecf55f2bbf06d6 Mon Sep 17 00:00:00 2001 From: stan Date: Fri, 20 Oct 2006 09:31:40 +0000 Subject: [PATCH] Bug 357 - Changed most die calls to Fatal git-svn-id: http://svn.zoneminder.com/svn/zm/trunk@2023 e3e1d417-86f3-4887-817a-d78f3d33393f --- scripts/zmdc.pl | 34 ++++++++++++++++++++++++++++------ scripts/zmpkg.pl | 20 ++++++++++---------- 2 files changed, 38 insertions(+), 16 deletions(-) diff --git a/scripts/zmdc.pl b/scripts/zmdc.pl index eea31721d..66ec264f9 100644 --- a/scripts/zmdc.pl +++ b/scripts/zmdc.pl @@ -74,11 +74,31 @@ my @daemons = ( 'zmtrack.pl' ); +sub Usage +{ + print( " +Usage: zmdc.pl [daemon [options]] +Parameters are :- + - 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 )) { diff --git a/scripts/zmpkg.pl b/scripts/zmpkg.pl index 27cdd583c..cdff6b46d 100644 --- a/scripts/zmpkg.pl +++ b/scripts/zmpkg.pl @@ -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( ) { chomp;