diff options
author | phajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-01-13 17:38:49 +0000 |
---|---|---|
committer | phajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-01-13 17:38:49 +0000 |
commit | c78566309f95a11cd5253e1cac681038d9885f21 (patch) | |
tree | 74bac802565ea385f1585d5d7d8ca15891b1979c /base | |
parent | 2ccbdbe2508fdf17fde95a96ee197d45faabe467 (diff) | |
download | chromium_src-c78566309f95a11cd5253e1cac681038d9885f21.zip chromium_src-c78566309f95a11cd5253e1cac681038d9885f21.tar.gz chromium_src-c78566309f95a11cd5253e1cac681038d9885f21.tar.bz2 |
Port crash_cache tool to Linux.
Review URL: http://codereview.chromium.org/17353
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@7939 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base')
-rw-r--r-- | base/process_util.h | 6 | ||||
-rw-r--r-- | base/process_util_posix.cc | 20 | ||||
-rw-r--r-- | base/process_util_win.cc | 14 |
3 files changed, 40 insertions, 0 deletions
diff --git a/base/process_util.h b/base/process_util.h index c88d341..7eabdbe 100644 --- a/base/process_util.h +++ b/base/process_util.h @@ -147,6 +147,12 @@ bool KillProcess(int process_id, int exit_code, bool wait); // process hasn't terminated yet. bool DidProcessCrash(ProcessHandle handle); +// Waits for process to exit. In POSIX systems, if the process hasn't been +// signaled then puts the exit code in |exit_code|; otherwise it's considered +// a failure. On Windows |exit_code| is always filled. Returns true on success, +// and closes |handle| in any case. +bool WaitForExitCode(ProcessHandle handle, int* exit_code); + // Wait for all the processes based on the named executable to exit. If filter // is non-null, then only processes selected by the filter are waited on. // Returns after all processes have exited or wait_milliseconds have expired. diff --git a/base/process_util_posix.cc b/base/process_util_posix.cc index dee917d..8e6781e 100644 --- a/base/process_util_posix.cc +++ b/base/process_util_posix.cc @@ -4,6 +4,7 @@ #include "base/process_util.h" +#include <errno.h> #include <signal.h> #include <sys/resource.h> #include <sys/time.h> @@ -96,6 +97,25 @@ void RaiseProcessToHighPriority() { // setpriority() or sched_getscheduler, but these all require extra rights. } +bool WaitForExitCode(ProcessHandle handle, int* exit_code) { + int status; + while (waitpid(handle, &status, 0) == -1) { + if (errno != EINTR) { + NOTREACHED(); + return false; + } + } + + if (WIFEXITED(status)) { + *exit_code = WEXITSTATUS(status); + return true; + } + + // If it didn't exit cleanly, it must have been signaled. + DCHECK(WIFSIGNALED(status)); + return false; +} + bool WaitForSingleProcess(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 diff --git a/base/process_util_win.cc b/base/process_util_win.cc index 1203629..a69f5d5 100644 --- a/base/process_util_win.cc +++ b/base/process_util_win.cc @@ -10,6 +10,7 @@ #include "base/histogram.h" #include "base/logging.h" +#include "base/scoped_handle_win.h" #include "base/scoped_ptr.h" namespace { @@ -226,6 +227,19 @@ bool DidProcessCrash(ProcessHandle handle) { return true; } +bool WaitForExitCode(ProcessHandle handle, int* exit_code) { + ScopedHandle closer(handle); // Ensure that we always close the handle. + if (::WaitForSingleObject(handle, INFINITE) != WAIT_OBJECT_0) { + NOTREACHED(); + return false; + } + DWORD temp_code; // Don't clobber out-parameters in case of failure. + if (!::GetExitCodeProcess(handle, &temp_code)) + return false; + *exit_code = temp_code; + return true; +} + NamedProcessIterator::NamedProcessIterator(const std::wstring& executable_name, const ProcessFilter* filter) : started_iteration_(false), |