[Box Backup-commit] COMMIT r2205 - box/trunk/lib/common
boxbackup-dev at fluffy.co.uk
boxbackup-dev at fluffy.co.uk
Sun Jul 27 21:11:25 BST 2008
Author: chris
Date: 2008-07-27 21:11:25 +0100 (Sun, 27 Jul 2008)
New Revision: 2205
Modified:
box/trunk/lib/common/Test.cpp
Log:
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.
Modified: box/trunk/lib/common/Test.cpp
===================================================================
--- box/trunk/lib/common/Test.cpp 2008-07-27 20:10:13 UTC (rev 2204)
+++ box/trunk/lib/common/Test.cpp 2008-07-27 20:11:25 UTC (rev 2205)
@@ -88,23 +88,46 @@
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)
{
- printf("Failed to open process %d: error %d\n",
- pid, (int)GetLastError());
+ 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)
+ {
+ 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)
More information about the Boxbackup-commit
mailing list