summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--base/process_util.h4
-rw-r--r--base/process_util_posix.cc24
-rw-r--r--base/process_util_win.cc5
-rw-r--r--chrome/test/ui/ui_test.cc2
4 files changed, 30 insertions, 5 deletions
diff --git a/base/process_util.h b/base/process_util.h
index 11c5e12..0f074b1 100644
--- a/base/process_util.h
+++ b/base/process_util.h
@@ -180,6 +180,10 @@ bool WaitForProcessesToExit(const std::wstring& executable_name,
bool WaitForSingleProcess(ProcessHandle handle,
int wait_milliseconds);
+// Returns true when |wait_milliseconds| have elapsed and the process
+// is still running.
+bool CrashAwareSleep(ProcessHandle handle, int wait_milliseconds);
+
// Waits a certain amount of time (can be 0) for all the processes with a given
// executable name to exit, then kills off any of them that are still around.
// If filter is non-null, then only processes selected by the filter are waited
diff --git a/base/process_util_posix.cc b/base/process_util_posix.cc
index e8845fb..453316d 100644
--- a/base/process_util_posix.cc
+++ b/base/process_util_posix.cc
@@ -182,7 +182,9 @@ bool WaitForExitCode(ProcessHandle handle, int* exit_code) {
return false;
}
-bool WaitForSingleProcess(ProcessHandle handle, int wait_milliseconds) {
+namespace {
+
+int WaitpidWithTimeout(ProcessHandle handle, int wait_milliseconds) {
// 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
@@ -228,11 +230,25 @@ bool WaitForSingleProcess(ProcessHandle handle, int wait_milliseconds) {
ret_pid = waitpid(handle, &status, WNOHANG);
}
- if (status != -1) {
+ return status;
+}
+
+} // namespace
+
+bool WaitForSingleProcess(ProcessHandle handle, int wait_milliseconds) {
+ int status = WaitpidWithTimeout(handle, wait_milliseconds);
+ if (status != -1)
return WIFEXITED(status);
- } else {
+ else
+ return false;
+}
+
+bool CrashAwareSleep(ProcessHandle handle, int wait_milliseconds) {
+ int status = WaitpidWithTimeout(handle, wait_milliseconds);
+ if (status != -1)
+ return !(WIFEXITED(status) || WIFSIGNALED(status));
+ else
return false;
- }
}
namespace {
diff --git a/base/process_util_win.cc b/base/process_util_win.cc
index 0ed5d86..9829a41 100644
--- a/base/process_util_win.cc
+++ b/base/process_util_win.cc
@@ -353,6 +353,11 @@ bool WaitForSingleProcess(ProcessHandle handle, int wait_milliseconds) {
return retval;
}
+bool CrashAwareSleep(ProcessHandle handle, int wait_milliseconds) {
+ bool retval = WaitForSingleObject(handle, wait_milliseconds) == WAIT_TIMEOUT;
+ return retval;
+}
+
bool CleanupProcesses(const std::wstring& executable_name,
int wait_milliseconds,
int exit_code,
diff --git a/chrome/test/ui/ui_test.cc b/chrome/test/ui/ui_test.cc
index b5ef095..2ad0952 100644
--- a/chrome/test/ui/ui_test.cc
+++ b/chrome/test/ui/ui_test.cc
@@ -576,7 +576,7 @@ bool UITest::IsBrowserRunning() {
}
bool UITest::CrashAwareSleep(int time_out_ms) {
- return WAIT_TIMEOUT == WaitForSingleObject(process_, time_out_ms);
+ return base::CrashAwareSleep(process_, time_out_ms);
}
/*static*/