OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 13 matching lines...) Expand all Loading... |
24 #include "base/eintr_wrapper.h" | 24 #include "base/eintr_wrapper.h" |
25 #include "base/file_util.h" | 25 #include "base/file_util.h" |
26 #include "base/logging.h" | 26 #include "base/logging.h" |
27 #include "base/memory/scoped_ptr.h" | 27 #include "base/memory/scoped_ptr.h" |
28 #include "base/process_util.h" | 28 #include "base/process_util.h" |
29 #include "base/stringprintf.h" | 29 #include "base/stringprintf.h" |
30 #include "base/synchronization/waitable_event.h" | 30 #include "base/synchronization/waitable_event.h" |
31 #include "base/third_party/dynamic_annotations/dynamic_annotations.h" | 31 #include "base/third_party/dynamic_annotations/dynamic_annotations.h" |
32 #include "base/threading/platform_thread.h" | 32 #include "base/threading/platform_thread.h" |
33 #include "base/threading/thread_restrictions.h" | 33 #include "base/threading/thread_restrictions.h" |
34 #include "base/time.h" | |
35 | 34 |
36 #if defined(OS_FREEBSD) | 35 #if defined(OS_FREEBSD) |
37 #include <sys/event.h> | 36 #include <sys/event.h> |
38 #include <sys/ucontext.h> | 37 #include <sys/ucontext.h> |
39 #endif | 38 #endif |
40 | 39 |
41 #if defined(OS_MACOSX) | 40 #if defined(OS_MACOSX) |
42 #include <crt_externs.h> | 41 #include <crt_externs.h> |
43 #include <sys/event.h> | 42 #include <sys/event.h> |
44 #else | 43 #else |
(...skipping 1145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1190 // TODO(port): use waitpid to avoid leaving zombies around | 1189 // TODO(port): use waitpid to avoid leaving zombies around |
1191 | 1190 |
1192 base::Time end_time = base::Time::Now() + | 1191 base::Time end_time = base::Time::Now() + |
1193 base::TimeDelta::FromMilliseconds(wait_milliseconds); | 1192 base::TimeDelta::FromMilliseconds(wait_milliseconds); |
1194 do { | 1193 do { |
1195 NamedProcessIterator iter(executable_name, filter); | 1194 NamedProcessIterator iter(executable_name, filter); |
1196 if (!iter.NextProcessEntry()) { | 1195 if (!iter.NextProcessEntry()) { |
1197 result = true; | 1196 result = true; |
1198 break; | 1197 break; |
1199 } | 1198 } |
1200 base::PlatformThread::Sleep(100); | 1199 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(100)); |
1201 } while ((end_time - base::Time::Now()) > base::TimeDelta()); | 1200 } while ((end_time - base::Time::Now()) > base::TimeDelta()); |
1202 | 1201 |
1203 return result; | 1202 return result; |
1204 } | 1203 } |
1205 | 1204 |
1206 bool CleanupProcesses(const FilePath::StringType& executable_name, | 1205 bool CleanupProcesses(const FilePath::StringType& executable_name, |
1207 int64 wait_milliseconds, | 1206 int64 wait_milliseconds, |
1208 int exit_code, | 1207 int exit_code, |
1209 const ProcessFilter* filter) { | 1208 const ProcessFilter* filter) { |
1210 bool exited_cleanly = | 1209 bool exited_cleanly = |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1257 << " to terminate, we got the following result: " << r; | 1256 << " to terminate, we got the following result: " << r; |
1258 } | 1257 } |
1259 return; | 1258 return; |
1260 } | 1259 } |
1261 | 1260 |
1262 // There's no good way to wait for a specific child to exit in a timed | 1261 // There's no good way to wait for a specific child to exit in a timed |
1263 // fashion. (No kqueue on Linux), so we just loop and sleep. | 1262 // fashion. (No kqueue on Linux), so we just loop and sleep. |
1264 | 1263 |
1265 // Wait for 2 * timeout_ 500 milliseconds intervals. | 1264 // Wait for 2 * timeout_ 500 milliseconds intervals. |
1266 for (unsigned i = 0; i < 2 * timeout_; ++i) { | 1265 for (unsigned i = 0; i < 2 * timeout_; ++i) { |
1267 PlatformThread::Sleep(500); // 0.5 seconds | 1266 PlatformThread::Sleep(TimeDelta::FromMilliseconds(500)); |
1268 if (IsChildDead(child_)) | 1267 if (IsChildDead(child_)) |
1269 return; | 1268 return; |
1270 } | 1269 } |
1271 | 1270 |
1272 if (kill(child_, SIGKILL) == 0) { | 1271 if (kill(child_, SIGKILL) == 0) { |
1273 // SIGKILL is uncatchable. Since the signal was delivered, we can | 1272 // SIGKILL is uncatchable. Since the signal was delivered, we can |
1274 // just wait for the process to die now in a blocking manner. | 1273 // just wait for the process to die now in a blocking manner. |
1275 if (HANDLE_EINTR(waitpid(child_, NULL, 0)) < 0) | 1274 if (HANDLE_EINTR(waitpid(child_, NULL, 0)) < 0) |
1276 DPLOG(WARNING) << "waitpid"; | 1275 DPLOG(WARNING) << "waitpid"; |
1277 } else { | 1276 } else { |
(...skipping 28 matching lines...) Expand all Loading... |
1306 if (IsChildDead(process)) | 1305 if (IsChildDead(process)) |
1307 return; | 1306 return; |
1308 | 1307 |
1309 BackgroundReaper* reaper = new BackgroundReaper(process, 0); | 1308 BackgroundReaper* reaper = new BackgroundReaper(process, 0); |
1310 PlatformThread::CreateNonJoinable(0, reaper); | 1309 PlatformThread::CreateNonJoinable(0, reaper); |
1311 } | 1310 } |
1312 | 1311 |
1313 #endif // !defined(OS_MACOSX) | 1312 #endif // !defined(OS_MACOSX) |
1314 | 1313 |
1315 } // namespace base | 1314 } // namespace base |
OLD | NEW |