Changeset 2224

Show
Ignore:
Timestamp:
07/08/2008 17:31:32 (5 months ago)
Author:
chris
Message:

Allow waiting for a process while killing it, will be needed for tests
that fork() to avoid zombies and for ServerIsAlive? to work.

Location:
box/trunk/lib/server
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • box/trunk/lib/server/ServerControl.cpp

    r2171 r2224  
    55#ifdef HAVE_SYS_TYPES_H 
    66        #include <sys/types.h> 
     7#endif 
     8 
     9#ifdef HAVE_SYS_WAIT_H 
     10        #include <sys/wait.h> 
    711#endif 
    812 
     
    161165#endif // WIN32 
    162166 
    163 bool KillServer(int pid) 
     167bool KillServer(int pid, bool WaitForProcess) 
    164168{ 
    165169        if (!KillServerInternal(pid)) 
     
    168172        } 
    169173 
     174        #ifdef HAVE_WAITPID 
     175        if (WaitForProcess) 
     176        { 
     177                int status, result; 
     178 
     179                result = waitpid(pid, &status, 0); 
     180                if (result != pid) 
     181                { 
     182                        BOX_WARNING("waitpid returned " << result); 
     183                } 
     184                TEST_THAT(result == pid); 
     185 
     186                TEST_THAT(WIFEXITED(status)); 
     187                if (WIFEXITED(status)) 
     188                { 
     189                        if (WEXITSTATUS(status) != 0) 
     190                        { 
     191                                BOX_WARNING("process exited with code " << 
     192                                        WEXITSTATUS(status)); 
     193                        } 
     194                        TEST_THAT(WEXITSTATUS(status) == 0); 
     195                } 
     196        } 
     197        #endif 
     198 
    170199        for (int i = 0; i < 30; i++) 
    171200        { 
    172201                if (i == 0)  
    173202                { 
    174                         printf("Waiting for server to die: "); 
     203                        printf("Waiting for server to die (pid %d): ", pid); 
    175204                } 
    176205 
  • box/trunk/lib/server/ServerControl.h

    r2171 r2224  
    55 
    66bool HUPServer(int pid); 
    7 bool KillServer(int pid); 
     7bool KillServer(int pid, bool WaitForProcess = false); 
    88 
    99#ifdef WIN32