Merge "init: Cleanly shut down subcontext processes"

This commit is contained in:
Treehugger Robot 2018-07-28 02:30:22 +00:00 committed by Gerrit Code Review
commit f6b823141e
3 changed files with 13 additions and 1 deletions

View file

@ -443,6 +443,7 @@ void DoReboot(unsigned int cmd, const std::string& reason, const std::string& re
for (const auto& s : ServiceList::GetInstance().services_in_shutdown_order()) {
if (!s->IsShutdownCritical()) s->Stop();
}
SubcontextTerminate();
ReapAnyOutstandingChildren();
// 3. send volume shutdown to vold

View file

@ -352,6 +352,7 @@ Result<std::vector<std::string>> Subcontext::ExpandArgs(const std::vector<std::s
}
static std::vector<Subcontext> subcontexts;
static bool shutting_down;
std::vector<Subcontext>* InitializeSubcontexts() {
if (SelinuxHasVendorInit()) {
@ -365,12 +366,21 @@ std::vector<Subcontext>* InitializeSubcontexts() {
bool SubcontextChildReap(pid_t pid) {
for (auto& subcontext : subcontexts) {
if (subcontext.pid() == pid) {
subcontext.Restart();
if (!shutting_down) {
subcontext.Restart();
}
return true;
}
}
return false;
}
void SubcontextTerminate() {
shutting_down = true;
for (auto& subcontext : subcontexts) {
kill(subcontext.pid(), SIGTERM);
}
}
} // namespace init
} // namespace android

View file

@ -63,6 +63,7 @@ class Subcontext {
int SubcontextMain(int argc, char** argv, const KeywordFunctionMap* function_map);
std::vector<Subcontext>* InitializeSubcontexts();
bool SubcontextChildReap(pid_t pid);
void SubcontextTerminate();
} // namespace init
} // namespace android