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

Commit 2d93a2a1 authored by Devin Moore's avatar Devin Moore Committed by Woody Lin
Browse files

reboot_utils: Check bootconfig for reboot parameters

Androidboot parameters have moved from /proc/cmdline to /proc/bootconfig
so we need to check both places in reboot_utils.
"ro.boot.*" properties can not be used because this is initialized
before the properties are set.

Test: boot Cuttlefish with init_fatal_panic and
init_fatal_reboot_target in bootconfig and in cmdline
Bug: 191494101

Merged-In: I6c230496ec1c3632470d20ff4a31f28db96ea71b
Change-Id: I6c230496ec1c3632470d20ff4a31f28db96ea71b
parent 028303d5
Loading
Loading
Loading
Loading
+32 −11
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@

#include "capabilities.h"
#include "reboot_utils.h"
#include "util.h"

namespace android {
namespace init {
@@ -38,25 +39,44 @@ namespace init {
static std::string init_fatal_reboot_target = "bootloader";
static bool init_fatal_panic = false;

// this needs to read the /proc/* files directly because it is called before
// ro.boot.* properties are initialized
void SetFatalRebootTarget(const std::optional<std::string>& reboot_target) {
    std::string cmdline;
    android::base::ReadFileToString("/proc/cmdline", &cmdline);
    cmdline = android::base::Trim(cmdline);

    const char kInitFatalPanicString[] = "androidboot.init_fatal_panic=true";
    const std::string kInitFatalPanicParamString = "androidboot.init_fatal_panic";
    if (cmdline.find(kInitFatalPanicParamString) == std::string::npos) {
        init_fatal_panic = false;
        ImportBootconfig(
                [kInitFatalPanicParamString](const std::string& key, const std::string& value) {
                    if (key == kInitFatalPanicParamString && value == "true") {
                        init_fatal_panic = true;
                    }
                });
    } else {
        const std::string kInitFatalPanicString = kInitFatalPanicParamString + "=true";
        init_fatal_panic = cmdline.find(kInitFatalPanicString) != std::string::npos;
    }

    if (reboot_target) {
        init_fatal_reboot_target = *reboot_target;
        return;
    }

    const char kRebootTargetString[] = "androidboot.init_fatal_reboot_target=";
    const std::string kRebootTargetString = "androidboot.init_fatal_reboot_target";
    auto start_pos = cmdline.find(kRebootTargetString);
    if (start_pos == std::string::npos) {
        return;  // We already default to bootloader if no setting is provided.
        ImportBootconfig([kRebootTargetString](const std::string& key, const std::string& value) {
            if (key == kRebootTargetString) {
                init_fatal_reboot_target = value;
            }
    start_pos += sizeof(kRebootTargetString) - 1;
        });
        // We already default to bootloader if no setting is provided.
    } else {
        const std::string kRebootTargetStringPattern = kRebootTargetString + "=";
        start_pos += sizeof(kRebootTargetStringPattern) - 1;

        auto end_pos = cmdline.find(' ', start_pos);
        // if end_pos isn't found, then we've run off the end, but this is okay as this is the last
@@ -64,6 +84,7 @@ void SetFatalRebootTarget(const std::optional<std::string>& reboot_target) {
        auto size = end_pos == std::string::npos ? -1 : end_pos - start_pos;
        init_fatal_reboot_target = cmdline.substr(start_pos, size);
    }
}

bool IsRebootCapable() {
    if (!CAP_IS_SUPPORTED(CAP_SYS_BOOT)) {