diff options
author | Chris Wilson <chris+github@qwirx.com> | 2008-08-07 16:31:32 +0000 |
---|---|---|
committer | Chris Wilson <chris+github@qwirx.com> | 2008-08-07 16:31:32 +0000 |
commit | 0a9ab08aeb2e4936ad46e1bbdf394b737dbab15d (patch) | |
tree | 2efb0de547caef529dc878a32f597e8733dff395 /lib/server/ServerControl.cpp | |
parent | 293b29f88b47236538d63bc3a54d01322b7798b8 (diff) |
Allow waiting for a process while killing it, will be needed for tests
that fork() to avoid zombies and for ServerIsAlive to work.
Diffstat (limited to 'lib/server/ServerControl.cpp')
-rw-r--r-- | lib/server/ServerControl.cpp | 33 |
1 files changed, 31 insertions, 2 deletions
diff --git a/lib/server/ServerControl.cpp b/lib/server/ServerControl.cpp index 590a7847..08b88531 100644 --- a/lib/server/ServerControl.cpp +++ b/lib/server/ServerControl.cpp @@ -6,6 +6,10 @@ #include <sys/types.h> #endif +#ifdef HAVE_SYS_WAIT_H + #include <sys/wait.h> +#endif + #ifdef HAVE_SIGNAL_H #include <signal.h> #endif @@ -160,18 +164,43 @@ bool KillServerInternal(int pid) #endif // WIN32 -bool KillServer(int pid) +bool KillServer(int pid, bool WaitForProcess) { if (!KillServerInternal(pid)) { return false; } + #ifdef HAVE_WAITPID + if (WaitForProcess) + { + int status, result; + + result = waitpid(pid, &status, 0); + if (result != pid) + { + BOX_WARNING("waitpid returned " << result); + } + TEST_THAT(result == pid); + + TEST_THAT(WIFEXITED(status)); + if (WIFEXITED(status)) + { + if (WEXITSTATUS(status) != 0) + { + BOX_WARNING("process exited with code " << + WEXITSTATUS(status)); + } + TEST_THAT(WEXITSTATUS(status) == 0); + } + } + #endif + for (int i = 0; i < 30; i++) { if (i == 0) { - printf("Waiting for server to die: "); + printf("Waiting for server to die (pid %d): ", pid); } printf("."); |