Spacing and parenthesis and some debug lines

This commit is contained in:
Isaac Connor 2018-05-31 10:25:16 -04:00
parent 2eb3c8ef6d
commit 21e26c8c14
1 changed files with 10 additions and 6 deletions

View File

@ -119,13 +119,13 @@ if ( $command eq 'version' ) {
} }
my $needs_daemon = $command !~ /(?:startup|shutdown|status|check|logrot|version)/; my $needs_daemon = $command !~ /(?:startup|shutdown|status|check|logrot|version)/;
my $daemon = shift @ARGV; my $daemon = shift @ARGV;
if ( $needs_daemon && ! $daemon ) { if ( $needs_daemon && !$daemon ) {
print(STDERR "No daemon given\n"); print(STDERR "No daemon given\n");
pod2usage(-exitstatus => -1); pod2usage(-exitstatus => -1);
} }
my @args; my @args;
my $daemon_patt = '('.join( '|', @daemons ).')'; my $daemon_patt = '('.join('|', @daemons).')';
if ( $needs_daemon ) { if ( $needs_daemon ) {
if ( $daemon =~ /^${daemon_patt}$/ ) { if ( $daemon =~ /^${daemon_patt}$/ ) {
$daemon = $1; $daemon = $1;
@ -139,7 +139,7 @@ foreach my $arg ( @ARGV ) {
# Detaint arguments, if they look ok # Detaint arguments, if they look ok
#if ( $arg =~ /^(-{0,2}[\w]+)/ ) #if ( $arg =~ /^(-{0,2}[\w]+)/ )
if ( $arg =~ /^(-{0,2}[\w\/?&=.-]+)$/ ) { if ( $arg =~ /^(-{0,2}[\w\/?&=.-]+)$/ ) {
push( @args, $1 ); push @args, $1;
} else { } else {
print(STDERR "Bogus argument '$arg' found"); print(STDERR "Bogus argument '$arg' found");
exit(-1); exit(-1);
@ -306,7 +306,7 @@ sub run {
$dbh = zmDbConnect(); $dbh = zmDbConnect();
} }
my @cpuload = CpuLoad(); my @cpuload = CpuLoad();
Debug("UPdating Server record @cpuload"); Debug("Updating Server record @cpuload");
if ( ! defined $dbh->do(q{UPDATE Servers SET Status=?,CpuLoad=?,TotalMem=?,FreeMem=?,TotalSwap=?,FreeSwap=? WHERE Id=?}, undef, if ( ! defined $dbh->do(q{UPDATE Servers SET Status=?,CpuLoad=?,TotalMem=?,FreeMem=?,TotalSwap=?,FreeSwap=? WHERE Id=?}, undef,
'Running', $cpuload[0], &totalmem, &freemem, &totalswap, &freeswap, $Config{ZM_SERVER_ID} ) ) { 'Running', $cpuload[0], &totalmem, &freemem, &totalswap, &freeswap, $Config{ZM_SERVER_ID} ) ) {
Error("Failed Updating status of Server record for Id=$Config{ZM_SERVER_ID}".$dbh->errstr()); Error("Failed Updating status of Server record for Id=$Config{ZM_SERVER_ID}".$dbh->errstr());
@ -382,7 +382,7 @@ Debug("check_for_processes_to_kill");
."\n" ."\n"
); );
if ( $Config{ZM_SERVER_ID} ) { if ( $Config{ZM_SERVER_ID} ) {
$dbh = zmDbConnect() if ! $dbh->ping(); $dbh = zmDbConnect() if ! ($dbh and $dbh->ping());
if ( ! defined $dbh->do(q{UPDATE Servers SET Status='NotRunning' WHERE Id=?}, undef, $Config{ZM_SERVER_ID}) ) { if ( ! defined $dbh->do(q{UPDATE Servers SET Status='NotRunning' WHERE Id=?}, undef, $Config{ZM_SERVER_ID}) ) {
Error("Failed Updating status of Server record for Id=$Config{ZM_SERVER_ID}".$dbh->errstr()); Error("Failed Updating status of Server record for Id=$Config{ZM_SERVER_ID}".$dbh->errstr());
} }
@ -399,7 +399,9 @@ sub cPrint {
# I think the purpose of this is to echo the logs to the client process so it can then display them. # I think the purpose of this is to echo the logs to the client process so it can then display them.
sub dPrint { sub dPrint {
my $logLevel = shift; my $logLevel = shift;
# One thought here, if no client exists to read these... does it block?
if ( fileno(CLIENT) ) { if ( fileno(CLIENT) ) {
Debug("Have fileno for CLIENT, printing ");
print CLIENT @_ print CLIENT @_
} }
if ( $logLevel == ZoneMinder::Logger::DEBUG ) { if ( $logLevel == ZoneMinder::Logger::DEBUG ) {
@ -439,8 +441,10 @@ sub start {
sigprocmask(SIG_BLOCK, $blockset, $sigset) or Fatal("Can't block SIGCHLD: $!"); sigprocmask(SIG_BLOCK, $blockset, $sigset) or Fatal("Can't block SIGCHLD: $!");
Debug("forking"); Debug("forking");
if ( my $cpid = fork() ) { if ( my $cpid = fork() ) {
Debug("before logReinit");
# This logReinit is required. Not sure why. # This logReinit is required. Not sure why.
logReinit(); logReinit();
Debug("aftere logReinit");
$process->{pid} = $cpid; $process->{pid} = $cpid;
$process->{started} = time(); $process->{started} = time();
@ -808,7 +812,7 @@ sub status {
foreach my $process ( values %cmd_hash ) { foreach my $process ( values %cmd_hash ) {
if ( $process->{pending} ) { if ( $process->{pending} ) {
dPrint(ZoneMinder::Logger::DEBUG, "'$process->{command}' pending at " dPrint(ZoneMinder::Logger::DEBUG, "'$process->{command}' pending at "
.strftime( '%y/%m/%d %H:%M:%S', localtime($process->{pending})) .strftime('%y/%m/%d %H:%M:%S', localtime($process->{pending}))
."\n" ."\n"
); );
} }