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

Commit ce276e54 authored by Kiyoung Kim's avatar Kiyoung Kim Committed by Automerger Merge Worker
Browse files

Merge "Check if service is executed before APEX is ready" am: fcb28f5d am: 2acff0c5

Original change: https://android-review.googlesource.com/c/platform/system/core/+/1612017

MUST ONLY BE SUBMITTED BY AUTOMERGER

Change-Id: I7cd02ba4c5324828de9fb23e6db9bf89a347c51b
parents 99231262 2acff0c5
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -1278,6 +1278,14 @@ static Result<void> GenerateLinkerConfiguration() {
        return ErrnoError() << "failed to execute linkerconfig";
    }

    auto current_mount_ns = GetCurrentMountNamespace();
    if (!current_mount_ns.ok()) {
        return current_mount_ns.error();
    }
    if (*current_mount_ns == NS_DEFAULT) {
        SetDefaultMountNamespaceReady();
    }

    LOG(INFO) << "linkerconfig generated " << linkerconfig_target
              << " with mounted APEX modules info";

+15 −0
Original line number Diff line number Diff line
@@ -301,5 +301,20 @@ Result<void> SwitchToMountNamespaceIfNeeded(MountNamespace target_mount_namespac
    return {};
}

base::Result<MountNamespace> GetCurrentMountNamespace() {
    std::string current_namespace_id = GetMountNamespaceId();
    if (current_namespace_id == "") {
        return Error() << "Failed to get current mount namespace ID";
    }

    if (current_namespace_id == bootstrap_ns_id) {
        return NS_BOOTSTRAP;
    } else if (current_namespace_id == default_ns_id) {
        return NS_DEFAULT;
    }

    return Error() << "Failed to find current mount namespace";
}

}  // namespace init
}  // namespace android
+2 −0
Original line number Diff line number Diff line
@@ -26,5 +26,7 @@ enum MountNamespace { NS_BOOTSTRAP, NS_DEFAULT };
bool SetupMountNamespaces();
base::Result<void> SwitchToMountNamespaceIfNeeded(MountNamespace target_mount_namespace);

base::Result<MountNamespace> GetCurrentMountNamespace();

}  // namespace init
}  // namespace android
+6 −11
Original line number Diff line number Diff line
@@ -125,11 +125,6 @@ static bool ExpandArgsAndExecv(const std::vector<std::string>& args, bool sigsto
    return execv(c_strings[0], c_strings.data()) == 0;
}

static bool AreRuntimeApexesReady() {
    struct stat buf;
    return stat("/apex/com.android.runtime/", &buf) == 0;
}

unsigned long Service::next_start_order_ = 1;
bool Service::is_exec_service_running_ = false;

@@ -312,7 +307,7 @@ void Service::Reap(const siginfo_t& siginfo) {
#else
    static bool is_apex_updatable = false;
#endif
    const bool is_process_updatable = !pre_apexd_ && is_apex_updatable;
    const bool is_process_updatable = !use_bootstrap_ns_ && is_apex_updatable;

    // If we crash > 4 times in 'fatal_crash_window_' minutes or before boot_completed,
    // reboot into bootloader or set crashing property
@@ -465,12 +460,12 @@ Result<void> Service::Start() {
        scon = *result;
    }

    if (!AreRuntimeApexesReady() && !pre_apexd_) {
        // If this service is started before the Runtime and ART APEXes get
        // available, mark it as pre-apexd one. Note that this marking is
    if (!IsDefaultMountNamespaceReady() && name_ != "apexd") {
        // If this service is started before APEXes and corresponding linker configuration
        // get available, mark it as pre-apexd one. Note that this marking is
        // permanent. So for example, if the service is re-launched (e.g., due
        // to crash), it is still recognized as pre-apexd... for consistency.
        pre_apexd_ = true;
        use_bootstrap_ns_ = true;
    }

    // For pre-apexd services, override mount namespace as "bootstrap" one before starting.
@@ -479,7 +474,7 @@ Result<void> Service::Start() {
    std::optional<MountNamespace> override_mount_namespace;
    if (name_ == "ueventd") {
        override_mount_namespace = NS_DEFAULT;
    } else if (pre_apexd_) {
    } else if (use_bootstrap_ns_) {
        override_mount_namespace = NS_BOOTSTRAP;
    }

+1 −1
Original line number Diff line number Diff line
@@ -207,7 +207,7 @@ class Service {

    std::vector<std::function<void(const siginfo_t& siginfo)>> reap_callbacks_;

    bool pre_apexd_ = false;
    bool use_bootstrap_ns_ = false;

    bool post_data_ = false;

Loading