Module: check_mk
Branch: master
Commit: 8b903b7a1cfa3aa707e5f61a081f46905ddde1e6
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=8b903b7a1cfa3a…
Author: Sebastian Herbord <sh(a)mathias-kettner.de>
Date: Wed Nov 4 09:24:17 2015 +0100
fixed and simplified handle management in wmi-helper and slightly improved error
reporting
---
agents/windows/Makefile | 4 +--
agents/windows/build_version | 2 +-
agents/windows/check_mk_agent-64.exe | Bin 831488 -> 5359530 bytes
agents/windows/check_mk_agent-64.unversioned.exe | Bin 831488 -> 5359530 bytes
agents/windows/check_mk_agent.cc | 9 ++++--
agents/windows/check_mk_agent.exe | Bin 750592 -> 4220996 bytes
agents/windows/check_mk_agent.msi | Bin 1840128 -> 9904128 bytes
agents/windows/check_mk_agent.unversioned.exe | Bin 750592 -> 4220996 bytes
agents/windows/install_agent-64.exe | Bin 383970 -> 1278363 bytes
agents/windows/install_agent.exe | Bin 375168 -> 1161435 bytes
agents/windows/wmiHelper.cc | 33 ++++++++++------------
agents/windows/wmiHelper.h | 8 ++----
12 files changed, 27 insertions(+), 29 deletions(-)
diff --git a/agents/windows/Makefile b/agents/windows/Makefile
index b1e8af7..7fce0f7 100644
--- a/agents/windows/Makefile
+++ b/agents/windows/Makefile
@@ -27,9 +27,9 @@ SHELL = /bin/bash
VERSION = 1.2.7i4
VERSION_DUMMY = @@@@@CHECK_MK_VERSION@@@@@
WINDRES = i686-w64-mingw32-windres
-COPTIONS = -s -O2 -Wall -Wformat=2 -Werror -static -static-libgcc -static-libstdc++
-fno-rtti -DCHECK_MK_VERSION='"$(VERSION_DUMMY)"'
-D__USE_MINGW_ANSI_STDIO
+#COPTIONS = -s -O2 -Wall -Wformat=2 -Werror -static -static-libgcc -static-libstdc++
-fno-rtti -std=c++11 -DCHECK_MK_VERSION='"$(VERSION_DUMMY)"'
-D__USE_MINGW_ANSI_STDIO
# for debug builds
-# COPTIONS = -O0 -Wall -Werror -static -static-libgcc -static-libstdc++ -fno-rtti
-ggdb -DCHECK_MK_VERSION='"$(VERSION_DUMMY)"' -D__USE_MINGW_ANSI_STDIO
+COPTIONS = -O0 -Wall -Werror -static -static-libgcc -static-libstdc++ -fno-rtti
-std=c++11 -ggdb -DCHECK_MK_VERSION='"$(VERSION_DUMMY)"'
-D__USE_MINGW_ANSI_STDIO
MKDIR = mkdir -p
ifeq ($(shell uname),Linux)
diff --git a/agents/windows/build_version b/agents/windows/build_version
index d27f552..51e227a 100644
--- a/agents/windows/build_version
+++ b/agents/windows/build_version
@@ -1 +1 @@
-624
+644
diff --git a/agents/windows/check_mk_agent-64.exe b/agents/windows/check_mk_agent-64.exe
index 2127098..4370941 100755
Binary files a/agents/windows/check_mk_agent-64.exe and
b/agents/windows/check_mk_agent-64.exe differ
diff --git a/agents/windows/check_mk_agent-64.unversioned.exe
b/agents/windows/check_mk_agent-64.unversioned.exe
index c632fcb..7f45f08 100755
Binary files a/agents/windows/check_mk_agent-64.unversioned.exe and
b/agents/windows/check_mk_agent-64.unversioned.exe differ
diff --git a/agents/windows/check_mk_agent.cc b/agents/windows/check_mk_agent.cc
index a30c8d9..7b7b70e 100644
--- a/agents/windows/check_mk_agent.cc
+++ b/agents/windows/check_mk_agent.cc
@@ -1642,9 +1642,10 @@ void save_logwatch_offsets(const std::string
&logwatch_statefile)
{
FILE *file = fopen(logwatch_statefile.c_str(), "w");
if (!file) {
- crash_log("Cannot open %s for writing.\n",
logwatch_statefile.c_str());
+ crash_log("Cannot open %s for writing: %s (%d).\n",
logwatch_statefile.c_str(), strerror(errno), errno);
// not stopping the agent from crashing. This way the user at least
- // notices something went wrong
+ // notices something went wrong.
+ // FIXME: unless there aren't any textfiles configured to be monitored
}
for (logwatch_textfiles_t::const_iterator it_tf =
g_config->logwatchTextfiles().begin();
it_tf != g_config->logwatchTextfiles().end(); ++it_tf) {
@@ -1654,7 +1655,9 @@ void save_logwatch_offsets(const std::string
&logwatch_statefile)
tf->path, tf->file_id, tf->file_size, tf->offset);
}
}
- fclose(file);
+ if (file != NULL) {
+ fclose(file);
+ }
}
void save_eventlog_offsets(const std::string &eventlog_statefile)
diff --git a/agents/windows/check_mk_agent.exe b/agents/windows/check_mk_agent.exe
index 8a04fce..76d62bf 100755
Binary files a/agents/windows/check_mk_agent.exe and b/agents/windows/check_mk_agent.exe
differ
diff --git a/agents/windows/check_mk_agent.msi b/agents/windows/check_mk_agent.msi
index 4535103..7b5043c 100755
Binary files a/agents/windows/check_mk_agent.msi and b/agents/windows/check_mk_agent.msi
differ
diff --git a/agents/windows/check_mk_agent.unversioned.exe
b/agents/windows/check_mk_agent.unversioned.exe
index c2ae79c..b58cef8 100755
Binary files a/agents/windows/check_mk_agent.unversioned.exe and
b/agents/windows/check_mk_agent.unversioned.exe differ
diff --git a/agents/windows/install_agent-64.exe b/agents/windows/install_agent-64.exe
index c88dc76..b5e0211 100755
Binary files a/agents/windows/install_agent-64.exe and
b/agents/windows/install_agent-64.exe differ
diff --git a/agents/windows/install_agent.exe b/agents/windows/install_agent.exe
index bf1b664..59cb8fa 100755
Binary files a/agents/windows/install_agent.exe and b/agents/windows/install_agent.exe
differ
diff --git a/agents/windows/wmiHelper.cc b/agents/windows/wmiHelper.cc
index f63067f..6dfe9e6 100644
--- a/agents/windows/wmiHelper.cc
+++ b/agents/windows/wmiHelper.cc
@@ -87,19 +87,23 @@ Variant::~Variant()
}
+void releaseInterface(IUnknown *ptr)
+{
+ if (ptr != NULL) {
+ ptr->Release();
+ }
+}
+
+
ObjectWrapper::ObjectWrapper(IWbemClassObject *object)
- : _owner(true)
- , _current(object)
+ : _current(object, releaseInterface)
{
}
ObjectWrapper::ObjectWrapper(const ObjectWrapper &reference)
- : _owner(true)
- , _current(reference._current)
+ : _current(reference._current)
{
- // take away ownership from the copied object
- const_cast<ObjectWrapper&>(reference)._owner = false;
}
@@ -130,9 +134,6 @@ int ObjectWrapper::typeId(const wchar_t *key) const
ObjectWrapper::~ObjectWrapper()
{
- if ((_current != NULL) && _owner) {
- _current->Release();
- }
}
@@ -150,7 +151,7 @@ VARIANT ObjectWrapper::getVarByKey(const wchar_t *key) const
Result::Result()
: ObjectWrapper(NULL)
- , _enumerator(NULL)
+ , _enumerator(NULL, releaseInterface)
{
}
@@ -165,7 +166,7 @@ Result::Result(const Result &reference)
Result::Result(IEnumWbemClassObject *enumerator)
: ObjectWrapper(NULL)
- , _enumerator(enumerator)
+ , _enumerator(enumerator, releaseInterface)
{
next();
}
@@ -173,7 +174,6 @@ Result::Result(IEnumWbemClassObject *enumerator)
Result::~Result()
{
- _enumerator->Release();
}
@@ -192,7 +192,7 @@ Result &Result::operator=(const Result &reference)
bool Result::valid() const
{
- return _current != NULL;
+ return _current.get() != NULL;
}
@@ -249,10 +249,7 @@ bool Result::next()
return false;
}
- if (_current != NULL) {
- _current->Release();
- }
- _current = obj;
+ _current.reset(obj, releaseInterface);
return true;
}
@@ -449,7 +446,7 @@ ObjectWrapper Helper::call(ObjectWrapper &result, LPCWSTR method)
BSTR methodName = SysAllocString(method);
res = _services->ExecMethod(className, methodName, 0,
- NULL, result._current, &outParams, NULL);
+ NULL, result._current.get(), &outParams, NULL);
SysFreeString(methodName);
diff --git a/agents/windows/wmiHelper.h b/agents/windows/wmiHelper.h
index 08b1346..4baf86a 100644
--- a/agents/windows/wmiHelper.h
+++ b/agents/windows/wmiHelper.h
@@ -31,7 +31,7 @@
#include <windows.h>
#include <wbemidl.h>
#include <vector>
-
+#include <memory>
std::string to_utf8(const wchar_t *string);
@@ -80,11 +80,9 @@ class ObjectWrapper {
friend class Helper;
- bool _owner;
-
protected:
- IWbemClassObject *_current;
+ std::shared_ptr<IWbemClassObject> _current;
public:
@@ -129,7 +127,7 @@ template <typename T> T ObjectWrapper::get(const wchar_t *key)
const
class Result : public ObjectWrapper
{
- IEnumWbemClassObject *_enumerator;
+ std::shared_ptr<IEnumWbemClassObject> _enumerator;
public: