Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(130)

Side by Side Diff: base/process/kill_posix.cc

Issue 191673003: Implement ScopedFD in terms of ScopedGeneric. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 <signal.h> 7 #include <signal.h>
8 #include <sys/types.h> 8 #include <sys/types.h>
9 #include <sys/wait.h> 9 #include <sys/wait.h>
10 #include <unistd.h> 10 #include <unistd.h>
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after
266 266
267 #if defined(OS_MACOSX) 267 #if defined(OS_MACOSX)
268 // Using kqueue on Mac so that we can wait on non-child processes. 268 // Using kqueue on Mac so that we can wait on non-child processes.
269 // We can't use kqueues on child processes because we need to reap 269 // We can't use kqueues on child processes because we need to reap
270 // our own children using wait. 270 // our own children using wait.
271 static bool WaitForSingleNonChildProcess(ProcessHandle handle, 271 static bool WaitForSingleNonChildProcess(ProcessHandle handle,
272 base::TimeDelta wait) { 272 base::TimeDelta wait) {
273 DCHECK_GT(handle, 0); 273 DCHECK_GT(handle, 0);
274 DCHECK(wait.InMilliseconds() == base::kNoTimeout || wait > base::TimeDelta()); 274 DCHECK(wait.InMilliseconds() == base::kNoTimeout || wait > base::TimeDelta());
275 275
276 int kq = kqueue(); 276 ScopedFD kq(kqueue());
277 if (kq == -1) { 277 if (!kq) {
278 DPLOG(ERROR) << "kqueue"; 278 DPLOG(ERROR) << "kqueue";
279 return false; 279 return false;
280 } 280 }
281 file_util::ScopedFD kq_closer(&kq);
282 281
283 struct kevent change = {0}; 282 struct kevent change = {0};
284 EV_SET(&change, handle, EVFILT_PROC, EV_ADD, NOTE_EXIT, 0, NULL); 283 EV_SET(&change, handle, EVFILT_PROC, EV_ADD, NOTE_EXIT, 0, NULL);
285 int result = HANDLE_EINTR(kevent(kq, &change, 1, NULL, 0, NULL)); 284 int result = HANDLE_EINTR(kevent(kq.get(), &change, 1, NULL, 0, NULL));
286 if (result == -1) { 285 if (result == -1) {
287 if (errno == ESRCH) { 286 if (errno == ESRCH) {
288 // If the process wasn't found, it must be dead. 287 // If the process wasn't found, it must be dead.
289 return true; 288 return true;
290 } 289 }
291 290
292 DPLOG(ERROR) << "kevent (setup " << handle << ")"; 291 DPLOG(ERROR) << "kevent (setup " << handle << ")";
293 return false; 292 return false;
294 } 293 }
295 294
(...skipping 13 matching lines...) Expand all
309 while (wait_forever || remaining_delta > base::TimeDelta()) { 308 while (wait_forever || remaining_delta > base::TimeDelta()) {
310 struct timespec remaining_timespec; 309 struct timespec remaining_timespec;
311 struct timespec* remaining_timespec_ptr; 310 struct timespec* remaining_timespec_ptr;
312 if (wait_forever) { 311 if (wait_forever) {
313 remaining_timespec_ptr = NULL; 312 remaining_timespec_ptr = NULL;
314 } else { 313 } else {
315 remaining_timespec = remaining_delta.ToTimeSpec(); 314 remaining_timespec = remaining_delta.ToTimeSpec();
316 remaining_timespec_ptr = &remaining_timespec; 315 remaining_timespec_ptr = &remaining_timespec;
317 } 316 }
318 317
319 result = kevent(kq, NULL, 0, &event, 1, remaining_timespec_ptr); 318 result = kevent(kq.get(), NULL, 0, &event, 1, remaining_timespec_ptr);
320 319
321 if (result == -1 && errno == EINTR) { 320 if (result == -1 && errno == EINTR) {
322 if (!wait_forever) { 321 if (!wait_forever) {
323 remaining_delta = deadline - base::TimeTicks::Now(); 322 remaining_delta = deadline - base::TimeTicks::Now();
324 } 323 }
325 result = 0; 324 result = 0;
326 } else { 325 } else {
327 break; 326 break;
328 } 327 }
329 } 328 }
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
488 if (IsChildDead(process)) 487 if (IsChildDead(process))
489 return; 488 return;
490 489
491 BackgroundReaper* reaper = new BackgroundReaper(process, 0); 490 BackgroundReaper* reaper = new BackgroundReaper(process, 0);
492 PlatformThread::CreateNonJoinable(0, reaper); 491 PlatformThread::CreateNonJoinable(0, reaper);
493 } 492 }
494 493
495 #endif // !defined(OS_MACOSX) 494 #endif // !defined(OS_MACOSX)
496 495
497 } // namespace base 496 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698