summaryrefslogtreecommitdiffstats
path: root/base
diff options
context:
space:
mode:
authorphajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-03-06 09:24:38 +0000
committerphajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-03-06 09:24:38 +0000
commitef0279270ece2edf8524afeb9ac6f9cd533ccb60 (patch)
tree3e0d50449e648ed4edc9b60e588b93dcbef27939 /base
parent000aa254e3089acb0f8574972e6ced26787dded7 (diff)
downloadchromium_src-ef0279270ece2edf8524afeb9ac6f9cd533ccb60.zip
chromium_src-ef0279270ece2edf8524afeb9ac6f9cd533ccb60.tar.gz
chromium_src-ef0279270ece2edf8524afeb9ac6f9cd533ccb60.tar.bz2
Make CrashAwareSleep more accurate on POSIX (checking if the process exists).
Review URL: http://codereview.chromium.org/39185 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@11103 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base')
-rw-r--r--base/process_util_posix.cc28
1 files changed, 20 insertions, 8 deletions
diff --git a/base/process_util_posix.cc b/base/process_util_posix.cc
index 1bcfb76..19df763 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 {