Changeset 2205

Show
Ignore:
Timestamp:
27/07/2008 21:11:25 (4 months ago)
Author:
chris
Message:

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.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • box/trunk/lib/common/Test.cpp

    r2185 r2205  
    8989bool ServerIsAlive(int pid) 
    9090{ 
    91 #ifdef WIN32 
    92         HANDLE hProcess = OpenProcess(PROCESS_QUERY_INFORMATION, false, pid); 
    93         if (hProcess == NULL) 
    94         { 
    95                 if (GetLastError() != ERROR_INVALID_PARAMETER) 
    96                 { 
    97                         printf("Failed to open process %d: error %d\n", 
    98                                 pid, (int)GetLastError()); 
    99                 } 
     91        #ifdef WIN32 
     92 
     93                HANDLE hProcess = OpenProcess(PROCESS_QUERY_INFORMATION, 
     94                        false, pid); 
     95                if (hProcess == NULL) 
     96                { 
     97                        if (GetLastError() != ERROR_INVALID_PARAMETER) 
     98                        { 
     99                                BOX_ERROR("Failed to open process " << pid << 
     100                                        ": " << 
     101                                        GetErrorMessage(GetLastError())); 
     102                        } 
     103                        return false; 
     104                } 
     105 
     106                DWORD exitCode; 
     107                BOOL result = GetExitCodeProcess(hProcess, &exitCode); 
     108                CloseHandle(hProcess); 
     109 
     110                if (result == 0) 
     111                { 
     112                        BOX_ERROR("Failed to get exit code for process " << 
     113                                pid << ": " << 
     114                                GetErrorMessage(GetLastError())) 
     115                        return false; 
     116                } 
     117 
     118                if (exitCode == STILL_ACTIVE) 
     119                { 
     120                        return true; 
     121                } 
     122                 
    100123                return false; 
    101         } 
    102         CloseHandle(hProcess); 
    103         return true; 
    104 #else // !WIN32 
    105         if(pid == 0) return false
    106         return ::kill(pid, 0) != -1; 
    107 #endif // WIN32 
     124 
     125        #else // !WIN32 
     126 
     127                if(pid == 0) return false; 
     128               return ::kill(pid, 0) != -1
     129 
     130       #endif // WIN32 
    108131} 
    109132