| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 <dirent.h> | 5 #include <dirent.h> |
| 6 #include <errno.h> | 6 #include <errno.h> |
| 7 #include <fcntl.h> | 7 #include <fcntl.h> |
| 8 #include <signal.h> | 8 #include <signal.h> |
| 9 #include <stdlib.h> | 9 #include <stdlib.h> |
| 10 #include <sys/resource.h> | 10 #include <sys/resource.h> |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 } | 119 } |
| 120 | 120 |
| 121 ProcessId GetProcId(ProcessHandle process) { | 121 ProcessId GetProcId(ProcessHandle process) { |
| 122 return process; | 122 return process; |
| 123 } | 123 } |
| 124 | 124 |
| 125 // Attempts to kill the process identified by the given process | 125 // Attempts to kill the process identified by the given process |
| 126 // entry structure. Ignores specified exit_code; posix can't force that. | 126 // entry structure. Ignores specified exit_code; posix can't force that. |
| 127 // Returns true if this is successful, false otherwise. | 127 // Returns true if this is successful, false otherwise. |
| 128 bool KillProcess(ProcessHandle process_id, int exit_code, bool wait) { | 128 bool KillProcess(ProcessHandle process_id, int exit_code, bool wait) { |
| 129 DCHECK(process_id > 1); | 129 DCHECK_GT(process_id, 1) << " tried to kill invalid process_id"; |
| 130 if (process_id <= 1) { | 130 if (process_id <= 1) |
| 131 LOG(ERROR) << "tried to kill process_id " << process_id; | |
| 132 return false; | 131 return false; |
| 133 } | |
| 134 | 132 |
| 135 bool result = kill(process_id, SIGTERM) == 0; | 133 bool result = kill(process_id, SIGTERM) == 0; |
| 136 | 134 |
| 137 if (result && wait) { | 135 if (result && wait) { |
| 138 int tries = 60; | 136 int tries = 60; |
| 139 // The process may not end immediately due to pending I/O | 137 // The process may not end immediately due to pending I/O |
| 140 bool exited = false; | 138 bool exited = false; |
| 141 while (tries-- > 0) { | 139 while (tries-- > 0) { |
| 142 pid_t pid = HANDLE_EINTR(waitpid(process_id, NULL, WNOHANG)); | 140 pid_t pid = HANDLE_EINTR(waitpid(process_id, NULL, WNOHANG)); |
| 143 if (pid == process_id) { | 141 if (pid == process_id) { |
| (...skipping 562 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 706 const ProcessFilter* filter) { | 704 const ProcessFilter* filter) { |
| 707 bool exited_cleanly = | 705 bool exited_cleanly = |
| 708 WaitForProcessesToExit(executable_name, wait_milliseconds, | 706 WaitForProcessesToExit(executable_name, wait_milliseconds, |
| 709 filter); | 707 filter); |
| 710 if (!exited_cleanly) | 708 if (!exited_cleanly) |
| 711 KillProcesses(executable_name, exit_code, filter); | 709 KillProcesses(executable_name, exit_code, filter); |
| 712 return exited_cleanly; | 710 return exited_cleanly; |
| 713 } | 711 } |
| 714 | 712 |
| 715 } // namespace base | 713 } // namespace base |
| OLD | NEW |