From 8715f827e588bb8cd0ffd555735befc315da2523 Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Sun, 27 Jul 2008 20:11:25 +0000 Subject: 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. --- lib/common/Test.cpp | 51 +++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 37 insertions(+), 14 deletions(-) (limited to 'lib') 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) -- cgit v1.2.3