| Index: base/process_util_posix.cc
|
| diff --git a/base/process_util_posix.cc b/base/process_util_posix.cc
|
| index 562b8e908f999f0550ede140952ab6f3a7cf9574..489c4cd705071ad4b6cbf5df33e395cc4a009605 100644
|
| --- a/base/process_util_posix.cc
|
| +++ b/base/process_util_posix.cc
|
| @@ -55,23 +55,25 @@ ProcessId GetProcId(ProcessHandle process) {
|
| // entry structure. Ignores specified exit_code; posix can't force that.
|
| // Returns true if this is successful, false otherwise.
|
| bool KillProcess(ProcessHandle process_id, int exit_code, bool wait) {
|
| - bool result = false;
|
| + bool result = kill(process_id, SIGTERM) == 0;
|
|
|
| - int status = kill(process_id, SIGTERM);
|
| - if (!status && wait) {
|
| + if (result && wait) {
|
| int tries = 60;
|
| // The process may not end immediately due to pending I/O
|
| while (tries-- > 0) {
|
| - int pid = waitpid(process_id, &status, WNOHANG);
|
| - if (pid == process_id) {
|
| - result = true;
|
| + int pid = waitpid(process_id, NULL, WNOHANG);
|
| + if (pid == process_id)
|
| break;
|
| - }
|
| +
|
| sleep(1);
|
| }
|
| +
|
| + result = false;
|
| }
|
| +
|
| if (!result)
|
| DLOG(ERROR) << "Unable to terminate process.";
|
| +
|
| return result;
|
| }
|
|
|
| @@ -140,13 +142,24 @@ void RaiseProcessToHighPriority() {
|
| // setpriority() or sched_getscheduler, but these all require extra rights.
|
| }
|
|
|
| -bool DidProcessCrash(ProcessHandle handle) {
|
| +bool DidProcessCrash(bool* child_exited, ProcessHandle handle) {
|
| int status;
|
| - if (waitpid(handle, &status, WNOHANG)) {
|
| - // I feel like dancing!
|
| + const int result = waitpid(handle, &status, WNOHANG);
|
| + if (result == -1) {
|
| + LOG(ERROR) << "waitpid failed pid:" << handle << " errno:" << errno;
|
| + if (child_exited)
|
| + *child_exited = false;
|
| + return false;
|
| + } else if (result == 0) {
|
| + // the child hasn't exited yet.
|
| + if (child_exited)
|
| + *child_exited = false;
|
| return false;
|
| }
|
|
|
| + if (child_exited)
|
| + *child_exited = true;
|
| +
|
| if (WIFSIGNALED(status)) {
|
| switch(WTERMSIG(status)) {
|
| case SIGSEGV:
|
|
|