summaryrefslogtreecommitdiffstats
path: root/init
diff options
context:
space:
mode:
authorLuis Hector Chavez2018-07-27 13:19:25 -0500
committerLuis Hector Chavez2018-07-27 13:19:44 -0500
commit92c49bcb3098050d41dd32a782a97cbd7a88675a (patch)
tree80a24c534b10442a437c6d6e073d4f75b3cd9832 /init
parent18be1e2f7e27de79b2a3c2197b8bb30c958a5644 (diff)
downloadplatform-system-core-92c49bcb3098050d41dd32a782a97cbd7a88675a.tar.gz
platform-system-core-92c49bcb3098050d41dd32a782a97cbd7a88675a.tar.xz
platform-system-core-92c49bcb3098050d41dd32a782a97cbd7a88675a.zip
init: Cleanly shut down subcontext processes
This change adds an explicit cleanup for the subcontext processes and avoids them from respawning, which causes a bunch of LOG(FATAL)s when the system is going down. Bug: 80425914 Test: kill -TERM $INIT_PID, no crashes for subcontext inits Change-Id: I135191d959c1dd921b102af316b24d2bc161d6c9
Diffstat (limited to 'init')
-rw-r--r--init/reboot.cpp1
-rw-r--r--init/subcontext.cpp12
-rw-r--r--init/subcontext.h1
3 files changed, 13 insertions, 1 deletions
diff --git a/init/reboot.cpp b/init/reboot.cpp
index 6f6e39f25..11507f489 100644
--- a/init/reboot.cpp
+++ b/init/reboot.cpp
@@ -443,6 +443,7 @@ void DoReboot(unsigned int cmd, const std::string& reason, const std::string& re
443 for (const auto& s : ServiceList::GetInstance().services_in_shutdown_order()) { 443 for (const auto& s : ServiceList::GetInstance().services_in_shutdown_order()) {
444 if (!s->IsShutdownCritical()) s->Stop(); 444 if (!s->IsShutdownCritical()) s->Stop();
445 } 445 }
446 SubcontextTerminate();
446 ReapAnyOutstandingChildren(); 447 ReapAnyOutstandingChildren();
447 448
448 // 3. send volume shutdown to vold 449 // 3. send volume shutdown to vold
diff --git a/init/subcontext.cpp b/init/subcontext.cpp
index 267d530f0..ee7251328 100644
--- a/init/subcontext.cpp
+++ b/init/subcontext.cpp
@@ -352,6 +352,7 @@ Result<std::vector<std::string>> Subcontext::ExpandArgs(const std::vector<std::s
352} 352}
353 353
354static std::vector<Subcontext> subcontexts; 354static std::vector<Subcontext> subcontexts;
355static bool shutting_down;
355 356
356std::vector<Subcontext>* InitializeSubcontexts() { 357std::vector<Subcontext>* InitializeSubcontexts() {
357 if (SelinuxHasVendorInit()) { 358 if (SelinuxHasVendorInit()) {
@@ -365,12 +366,21 @@ std::vector<Subcontext>* InitializeSubcontexts() {
365bool SubcontextChildReap(pid_t pid) { 366bool SubcontextChildReap(pid_t pid) {
366 for (auto& subcontext : subcontexts) { 367 for (auto& subcontext : subcontexts) {
367 if (subcontext.pid() == pid) { 368 if (subcontext.pid() == pid) {
368 subcontext.Restart(); 369 if (!shutting_down) {
370 subcontext.Restart();
371 }
369 return true; 372 return true;
370 } 373 }
371 } 374 }
372 return false; 375 return false;
373} 376}
374 377
378void SubcontextTerminate() {
379 shutting_down = true;
380 for (auto& subcontext : subcontexts) {
381 kill(subcontext.pid(), SIGTERM);
382 }
383}
384
375} // namespace init 385} // namespace init
376} // namespace android 386} // namespace android
diff --git a/init/subcontext.h b/init/subcontext.h
index 22d7d43bd..628fd50e7 100644
--- a/init/subcontext.h
+++ b/init/subcontext.h
@@ -63,6 +63,7 @@ class Subcontext {
63int SubcontextMain(int argc, char** argv, const KeywordFunctionMap* function_map); 63int SubcontextMain(int argc, char** argv, const KeywordFunctionMap* function_map);
64std::vector<Subcontext>* InitializeSubcontexts(); 64std::vector<Subcontext>* InitializeSubcontexts();
65bool SubcontextChildReap(pid_t pid); 65bool SubcontextChildReap(pid_t pid);
66void SubcontextTerminate();
66 67
67} // namespace init 68} // namespace init
68} // namespace android 69} // namespace android