Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 92c49bcb authored by Luis Hector Chavez's avatar Luis Hector Chavez
Browse files

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
parent 18be1e2f
Loading
Loading
Loading
Loading
+1 −0
Original line number Original line Diff line number Diff line
@@ -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()) {
    for (const auto& s : ServiceList::GetInstance().services_in_shutdown_order()) {
        if (!s->IsShutdownCritical()) s->Stop();
        if (!s->IsShutdownCritical()) s->Stop();
    }
    }
    SubcontextTerminate();
    ReapAnyOutstandingChildren();
    ReapAnyOutstandingChildren();


    // 3. send volume shutdown to vold
    // 3. send volume shutdown to vold
+11 −1
Original line number Original line Diff line number Diff line
@@ -352,6 +352,7 @@ Result<std::vector<std::string>> Subcontext::ExpandArgs(const std::vector<std::s
}
}


static std::vector<Subcontext> subcontexts;
static std::vector<Subcontext> subcontexts;
static bool shutting_down;


std::vector<Subcontext>* InitializeSubcontexts() {
std::vector<Subcontext>* InitializeSubcontexts() {
    if (SelinuxHasVendorInit()) {
    if (SelinuxHasVendorInit()) {
@@ -365,12 +366,21 @@ std::vector<Subcontext>* InitializeSubcontexts() {
bool SubcontextChildReap(pid_t pid) {
bool SubcontextChildReap(pid_t pid) {
    for (auto& subcontext : subcontexts) {
    for (auto& subcontext : subcontexts) {
        if (subcontext.pid() == pid) {
        if (subcontext.pid() == pid) {
            if (!shutting_down) {
                subcontext.Restart();
                subcontext.Restart();
            }
            return true;
            return true;
        }
        }
    }
    }
    return false;
    return false;
}
}


void SubcontextTerminate() {
    shutting_down = true;
    for (auto& subcontext : subcontexts) {
        kill(subcontext.pid(), SIGTERM);
    }
}

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


}  // namespace init
}  // namespace init
}  // namespace android
}  // namespace android