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

Commit 2c005614 authored by Tom Cherry's avatar Tom Cherry Committed by Android (Google) Code Review
Browse files

Merge changes from topic "libinit_test_utils-build-error" into rvc-dev

* changes:
  Stop & Resume property service when switching to bootstrap namespace
  init: handle property service callbacks asynchronously
  Refactor libinit_test_utils to not use libinit and expose its libraries
parents 1c6f44b0 352ae2d2
Loading
Loading
Loading
Loading
+34 −0
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@ init_common_sources = [
    "rlimit_parser.cpp",
    "service.cpp",
    "service_list.cpp",
    "service_lock.cpp",
    "service_parser.cpp",
    "service_utils.cpp",
    "subcontext.cpp",
@@ -81,6 +82,7 @@ cc_defaults {
        "-Wextra",
        "-Wno-unused-parameter",
        "-Werror",
        "-Wthread-safety",
        "-DALLOW_FIRST_STAGE_CONSOLE=0",
        "-DALLOW_LOCAL_PROP_OVERRIDE=0",
        "-DALLOW_PERMISSIVE_SELINUX=0",
@@ -88,6 +90,7 @@ cc_defaults {
        "-DWORLD_WRITABLE_KMSG=0",
        "-DDUMP_ON_UMOUNT_FAILURE=0",
        "-DSHUTDOWN_ZERO_TIMEOUT=0",
        "-DINIT_FULL_SOURCES",
    ],
    product_variables: {
        debuggable: {
@@ -267,6 +270,37 @@ cc_benchmark {
    static_libs: ["libinit"],
}

cc_defaults {
    name: "libinit_test_utils_libraries_defaults",
    shared_libs: [
        "libbase",
        "libcutils",
        "libselinux",
        "libhidl-gen-utils",
        "liblog",
        "libprocessgroup",
        "libprotobuf-cpp-lite",
    ],
}

cc_library_static {
    name: "libinit_test_utils",
    defaults: ["libinit_test_utils_libraries_defaults"],
    cflags: [
        "-Wall",
        "-Wextra",
        "-Wno-unused-parameter",
        "-Werror",
    ],
    srcs: init_common_sources + [
        "test_utils/service_utils.cpp",
    ],
    whole_static_libs: [
        "libcap",
    ],
    export_include_dirs: ["test_utils/include"], // for tests
}

// Host Verifier
// ------------------------------------------------------------------------------

+15 −7
Original line number Diff line number Diff line
@@ -41,10 +41,12 @@ void ActionManager::AddAction(std::unique_ptr<Action> action) {
}

void ActionManager::QueueEventTrigger(const std::string& trigger) {
    auto lock = std::lock_guard{event_queue_lock_};
    event_queue_.emplace(trigger);
}

void ActionManager::QueuePropertyChange(const std::string& name, const std::string& value) {
    auto lock = std::lock_guard{event_queue_lock_};
    event_queue_.emplace(std::make_pair(name, value));
}

@@ -53,6 +55,7 @@ void ActionManager::QueueAllPropertyActions() {
}

void ActionManager::QueueBuiltinAction(BuiltinFunction func, const std::string& name) {
    auto lock = std::lock_guard{event_queue_lock_};
    auto action = std::make_unique<Action>(true, nullptr, "<Builtin Action>", 0, name,
                                           std::map<std::string, std::string>{});
    action->AddCommand(std::move(func), {name}, 0);
@@ -62,6 +65,8 @@ void ActionManager::QueueBuiltinAction(BuiltinFunction func, const std::string&
}

void ActionManager::ExecuteOneCommand() {
    {
        auto lock = std::lock_guard{event_queue_lock_};
        // Loop through the event queue until we have an action to execute
        while (current_executing_actions_.empty() && !event_queue_.empty()) {
            for (const auto& action : actions_) {
@@ -72,6 +77,7 @@ void ActionManager::ExecuteOneCommand() {
            }
            event_queue_.pop();
        }
    }

    if (current_executing_actions_.empty()) {
        return;
@@ -103,6 +109,7 @@ void ActionManager::ExecuteOneCommand() {
}

bool ActionManager::HasMoreCommands() const {
    auto lock = std::lock_guard{event_queue_lock_};
    return !current_executing_actions_.empty() || !event_queue_.empty();
}

@@ -113,6 +120,7 @@ void ActionManager::DumpState() const {
}

void ActionManager::ClearQueue() {
    auto lock = std::lock_guard{event_queue_lock_};
    // We are shutting down so don't claim the oneshot builtin actions back
    current_executing_actions_ = {};
    event_queue_ = {};
+6 −1
Original line number Diff line number Diff line
@@ -16,9 +16,12 @@

#pragma once

#include <mutex>
#include <string>
#include <vector>

#include <android-base/thread_annotations.h>

#include "action.h"
#include "builtins.h"

@@ -48,7 +51,9 @@ class ActionManager {
    void operator=(ActionManager const&) = delete;

    std::vector<std::unique_ptr<Action>> actions_;
    std::queue<std::variant<EventTrigger, PropertyChange, BuiltinAction>> event_queue_;
    std::queue<std::variant<EventTrigger, PropertyChange, BuiltinAction>> event_queue_
            GUARDED_BY(event_queue_lock_);
    mutable std::mutex event_queue_lock_;
    std::queue<const Action*> current_executing_actions_;
    std::size_t current_command_;
};
+1 −1
Original line number Diff line number Diff line
@@ -21,7 +21,7 @@
#include <android-base/properties.h>
#include <android-base/strings.h>

#if defined(__ANDROID__)
#ifdef INIT_FULL_SOURCES
#include "property_service.h"
#include "selinux.h"
#else
+15 −0
Original line number Diff line number Diff line
@@ -151,6 +151,7 @@ static Result<void> reboot_into_recovery(const std::vector<std::string>& options

template <typename F>
static void ForEachServiceInClass(const std::string& classname, F function) {
    auto lock = std::lock_guard{service_lock};
    for (const auto& service : ServiceList::GetInstance()) {
        if (service->classnames().count(classname)) std::invoke(function, service);
    }
@@ -162,6 +163,7 @@ static Result<void> do_class_start(const BuiltinArguments& args) {
        return {};
    // Starting a class does not start services which are explicitly disabled.
    // They must  be started individually.
    auto lock = std::lock_guard{service_lock};
    for (const auto& service : ServiceList::GetInstance()) {
        if (service->classnames().count(args[1])) {
            if (auto result = service->StartIfNotDisabled(); !result.ok()) {
@@ -184,6 +186,7 @@ static Result<void> do_class_start_post_data(const BuiltinArguments& args) {
        // stopped either.
        return {};
    }
    auto lock = std::lock_guard{service_lock};
    for (const auto& service : ServiceList::GetInstance()) {
        if (service->classnames().count(args[1])) {
            if (auto result = service->StartIfPostData(); !result.ok()) {
@@ -234,6 +237,7 @@ static Result<void> do_domainname(const BuiltinArguments& args) {
}

static Result<void> do_enable(const BuiltinArguments& args) {
    auto lock = std::lock_guard{service_lock};
    Service* svc = ServiceList::GetInstance().FindService(args[1]);
    if (!svc) return Error() << "Could not find service";

@@ -245,6 +249,7 @@ static Result<void> do_enable(const BuiltinArguments& args) {
}

static Result<void> do_exec(const BuiltinArguments& args) {
    auto lock = std::lock_guard{service_lock};
    auto service = Service::MakeTemporaryOneshotService(args.args);
    if (!service.ok()) {
        return Error() << "Could not create exec service: " << service.error();
@@ -258,6 +263,7 @@ static Result<void> do_exec(const BuiltinArguments& args) {
}

static Result<void> do_exec_background(const BuiltinArguments& args) {
    auto lock = std::lock_guard{service_lock};
    auto service = Service::MakeTemporaryOneshotService(args.args);
    if (!service.ok()) {
        return Error() << "Could not create exec background service: " << service.error();
@@ -271,6 +277,7 @@ static Result<void> do_exec_background(const BuiltinArguments& args) {
}

static Result<void> do_exec_start(const BuiltinArguments& args) {
    auto lock = std::lock_guard{service_lock};
    Service* service = ServiceList::GetInstance().FindService(args[1]);
    if (!service) {
        return Error() << "Service not found";
@@ -340,6 +347,7 @@ static Result<void> do_insmod(const BuiltinArguments& args) {
}

static Result<void> do_interface_restart(const BuiltinArguments& args) {
    auto lock = std::lock_guard{service_lock};
    Service* svc = ServiceList::GetInstance().FindInterface(args[1]);
    if (!svc) return Error() << "interface " << args[1] << " not found";
    svc->Restart();
@@ -347,6 +355,7 @@ static Result<void> do_interface_restart(const BuiltinArguments& args) {
}

static Result<void> do_interface_start(const BuiltinArguments& args) {
    auto lock = std::lock_guard{service_lock};
    Service* svc = ServiceList::GetInstance().FindInterface(args[1]);
    if (!svc) return Error() << "interface " << args[1] << " not found";
    if (auto result = svc->Start(); !result.ok()) {
@@ -356,6 +365,7 @@ static Result<void> do_interface_start(const BuiltinArguments& args) {
}

static Result<void> do_interface_stop(const BuiltinArguments& args) {
    auto lock = std::lock_guard{service_lock};
    Service* svc = ServiceList::GetInstance().FindInterface(args[1]);
    if (!svc) return Error() << "interface " << args[1] << " not found";
    svc->Stop();
@@ -740,6 +750,7 @@ static Result<void> do_setrlimit(const BuiltinArguments& args) {
}

static Result<void> do_start(const BuiltinArguments& args) {
    auto lock = std::lock_guard{service_lock};
    Service* svc = ServiceList::GetInstance().FindService(args[1]);
    if (!svc) return Error() << "service " << args[1] << " not found";
    if (auto result = svc->Start(); !result.ok()) {
@@ -749,6 +760,7 @@ static Result<void> do_start(const BuiltinArguments& args) {
}

static Result<void> do_stop(const BuiltinArguments& args) {
    auto lock = std::lock_guard{service_lock};
    Service* svc = ServiceList::GetInstance().FindService(args[1]);
    if (!svc) return Error() << "service " << args[1] << " not found";
    svc->Stop();
@@ -756,6 +768,7 @@ static Result<void> do_stop(const BuiltinArguments& args) {
}

static Result<void> do_restart(const BuiltinArguments& args) {
    auto lock = std::lock_guard{service_lock};
    Service* svc = ServiceList::GetInstance().FindService(args[1]);
    if (!svc) return Error() << "service " << args[1] << " not found";
    svc->Restart();
@@ -1111,6 +1124,7 @@ static Result<void> ExecWithFunctionOnFailure(const std::vector<std::string>& ar
            function(StringPrintf("Exec service failed, status %d", siginfo.si_status));
        }
    });
    auto lock = std::lock_guard{service_lock};
    if (auto result = (*service)->ExecStart(); !result.ok()) {
        function("ExecStart failed: " + result.error().message());
    }
@@ -1250,6 +1264,7 @@ static Result<void> parse_apex_configs() {
        }
        success &= parser.ParseConfigFile(c);
    }
    auto lock = std::lock_guard{service_lock};
    ServiceList::GetInstance().MarkServicesUpdate();
    if (success) {
        return {};
Loading