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

Unified Diff: base/process_util_posix.cc

Issue 39185: Make CrashAwareSleep more accurate on POSIX (checking if the process exists). (Closed)
Patch Set: wrap success Created 11 years, 10 months 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 | « no previous file | no next file » | 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 1bcfb76dd2ffc3a9eca8ac758751bdcbe209add7..19df76372dbd8f478a3a94b8927abaa7aacbeb51 100644
--- a/base/process_util_posix.cc
+++ b/base/process_util_posix.cc
@@ -184,7 +184,8 @@ bool WaitForExitCode(ProcessHandle handle, int* exit_code) {
namespace {
-int WaitpidWithTimeout(ProcessHandle handle, int wait_milliseconds) {
+int WaitpidWithTimeout(ProcessHandle handle, int wait_milliseconds,
+ bool* success) {
// This POSIX version of this function only guarantees that we wait no less
// than |wait_milliseconds| for the proces to exit. The child process may
// exit sometime before the timeout has ended but we may still block for
@@ -230,25 +231,36 @@ int WaitpidWithTimeout(ProcessHandle handle, int wait_milliseconds) {
ret_pid = waitpid(handle, &status, WNOHANG);
}
+ if (success)
+ *success = (ret_pid != -1);
+
return status;
}
} // namespace
bool WaitForSingleProcess(ProcessHandle handle, int wait_milliseconds) {
- int status = WaitpidWithTimeout(handle, wait_milliseconds);
- if (status != -1)
+ bool waitpid_success;
+ int status = WaitpidWithTimeout(handle, wait_milliseconds, &waitpid_success);
+ if (status != -1) {
+ DCHECK(waitpid_success);
return WIFEXITED(status);
- else
+ } else {
return false;
+ }
}
bool CrashAwareSleep(ProcessHandle handle, int wait_milliseconds) {
- int status = WaitpidWithTimeout(handle, wait_milliseconds);
- if (status != -1)
+ bool waitpid_success;
+ int status = WaitpidWithTimeout(handle, wait_milliseconds, &waitpid_success);
+ if (status != -1) {
+ DCHECK(waitpid_success);
return !(WIFEXITED(status) || WIFSIGNALED(status));
- else
- return true;
+ } else {
+ // If waitpid returned with an error, then the process doesn't exist
+ // (which most probably means it didn't exist before our call).
+ return waitpid_success;
+ }
}
namespace {
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698