Index: base/process_util_posix.cc |
diff --git a/base/process_util_posix.cc b/base/process_util_posix.cc |
index 92ef9643f3358ea0ef4b42798b1e7c8ea3b7facb..3d296748daa4ab6caf2440b380a8f4c2d96f81ed 100644 |
--- a/base/process_util_posix.cc |
+++ b/base/process_util_posix.cc |
@@ -237,6 +237,8 @@ bool KillProcess(ProcessHandle process_id, int exit_code, bool wait) { |
sleep_ms *= 2; |
} |
+ // If we're waiting and the child hasn't died by now, force it |
+ // with a SIGKILL. |
if (!exited) |
result = kill(process_id, SIGKILL) == 0; |
} |
@@ -634,40 +636,45 @@ void RaiseProcessToHighPriority() { |
// setpriority() or sched_getscheduler, but these all require extra rights. |
} |
-bool DidProcessCrash(bool* child_exited, ProcessHandle handle) { |
- int status; |
+TerminationStatus GetTerminationStatus(ProcessHandle handle, int* exit_code) { |
+ int status = 0; |
const pid_t result = HANDLE_EINTR(waitpid(handle, &status, WNOHANG)); |
if (result == -1) { |
PLOG(ERROR) << "waitpid(" << handle << ")"; |
- if (child_exited) |
- *child_exited = false; |
- return false; |
+ if (exit_code) |
+ *exit_code = 0; |
+ return TERMINATION_STATUS_NORMAL_TERMINATION; |
} else if (result == 0) { |
// the child hasn't exited yet. |
- if (child_exited) |
- *child_exited = false; |
- return false; |
+ if (exit_code) |
+ *exit_code = 0; |
+ return TERMINATION_STATUS_STILL_RUNNING; |
} |
- if (child_exited) |
- *child_exited = true; |
+ if (exit_code) |
+ *exit_code = status; |
if (WIFSIGNALED(status)) { |
switch (WTERMSIG(status)) { |
- case SIGSEGV: |
- case SIGILL: |
case SIGABRT: |
+ case SIGBUS: |
case SIGFPE: |
- return true; |
+ case SIGILL: |
+ case SIGSEGV: |
+ return TERMINATION_STATUS_PROCESS_CRASHED; |
+ case SIGINT: |
+ case SIGKILL: |
+ case SIGTERM: |
+ return TERMINATION_STATUS_PROCESS_WAS_KILLED; |
default: |
- return false; |
+ break; |
} |
} |
- if (WIFEXITED(status)) |
- return WEXITSTATUS(status) != 0; |
+ if (WIFEXITED(status) && WEXITSTATUS(status) != 0) |
+ return TERMINATION_STATUS_ABNORMAL_TERMINATION; |
- return false; |
+ return TERMINATION_STATUS_NORMAL_TERMINATION; |
} |
bool WaitForExitCode(ProcessHandle handle, int* exit_code) { |