Merge "init: Introduce the function ReapAndRemove()" into main am: c93c5eff0e
am: b0e5d6405e
am: 0ae7962866
Original change: https://android-review.googlesource.com/c/platform/system/core/+/2838464 Change-Id: I3ef25bac13a2aae73b94f887447752db292a6f47 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
commit
b33c258084
2 changed files with 20 additions and 10 deletions
|
@ -118,8 +118,23 @@ static pid_t ReapOneProcess() {
|
|||
return pid;
|
||||
}
|
||||
|
||||
void ReapAnyOutstandingChildren() {
|
||||
while (ReapOneProcess() != 0) {
|
||||
std::set<pid_t> ReapAnyOutstandingChildren() {
|
||||
std::set<pid_t> reaped_pids;
|
||||
for (;;) {
|
||||
const pid_t pid = ReapOneProcess();
|
||||
if (pid <= 0) {
|
||||
return reaped_pids;
|
||||
}
|
||||
reaped_pids.emplace(pid);
|
||||
}
|
||||
}
|
||||
|
||||
static void ReapAndRemove(std::vector<pid_t>& alive_pids) {
|
||||
for (auto pid : ReapAnyOutstandingChildren()) {
|
||||
const auto it = std::find(alive_pids.begin(), alive_pids.end(), pid);
|
||||
if (it != alive_pids.end()) {
|
||||
alive_pids.erase(it);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -142,13 +157,7 @@ void WaitToBeReaped(int sigchld_fd, const std::vector<pid_t>& pids,
|
|||
}
|
||||
std::vector<pid_t> alive_pids(pids.begin(), pids.end());
|
||||
while (!alive_pids.empty() && t.duration() < timeout) {
|
||||
pid_t pid;
|
||||
while ((pid = ReapOneProcess()) != 0) {
|
||||
auto it = std::find(alive_pids.begin(), alive_pids.end(), pid);
|
||||
if (it != alive_pids.end()) {
|
||||
alive_pids.erase(it);
|
||||
}
|
||||
}
|
||||
ReapAndRemove(alive_pids);
|
||||
if (alive_pids.empty()) {
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -18,12 +18,13 @@
|
|||
#define _INIT_SIGCHLD_HANDLER_H_
|
||||
|
||||
#include <chrono>
|
||||
#include <set>
|
||||
#include <vector>
|
||||
|
||||
namespace android {
|
||||
namespace init {
|
||||
|
||||
void ReapAnyOutstandingChildren();
|
||||
std::set<pid_t> ReapAnyOutstandingChildren();
|
||||
|
||||
void WaitToBeReaped(int sigchld_fd, const std::vector<pid_t>& pids,
|
||||
std::chrono::milliseconds timeout);
|
||||
|
|
Loading…
Reference in a new issue