Module: check_mk
Branch: master
Commit: 9ee593f7af2591e41321135046bfe6b78eb83d88
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=9ee593f7af2591…
Author: Sven Panne <sp(a)mathias-kettner.de>
Date: Fri Sep 15 14:49:09 2017 +0200
Make -Wconversion a bit happier. Improved naming.
Change-Id: I109c422b5c00ee16e95732961e8ed7c6042afd6e
---
livestatus/src/HostSpecialIntColumn.cc | 4 ++--
livestatus/src/LogCache.cc | 12 ++++++------
livestatus/src/Logfile.h | 2 +-
livestatus/src/Poller.h | 19 +++++++++++++------
livestatus/src/StatusSpecialIntColumn.cc | 3 ++-
livestatus/src/mk_inventory.cc | 2 +-
livestatus/src/mk_inventory.h | 3 ++-
7 files changed, 27 insertions(+), 18 deletions(-)
diff --git a/livestatus/src/HostSpecialIntColumn.cc
b/livestatus/src/HostSpecialIntColumn.cc
index fbac0a0..96df548 100644
--- a/livestatus/src/HostSpecialIntColumn.cc
+++ b/livestatus/src/HostSpecialIntColumn.cc
@@ -49,8 +49,8 @@ int32_t HostSpecialIntColumn::getValue(Row row,
dummy_service_description());
case Type::mk_inventory_last: {
- return mk_inventory_last(_mc->mkInventoryPath() + "/" +
- hst->name);
+ return static_cast<int32_t>(mk_inventory_last(
+ _mc->mkInventoryPath() + "/" + hst->name));
}
}
}
diff --git a/livestatus/src/LogCache.cc b/livestatus/src/LogCache.cc
index e12d8f7..11a72e6 100644
--- a/livestatus/src/LogCache.cc
+++ b/livestatus/src/LogCache.cc
@@ -148,8 +148,8 @@ void LogCache::handleNewMessage(Logfile *logfile, time_t /*unused*/,
// Do not touch the logfile the Query is currently accessing
break;
}
- if (it->second->numEntries() > 0) {
- num_cached_log_messages -= it->second->numEntries();
+ if (it->second->size() > 0) {
+ num_cached_log_messages -= it->second->size();
it->second->flush(); // drop all messages of that file
if (static_cast<unsigned long>(num_cached_log_messages) <=
_max_cached_messages) {
@@ -170,7 +170,7 @@ void LogCache::handleNewMessage(Logfile *logfile, time_t /*unused*/,
// Starting from the current logfile (wo broke out of the
// previous loop just when 'it' pointed to that)
for (; it != _logfiles.end(); ++it) {
- if (it->second->numEntries() > 0 &&
+ if (it->second->size() > 0 &&
(it->second->classesRead() & ~logclasses) != 0) {
Debug(logger()) << "freeing classes " << ~logclasses
<< " of file "
<< it->second->path();
@@ -190,10 +190,10 @@ void LogCache::handleNewMessage(Logfile *logfile, time_t
/*unused*/,
// flushing logfiles from the oldest to the newest starting
// at the file just after (i.e. newer than) the current logfile
for (it = ++queryit; it != _logfiles.end(); ++it) {
- if (it->second->numEntries() > 0) {
- Debug(logger()) << "flush newer log, " <<
it->second->numEntries()
+ if (it->second->size() > 0) {
+ Debug(logger()) << "flush newer log, " <<
it->second->size()
<< " number of entries";
- num_cached_log_messages -= it->second->numEntries();
+ num_cached_log_messages -= it->second->size();
it->second->flush();
if (static_cast<unsigned long>(num_cached_log_messages) <=
_max_cached_messages) {
diff --git a/livestatus/src/Logfile.h b/livestatus/src/Logfile.h
index 54c7413..dd39c8e 100644
--- a/livestatus/src/Logfile.h
+++ b/livestatus/src/Logfile.h
@@ -75,7 +75,7 @@ public:
void flush();
time_t since() { return _since; }
unsigned classesRead() { return _logclasses_read; }
- long numEntries() { return _entries.size(); }
+ size_t size() { return _entries.size(); }
logfile_entries_t *getEntriesFromQuery(const Query *query,
LogCache *logcache, time_t since,
time_t until, unsigned);
diff --git a/livestatus/src/Poller.h b/livestatus/src/Poller.h
index 55aeb89..abebfe3 100644
--- a/livestatus/src/Poller.h
+++ b/livestatus/src/Poller.h
@@ -28,6 +28,7 @@
#include "config.h" // IWYU pragma: keep
#include <poll.h>
#include <cerrno>
+#include <chrono>
#include <string>
#include <unordered_map>
#include <vector>
@@ -46,10 +47,13 @@ public:
// encapsulated in e.g. glibc's TEMP_FAILURE_RETRY macro, see:
//
https://www.gnu.org/software/libc/manual/html_node/Interrupted-Primitives.h…
do {
- retval = ::poll(
- &_pollfds[0], _pollfds.size(),
- std::chrono::duration_cast<std::chrono::milliseconds>(timeout)
- .count());
+ auto millis =
+ std::chrono::duration_cast<std::chrono::milliseconds>(timeout);
+ // The cast below is OK because int has at least 32 bits on all
+ // platforms we care about: The timeout is then limited to 24.85
+ // days, which should be more than enough for our needs.
+ retval = ::poll(&_pollfds[0], _pollfds.size(),
+ static_cast<int>(millis.count()));
} while (retval == -1 && errno == EINTR);
return retval;
}
@@ -70,8 +74,11 @@ private:
std::unordered_map<int, size_t> _fd_to_pollfd;
static short toMask(PollEvents e) {
- return (is_empty_bit_mask(e & PollEvents::in) ? 0 : POLLIN) |
- (is_empty_bit_mask(e & PollEvents::out) ? 0 : POLLOUT);
+ // The cast below is OK because all POLLFOO values are within the
+ // guaranteed short value range.
+ return static_cast<short>(
+ (is_empty_bit_mask(e & PollEvents::in) ? 0 : POLLIN) |
+ (is_empty_bit_mask(e & PollEvents::out) ? 0 : POLLOUT));
}
};
diff --git a/livestatus/src/StatusSpecialIntColumn.cc
b/livestatus/src/StatusSpecialIntColumn.cc
index e6bc82f..bbb155b 100644
--- a/livestatus/src/StatusSpecialIntColumn.cc
+++ b/livestatus/src/StatusSpecialIntColumn.cc
@@ -34,7 +34,8 @@ int32_t StatusSpecialIntColumn::getValue(Row /* row */,
switch (_type) {
case Type::mk_inventory_last:
// Check_MK Inventory touches the file ".last" after each
inventory
- return mk_inventory_last(_mc->mkInventoryPath() + "/.last");
+ return static_cast<int32_t>(
+ mk_inventory_last(_mc->mkInventoryPath() + "/.last"));
}
// never reached, make -Wall happy
return 0;
diff --git a/livestatus/src/mk_inventory.cc b/livestatus/src/mk_inventory.cc
index d6dd045..fd6ef91 100644
--- a/livestatus/src/mk_inventory.cc
+++ b/livestatus/src/mk_inventory.cc
@@ -27,7 +27,7 @@
using std::string;
-int mk_inventory_last(const string &path) {
+time_t mk_inventory_last(const string &path) {
struct stat st;
return stat(path.c_str(), &st) != 0 ? 0 : st.st_mtime;
}
diff --git a/livestatus/src/mk_inventory.h b/livestatus/src/mk_inventory.h
index 021a11a..da162fb 100644
--- a/livestatus/src/mk_inventory.h
+++ b/livestatus/src/mk_inventory.h
@@ -26,8 +26,9 @@
#define mk_inventory_h
#include "config.h" // IWYU pragma: keep
+#include <ctime>
#include <string>
-int mk_inventory_last(const std::string &path);
+time_t mk_inventory_last(const std::string &path);
#endif // mk_inventory_h