Module: check_mk
Branch: master
Commit: a3ff6814d93380226b13681b4c687c03d829df56
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=a3ff6814d93380…
Author: Andreas Boesl <ab(a)mathias-kettner.de>
Date: Tue May 19 13:58:13 2015 +0200
updated information of werk 2274
---
.werks/2274 | 5 +++
agents/windows/build_version | 2 +-
agents/windows/check_mk_agent-64.exe | Bin 301056 -> 301056 bytes
agents/windows/check_mk_agent-64.unversioned.exe | Bin 301056 -> 301056 bytes
agents/windows/check_mk_agent.cc | 46 +++++++++++++---------
agents/windows/check_mk_agent.exe | Bin 182784 -> 182784 bytes
agents/windows/check_mk_agent.msi | Bin 732160 -> 732160 bytes
agents/windows/check_mk_agent.unversioned.exe | Bin 182784 -> 182784 bytes
agents/windows/install_agent-64.exe | Bin 178467 -> 178461 bytes
agents/windows/install_agent.exe | Bin 159356 -> 159422 bytes
10 files changed, 33 insertions(+), 20 deletions(-)
diff --git a/.werks/2274 b/.werks/2274
index 6eb1569..a6a7c76 100644
--- a/.werks/2274
+++ b/.werks/2274
@@ -7,3 +7,8 @@ Date: 1432024643
Class: feature
If you need stdout only simply use <tt>check_mk_agent.exe file myfile</tt>.
+
+This feature also includes a small fix. If a plugin script wrote something to
+stderr there was a possibility that the following stdout information was skipped.
+This bug was only observed on a Win2k3 system.
+
diff --git a/agents/windows/build_version b/agents/windows/build_version
index 4c5c807..9386c22 100644
--- a/agents/windows/build_version
+++ b/agents/windows/build_version
@@ -1 +1 @@
-158
+161
diff --git a/agents/windows/check_mk_agent-64.exe b/agents/windows/check_mk_agent-64.exe
index 3e24442..a351f11 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 6bd1285..9bb08cd 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 6ed2410..f6c7308 100755
--- a/agents/windows/check_mk_agent.cc
+++ b/agents/windows/check_mk_agent.cc
@@ -2837,8 +2837,10 @@ int launch_program(script_container* cont)
STARTUPINFO si;
SECURITY_ATTRIBUTES sa;
SECURITY_DESCRIPTOR sd; // security information for pipes
+
PROCESS_INFORMATION pi;
- HANDLE newstdout,read_stdout; // pipe handles
+ HANDLE script_stdout,read_stdout; // pipe handles
+ HANDLE script_stderr,read_stderr;
// initialize security descriptor (Windows NT)
if (IsWinNT())
@@ -2849,39 +2851,36 @@ int launch_program(script_container* cont)
}
else
sa.lpSecurityDescriptor = NULL;
+
sa.nLength = sizeof(SECURITY_ATTRIBUTES);
sa.bInheritHandle = true; // allow inheritable handles
- if (!CreatePipe(&read_stdout,&newstdout,&sa,0)) // create stdout pipe
- {
+ if (!CreatePipe(&read_stdout,&script_stdout,&sa,0)) // create stdout
pipe
+ return 1;
+
+ if (!CreatePipe(&read_stderr,&script_stderr,&sa,0)) // create stderr
pipe
return 1;
- }
//set startupinfo for the spawned process
GetStartupInfo(&si);
si.dwFlags = STARTF_USESTDHANDLES|STARTF_USESHOWWINDOW;
si.wShowWindow = SW_HIDE;
- si.hStdOutput = newstdout;
-
-
- // Redirect sterr to NUL device
- SECURITY_ATTRIBUTES secattr;
- secattr.nLength = sizeof secattr;
- secattr.lpSecurityDescriptor = NULL;
- secattr.bInheritHandle = TRUE;
- HANDLE hnul = CreateFile("NUL", GENERIC_WRITE, 0, &secattr,
OPEN_EXISTING, 0, NULL);
+ si.hStdOutput = script_stdout;
if (with_stderr)
- si.hStdError = newstdout;
+ si.hStdError = script_stdout;
else
- si.hStdError = hnul;
+ si.hStdError = script_stderr;
// spawn the child process
if (!CreateProcess(NULL,cont->path,NULL,NULL,TRUE,CREATE_NEW_CONSOLE,
NULL,NULL,&si,&pi))
{
- CloseHandle(newstdout);
+ CloseHandle(script_stdout);
CloseHandle(read_stdout);
+
+ CloseHandle(script_stderr);
+ CloseHandle(read_stderr);
return 1;
}
@@ -2908,9 +2907,18 @@ int launch_program(script_container* cont)
exit_code = 2;
break;
}
+
GetExitCodeProcess(pi.hProcess, &exit); // while the process is running
while (!buffer_full) {
+ if (!with_stderr) {
+ PeekNamedPipe(read_stderr, buf, sizeof(buf), &bread, &avail,
NULL);
+ if (avail > 0)
+ // Just read from the pipe, we do not use this data
+ ReadFile(read_stderr, buf, sizeof(buf) - 1, &bread, NULL);
+ }
+
PeekNamedPipe(read_stdout, buf, sizeof(buf), &bread, &avail, NULL);
+
if (avail == 0)
break;
@@ -2953,10 +2961,10 @@ int launch_program(script_container* cont)
CloseHandle(cont->job_object);
CloseHandle(pi.hThread);
CloseHandle(pi.hProcess);
- CloseHandle(newstdout);
+ CloseHandle(script_stdout);
CloseHandle(read_stdout);
- if (!with_stderr)
- CloseHandle(hnul);
+ CloseHandle(script_stderr);
+ CloseHandle(read_stderr);
return exit_code;
}
diff --git a/agents/windows/check_mk_agent.exe b/agents/windows/check_mk_agent.exe
index 77655d9..c363734 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 e55928a..e46b1cf 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 d10fb2d..d837089 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 b7b9dc7..eb35a9c 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 607f59d..d098fc8 100755
Binary files a/agents/windows/install_agent.exe and b/agents/windows/install_agent.exe
differ