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

Commit 847b80a1 authored by Bart Van Assche's avatar Bart Van Assche
Browse files

Introduce the Service::CheckConsole() method



The Service::Start() method is so long that its length negatively
affects readability of the code. Hence this patch that splits
Service::Start().

Test: Booted Android in Cuttlefish.
Change-Id: Ib8e1e87fbd335520cbe3aac2a88d250fcf3b4ff0
Signed-off-by: default avatarBart Van Assche <bvanassche@google.com>
parent b99ace4a
Loading
Loading
Loading
Loading
+22 −14
Original line number Diff line number Diff line
@@ -405,6 +405,26 @@ static void ClosePipe(const std::array<int, 2>* pipe) {
    }
}

Result<void> Service::CheckConsole() {
    if (!(flags_ & SVC_CONSOLE)) {
        return {};
    }

    if (proc_attr_.console.empty()) {
        proc_attr_.console = "/dev/" + GetProperty("ro.boot.console", "console");
    }

    // Make sure that open call succeeds to ensure a console driver is
    // properly registered for the device node
    int console_fd = open(proc_attr_.console.c_str(), O_RDWR | O_CLOEXEC);
    if (console_fd < 0) {
        flags_ |= SVC_DISABLED;
        return ErrnoError() << "Couldn't open console '" << proc_attr_.console << "'";
    }
    close(console_fd);
    return {};
}

Result<void> Service::Start() {
    auto reboot_on_failure = make_scope_guard([this] {
        if (on_failure_reboot_target_) {
@@ -442,20 +462,8 @@ Result<void> Service::Start() {
        return ErrnoError() << "pipe()";
    }

    bool needs_console = (flags_ & SVC_CONSOLE);
    if (needs_console) {
        if (proc_attr_.console.empty()) {
            proc_attr_.console = "/dev/" + GetProperty("ro.boot.console", "console");
        }

        // Make sure that open call succeeds to ensure a console driver is
        // properly registered for the device node
        int console_fd = open(proc_attr_.console.c_str(), O_RDWR | O_CLOEXEC);
        if (console_fd < 0) {
            flags_ |= SVC_DISABLED;
            return ErrnoError() << "Couldn't open console '" << proc_attr_.console << "'";
        }
        close(console_fd);
    if (Result<void> result = CheckConsole(); !result.ok()) {
        return result;
    }

    struct stat sb;
+1 −0
Original line number Diff line number Diff line
@@ -145,6 +145,7 @@ class Service {
    void KillProcessGroup(int signal, bool report_oneshot = false);
    void SetProcessAttributesAndCaps();
    void ResetFlagsForStart();
    Result<void> CheckConsole();

    static unsigned long next_start_order_;
    static bool is_exec_service_running_;