From 81860d99a624469a7d812dad78e39bdb03b2c32b Mon Sep 17 00:00:00 2001 From: Dmitry Smirnov Date: Thu, 9 Apr 2015 03:29:38 +1000 Subject: [PATCH] zmdc.pl: PBP/5 + reformatting --- scripts/zmdc.pl.in | 104 +++++++++++++++++++++++++++++++-------------- 1 file changed, 72 insertions(+), 32 deletions(-) diff --git a/scripts/zmdc.pl.in b/scripts/zmdc.pl.in index c209ae63f..8f0810d8c 100644 --- a/scripts/zmdc.pl.in +++ b/scripts/zmdc.pl.in @@ -73,14 +73,14 @@ my @daemons = ( ); sub Usage -{ +{ print( " Usage: zmdc.pl [daemon [options]] Parameters are :- - One of 'startup|shutdown|status|check|logrot' or 'start|stop|restart|reload|version'. [daemon [options]] - Daemon name and options, required for second group of commands -"); +"); exit( -1 ); } @@ -91,8 +91,8 @@ if( !$command ) Usage(); } if ( $command eq 'version' ) { - print ZoneMinder::Base::ZM_VERSION."\n"; - exit( 0 ); + print ZoneMinder::Base::ZM_VERSION."\n"; + exit( 0 ); } my $needs_daemon = $command !~ /(?:startup|shutdown|status|check|logrot|version)/; my $daemon = shift( @ARGV ); @@ -152,7 +152,7 @@ if ( !$server_up ) print( "Unable to connect to server\n" ); exit( -1 ); } - # The server isn't there + # The server isn't there print( "Starting server\n" ); close( CLIENT ); @@ -235,12 +235,15 @@ sub run logInit(); - dPrint( ZoneMinder::Logger::INFO, "Server starting at ".strftime( '%y/%m/%d %H:%M:%S', localtime() )."\n" ); + dPrint( ZoneMinder::Logger::INFO, "Server starting at " + .strftime( '%y/%m/%d %H:%M:%S', localtime() ) + ."\n" + ); - if ( open( PID, ">".ZM_PID ) ) + if ( open( my $PID, '>', ZM_PID ) ) { - print( PID $$ ); - close( PID ); + print( $PID $$ ); + close( $PID ); } killAll( 1 ); @@ -354,7 +357,10 @@ sub run restartPending(); } } - dPrint( ZoneMinder::Logger::INFO, "Server exiting at ".strftime( '%y/%m/%d %H:%M:%S', localtime() )."\n" ); + dPrint( ZoneMinder::Logger::INFO, "Server exiting at " + .strftime( '%y/%m/%d %H:%M:%S', localtime() ) + ."\n" + ); unlink( main::SOCK_FILE ); unlink( ZM_PID ); exit(); @@ -413,7 +419,10 @@ sub start } elsif ( $process->{pid} && $pid_hash{$process->{pid}} ) { - dPrint( ZoneMinder::Logger::INFO, "'$process->{command}' already running at ".strftime( '%y/%m/%d %H:%M:%S', localtime( $process->{started}) ).", pid = $process->{pid}\n" ); + dPrint( ZoneMinder::Logger::INFO, "'$process->{command}' already running at " + .strftime( '%y/%m/%d %H:%M:%S', localtime( $process->{started}) ) + .", pid = $process->{pid}\n" + ); return(); } @@ -428,7 +437,10 @@ sub start $process->{started} = time(); delete( $process->{pending} ); - dPrint( ZoneMinder::Logger::INFO, "'$command' starting at ".strftime( '%y/%m/%d %H:%M:%S', localtime( $process->{started}) ).", pid = $process->{pid}\n" ); + dPrint( ZoneMinder::Logger::INFO, "'$command' starting at " + .strftime( '%y/%m/%d %H:%M:%S', localtime( $process->{started}) ) + .", pid = $process->{pid}\n" + ); $cmd_hash{$process->{command}} = $pid_hash{$cpid} = $process; sigprocmask( SIG_SETMASK, $sigset ) or Fatal( "Can't restore SIGCHLD: $!" ); @@ -437,7 +449,11 @@ sub start { logReinit(); - dPrint( ZoneMinder::Logger::INFO, "'".join( ' ', ( $daemon, @args ) )."' started at ".strftime( '%y/%m/%d %H:%M:%S', localtime() )."\n" ); + dPrint( ZoneMinder::Logger::INFO, "'".join( ' ', ( $daemon, @args ) ) + ."' started at " + .strftime( '%y/%m/%d %H:%M:%S', localtime() ) + ."\n" + ); if ( $daemon =~ /^${daemon_patt}$/ ) { @@ -501,7 +517,10 @@ sub _stop elsif ( $process->{pending} ) { delete( $cmd_hash{$command} ); - dPrint( ZoneMinder::Logger::INFO, "Command '$command' removed from pending list at ".strftime( '%y/%m/%d %H:%M:%S', localtime() )."\n" ); + dPrint( ZoneMinder::Logger::INFO, "Command '$command' removed from pending list at " + .strftime( '%y/%m/%d %H:%M:%S', localtime() ) + ."\n" + ); return(); } @@ -512,7 +531,11 @@ sub _stop return(); } - dPrint( ZoneMinder::Logger::INFO, "'$daemon ".join( ' ', @args )."' stopping at ".strftime( '%y/%m/%d %H:%M:%S', localtime() )."\n" ); + dPrint( ZoneMinder::Logger::INFO, "'$daemon ".join( ' ', @args ) + ."' stopping at " + .strftime( '%y/%m/%d %H:%M:%S', localtime() ) + ."\n" + ); $process->{keepalive} = !$final; kill( 'TERM', $cpid ); delete( $cmd_hash{$command} ); @@ -694,7 +717,10 @@ sub shutdownAll stop( $process->{daemon}, @{$process->{args}} ); } killAll( 5 ); - dPrint( ZoneMinder::Logger::INFO, "Server shutdown at ".strftime( '%y/%m/%d %H:%M:%S', localtime() )."\n" ); + dPrint( ZoneMinder::Logger::INFO, "Server shutdown at " + .strftime( '%y/%m/%d %H:%M:%S', localtime() ) + ."\n" + ); unlink( main::SOCK_FILE ); unlink( ZM_PID ); close( CLIENT ); @@ -750,7 +776,10 @@ sub status if ( $process->{pending} ) { - dPrint( ZoneMinder::Logger::DEBUG, "'$process->{command}' pending at ".strftime( '%y/%m/%d %H:%M:%S', localtime( $process->{pending}) )."\n" ); + dPrint( ZoneMinder::Logger::DEBUG, "'$process->{command}' pending at " + .strftime( '%y/%m/%d %H:%M:%S', localtime( $process->{pending}) ) + ."\n" + ); } else { @@ -761,13 +790,19 @@ sub status return(); } } - dPrint( ZoneMinder::Logger::DEBUG, "'$process->{command}' running since ".strftime( '%y/%m/%d %H:%M:%S', localtime( $process->{started}) ).", pid = $process->{pid}" ); + dPrint( ZoneMinder::Logger::DEBUG, "'$process->{command}' running since " + .strftime( '%y/%m/%d %H:%M:%S', localtime( $process->{started}) ) + .", pid = $process->{pid}" + ); } else { foreach my $process ( values(%pid_hash) ) { - my $out_str = "'$process->{command}' running since ".strftime( '%y/%m/%d %H:%M:%S', localtime( $process->{started}) ).", pid = $process->{pid}"; + my $out_str = "'$process->{command}' running since " + .strftime( '%y/%m/%d %H:%M:%S', localtime( $process->{started}) ) + .", pid = $process->{pid}" + ; $out_str .= ", valid" if ( kill( 0, $process->{pid} ) ); $out_str .= "\n"; dPrint( ZoneMinder::Logger::DEBUG, $out_str ); @@ -776,7 +811,10 @@ sub status { if ( $process->{pending} ) { - dPrint( ZoneMinder::Logger::DEBUG, "'$process->{command}' pending at ".strftime( '%y/%m/%d %H:%M:%S', localtime( $process->{pending}) )."\n" ); + dPrint( ZoneMinder::Logger::DEBUG, "'$process->{command}' pending at " + .strftime( '%y/%m/%d %H:%M:%S', localtime( $process->{pending}) ) + ."\n" + ); } } } @@ -786,19 +824,21 @@ sub killAll { my $delay = shift; sleep( $delay ); - my $killall; - if ( '@HOST_OS@' eq 'BSD' ) { - $killall = 'killall -'; - } else { - $killall = 'killall -q -s '; - } - foreach my $daemon ( @daemons ) { + my $killall; + if ( '@HOST_OS@' eq 'BSD' ) + { + $killall = 'killall -'; + } else { + $killall = 'killall -q -s '; + } + foreach my $daemon ( @daemons ) + { - my $cmd = $killall ."TERM $daemon"; - Debug( $cmd ); - qx( $cmd ); - } - sleep( $delay ); + my $cmd = $killall ."TERM $daemon"; + Debug( $cmd ); + qx( $cmd ); + } + sleep( $delay ); foreach my $daemon ( @daemons ) { my $cmd = $killall."KILL $daemon";