Module: check_mk
Branch: master
Commit: 6e8bb26d0f2eb30f40da2baf56caeabe2f766a18
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=6e8bb26d0f2eb3…
Author: Jukka Aro <ja(a)mathias-kettner.de>
Date: Thu Feb 15 12:31:29 2018 +0100
Windows agent: move section helper functions
Declare and define time-related helper functions in Section.* as this is
where they are needed. Avoid explicitly extern-declared function
declarations in source files. Fix external linkage to outside of
libcheck_mk_agent.a as it is unclear how this ever worked(!).
---
agents/windows/Section.cc | 23 +++++++++++++++++++++++
agents/windows/Section.h | 8 ++++++++
agents/windows/build_version | 2 +-
agents/windows/check_mk_agent.cc | 19 -------------------
agents/windows/sections/SectionFileinfo.cc | 13 ++++++-------
agents/windows/sections/SectionPS.cc | 11 +++++------
agents/windows/sections/SectionSpool.cc | 5 ++---
agents/windows/sections/SectionSystemtime.cc | 5 ++---
agents/windows/sections/SectionWinperf.cc | 7 +++----
9 files changed, 50 insertions(+), 43 deletions(-)
diff --git a/agents/windows/Section.cc b/agents/windows/Section.cc
index c517fb6..23e02af 100644
--- a/agents/windows/Section.cc
+++ b/agents/windows/Section.cc
@@ -27,6 +27,29 @@
#include "Environment.h"
#include "Logger.h"
+namespace section_helpers {
+
+static const double SEC_TO_UNIX_EPOCH = 11644473600.0;
+static const double WINDOWS_TICK = 10000000.0;
+
+double file_time(const FILETIME *filetime) {
+ ULARGE_INTEGER uli{0};
+ uli.LowPart = filetime->dwLowDateTime;
+ uli.HighPart = filetime->dwHighDateTime;
+
+ return (double(uli.QuadPart) / WINDOWS_TICK) - SEC_TO_UNIX_EPOCH;
+}
+
+double current_time(const WinApiAdaptor &winapi) {
+ SYSTEMTIME systime{0};
+ FILETIME filetime{0};
+ winapi.GetSystemTime(&systime);
+ winapi.SystemTimeToFileTime(&systime, &filetime);
+ return file_time(&filetime);
+}
+
+} // namespace section_helpers
+
Section::Section(const std::string &outputName, const std::string &configName,
const Environment &env, Logger *logger,
const WinApiAdaptor &winapi)
diff --git a/agents/windows/Section.h b/agents/windows/Section.h
index 0cd3864..c483499 100644
--- a/agents/windows/Section.h
+++ b/agents/windows/Section.h
@@ -37,6 +37,14 @@
class Environment;
class Logger;
+namespace section_helpers {
+
+double file_time(const FILETIME *filetime);
+
+double current_time(const WinApiAdaptor &winapi);
+
+} // namespace section_helpers
+
class Section {
friend class SectionGroup;
diff --git a/agents/windows/build_version b/agents/windows/build_version
index 4253b05..e5bffd6 100644
--- a/agents/windows/build_version
+++ b/agents/windows/build_version
@@ -1 +1 @@
-3106
+3108
diff --git a/agents/windows/check_mk_agent.cc b/agents/windows/check_mk_agent.cc
index b56a27e..152f1f8 100644
--- a/agents/windows/check_mk_agent.cc
+++ b/agents/windows/check_mk_agent.cc
@@ -225,25 +225,6 @@ volatile bool g_should_terminate = false;
// | Global helper functions |
// '----------------------------------------------------------------------'
-double file_time(const FILETIME *filetime) {
- static const double SEC_TO_UNIX_EPOCH = 11644473600.0;
- static const double WINDOWS_TICK = 10000000.0;
-
- _ULARGE_INTEGER uli;
- uli.LowPart = filetime->dwLowDateTime;
- uli.HighPart = filetime->dwHighDateTime;
-
- return (double(uli.QuadPart) / WINDOWS_TICK) - SEC_TO_UNIX_EPOCH;
-}
-
-double current_time() {
- SYSTEMTIME systime;
- FILETIME filetime;
- s_winapi.GetSystemTime(&systime);
- s_winapi.SystemTimeToFileTime(&systime, &filetime);
- return file_time(&filetime);
-}
-
template <typename T>
bool in_set(const T &val, const std::set<T> &test_set) {
return test_set.find(val) != test_set.end();
diff --git a/agents/windows/sections/SectionFileinfo.cc
b/agents/windows/sections/SectionFileinfo.cc
index 3eb4178..b111aab 100644
--- a/agents/windows/sections/SectionFileinfo.cc
+++ b/agents/windows/sections/SectionFileinfo.cc
@@ -28,9 +28,6 @@
#include <sstream>
#include "Logger.h"
-extern double current_time();
-extern double file_time(const FILETIME *filetime);
-
SectionFileinfo::SectionFileinfo(Configuration &config, Logger *logger,
const WinApiAdaptor &winapi)
: Section("fileinfo", "fileinfo", config.getEnvironment(),
logger, winapi)
@@ -40,7 +37,8 @@ SectionFileinfo::SectionFileinfo(Configuration &config, Logger
*logger,
bool SectionFileinfo::produceOutputInner(std::ostream &out) {
Debug(_logger) << "SectionFileinfo::produceOutputInner";
- out << std::fixed << std::setprecision(0) << current_time()
<< "\n";
+ out << std::fixed << std::setprecision(0)
+ << section_helpers::current_time(_winapi) << "\n";
for (const std::string &path : *_fileinfo_paths) {
outputFileinfos(out, path.c_str());
@@ -136,7 +134,8 @@ void SectionFileinfo::outputFileinfos(std::ostream &out, const
char *path) {
}
if (!found_file) {
- out << path << "|missing|" << current_time() <<
"\n";
+ out << path << "|missing|" <<
section_helpers::current_time(_winapi)
+ << "\n";
}
}
@@ -150,8 +149,8 @@ bool SectionFileinfo::outputFileinfo(std::ostream &out,
(unsigned long long)findData.nFileSizeLow +
(((unsigned long long)findData.nFileSizeHigh) << 32);
out << filename << "|" << size << "|"
<< std::fixed
- << std::setprecision(0) <<
file_time(&findData.ftLastWriteTime)
- << "\n";
+ << std::setprecision(0)
+ << section_helpers::file_time(&findData.ftLastWriteTime) <<
"\n";
return true;
}
return false;
diff --git a/agents/windows/sections/SectionPS.cc b/agents/windows/sections/SectionPS.cc
index 850dfc4..45b7b95 100644
--- a/agents/windows/sections/SectionPS.cc
+++ b/agents/windows/sections/SectionPS.cc
@@ -29,9 +29,6 @@
#include "PerfCounter.h"
#include "dynamic_func.h"
-extern double file_time(const FILETIME *filetime);
-extern double current_time();
-
SectionPS::SectionPS(Configuration &config, Logger *logger,
const WinApiAdaptor &winapi)
: Section("ps", "ps", config.getEnvironment(), logger, winapi)
@@ -203,7 +200,8 @@ bool SectionPS::outputWMI(std::ostream &out) {
std::tm t;
ss >> std::get_time(&t, L"%Y%m%d%H%M%S");
time_t creation_time = mktime(&t);
- auto uptime = (ULONGLONG)((time_t)current_time() - creation_time);
+ auto uptime = (ULONGLONG)(
+ (time_t)section_helpers::current_time(_winapi) - creation_time);
outputProcess(
out,
std::stoull(result.get<std::string>(L"VirtualSize")),
@@ -310,8 +308,9 @@ bool SectionPS::outputNative(std::ostream &out) {
}
// Uptime
- double ft = file_time(&createTime);
- ULONGLONG uptime = (ULONGLONG)(current_time() - ft);
+ double ft = section_helpers::file_time(&createTime);
+ ULONGLONG uptime =
+ (ULONGLONG)(section_helpers::current_time(_winapi) - ft);
// Note: CPU utilization is determined out of usermodetime and
// kernelmodetime
diff --git a/agents/windows/sections/SectionSpool.cc
b/agents/windows/sections/SectionSpool.cc
index 1efe4a3..f9ec66f 100644
--- a/agents/windows/sections/SectionSpool.cc
+++ b/agents/windows/sections/SectionSpool.cc
@@ -32,8 +32,6 @@
namespace fs = std::experimental::filesystem;
-extern double file_time(const FILETIME *filetime);
-
SectionSpool::SectionSpool(const Environment &env, Logger *logger,
const WinApiAdaptor &winapi)
: Section("spool", "spool", env, logger, winapi) {
@@ -63,7 +61,8 @@ bool SectionSpool::produceOutputInner(std::ostream &out) {
FindExSearchNameMatch, NULL, 0),
_winapi};
if (searchHandle) {
- double mtime = file_time(&(filedata.ftLastWriteTime));
+ double mtime =
+ section_helpers::file_time(&(filedata.ftLastWriteTime));
int age = now - mtime;
if (age > max_age) {
Informational(_logger)
diff --git a/agents/windows/sections/SectionSystemtime.cc
b/agents/windows/sections/SectionSystemtime.cc
index 5953639..fa31b17 100644
--- a/agents/windows/sections/SectionSystemtime.cc
+++ b/agents/windows/sections/SectionSystemtime.cc
@@ -26,14 +26,13 @@
#include <iomanip>
#include "Logger.h"
-extern double current_time();
-
SectionSystemtime::SectionSystemtime(const Environment &env, Logger *logger,
const WinApiAdaptor &winapi)
: Section("systemtime", "systemtime", env, logger, winapi) {}
bool SectionSystemtime::produceOutputInner(std::ostream &out) {
Debug(_logger) << "SectionSystemtime::produceOutputInner";
- out << std::fixed << std::setprecision(0) << current_time();
+ out << std::fixed << std::setprecision(0)
+ << section_helpers::current_time(_winapi);
return true;
}
diff --git a/agents/windows/sections/SectionWinperf.cc
b/agents/windows/sections/SectionWinperf.cc
index 1d66638..7d174f5 100644
--- a/agents/windows/sections/SectionWinperf.cc
+++ b/agents/windows/sections/SectionWinperf.cc
@@ -30,8 +30,6 @@
#include "PerfCounter.h"
#include "stringutil.h"
-extern double current_time();
-
SectionWinperf::SectionWinperf(const std::string &name, const Environment &env,
Logger *logger, const WinApiAdaptor &winapi)
: Section("winperf_" + name, "winperf_" + name, env, logger,
winapi)
@@ -50,8 +48,9 @@ bool SectionWinperf::produceOutputInner(std::ostream &out) {
if (!counterObject.isEmpty()) {
LARGE_INTEGER Frequency;
_winapi.QueryPerformanceFrequency(&Frequency);
- out << std::fixed << std::setprecision(2) << current_time()
<< " "
- << _base << " " << Frequency.QuadPart
<< "\n";
+ out << std::fixed << std::setprecision(2)
+ << section_helpers::current_time(_winapi) << " "
<< _base << " "
+ << Frequency.QuadPart << "\n";
std::vector<PERF_INSTANCE_DEFINITION *> instances =
counterObject.instances();