Index: base/process_util_posix.cc |
diff --git a/base/process_util_posix.cc b/base/process_util_posix.cc |
index a19cc2a999ecb5bc8b469778420afb1fb4b0f28b..284d00fed4eacfc4b18b4d060223450f06616fe7 100644 |
--- a/base/process_util_posix.cc |
+++ b/base/process_util_posix.cc |
@@ -152,6 +152,50 @@ void ResetChildSignalHandlersToDefaults() { |
signal(SIGTERM, SIG_DFL); |
} |
+TerminationStatus GetTerminationStatusImpl(ProcessHandle handle, |
+ bool can_block, |
+ int* exit_code) { |
+ int status = 0; |
+ const pid_t result = HANDLE_EINTR(waitpid(handle, &status, |
+ can_block ? 0 : WNOHANG)); |
+ if (result == -1) { |
+ DPLOG(ERROR) << "waitpid(" << handle << ")"; |
+ if (exit_code) |
+ *exit_code = 0; |
+ return TERMINATION_STATUS_NORMAL_TERMINATION; |
+ } else if (result == 0) { |
+ // the child hasn't exited yet. |
+ if (exit_code) |
+ *exit_code = 0; |
+ return TERMINATION_STATUS_STILL_RUNNING; |
+ } |
+ |
+ if (exit_code) |
+ *exit_code = status; |
+ |
+ if (WIFSIGNALED(status)) { |
+ switch (WTERMSIG(status)) { |
+ case SIGABRT: |
+ case SIGBUS: |
+ case SIGFPE: |
+ case SIGILL: |
+ case SIGSEGV: |
+ return TERMINATION_STATUS_PROCESS_CRASHED; |
+ case SIGINT: |
+ case SIGKILL: |
+ case SIGTERM: |
+ return TERMINATION_STATUS_PROCESS_WAS_KILLED; |
+ default: |
+ break; |
+ } |
+ } |
+ |
+ if (WIFEXITED(status) && WEXITSTATUS(status) != 0) |
+ return TERMINATION_STATUS_ABNORMAL_TERMINATION; |
+ |
+ return TERMINATION_STATUS_NORMAL_TERMINATION; |
+} |
+ |
} // anonymous namespace |
ProcessId GetCurrentProcId() { |
@@ -754,44 +798,12 @@ void RaiseProcessToHighPriority() { |
} |
TerminationStatus GetTerminationStatus(ProcessHandle handle, int* exit_code) { |
- int status = 0; |
- const pid_t result = HANDLE_EINTR(waitpid(handle, &status, WNOHANG)); |
- if (result == -1) { |
- DPLOG(ERROR) << "waitpid(" << handle << ")"; |
- if (exit_code) |
- *exit_code = 0; |
- return TERMINATION_STATUS_NORMAL_TERMINATION; |
- } else if (result == 0) { |
- // the child hasn't exited yet. |
- if (exit_code) |
- *exit_code = 0; |
- return TERMINATION_STATUS_STILL_RUNNING; |
- } |
- |
- if (exit_code) |
- *exit_code = status; |
- |
- if (WIFSIGNALED(status)) { |
- switch (WTERMSIG(status)) { |
- case SIGABRT: |
- case SIGBUS: |
- case SIGFPE: |
- case SIGILL: |
- case SIGSEGV: |
- return TERMINATION_STATUS_PROCESS_CRASHED; |
- case SIGINT: |
- case SIGKILL: |
- case SIGTERM: |
- return TERMINATION_STATUS_PROCESS_WAS_KILLED; |
- default: |
- break; |
- } |
- } |
- |
- if (WIFEXITED(status) && WEXITSTATUS(status) != 0) |
- return TERMINATION_STATUS_ABNORMAL_TERMINATION; |
+ return GetTerminationStatusImpl(handle, false /* can_block */, exit_code); |
+} |
- return TERMINATION_STATUS_NORMAL_TERMINATION; |
+TerminationStatus WaitForTerminationStatus(ProcessHandle handle, |
+ int* exit_code) { |
+ return GetTerminationStatusImpl(handle, true /* can_block */, exit_code); |
} |
bool WaitForExitCode(ProcessHandle handle, int* exit_code) { |