Module: check_mk
Branch: master
Commit: e078fb842dac704c63fa6d3602eee0958fb0b67d
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=e078fb842dac70…
Author: Andreas Boesl <ab(a)mathias-kettner.de>
Date: Tue Sep 20 15:12:33 2016 +0200
3810 FIX windows agent: no longer truncates plugin output, no longer freezes when plugin
produces too much output
Contains two bugfixes.
Fixed race condition where data from a script was not completely read from the
suprocess's pipes.
Fixed an agent freeze when the plugin data exceeded 2MB.
---
.werks/3810 | 14 ++++++++++++++
ChangeLog | 1 +
agents/windows/ExternalCmd.cc | 22 +++++++++++-----------
agents/windows/ExternalCmd.h | 4 ++++
agents/windows/build_version | 2 +-
agents/windows/check_mk_agent-64.exe | Bin 1323520 -> 1323008 bytes
agents/windows/check_mk_agent-64.unstripped.exe | Bin 15356869 -> 15007391 bytes
agents/windows/check_mk_agent-64.unversioned.exe | Bin 1323520 -> 1323008 bytes
agents/windows/check_mk_agent.exe | Bin 1297920 -> 1297408 bytes
agents/windows/check_mk_agent.msi | Bin 2891264 -> 2890240 bytes
agents/windows/check_mk_agent.unstripped.exe | Bin 13279233 -> 13270746 bytes
agents/windows/check_mk_agent.unversioned.exe | Bin 1297920 -> 1297408 bytes
agents/windows/install_agent-64.exe | Bin 584441 -> 584250 bytes
agents/windows/install_agent.exe | Bin 581128 -> 580927 bytes
agents/windows/sections/SectionMRPE.cc | 1 +
agents/windows/sections/SectionPluginGroup.cc | 4 ++--
16 files changed, 34 insertions(+), 14 deletions(-)
diff --git a/.werks/3810 b/.werks/3810
new file mode 100644
index 0000000..53b3bc2
--- /dev/null
+++ b/.werks/3810
@@ -0,0 +1,14 @@
+Title: windows agent: no longer truncates plugin output, no longer freezes when plugin
produces too much output
+Level: 1
+Component: checks
+Compatible: compat
+Version: 1.4.0i1
+Date: 1474377073
+Class: fix
+
+Contains two bugfixes.
+Fixed race condition where data from a script was not completely read from the
suprocess's pipes.
+
+Fixed an agent freeze when the plugin data exceeded 2MB.
+
+
diff --git a/ChangeLog b/ChangeLog
index 1cee385..adb89ef 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -399,6 +399,7 @@
* 3862 FIX: mknotifyd mknotifyd.connection: New service description (when
enabled)...
* 3807 FIX: mssql_counters: fixed crash when the check is unable to parse a timestamp
provided by the plugin
* 3808 FIX: df.include: fixed incorrect levels calculations on very small
filesystems...
+ * 3810 FIX: windows agent: no longer truncates plugin output, no longer freezes when
plugin produces too much output...
Multisite:
* 3187 notification view: new filter for log command via regex
diff --git a/agents/windows/ExternalCmd.cc b/agents/windows/ExternalCmd.cc
index 9064afc..78dbb09 100644
--- a/agents/windows/ExternalCmd.cc
+++ b/agents/windows/ExternalCmd.cc
@@ -48,20 +48,13 @@ ExternalCmd::ExternalCmd(const char *cmdline) {
// child process needs to be able to inherit the pipe handles
security_attributes.bInheritHandle = true;
- HANDLE script_stdout{INVALID_HANDLE_VALUE};
- HANDLE script_stderr{INVALID_HANDLE_VALUE};
- OnScopeExit release_handles([script_stdout, script_stderr]() {
- ::CloseHandle(script_stdout);
- ::CloseHandle(script_stderr);
- });
-
- if (!CreatePipe(&_stdout, &script_stdout, &security_attributes, 0)) {
+ if (!CreatePipe(&_stdout, &_script_stdout, &security_attributes, 0)) {
throw win_exception("failed to create pipe");
}
if (with_stderr) {
- if (!CreatePipe(&_stderr, &script_stderr, &security_attributes, 0))
{
+ if (!CreatePipe(&_stderr, &_script_stderr, &security_attributes, 0))
{
throw win_exception("failed to create pipe");
}
}
@@ -73,8 +66,9 @@ ExternalCmd::ExternalCmd(const char *cmdline) {
GetStartupInfo(&si);
si.dwFlags = STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW;
si.wShowWindow = SW_HIDE;
- si.hStdOutput = script_stdout;
- si.hStdError = with_stderr ? script_stdout : script_stderr;
+ si.hStdOutput = _script_stdout;
+ si.hStdError = with_stderr ? _script_stdout : _script_stderr;
+
PROCESS_INFORMATION pi;
ZeroMemory(&pi, sizeof(PROCESS_INFORMATION));
@@ -111,6 +105,12 @@ void ExternalCmd::terminateJob(DWORD exit_code) {
_job_object = INVALID_HANDLE_VALUE;
}
+void ExternalCmd::closeScriptHandles() {
+ ::CloseHandle(_script_stderr);
+ ::CloseHandle(_script_stdout);
+}
+
+
DWORD ExternalCmd::exitCode() {
DWORD res;
GetExitCodeProcess(_process, &res);
diff --git a/agents/windows/ExternalCmd.h b/agents/windows/ExternalCmd.h
index 5d1db99..89939c3 100644
--- a/agents/windows/ExternalCmd.h
+++ b/agents/windows/ExternalCmd.h
@@ -41,6 +41,8 @@ public:
DWORD stderrAvailable();
+ void closeScriptHandles();
+
DWORD readStdout(char *buffer, size_t buffer_size, bool block = true);
DWORD readStderr(char *buffer, size_t buffer_size, bool block = true);
@@ -49,6 +51,8 @@ private:
DWORD readPipe(HANDLE pipe, char *buffer, size_t buffer_size, bool block);
private:
+ HANDLE _script_stderr{INVALID_HANDLE_VALUE};
+ HANDLE _script_stdout{INVALID_HANDLE_VALUE};
HANDLE _process{INVALID_HANDLE_VALUE};
HANDLE _job_object{INVALID_HANDLE_VALUE};
HANDLE _stdout{INVALID_HANDLE_VALUE};
diff --git a/agents/windows/build_version b/agents/windows/build_version
index 1296a95..621d402 100644
--- a/agents/windows/build_version
+++ b/agents/windows/build_version
@@ -1 +1 @@
-2081
+2083
diff --git a/agents/windows/check_mk_agent-64.exe b/agents/windows/check_mk_agent-64.exe
index cb7539f..2c28a99 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.unstripped.exe
b/agents/windows/check_mk_agent-64.unstripped.exe
index 5bfc1e9..9419387 100755
Binary files a/agents/windows/check_mk_agent-64.unstripped.exe and
b/agents/windows/check_mk_agent-64.unstripped.exe differ
diff --git a/agents/windows/check_mk_agent-64.unversioned.exe
b/agents/windows/check_mk_agent-64.unversioned.exe
index 337f707..040b7e7 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.exe b/agents/windows/check_mk_agent.exe
index 97de829..b12d127 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 f53f6ac..a7881a9 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.unstripped.exe
b/agents/windows/check_mk_agent.unstripped.exe
index e1709e5..cf46c32 100755
Binary files a/agents/windows/check_mk_agent.unstripped.exe and
b/agents/windows/check_mk_agent.unstripped.exe differ
diff --git a/agents/windows/check_mk_agent.unversioned.exe
b/agents/windows/check_mk_agent.unversioned.exe
index ea3e09d..3c4a1b0 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 e61b1ab..842360b 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 2e8443a..6e81291 100755
Binary files a/agents/windows/install_agent.exe and b/agents/windows/install_agent.exe
differ
diff --git a/agents/windows/sections/SectionMRPE.cc
b/agents/windows/sections/SectionMRPE.cc
index b610d39..9fba51a 100644
--- a/agents/windows/sections/SectionMRPE.cc
+++ b/agents/windows/sections/SectionMRPE.cc
@@ -163,6 +163,7 @@ bool SectionMRPE::produceOutputInner(std::ostream &out,
int nagios_code = command.exitCode();
out << nagios_code << " " << plugin_output
<< "\n";
crash_log("Script finished");
+ command.closeScriptHandles();
} catch (const std::exception &e) {
crash_log("mrpe failed: %s", e.what());
out << "3 Unable to execute - plugin may be missing.\n";
diff --git a/agents/windows/sections/SectionPluginGroup.cc
b/agents/windows/sections/SectionPluginGroup.cc
index d2feb1d..23d80d5 100644
--- a/agents/windows/sections/SectionPluginGroup.cc
+++ b/agents/windows/sections/SectionPluginGroup.cc
@@ -103,6 +103,7 @@ static int launch_program(script_container *cont) {
HeapSize(GetProcessHeap(), 0, cont->buffer_work);
} else {
result = BUFFER_FULL;
+ break;
}
}
if (result != BUFFER_FULL) {
@@ -122,8 +123,6 @@ static int launch_program(script_container *cont) {
crash_log("plugin produced more than 2MB output ->
dropped");
}
- cont->exit_code = command.exitCode();
-
if (cont->exit_code != STILL_ACTIVE) {
result = SUCCESS;
}
@@ -147,6 +146,7 @@ static int launch_program(script_container *cont) {
memcpy(cont->buffer_work, buffer_u8.c_str(), buffer_u8.size() + 1);
}
+ command.closeScriptHandles();
} catch (const std::exception &e) {
crash_log("%s", e.what());
result = CANCELED;