Module: check_mk
Branch: master
Commit: 377e997e76a79b8228e62300aaf58754a6813c25
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=377e997e76a79b…
Author: Jukka Aro <ja(a)mathias-kettner.de>
Date: Thu Mar 1 08:27:27 2018 +0100
Win-agent: favor std::string over const char *
---
agents/windows/build_version | 2 +-
agents/windows/sections/SectionEventlog.cc | 13 ++++++-------
agents/windows/sections/SectionEventlog.h | 4 ++--
3 files changed, 9 insertions(+), 10 deletions(-)
diff --git a/agents/windows/build_version b/agents/windows/build_version
index 0e75b70..b2858f3 100644
--- a/agents/windows/build_version
+++ b/agents/windows/build_version
@@ -1 +1 @@
-3140
+3142
diff --git a/agents/windows/sections/SectionEventlog.cc
b/agents/windows/sections/SectionEventlog.cc
index 1cb3a5c..a0f2033 100644
--- a/agents/windows/sections/SectionEventlog.cc
+++ b/agents/windows/sections/SectionEventlog.cc
@@ -296,7 +296,7 @@ uint64_t SectionEventlog::outputEventlog(std::ostream &out,
IEventLog &log,
// Keeps memory of an event log we have found. It
// might already be known and will not be stored twice.
-void SectionEventlog::registerEventlog(const char *logname) {
+void SectionEventlog::registerEventlog(const std::string &logname) {
// check if we already know this one...
for (auto &state : _states) {
if (ci_equal(state.name, logname)) {
@@ -316,11 +316,9 @@ bool SectionEventlog::find_eventlogs(std::ostream &out) {
state.newly_discovered = false;
}
- char regpath[128];
- snprintf(regpath, sizeof(regpath),
- "SYSTEM\\CurrentControlSet\\Services\\Eventlog");
+ const std::string
regpath{"SYSTEM\\CurrentControlSet\\Services\\Eventlog"};
HKEY key = nullptr;
- DWORD ret = _winapi.RegOpenKeyEx(HKEY_LOCAL_MACHINE, regpath, 0,
+ DWORD ret = _winapi.RegOpenKeyEx(HKEY_LOCAL_MACHINE, regpath.c_str(), 0,
KEY_ENUMERATE_SUB_KEYS, &key);
HKeyHandle hKey{key, _winapi};
bool success = true;
@@ -332,8 +330,9 @@ bool SectionEventlog::find_eventlogs(std::ostream &out) {
len = sizeof(buffer);
DWORD r = _winapi.RegEnumKeyEx(hKey.get(), i, buffer, &len, NULL,
NULL, NULL, NULL);
- if (r == ERROR_SUCCESS)
+ if (r == ERROR_SUCCESS) {
registerEventlog(buffer);
+ }
else if (r != ERROR_MORE_DATA) {
if (r != ERROR_NO_MORE_ITEMS) {
out << "ERROR: Cannot enumerate over event logs: error
"
@@ -356,7 +355,7 @@ bool SectionEventlog::find_eventlogs(std::ostream &out) {
if (*_vista_api) {
for (const auto &eventlog : *_config) {
if (eventlog.vista_api) {
- registerEventlog(eventlog.name.c_str());
+ registerEventlog(eventlog.name);
}
}
}
diff --git a/agents/windows/sections/SectionEventlog.h
b/agents/windows/sections/SectionEventlog.h
index 13d489b..fd48bae 100644
--- a/agents/windows/sections/SectionEventlog.h
+++ b/agents/windows/sections/SectionEventlog.h
@@ -58,7 +58,7 @@ std::ostream &operator<<(std::ostream &out, const config
&val);
// which record entry we have seen its messages so
// far.
struct state {
- state(const char *name) : name(name), newly_discovered(true) {}
+ state(const std::string &name) : name(name), newly_discovered(true) {}
std::string name;
uint64_t record_no{0};
bool newly_discovered;
@@ -105,7 +105,7 @@ private:
uint64_t outputEventlog(std::ostream &out, IEventLog &log,
uint64_t previouslyReadId, eventlog::Level level,
bool hideContext);
- void registerEventlog(const char *logname);
+ void registerEventlog(const std::string &logname);
bool find_eventlogs(std::ostream &out);
void saveEventlogOffsets(const std::string &statefile);
void readHintOffsets();