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

Commit 33b0992e authored by Jooyung Han's avatar Jooyung Han
Browse files

init: refactor perform_apex_config

Removed --bootstrap arg. The init process knows which mount namespace is
the current one. Besides, the arg doesn't work well with the cases like
"microdroid" because there's only a single mount namespace.

This will work with the upcoming change for APEXd's mount-before-data,
which will use a single mount namespace as well.

Bug: 381173118
Flag: com.android.apex.flags.mount_before_data
Test: m & cvd create
Change-Id: I2400c314201c7b7bfe73866ae95059e398ea945a
parent d3bba948
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -176,7 +176,6 @@ libinit_cc_defaults {
        "libsnapshot_cow",
        "libsnapshot_init",
        "libxml2",
        "lib_apex_manifest_proto_lite",
        "update_metadata-protos",
        "libgenfslabelsversion.ffi",
    ],
+1 −2
Original line number Diff line number Diff line
@@ -716,12 +716,11 @@ provides the `aidl_lazy_test_1` interface.
  _options_ include "barrier=1", "noauto\_da\_alloc", "discard", ... as
  a comma separated string, e.g. barrier=1,noauto\_da\_alloc

`perform_apex_config [--bootstrap]`
`perform_apex_config`
> Performs tasks after APEXes are mounted. For example, creates data directories
  for the mounted APEXes, parses config file(s) from them, and updates linker
  configurations. Intended to be used only once when apexd notifies the mount
  event by setting `apexd.status` to ready.
  Use --bootstrap when invoking in the bootstrap mount namespace.

`restart [--only-if-running] <service>`
> Stops and restarts a running service, does nothing if the service is currently
+2 −2
Original line number Diff line number Diff line
@@ -142,9 +142,9 @@ Result<void> ParseRcScriptsFromApex(const std::string& apex_name) {
    return ParseRcScripts(configs);
}

Result<void> ParseRcScriptsFromAllApexes(bool bootstrap) {
Result<void> ParseRcScriptsFromAllApexes(bool is_default_mnt_ns) {
    std::set<std::string> skip_apexes;
    if (!bootstrap) {
    if (is_default_mnt_ns) {
        // In case we already loaded config files from bootstrap APEXes, we need to avoid loading
        // them again. We can get the list of bootstrap APEXes by scanning /bootstrap-apex and
        // skip them in CollectRcScriptsFromApex.
+1 −1
Original line number Diff line number Diff line
@@ -32,7 +32,7 @@ std::set<std::string> GetApexListFrom(const std::string& apex_dir);
Result<void> ParseRcScriptsFromApex(const std::string& apex_name);

// Parse all RC scripts for all apexes under /apex.
Result<void> ParseRcScriptsFromAllApexes(bool bootstrap);
Result<void> ParseRcScriptsFromAllApexes(bool is_default_mnt_ns);

}  // namespace init
}  // namespace android
+20 −32
Original line number Diff line number Diff line
@@ -1187,14 +1187,6 @@ 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";

@@ -1214,9 +1206,6 @@ static Result<void> MountLinkerConfigForDefaultNamespace() {

    return {};
}
static Result<void> do_update_linker_config(const BuiltinArguments&) {
    return GenerateLinkerConfiguration();
}

/*
 * Creates a directory under /data/misc/apexdata/ for each APEX.
@@ -1233,31 +1222,31 @@ static void create_apex_data_dirs() {
}

static Result<void> do_perform_apex_config(const BuiltinArguments& args) {
    bool bootstrap = false;
    if (args.size() == 2) {
        if (args[1] != "--bootstrap") {
            return Error() << "Unexpected argument: " << args[1];
        }
        bootstrap = true;
    }

    if (!bootstrap) {
    // Do create apex data directories if /data/misc/apexdata exists
    if (access("/data/misc/apexdata", 0) == 0) {
        create_apex_data_dirs();
    }

    auto parse_result = ParseRcScriptsFromAllApexes(bootstrap);
    if (!parse_result.ok()) {
        return parse_result.error();
    MountNamespace current_mnt_ns = GetCurrentMountNamespace().value_or(NS_BOOTSTRAP);
    // We don't want to parse the same apexes twice in the same mount namespace.
    static std::map<MountNamespace, bool> apex_parsed;
    if (!std::exchange(apex_parsed[current_mnt_ns], true)) {
        if (auto st = ParseRcScriptsFromAllApexes(current_mnt_ns == NS_DEFAULT); !st.ok()) {
            LOG(ERROR) << st.error();
        }

    auto update_linker_config = do_update_linker_config(args);
    if (!update_linker_config.ok()) {
        return update_linker_config.error();
        if (auto st = GenerateLinkerConfiguration(); !st.ok()) {
            LOG(ERROR) << st.error();
        }

    if (!bootstrap) {
        // Once the linker configuration is generated for the default mount namespace, processes can
        // be started. Note that if there's only a single mount namespace, the bootstrap mount
        // namespace is equal to the default mount namespace.
        if (current_mnt_ns == NS_DEFAULT || !NeedsTwoMountNamespaces()) {
            SetDefaultMountNamespaceReady();
            // Now, we can start delayed services as well.
            ServiceList::GetInstance().StartDelayedServices();
        }
    }
    return {};
}

@@ -1322,7 +1311,6 @@ const BuiltinFunctionMap& GetBuiltinFunctionMap() {
        {"perform_apex_config",     {0,     1,    {false,  do_perform_apex_config}}},
        {"umount",                  {1,     1,    {false,  do_umount}}},
        {"umount_all",              {0,     1,    {false,  do_umount_all}}},
        {"update_linker_config",    {0,     0,    {false,  do_update_linker_config}}},
        {"readahead",               {1,     2,    {true,   do_readahead}}},
        {"restart",                 {1,     2,    {false,  do_restart}}},
        {"restorecon",              {1,     kMax, {true,   do_restorecon}}},
Loading