Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(866)

Unified Diff: base/process_util_posix.cc

Issue 11316261: Linux: inform the Zygote when it's waiting on a dead process (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address Adam's remarks. Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/process_util.h ('k') | content/browser/browser_child_process_host_impl.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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) {
« no previous file with comments | « base/process_util.h ('k') | content/browser/browser_child_process_host_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698