| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 "chrome/common/process_watcher.h" | 5 #include "chrome/common/process_watcher.h" |
| 6 | 6 |
| 7 #include <errno.h> | 7 #include <errno.h> |
| 8 #include <signal.h> | 8 #include <signal.h> |
| 9 #include <sys/event.h> | 9 #include <sys/event.h> |
| 10 #include <sys/types.h> | 10 #include <sys/types.h> |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 PLOG(ERROR) << "Failed to create kqueue"; | 35 PLOG(ERROR) << "Failed to create kqueue"; |
| 36 return; | 36 return; |
| 37 } | 37 } |
| 38 | 38 |
| 39 struct kevent event_to_add = {0}; | 39 struct kevent event_to_add = {0}; |
| 40 EV_SET(&event_to_add, child, EVFILT_PROC, EV_ADD, NOTE_EXIT, 0, NULL); | 40 EV_SET(&event_to_add, child, EVFILT_PROC, EV_ADD, NOTE_EXIT, 0, NULL); |
| 41 // Register interest with kqueue. | 41 // Register interest with kqueue. |
| 42 int result = HANDLE_EINTR(kevent(kq, &event_to_add, 1, NULL, 0, NULL)); | 42 int result = HANDLE_EINTR(kevent(kq, &event_to_add, 1, NULL, 0, NULL)); |
| 43 if (result == -1 && errno == ESRCH) { | 43 if (result == -1 && errno == ESRCH) { |
| 44 // A "No Such Process" error is fine, the process may have died already | 44 // A "No Such Process" error is fine, the process may have died already |
| 45 // and been reaped by someone else. | 45 // and been reaped by someone else. But make sure that it was/is reaped. |
| 46 // Don't report an error in case it was already reaped. |
| 47 HANDLE_EINTR(waitpid(child, NULL, WNOHANG)); |
| 46 return; | 48 return; |
| 47 } | 49 } |
| 48 | 50 |
| 49 if (result == -1) { | 51 if (result == -1) { |
| 50 PLOG(ERROR) << "Failed to register event to listen for death of pid " | 52 PLOG(ERROR) << "Failed to register event to listen for death of pid " |
| 51 << child; | 53 << child; |
| 52 return; | 54 return; |
| 53 } | 55 } |
| 54 | 56 |
| 55 struct kevent event = {0}; | 57 struct kevent event = {0}; |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 PLOG(ERROR) << "While waiting for " << child << " to terminate we" | 111 PLOG(ERROR) << "While waiting for " << child << " to terminate we" |
| 110 << " failed to deliver a SIGKILL signal"; | 112 << " failed to deliver a SIGKILL signal"; |
| 111 } | 113 } |
| 112 } | 114 } |
| 113 | 115 |
| 114 } // namespace | 116 } // namespace |
| 115 | 117 |
| 116 void ProcessWatcher::EnsureProcessTerminated(base::ProcessHandle process) { | 118 void ProcessWatcher::EnsureProcessTerminated(base::ProcessHandle process) { |
| 117 WaitForChildToDie(process, 2); | 119 WaitForChildToDie(process, 2); |
| 118 } | 120 } |
| OLD | NEW |