Module: check_mk
Branch: master
Commit: b31850d3f98316f75a4193146c51dbe1e861bf26
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=b31850d3f98316…
Author: Sven Panne <sp(a)mathias-kettner.de>
Date: Mon Oct 2 12:20:09 2017 +0200
Improved line number typing chaos, using the right type (size_t) as much as possible.
Change-Id: I6347ff08544069e521e247e2e4cc6b18cb8c1fc6
---
livestatus/src/HostServiceState.h | 2 +-
livestatus/src/LogEntry.cc | 4 ++--
livestatus/src/LogEntry.h | 6 ++++--
livestatus/src/Logfile.cc | 5 ++---
livestatus/src/Logfile.h | 6 +++---
livestatus/src/MonitoringCore.h | 2 +-
livestatus/src/module.cc | 4 ++--
7 files changed, 15 insertions(+), 14 deletions(-)
diff --git a/livestatus/src/HostServiceState.h b/livestatus/src/HostServiceState.h
index 24852cb..adf89f7 100644
--- a/livestatus/src/HostServiceState.h
+++ b/livestatus/src/HostServiceState.h
@@ -46,7 +46,7 @@ class HostServiceState {
public:
bool _is_host;
time_t _time;
- int _lineno;
+ int32_t _lineno;
time_t _from;
time_t _until;
diff --git a/livestatus/src/LogEntry.cc b/livestatus/src/LogEntry.cc
index 91a58f4..b8c0856 100644
--- a/livestatus/src/LogEntry.cc
+++ b/livestatus/src/LogEntry.cc
@@ -38,8 +38,8 @@ static constexpr size_t timestamp_prefix_length = 13;
// TODO(sp) Fix classifyLogMessage() below to always set all fields and remove
// this set-me-to-zero-to-be-sure-block.
-LogEntry::LogEntry(MonitoringCore *mc, unsigned lineno, string line)
- : _lineno(lineno)
+LogEntry::LogEntry(MonitoringCore *mc, size_t lineno, string line)
+ : _lineno(static_cast<int32_t>(lineno))
, _complete(std::move(line))
, _state(0)
, _attempt(0)
diff --git a/livestatus/src/LogEntry.h b/livestatus/src/LogEntry.h
index f24267e..283a520 100644
--- a/livestatus/src/LogEntry.h
+++ b/livestatus/src/LogEntry.h
@@ -76,7 +76,9 @@ public:
};
static constexpr uint32_t all_classes = 0xffffu;
- unsigned _lineno; // line number in file
+ // TODO(sp): Wrong type, caused by TableLog accessing it via
+ // OffsetIntColumn, should be size_t
+ int32_t _lineno; // line number in file
time_t _time;
Class _logclass;
LogEntryType _type;
@@ -99,7 +101,7 @@ public:
Command _command;
// NOTE: line gets modified!
- LogEntry(MonitoringCore *mc, unsigned lineno, std::string line);
+ LogEntry(MonitoringCore *mc, size_t lineno, std::string line);
unsigned updateReferences(MonitoringCore *mc);
static ServiceState parseServiceState(const std::string &str);
static HostState parseHostState(const std::string &str);
diff --git a/livestatus/src/Logfile.cc b/livestatus/src/Logfile.cc
index 9079ff2..f4a5159 100644
--- a/livestatus/src/Logfile.cc
+++ b/livestatus/src/Logfile.cc
@@ -190,8 +190,7 @@ long Logfile::freeMessages(unsigned logclasses) {
return freed;
}
-bool Logfile::processLogLine(uint32_t lineno, string line,
- unsigned logclasses) {
+bool Logfile::processLogLine(size_t lineno, string line, unsigned logclasses) {
auto entry = make_unique<LogEntry>(_mc, lineno, std::move(line));
// ignored invalid lines
if (entry->_logclass == LogEntry::Class::invalid) {
@@ -258,7 +257,7 @@ bool Logfile::answerQueryReverse(Query *query, LogCache *logcache,
time_t since,
return true;
}
-uint64_t Logfile::makeKey(time_t t, unsigned lineno) {
+uint64_t Logfile::makeKey(time_t t, size_t lineno) {
return (static_cast<uint64_t>(t) << 32) |
static_cast<uint64_t>(lineno);
}
diff --git a/livestatus/src/Logfile.h b/livestatus/src/Logfile.h
index dd39c8e..072bde4 100644
--- a/livestatus/src/Logfile.h
+++ b/livestatus/src/Logfile.h
@@ -54,7 +54,7 @@ private:
time_t _since; // time of first entry
bool _watch; // true only for current logfile
fpos_t _read_pos; // read until this position
- uint32_t _lineno; // read until this line
+ size_t _lineno; // read until this line
logfile_entries_t _entries;
#ifdef CMC
@@ -92,8 +92,8 @@ public:
private:
void loadRange(FILE *file, unsigned missing_types, LogCache *, time_t since,
time_t until, unsigned logclasses);
- bool processLogLine(uint32_t lineno, std::string line, unsigned logclasses);
- uint64_t makeKey(time_t, unsigned);
+ bool processLogLine(size_t lineno, std::string line, unsigned logclasses);
+ uint64_t makeKey(time_t, size_t);
Logger *logger() const;
};
diff --git a/livestatus/src/MonitoringCore.h b/livestatus/src/MonitoringCore.h
index 10c3e0e..44cce64 100644
--- a/livestatus/src/MonitoringCore.h
+++ b/livestatus/src/MonitoringCore.h
@@ -71,7 +71,7 @@ public:
const Contact *contact) = 0;
virtual std::chrono::system_clock::time_point last_logfile_rotation() = 0;
- virtual uint32_t maxLinesPerLogFile() const = 0;
+ virtual size_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 5040d89..cc3ea64 100644
--- a/livestatus/src/module.cc
+++ b/livestatus/src/module.cc
@@ -122,7 +122,7 @@ static vector<ThreadInfo> fl_thread_info;
static thread_local ThreadInfo *tl_info;
size_t fl_max_cached_messages = 500000;
// do never read more than that number of lines from a logfile
-static uint32_t fl_max_lines_per_logfile = 1000000;
+static size_t fl_max_lines_per_logfile = 1000000;
size_t fl_max_response_size = 100 * 1024 * 1024; // limit answer to 10 MB
int g_thread_running = 0;
static AuthorizationKind fl_service_authorization = AuthorizationKind::loose;
@@ -618,7 +618,7 @@ public:
return {"", ""};
}
- uint32_t maxLinesPerLogFile() const override {
+ size_t maxLinesPerLogFile() const override {
return fl_max_lines_per_logfile;
}