Merge "init: Cleanly shut down subcontext processes"
diff --git a/init/reboot.cpp b/init/reboot.cpp
index 6f6e39f..11507f4 100644
--- a/init/reboot.cpp
+++ b/init/reboot.cpp
@@ -443,6 +443,7 @@
for (const auto& s : ServiceList::GetInstance().services_in_shutdown_order()) {
if (!s->IsShutdownCritical()) s->Stop();
}
+ SubcontextTerminate();
ReapAnyOutstandingChildren();
// 3. send volume shutdown to vold
diff --git a/init/subcontext.cpp b/init/subcontext.cpp
index 267d530..ee72513 100644
--- a/init/subcontext.cpp
+++ b/init/subcontext.cpp
@@ -352,6 +352,7 @@
}
static std::vector<Subcontext> subcontexts;
+static bool shutting_down;
std::vector<Subcontext>* InitializeSubcontexts() {
if (SelinuxHasVendorInit()) {
@@ -365,12 +366,21 @@
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
diff --git a/init/subcontext.h b/init/subcontext.h
index 22d7d43..628fd50 100644
--- a/init/subcontext.h
+++ b/init/subcontext.h
@@ -63,6 +63,7 @@
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