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 <signal.h> | 7 #include <signal.h> |
8 #include <sys/event.h> | 8 #include <sys/event.h> |
9 #include <sys/types.h> | 9 #include <sys/types.h> |
10 #include <sys/wait.h> | 10 #include <sys/wait.h> |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
59 // mean that zombies be allowed to kick you while you're down.) | 59 // mean that zombies be allowed to kick you while you're down.) |
60 // | 60 // |
61 // The fact that this function seemingly can be called to wait on a child | 61 // The fact that this function seemingly can be called to wait on a child |
62 // that's not only already terminated but already reaped is a bit of a | 62 // that's not only already terminated but already reaped is a bit of a |
63 // problem: a reaped child's pid can be reclaimed and may refer to a distinct | 63 // problem: a reaped child's pid can be reclaimed and may refer to a distinct |
64 // process in that case. The fact that this function can seemingly be called | 64 // process in that case. The fact that this function can seemingly be called |
65 // to wait on a process that's not even a child is also a problem: kqueue will | 65 // to wait on a process that's not even a child is also a problem: kqueue will |
66 // work in that case, but waitpid won't, and killing a non-child might not be | 66 // work in that case, but waitpid won't, and killing a non-child might not be |
67 // the best approach. | 67 // the best approach. |
68 void WaitForChildToDie(pid_t child, int timeout) { | 68 void WaitForChildToDie(pid_t child, int timeout) { |
69 DCHECK(child > 0); | 69 DCHECK_GT(child, 0); |
70 DCHECK(timeout > 0); | 70 DCHECK_GT(timeout, 0); |
71 | 71 |
72 // DON'T ADD ANY EARLY RETURNS TO THIS FUNCTION without ensuring that | 72 // DON'T ADD ANY EARLY RETURNS TO THIS FUNCTION without ensuring that |
73 // |child| has been reaped. Specifically, even if a kqueue, kevent, or other | 73 // |child| has been reaped. Specifically, even if a kqueue, kevent, or other |
74 // call fails, this function should fall back to the last resort of trying | 74 // call fails, this function should fall back to the last resort of trying |
75 // to kill and reap the process. Not observing this rule will resurrect | 75 // to kill and reap the process. Not observing this rule will resurrect |
76 // zombies. | 76 // zombies. |
77 | 77 |
78 int result; | 78 int result; |
79 | 79 |
80 ScopedFD kq(HANDLE_EINTR(kqueue())); | 80 ScopedFD kq(HANDLE_EINTR(kqueue())); |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
163 } | 163 } |
164 } | 164 } |
165 | 165 |
166 } // namespace | 166 } // namespace |
167 | 167 |
168 void EnsureProcessTerminated(Process process) { | 168 void EnsureProcessTerminated(Process process) { |
169 WaitForChildToDie(process.Pid(), kWaitBeforeKillSeconds); | 169 WaitForChildToDie(process.Pid(), kWaitBeforeKillSeconds); |
170 } | 170 } |
171 | 171 |
172 } // namespace base | 172 } // namespace base |
OLD | NEW |