| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/process/kill.h" | 5 #include "base/process/kill.h" |
| 6 | 6 |
| 7 #include <errno.h> | 7 #include <errno.h> |
| 8 #include <signal.h> | 8 #include <signal.h> |
| 9 #include <sys/types.h> | 9 #include <sys/types.h> |
| 10 #include <sys/wait.h> | 10 #include <sys/wait.h> |
| 11 #include <unistd.h> | 11 #include <unistd.h> |
| 12 | 12 |
| 13 #include "base/files/file_util.h" | 13 #include "base/files/file_util.h" |
| 14 #include "base/files/scoped_file.h" | 14 #include "base/files/scoped_file.h" |
| 15 #include "base/logging.h" | 15 #include "base/logging.h" |
| 16 #include "base/macros.h" | 16 #include "base/macros.h" |
| 17 #include "base/posix/eintr_wrapper.h" | 17 #include "base/posix/eintr_wrapper.h" |
| 18 #include "base/process/process_iterator.h" | 18 #include "base/process/process_iterator.h" |
| 19 #include "base/synchronization/waitable_event.h" | 19 #include "base/synchronization/waitable_event.h" |
| 20 #include "base/threading/platform_thread.h" | 20 #include "base/threading/platform_thread.h" |
| 21 #include "build/build_config.h" | 21 #include "build/build_config.h" |
| 22 | 22 |
| 23 namespace base { | 23 namespace base { |
| 24 | 24 |
| 25 namespace { | 25 namespace { |
| 26 | 26 |
| 27 TerminationStatus GetTerminationStatusImpl(ProcessHandle handle, | 27 TerminationStatus GetTerminationStatusImpl(ProcessHandle handle, |
| 28 bool can_block, | 28 bool can_block, |
| 29 int* exit_code) { | 29 int* exit_code) { |
| 30 LOG(ERROR) << "In GetTerminationStatusImpl can_block=" << can_block; |
| 31 fflush(stderr); |
| 30 int status = 0; | 32 int status = 0; |
| 31 const pid_t result = HANDLE_EINTR(waitpid(handle, &status, | 33 const pid_t result = HANDLE_EINTR(waitpid(handle, &status, |
| 32 can_block ? 0 : WNOHANG)); | 34 can_block ? 0 : WNOHANG)); |
| 35 LOG(ERROR) << "waitpid result=" << result << "status=" << status; |
| 36 fflush(stderr); |
| 37 |
| 33 if (result == -1) { | 38 if (result == -1) { |
| 34 DPLOG(ERROR) << "waitpid(" << handle << ")"; | 39 DPLOG(ERROR) << "waitpid(" << handle << ")"; |
| 35 if (exit_code) | 40 if (exit_code) |
| 36 *exit_code = 0; | 41 *exit_code = 0; |
| 42 LOG(ERROR) << "Normal termination"; |
| 43 fflush(stderr); |
| 37 return TERMINATION_STATUS_NORMAL_TERMINATION; | 44 return TERMINATION_STATUS_NORMAL_TERMINATION; |
| 38 } else if (result == 0) { | 45 } else if (result == 0) { |
| 39 // the child hasn't exited yet. | 46 // the child hasn't exited yet. |
| 40 if (exit_code) | 47 if (exit_code) |
| 41 *exit_code = 0; | 48 *exit_code = 0; |
| 49 LOG(ERROR) << "Still running"; |
| 50 fflush(stderr); |
| 42 return TERMINATION_STATUS_STILL_RUNNING; | 51 return TERMINATION_STATUS_STILL_RUNNING; |
| 43 } | 52 } |
| 44 | 53 |
| 45 if (exit_code) | 54 if (exit_code) |
| 46 *exit_code = status; | 55 *exit_code = status; |
| 47 | 56 |
| 48 if (WIFSIGNALED(status)) { | 57 if (WIFSIGNALED(status)) { |
| 58 LOG(ERROR) << "WIFSIGNALED: signal" << WTERMSIG(status); |
| 59 fflush(stderr); |
| 49 switch (WTERMSIG(status)) { | 60 switch (WTERMSIG(status)) { |
| 50 case SIGABRT: | 61 case SIGABRT: |
| 51 case SIGBUS: | 62 case SIGBUS: |
| 52 case SIGFPE: | 63 case SIGFPE: |
| 53 case SIGILL: | 64 case SIGILL: |
| 54 case SIGSEGV: | 65 case SIGSEGV: |
| 55 case SIGTRAP: | 66 case SIGTRAP: |
| 56 case SIGSYS: | 67 case SIGSYS: |
| 68 LOG(ERROR) << "Process crashed"; |
| 57 return TERMINATION_STATUS_PROCESS_CRASHED; | 69 return TERMINATION_STATUS_PROCESS_CRASHED; |
| 58 case SIGKILL: | 70 case SIGKILL: |
| 59 #if defined(OS_CHROMEOS) | 71 #if defined(OS_CHROMEOS) |
| 60 // On ChromeOS, only way a process gets kill by SIGKILL | 72 // On ChromeOS, only way a process gets kill by SIGKILL |
| 61 // is by oom-killer. | 73 // is by oom-killer. |
| 62 return TERMINATION_STATUS_PROCESS_WAS_KILLED_BY_OOM; | 74 return TERMINATION_STATUS_PROCESS_WAS_KILLED_BY_OOM; |
| 63 #endif | 75 #endif |
| 64 case SIGINT: | 76 case SIGINT: |
| 65 case SIGTERM: | 77 case SIGTERM: |
| 78 LOG(ERROR) << "Process was killed"; |
| 66 return TERMINATION_STATUS_PROCESS_WAS_KILLED; | 79 return TERMINATION_STATUS_PROCESS_WAS_KILLED; |
| 67 default: | 80 default: |
| 68 break; | 81 break; |
| 69 } | 82 } |
| 70 } | 83 } |
| 71 | 84 |
| 72 if (WIFEXITED(status) && WEXITSTATUS(status) != 0) | 85 if (WIFEXITED(status) && WEXITSTATUS(status) != 0) { |
| 86 LOG(ERROR) << "Abnormal termination"; |
| 73 return TERMINATION_STATUS_ABNORMAL_TERMINATION; | 87 return TERMINATION_STATUS_ABNORMAL_TERMINATION; |
| 88 } |
| 74 | 89 |
| 90 LOG(ERROR) << "Normal termination (last resort)"; |
| 75 return TERMINATION_STATUS_NORMAL_TERMINATION; | 91 return TERMINATION_STATUS_NORMAL_TERMINATION; |
| 76 } | 92 } |
| 77 | 93 |
| 78 } // namespace | 94 } // namespace |
| 79 | 95 |
| 80 #if !defined(OS_NACL_NONSFI) | 96 #if !defined(OS_NACL_NONSFI) |
| 81 bool KillProcessGroup(ProcessHandle process_group_id) { | 97 bool KillProcessGroup(ProcessHandle process_group_id) { |
| 82 bool result = kill(-1 * process_group_id, SIGKILL) == 0; | 98 bool result = kill(-1 * process_group_id, SIGKILL) == 0; |
| 83 if (!result) | 99 if (!result) |
| 84 DPLOG(ERROR) << "Unable to terminate process group " << process_group_id; | 100 DPLOG(ERROR) << "Unable to terminate process group " << process_group_id; |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 225 return; | 241 return; |
| 226 | 242 |
| 227 BackgroundReaper* reaper = new BackgroundReaper(pid, 0); | 243 BackgroundReaper* reaper = new BackgroundReaper(pid, 0); |
| 228 PlatformThread::CreateNonJoinable(0, reaper); | 244 PlatformThread::CreateNonJoinable(0, reaper); |
| 229 } | 245 } |
| 230 | 246 |
| 231 #endif // !defined(OS_MACOSX) | 247 #endif // !defined(OS_MACOSX) |
| 232 #endif // !defined(OS_NACL_NONSFI) | 248 #endif // !defined(OS_NACL_NONSFI) |
| 233 | 249 |
| 234 } // namespace base | 250 } // namespace base |
| OLD | NEW |