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

Commit 379123f9 authored by Tom Cherry's avatar Tom Cherry Committed by Gerrit Code Review
Browse files

Merge "init: remove Parser singleton and related cleanup"

parents 13c3a582 67dee626
Loading
Loading
Loading
Loading
+1 −2
Original line number Diff line number Diff line
@@ -67,10 +67,10 @@ cc_library_static {
        "devices.cpp",
        "firmware_handler.cpp",
        "import_parser.cpp",
        "init_parser.cpp",
        "log.cpp",
        "parser.cpp",
        "service.cpp",
        "tokenizer.cpp",
        "uevent_listener.cpp",
        "ueventd_parser.cpp",
        "util.cpp",
@@ -153,7 +153,6 @@ cc_test {
    defaults: ["init_defaults"],
    srcs: [
        "devices_test.cpp",
        "init_parser_test.cpp",
        "init_test.cpp",
        "property_service_test.cpp",
        "service_test.cpp",
+1 −1
Original line number Diff line number Diff line
@@ -24,8 +24,8 @@
#include <vector>

#include "builtins.h"
#include "init_parser.h"
#include "keyword_map.h"
#include "parser.h"

namespace android {
namespace init {
+7 −13
Original line number Diff line number Diff line
@@ -57,7 +57,7 @@
#include "action.h"
#include "bootchart.h"
#include "init.h"
#include "init_parser.h"
#include "parser.h"
#include "property_service.h"
#include "reboot.h"
#include "service.h"
@@ -388,21 +388,15 @@ exit_success:
 * start_index: index of the first path in the args list
 */
static void import_late(const std::vector<std::string>& args, size_t start_index, size_t end_index) {
    Parser& parser = Parser::GetInstance();
    auto& action_manager = ActionManager::GetInstance();
    auto& service_manager = ServiceManager::GetInstance();
    Parser parser = CreateParser(action_manager, service_manager);
    if (end_index <= start_index) {
        // Fallbacks for partitions on which early mount isn't enabled.
        if (!parser.is_system_etc_init_loaded()) {
            parser.ParseConfig("/system/etc/init");
            parser.set_is_system_etc_init_loaded(true);
        }
        if (!parser.is_vendor_etc_init_loaded()) {
            parser.ParseConfig("/vendor/etc/init");
            parser.set_is_vendor_etc_init_loaded(true);
        }
        if (!parser.is_odm_etc_init_loaded()) {
            parser.ParseConfig("/odm/etc/init");
            parser.set_is_odm_etc_init_loaded(true);
        for (const auto& path : late_import_paths) {
            parser.ParseConfig(path);
        }
        late_import_paths.clear();
    } else {
        for (size_t i = start_index; i < end_index; ++i) {
            parser.ParseConfig(args[i]);
+2 −2
Original line number Diff line number Diff line
@@ -17,11 +17,11 @@
#ifndef _INIT_IMPORT_PARSER_H
#define _INIT_IMPORT_PARSER_H

#include "init_parser.h"

#include <string>
#include <vector>

#include "parser.h"

namespace android {
namespace init {

+33 −21
Original line number Diff line number Diff line
@@ -55,16 +55,13 @@
#include <memory>
#include <vector>

#include "action.h"
#include "bootchart.h"
#include "import_parser.h"
#include "init_first_stage.h"
#include "init_parser.h"
#include "keychords.h"
#include "log.h"
#include "property_service.h"
#include "reboot.h"
#include "service.h"
#include "signal_handler.h"
#include "ueventd.h"
#include "util.h"
@@ -98,11 +95,43 @@ static std::string wait_prop_name;
static std::string wait_prop_value;
static bool shutting_down;

std::vector<std::string> late_import_paths;

void DumpState() {
    ServiceManager::GetInstance().DumpState();
    ActionManager::GetInstance().DumpState();
}

Parser CreateParser(ActionManager& action_manager, ServiceManager& service_manager) {
    Parser parser;

    parser.AddSectionParser("service", std::make_unique<ServiceParser>(&service_manager));
    parser.AddSectionParser("on", std::make_unique<ActionParser>(&action_manager));
    parser.AddSectionParser("import", std::make_unique<ImportParser>(&parser));

    return parser;
}

static void LoadBootScripts(ActionManager& action_manager, ServiceManager& service_manager) {
    Parser parser = CreateParser(action_manager, service_manager);

    std::string bootscript = GetProperty("ro.boot.init_rc", "");
    if (bootscript.empty()) {
        parser.ParseConfig("/init.rc");
        if (!parser.ParseConfig("/system/etc/init")) {
            late_import_paths.emplace_back("/system/etc/init");
        }
        if (!parser.ParseConfig("/vendor/etc/init")) {
            late_import_paths.emplace_back("/vendor/etc/init");
        }
        if (!parser.ParseConfig("/odm/etc/init")) {
            late_import_paths.emplace_back("/odm/etc/init");
        }
    } else {
        parser.ParseConfig(bootscript);
    }
}

void register_epoll_handler(int fd, void (*fn)()) {
    epoll_event ev;
    ev.events = EPOLLIN;
@@ -1102,25 +1131,8 @@ int main(int argc, char** argv) {

    ActionManager& am = ActionManager::GetInstance();
    ServiceManager& sm = ServiceManager::GetInstance();
    Parser& parser = Parser::GetInstance();

    parser.AddSectionParser("service", std::make_unique<ServiceParser>(&sm));
    parser.AddSectionParser("on", std::make_unique<ActionParser>(&am));
    parser.AddSectionParser("import", std::make_unique<ImportParser>(&parser));
    std::string bootscript = GetProperty("ro.boot.init_rc", "");
    if (bootscript.empty()) {
        parser.ParseConfig("/init.rc");
        parser.set_is_system_etc_init_loaded(
                parser.ParseConfig("/system/etc/init"));
        parser.set_is_vendor_etc_init_loaded(
                parser.ParseConfig("/vendor/etc/init"));
        parser.set_is_odm_etc_init_loaded(parser.ParseConfig("/odm/etc/init"));
    } else {
        parser.ParseConfig(bootscript);
        parser.set_is_system_etc_init_loaded(true);
        parser.set_is_vendor_etc_init_loaded(true);
        parser.set_is_odm_etc_init_loaded(true);
    }
    LoadBootScripts(am, sm);

    // Turning this on and letting the INFO logging be discarded adds 0.2s to
    // Nexus 9 boot time, so it's disabled by default.
Loading