From 7c1f2a2791ff62851d425e34d830882fe20a8b70 Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Fri, 23 Jun 2017 10:13:08 -0400 Subject: [PATCH 01/12] fix level=>effectiveLevel --- scripts/ZoneMinder/lib/ZoneMinder/Logger.pm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/ZoneMinder/lib/ZoneMinder/Logger.pm b/scripts/ZoneMinder/lib/ZoneMinder/Logger.pm index ee1022263..44c7f7e8e 100644 --- a/scripts/ZoneMinder/lib/ZoneMinder/Logger.pm +++ b/scripts/ZoneMinder/lib/ZoneMinder/Logger.pm @@ -375,8 +375,8 @@ sub level { $this->{effectiveLevel} = $this->{termLevel} if ( $this->{termLevel} > $this->{effectiveLevel} ); $this->{effectiveLevel} = $this->{databaseLevel} if ( $this->{databaseLevel} > $this->{effectiveLevel} ); $this->{effectiveLevel} = $this->{fileLevel} if ( $this->{fileLevel} > $this->{effectiveLevel} ); - $this->{effectiveLevel} = $this->{syslogLevel} if ( $this->{syslogLevel} > $this->{level} ); - $this->{effectiveLevel} = $this->{level} if ( $this->{effectiveLevel} > $this->{level} ); + $this->{effectiveLevel} = $this->{syslogLevel} if ( $this->{syslogLevel} > $this->{effectiveLevel} ); + $this->{effectiveLevel} = $this->{level} if ( $this->{effectiveLevel} > $this->{effectiveLevel} ); } return( $this->{level} ); } From 0937bfdf846ac67b4007a625710116a5e27b8461 Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Wed, 6 Jun 2018 13:37:12 -0400 Subject: [PATCH 02/12] consoleTableBody needs to be an id in order for dragndrop sorting to work --- web/skins/classic/views/console.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web/skins/classic/views/console.php b/web/skins/classic/views/console.php index 119a223eb..c5a9f54f1 100644 --- a/web/skins/classic/views/console.php +++ b/web/skins/classic/views/console.php @@ -223,7 +223,7 @@ ob_start(); - + Date: Wed, 6 Jun 2018 16:59:07 -0400 Subject: [PATCH 03/12] We should be able to edit zones even if zm isn't running --- web/skins/classic/views/console.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web/skins/classic/views/console.php b/web/skins/classic/views/console.php index 119a223eb..8777c04fd 100644 --- a/web/skins/classic/views/console.php +++ b/web/skins/classic/views/console.php @@ -318,7 +318,7 @@ for( $monitor_i = 0; $monitor_i < count($displayMonitors); $monitor_i += 1 ) { - + From aa055c147b7f27d942867d54aac70045d27adf01 Mon Sep 17 00:00:00 2001 From: Andrew Bauer Date: Thu, 7 Jun 2018 14:32:36 -0500 Subject: [PATCH 04/12] classic skin - fix dvr control buttons The buttons were being drawn too small which cropped the symbols inside the buttons. Deleting the classic-skin-specific override of the css file allows the default css to apply which looks good to me. --- web/skins/classic/css/classic/views/watch.css | 7 ------- 1 file changed, 7 deletions(-) diff --git a/web/skins/classic/css/classic/views/watch.css b/web/skins/classic/css/classic/views/watch.css index 4ebb30dda..247be4f05 100644 --- a/web/skins/classic/css/classic/views/watch.css +++ b/web/skins/classic/css/classic/views/watch.css @@ -38,13 +38,6 @@ text-align: center; } -#dvrControls input { - height: 20px; - width: 28px; - padding-bottom: 3px; - margin: 0 3px; -} - #dvrControls input[disabled] { color: #aaaaaa; } From be61c50efa1cc70eaca384ab0e4f94c9b92c7517 Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Thu, 7 Jun 2018 17:25:02 -0400 Subject: [PATCH 05/12] Fix setting Debug option when ZM_LOG_DEBUG_TARGET is empty and fix setting effectiveLevel --- scripts/ZoneMinder/lib/ZoneMinder/Logger.pm | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/scripts/ZoneMinder/lib/ZoneMinder/Logger.pm b/scripts/ZoneMinder/lib/ZoneMinder/Logger.pm index aec308b65..0624e3e26 100644 --- a/scripts/ZoneMinder/lib/ZoneMinder/Logger.pm +++ b/scripts/ZoneMinder/lib/ZoneMinder/Logger.pm @@ -245,7 +245,8 @@ sub initialise( @ ) { $tempSyslogLevel = $level if defined($level = $this->getTargettedEnv('LOG_LEVEL_SYSLOG')); if ( $Config{ZM_LOG_DEBUG} ) { - foreach my $target ( split( /\|/, $Config{ZM_LOG_DEBUG_TARGET} ) ) { + # Splitting on an empty string doesn't return an empty string, it returns an empty array + foreach my $target ( $Config{ZM_LOG_DEBUG_TARGET} ? split(/\|/, $Config{ZM_LOG_DEBUG_TARGET}) : '' ) { if ( $target eq $this->{id} || $target eq '_'.$this->{id} || $target eq $this->{idRoot} @@ -392,6 +393,12 @@ sub level { # ICON: I am remarking this out because I don't see the point of having an effective level, if we are just going to set it to level. #$this->{effectiveLevel} = $this->{level} if ( $this->{level} > $this->{effectiveLevel} ); + # ICON: The point is that LOG_DEBUG can be set either in db or in env var and will get passed in here. + # So this will turn on debug, even if not output has Debug level turned on. I think it should be the other way around + + # ICON: Let's try this line instead. effectiveLevel is 1 DEBUG from above, but LOG_DEBUG is off, then $this->level will be 0, and + # so effectiveLevel will become 0 + $this->{effectiveLevel} = $this->{level} if ( $this->{level} < $this->{effectiveLevel} ); } return $this->{level}; } From 61445620aaf319db7d2697cd93050d5bf91af048 Mon Sep 17 00:00:00 2001 From: Andrew Bauer Date: Fri, 8 Jun 2018 07:53:23 -0500 Subject: [PATCH 06/12] create the pid file before doing anything else (#2114) * create the pid file before doing anything else * update comment --- scripts/zmdc.pl.in | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/scripts/zmdc.pl.in b/scripts/zmdc.pl.in index b65388892..d8565cfe9 100644 --- a/scripts/zmdc.pl.in +++ b/scripts/zmdc.pl.in @@ -245,6 +245,16 @@ our %terminating_processes; our $zm_terminate = 0; sub run { + + # Call this first otherwise stdout/stderror redirects to the pidfile = bad + if ( open(my $PID, '>', ZM_PID) ) { + print($PID $$); + close($PID); + } else { + # Log not initialized at this point so use die instead + die "Can't open pid file at ".ZM_PID."\n"; + } + my $fd = 0; while( $fd < POSIX::sysconf(&POSIX::_SC_OPEN_MAX) ) { POSIX::close($fd++); @@ -259,13 +269,6 @@ sub run { ."\n" ); - if ( open(my $PID, '>', ZM_PID) ) { - print($PID $$); - close($PID); - } else { - Error("Can't open pid file at " . ZM_PID); - } - # Tell any existing processes to die, wait 1 second between TERM and KILL killAll(1); From fc0369b9a4e7562868fed109ff45ee68e3672ae2 Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Fri, 8 Jun 2018 09:04:31 -0400 Subject: [PATCH 07/12] when detecting a down db connection, need to clear the stored sth as it is no longer valid. --- scripts/ZoneMinder/lib/ZoneMinder/Logger.pm | 48 +++++++++++---------- 1 file changed, 26 insertions(+), 22 deletions(-) diff --git a/scripts/ZoneMinder/lib/ZoneMinder/Logger.pm b/scripts/ZoneMinder/lib/ZoneMinder/Logger.pm index 0624e3e26..ac7b772e9 100644 --- a/scripts/ZoneMinder/lib/ZoneMinder/Logger.pm +++ b/scripts/ZoneMinder/lib/ZoneMinder/Logger.pm @@ -549,30 +549,34 @@ sub logPrint { print(STDERR $message) if $level <= $this->{termLevel}; if ( $level <= $this->{databaseLevel} ) { - if ( ( $this->{dbh} and $this->{dbh}->ping() ) or ( $this->{dbh} = ZoneMinder::Database::zmDbConnect() ) ) { - - - my $sql = 'INSERT INTO Logs ( TimeKey, Component, Pid, Level, Code, Message, File, Line ) VALUES ( ?, ?, ?, ?, ?, ?, ?, NULL )'; - $this->{sth} = $this->{dbh}->prepare_cached($sql) if ! $this->{sth}; - if ( !$this->{sth} ) { + if ( ! ( $this->{dbh} and $this->{dbh}->ping() ) ) { + $this->{sth} = undef; + if ( ! ( $this->{dbh} = ZoneMinder::Database::zmDbConnect() ) ) { + print(STDERR "Can't log to database: "); $this->{databaseLevel} = NOLOG; - Error("Can't prepare log entry '$sql': ".$this->{dbh}->errstr()); - } else { - my $res = $this->{sth}->execute($seconds+($microseconds/1000000.0) - , $this->{id} - , $$ - , $level - , $code - , $string - , $this->{fileName} - ); - if ( !$res ) { - $this->{databaseLevel} = NOLOG; - Error("Can't execute log entry '$sql': ".$this->{dbh}->errstr()); - } + return; } - } else { - print(STDERR "Can't log to database: "); + } + + my $sql = 'INSERT INTO Logs ( TimeKey, Component, Pid, Level, Code, Message, File, Line ) VALUES ( ?, ?, ?, ?, ?, ?, ?, NULL )'; + $this->{sth} = $this->{dbh}->prepare_cached($sql) if ! $this->{sth}; + if ( !$this->{sth} ) { + $this->{databaseLevel} = NOLOG; + Error("Can't prepare log entry '$sql': ".$this->{dbh}->errstr()); + return; + } + + my $res = $this->{sth}->execute($seconds+($microseconds/1000000.0) + , $this->{id} + , $$ + , $level + , $code + , $string + , $this->{fileName} + ); + if ( !$res ) { + $this->{databaseLevel} = NOLOG; + Error("Can't execute log entry '$sql': ".$this->{dbh}->errstr()); } } # end if doing db logging } # end if level < effectivelevel From 7c32e4d86ccb417d93493ad89032aa342d399a2b Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Fri, 8 Jun 2018 09:15:19 -0400 Subject: [PATCH 08/12] Move zmDbConnect up before logInit because the db handle got closed --- scripts/zmdc.pl.in | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/zmdc.pl.in b/scripts/zmdc.pl.in index d8565cfe9..aa4cbc488 100644 --- a/scripts/zmdc.pl.in +++ b/scripts/zmdc.pl.in @@ -262,6 +262,8 @@ sub run { setpgrp(); + # dbh got closed with the rest of the fd's above, so need to reconnect. + my $dbh = zmDbConnect(1); logInit(); dPrint(ZoneMinder::Logger::INFO, 'Server starting at ' @@ -273,7 +275,6 @@ sub run { killAll(1); dPrint(ZoneMinder::Logger::INFO, 'Socket should be open at ' .main::SOCK_FILE); - my $dbh = zmDbConnect(1); socket(SERVER, PF_UNIX, SOCK_STREAM, 0) or Fatal("Can't open socket: $!"); unlink(main::SOCK_FILE) or Error('Unable to unlink ' . main::SOCK_FILE .". Error message was: $!") if -e main::SOCK_FILE; bind(SERVER, $saddr) or Fatal("Can't bind to " . main::SOCK_FILE . ": $!"); From d30d8efaf0ae23dc72839cca09ef7a3627f88b51 Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Fri, 8 Jun 2018 09:17:25 -0400 Subject: [PATCH 09/12] clear stored sth on initialize and re-initialize --- scripts/ZoneMinder/lib/ZoneMinder/Logger.pm | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/scripts/ZoneMinder/lib/ZoneMinder/Logger.pm b/scripts/ZoneMinder/lib/ZoneMinder/Logger.pm index ac7b772e9..1714da201 100644 --- a/scripts/ZoneMinder/lib/ZoneMinder/Logger.pm +++ b/scripts/ZoneMinder/lib/ZoneMinder/Logger.pm @@ -279,6 +279,9 @@ sub initialise( @ ) { $this->{initialised} = !undef; + # this function can get called on a previously initialized log Object, so clean any sth's + $this->{sth} = undef; + Debug( 'LogOpts: level='.$codes{$this->{level}} .'/'.$codes{$this->{effectiveLevel}} .', screen='.$codes{$this->{termLevel}} @@ -320,6 +323,8 @@ sub reinitialise { my $screenLevel = $this->termLevel(); $this->termLevel(NOLOG); $this->termLevel($screenLevel) if $screenLevel > NOLOG; + + $this->{sth} = undef; } # Prevents undefined logging levels From 5cdbc85dcc502b2a7d7e3c4074e30ef80e81408b Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Fri, 8 Jun 2018 14:18:38 -0400 Subject: [PATCH 10/12] Slightly more efficient logPrint. Don't create the message string unless it is going to be used --- scripts/ZoneMinder/lib/ZoneMinder/Logger.pm | 42 ++++++++++----------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/scripts/ZoneMinder/lib/ZoneMinder/Logger.pm b/scripts/ZoneMinder/lib/ZoneMinder/Logger.pm index dc7e361f6..213b83dac 100644 --- a/scripts/ZoneMinder/lib/ZoneMinder/Logger.pm +++ b/scripts/ZoneMinder/lib/ZoneMinder/Logger.pm @@ -529,29 +529,29 @@ sub logPrint { if ( $level <= $this->{effectiveLevel} ) { $string =~ s/[\r\n]+$//g; - - my $code = $codes{$level}; + if ( $level <= $this->{syslogLevel} ) { + syslog($priorities{$level}, $codes{$level}.' [%s]', $string); + } my ($seconds, $microseconds) = gettimeofday(); - my $message = sprintf( - '%s.%06d %s[%d].%s [%s]' - , strftime('%x %H:%M:%S', localtime($seconds)) - , $microseconds - , $this->{id} - , $$ - , $code - , $string - ); - if ( $this->{trace} ) { - $message = Carp::shortmess($message); - } else { - $message = $message."\n"; + if ( $level <= $this->{fileLevel} or $level <= $this->{termLevel} ) { + my $message = sprintf( + '%s.%06d %s[%d].%s [%s]' + , strftime('%x %H:%M:%S', localtime($seconds)) + , $microseconds + , $this->{id} + , $$ + , $codes{$level} + , $string + ); + if ( $this->{trace} ) { + $message = Carp::shortmess($message); + } else { + $message = $message."\n"; + } + print($LOGFILE $message) if $level <= $this->{fileLevel}; + print(STDERR $message) if $level <= $this->{termLevel}; } - if ( $level <= $this->{syslogLevel} ) { - syslog($priorities{$level}, $code.' [%s]', $string); - } - print($LOGFILE $message) if $level <= $this->{fileLevel}; - print(STDERR $message) if $level <= $this->{termLevel}; if ( $level <= $this->{databaseLevel} ) { if ( ! ( $this->{dbh} and $this->{dbh}->ping() ) ) { @@ -575,7 +575,7 @@ sub logPrint { , $this->{id} , $$ , $level - , $code + , $codes{$level} , $string , $this->{fileName} ); From 374123f9c298a4897cbdf819cbdb9fa3714ad034 Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Fri, 8 Jun 2018 14:21:27 -0400 Subject: [PATCH 11/12] get rid of debugging and turn of extra logReInit --- scripts/zmdc.pl.in | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/scripts/zmdc.pl.in b/scripts/zmdc.pl.in index aa4cbc488..e2a69aa57 100644 --- a/scripts/zmdc.pl.in +++ b/scripts/zmdc.pl.in @@ -373,9 +373,7 @@ sub run { #print( "Select timed out\n" ); } -Debug("restartPending"); restartPending(); -Debug("check_for_processes_to_kill"); check_for_processes_to_kill(); } # end while @@ -404,7 +402,6 @@ sub dPrint { my $logLevel = shift; # One thought here, if no client exists to read these... does it block? if ( fileno(CLIENT) ) { - Debug("Have fileno for CLIENT, printing "); print CLIENT @_ } if ( $logLevel == ZoneMinder::Logger::DEBUG ) { @@ -440,14 +437,10 @@ sub start { my $sigset = POSIX::SigSet->new; my $blockset = POSIX::SigSet->new(SIGCHLD); - Debug("Blocking SIGCHLD"); sigprocmask(SIG_BLOCK, $blockset, $sigset) or Fatal("Can't block SIGCHLD: $!"); - Debug("forking"); if ( my $cpid = fork() ) { - Debug("before logReinit"); # This logReinit is required. Not sure why. - logReinit(); - Debug("aftere logReinit"); + #logReinit(); $process->{pid} = $cpid; $process->{started} = time(); @@ -460,7 +453,6 @@ sub start { $cmd_hash{$process->{command}} = $pid_hash{$cpid} = $process; sigprocmask(SIG_SETMASK, $sigset) or Fatal("Can't restore SIGCHLD: $!"); - Debug("unblocking child"); } elsif ( defined($cpid) ) { # Force reconnection to the db. $dbh = zmDbConnect(1); @@ -523,7 +515,7 @@ sub send_stop { .strftime('%y/%m/%d %H:%M:%S', localtime()) ."\n" ); - sigprocmask(SIG_UNBLOCK, $blockset) or die "dying at unblock...\n"; + sigprocmask(SIG_UNBLOCK, $blockset) or die "dying at unblock...\n"; return(); } @@ -715,7 +707,6 @@ sub reaper { } # end while waitpid $SIG{CHLD} = \&reaper; $! = $saved_status; - Debug("Leaving reaper"); } sub restartPending { @@ -727,7 +718,6 @@ sub restartPending { start($process->{daemon}, @{$process->{args}}); } } - Debug("done restartPending"); } sub shutdownAll { From be26f14566e05edc2bcd0107ab53190e81ec60dd Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Fri, 8 Jun 2018 14:59:14 -0400 Subject: [PATCH 12/12] put back zmsystemctl.pl --- scripts/zmpkg.pl.in | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) diff --git a/scripts/zmpkg.pl.in b/scripts/zmpkg.pl.in index e146f76c8..d11e04d5a 100644 --- a/scripts/zmpkg.pl.in +++ b/scripts/zmpkg.pl.in @@ -149,21 +149,8 @@ if ( $command =~ /^(start|stop|restart)$/ ) { $command = $1; if ( systemdRunning() && !calledBysystem() ) { - Info("Redirecting command through systemctl"); - my $path = qx(which systemctl); - Info("Path is $path"); - Info("Status is $?"); - my $status = $? >> 8; - Info("Status is $status"); - ( $path ) = $path =~ /^(.*)$/; - - if ( !$path || $status ) { - Fatal('Unable to determine systemctl executable. Is systemd in use?'); - } - Info("exec $path $command zoneminder"); - exec("$path $command zoneminder"); - } else { - Debug("called by SystemD"); + qx(@BINDIR@/zmsystemctl.pl $command); + $command = ''; } }