Module: check_mk
Branch: master
Commit: e546de6c050374f1c9c45a2de5f2cfd86f374270
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=e546de6c050374…
Author: Sven Panne <sp(a)mathias-kettner.de>
Date: Tue Mar 28 11:39:02 2017 +0200
Removed yet another global variable.
Change-Id: Ib9318bfd5dae6ab3659c18550625c57909eec208
---
livestatus/src/Logfile.cc | 9 +++------
livestatus/src/MonitoringCore.h | 1 +
livestatus/src/module.cc | 10 +++++++---
3 files changed, 11 insertions(+), 9 deletions(-)
diff --git a/livestatus/src/Logfile.cc b/livestatus/src/Logfile.cc
index f100180..7fa549c 100644
--- a/livestatus/src/Logfile.cc
+++ b/livestatus/src/Logfile.cc
@@ -51,8 +51,6 @@ using std::make_unique;
using std::string;
using std::vector;
-extern unsigned long g_max_lines_per_logfile;
-
Logfile::Logfile(MonitoringCore *mc, fs::path path, bool watch)
: _mc(mc)
, _path(std::move(path))
@@ -159,10 +157,9 @@ void Logfile::loadRange(FILE *file, unsigned missing_types, LogCache
*logcache,
time_t since, time_t until, unsigned logclasses) {
vector<char> linebuffer(65536);
while (fgets(&linebuffer[0], linebuffer.size(), file) != nullptr) {
- if (_lineno >= g_max_lines_per_logfile) {
- Error(logger()) << "more than " <<
g_max_lines_per_logfile
- << " lines in " << this->_path
- << ", ignoring the rest!";
+ if (_lineno >= _mc->maxLinesPerLogFile()) {
+ Error(logger()) << "more than " <<
_mc->maxLinesPerLogFile()
+ << " lines in " << _path <<
", ignoring the rest!";
return;
}
_lineno++;
diff --git a/livestatus/src/MonitoringCore.h b/livestatus/src/MonitoringCore.h
index 1f4210e..1c2bdbc 100644
--- a/livestatus/src/MonitoringCore.h
+++ b/livestatus/src/MonitoringCore.h
@@ -68,6 +68,7 @@ public:
Contact *contact) = 0;
virtual std::chrono::system_clock::time_point last_logfile_rotation() = 0;
+ virtual uint32_t maxLinesPerLogFile() const = 0;
virtual Command find_command(std::string name) const = 0;
virtual std::vector<Command> commands() const = 0;
diff --git a/livestatus/src/module.cc b/livestatus/src/module.cc
index 8f2af50..26292b5 100644
--- a/livestatus/src/module.cc
+++ b/livestatus/src/module.cc
@@ -120,7 +120,7 @@ static vector<ThreadInfo> fl_thread_info;
static thread_local ThreadInfo *tl_info;
unsigned long g_max_cached_messages = 500000;
// do never read more than that number of lines from a logfile
-unsigned long g_max_lines_per_logfile = 1000000;
+static uint32_t fl_max_lines_per_logfile = 1000000;
unsigned long g_max_response_size = 100 * 1024 * 1024; // limit answer to 10 MB
int g_thread_running = 0;
AuthorizationKind g_service_authorization = AuthorizationKind::loose;
@@ -610,6 +610,10 @@ public:
return {"", ""};
}
+ uint32_t maxLinesPerLogFile() const override {
+ return fl_max_lines_per_logfile;
+ }
+
vector<Command> commands() const override {
extern command *command_list;
vector<Command> commands;
@@ -906,10 +910,10 @@ void livestatus_parse_arguments(const char *args_orig) {
<< "setting max number of cached log messages to "
<< g_max_cached_messages;
} else if (strcmp(left, "max_lines_per_logfile") == 0) {
- g_max_lines_per_logfile = strtoul(right, nullptr, 10);
+ fl_max_lines_per_logfile = strtoul(right, nullptr, 10);
Notice(fl_logger_nagios)
<< "setting max number lines per logfile to "
- << g_max_lines_per_logfile;
+ << fl_max_lines_per_logfile;
} else if (strcmp(left, "thread_stack_size") == 0) {
g_thread_stack_size = strtoul(right, nullptr, 10);
Notice(fl_logger_nagios) << "setting size of thread stacks to
"