Commit da8f1822 authored by Peter Hutterer's avatar Peter Hutterer
Browse files

process: on termination, check if the process exited and set the error code



This changes the meaning of Process::TERMINATED to "currently in termination
but we're not sure what happened to it"
Signed-off-by: Peter Hutterer's avatarPeter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Chase Douglas's avatarChase Douglas <chase.douglas@ubuntu.com>
parent 200e0d85
...@@ -70,6 +70,8 @@ class Process { ...@@ -70,6 +70,8 @@ class Process {
* * A process in state ERROR or NONE will fail to Kill() or Terminate() * * A process in state ERROR or NONE will fail to Kill() or Terminate()
* * A process in state FINISHED_SUCCESS or FINISHED_FAILURE will always * * A process in state FINISHED_SUCCESS or FINISHED_FAILURE will always
* succeed to Kill() or Terminate() * succeed to Kill() or Terminate()
* * A process in state TERMINATED may change state to FINISHED_SUCCESS
* or FINISHED_FAILURE when queried again.
*/ */
enum State { enum State {
ERROR, /**< An error has occured, state is now unknown */ ERROR, /**< An error has occured, state is now unknown */
...@@ -77,7 +79,8 @@ class Process { ...@@ -77,7 +79,8 @@ class Process {
RUNNING, /**< The process has been started */ RUNNING, /**< The process has been started */
FINISHED_SUCCESS, /**< The process finished with an exit code of 0 */ FINISHED_SUCCESS, /**< The process finished with an exit code of 0 */
FINISHED_FAILURE, /**< The process finished with a non-zero exit code */ FINISHED_FAILURE, /**< The process finished with a non-zero exit code */
TERMINATED, /**< The process was successfully terminated by this library */ TERMINATED, /**< The process was successfully terminated by this
library but it's state is currently unknown */
}; };
/** /**
......
...@@ -131,9 +131,15 @@ bool xorg::testing::Process::WaitForExit(unsigned int timeout) { ...@@ -131,9 +131,15 @@ bool xorg::testing::Process::WaitForExit(unsigned int timeout) {
int status; int status;
int pid = waitpid(Pid(), &status, WNOHANG); int pid = waitpid(Pid(), &status, WNOHANG);
if (pid == Pid()) if (pid == Pid()) {
return true; if (WIFEXITED(status)) {
else if (pid == -1) d_->state = WEXITSTATUS(status) ? FINISHED_FAILURE : FINISHED_SUCCESS;
return true;
} else if (WIFSIGNALED(status)) {
d_->state = FINISHED_FAILURE;
return true;
}
} else if (pid == -1)
return errno == ECHILD; return errno == ECHILD;
usleep(10); usleep(10);
...@@ -171,8 +177,9 @@ bool xorg::testing::Process::KillSelf(int signal, unsigned int timeout) { ...@@ -171,8 +177,9 @@ bool xorg::testing::Process::KillSelf(int signal, unsigned int timeout) {
bool wait_success = true; bool wait_success = true;
wait_success = WaitForExit(timeout); wait_success = WaitForExit(timeout);
if (!wait_success) if (wait_success)
return false; d_->pid = -1;
return wait_success;
} }
d_->pid = -1; d_->pid = -1;
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment