summaryrefslogtreecommitdiff
path: root/lib/common/Test.cpp
diff options
context:
space:
mode:
authorChris Wilson <chris+github@qwirx.com>2008-07-27 20:11:25 +0000
committerChris Wilson <chris+github@qwirx.com>2008-07-27 20:11:25 +0000
commit8715f827e588bb8cd0ffd555735befc315da2523 (patch)
tree670b61968dec3d02f1344568c9e046c8b401b491 /lib/common/Test.cpp
parent1736731fbd890fe0d2ef28dab2ee675cb57292d1 (diff)
On Windows XP, you can open a process even after it's terminated, to
retrieve the exit code, so the check for process liveness has to be modified to make the basicserver test pass.
Diffstat (limited to 'lib/common/Test.cpp')
-rw-r--r--lib/common/Test.cpp51
1 files changed, 37 insertions, 14 deletions
diff --git a/lib/common/Test.cpp b/lib/common/Test.cpp
index 72b1948a..f53d3b37 100644
--- a/lib/common/Test.cpp
+++ b/lib/common/Test.cpp
@@ -88,23 +88,46 @@ int RunCommand(const std::string& rCommandLine)
bool ServerIsAlive(int pid)
{
-#ifdef WIN32
- HANDLE hProcess = OpenProcess(PROCESS_QUERY_INFORMATION, false, pid);
- if (hProcess == NULL)
- {
- if (GetLastError() != ERROR_INVALID_PARAMETER)
+ #ifdef WIN32
+
+ HANDLE hProcess = OpenProcess(PROCESS_QUERY_INFORMATION,
+ false, pid);
+ if (hProcess == NULL)
+ {
+ if (GetLastError() != ERROR_INVALID_PARAMETER)
+ {
+ BOX_ERROR("Failed to open process " << pid <<
+ ": " <<
+ GetErrorMessage(GetLastError()));
+ }
+ return false;
+ }
+
+ DWORD exitCode;
+ BOOL result = GetExitCodeProcess(hProcess, &exitCode);
+ CloseHandle(hProcess);
+
+ if (result == 0)
{
- printf("Failed to open process %d: error %d\n",
- pid, (int)GetLastError());
+ BOX_ERROR("Failed to get exit code for process " <<
+ pid << ": " <<
+ GetErrorMessage(GetLastError()))
+ return false;
}
+
+ if (exitCode == STILL_ACTIVE)
+ {
+ return true;
+ }
+
return false;
- }
- CloseHandle(hProcess);
- return true;
-#else // !WIN32
- if(pid == 0) return false;
- return ::kill(pid, 0) != -1;
-#endif // WIN32
+
+ #else // !WIN32
+
+ if(pid == 0) return false;
+ return ::kill(pid, 0) != -1;
+
+ #endif // WIN32
}
int ReadPidFile(const char *pidFile)