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

Commit 74edcea9 authored by Yabin Cui's avatar Yabin Cui
Browse files

init: Let property_get return std::string.

Bug: 22654233

Change-Id: Id6091f58432f75e966b9871256049fbe17766c10
parent 89cc750e
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -77,8 +77,8 @@ static void log_header() {
        return;
    }

    char fingerprint[PROP_VALUE_MAX];
    if (property_get("ro.build.fingerprint", fingerprint) == -1) {
    std::string fingerprint = property_get("ro.build.fingerprint");
    if (fingerprint.empty()) {
        return;
    }

@@ -92,7 +92,7 @@ static void log_header() {
    fprintf(out, "version = Android init 0.8 " __TIME__  "\n");
    fprintf(out, "title = Boot chart for Android (%s)\n", date);
    fprintf(out, "system.uname = %s %s %s %s\n", uts.sysname, uts.release, uts.version, uts.machine);
    fprintf(out, "system.release = %s\n", fingerprint);
    fprintf(out, "system.release = %s\n", fingerprint.c_str());
    // TODO: use /proc/cpuinfo "model name" line for x86, "Processor" line for arm.
    fprintf(out, "system.cpu = %s\n", uts.machine);
    fprintf(out, "system.kernel.options = %s\n", kernel_cmdline.c_str());
+2 −3
Original line number Diff line number Diff line
@@ -920,9 +920,8 @@ int do_installkey(int nargs, char **args)
        return -1;
    }

    char prop_value[PROP_VALUE_MAX] = {0};
    property_get("ro.crypto.type", prop_value);
    if (strcmp(prop_value, "file")) {
    std::string prop_value = property_get("ro.crypto.type");
    if (prop_value != "file") {
        return 0;
    }

+10 −11
Original line number Diff line number Diff line
@@ -76,7 +76,7 @@ static struct action *cur_action = NULL;
static struct command *cur_command = NULL;

static int have_console;
static char console_name[PROP_VALUE_MAX] = "/dev/console";
static std::string console_name = "/dev/console";
static time_t process_needs_restart;

static const char *ENV[32];
@@ -160,7 +160,7 @@ void zap_stdio(void)
static void open_console()
{
    int fd;
    if ((fd = open(console_name, O_RDWR)) < 0) {
    if ((fd = open(console_name.c_str(), O_RDWR)) < 0) {
        fd = open("/dev/null", O_RDWR);
    }
    ioctl(fd, TIOCSCTTY, 0);
@@ -727,12 +727,12 @@ static int keychord_init_action(int nargs, char **args)

static int console_init_action(int nargs, char **args)
{
    char console[PROP_VALUE_MAX];
    if (property_get("ro.boot.console", console) > 0) {
        snprintf(console_name, sizeof(console_name), "/dev/%s", console);
    std::string console = property_get("ro.boot.console");
    if (!console.empty()) {
        console_name = "/dev/" + console;
    }

    int fd = open(console_name, O_RDWR | O_CLOEXEC);
    int fd = open(console_name.c_str(), O_RDWR | O_CLOEXEC);
    if (fd >= 0)
        have_console = 1;
    close(fd);
@@ -793,9 +793,8 @@ static void export_kernel_boot_props() {
        { "ro.boot.revision",   "ro.revision",   "0", },
    };
    for (size_t i = 0; i < ARRAY_SIZE(prop_map); i++) {
        char value[PROP_VALUE_MAX];
        int rc = property_get(prop_map[i].src_prop, value);
        property_set(prop_map[i].dst_prop, (rc > 0) ? value : prop_map[i].default_value);
        std::string value = property_get(prop_map[i].src_prop);
        property_set(prop_map[i].dst_prop, (!value.empty()) ? value.c_str() : prop_map[i].default_value);
    }
}

@@ -1054,8 +1053,8 @@ int main(int argc, char** argv) {
    queue_builtin_action(mix_hwrng_into_linux_rng_action, "mix_hwrng_into_linux_rng");

    // Don't mount filesystems or start core system services in charger mode.
    char bootmode[PROP_VALUE_MAX];
    if (property_get("ro.bootmode", bootmode) > 0 && strcmp(bootmode, "charger") == 0) {
    std::string bootmode = property_get("ro.bootmode");
    if (bootmode == "charger") {
        action_for_each_trigger("charger", action_add_queue_tail);
    } else {
        action_for_each_trigger("late-init", action_add_queue_tail);
+6 −12
Original line number Diff line number Diff line
@@ -247,9 +247,7 @@ int expand_props(char *dst, const char *src, int dst_size)
    while (*src_ptr && left > 0) {
        char *c;
        char prop[PROP_NAME_MAX + 1];
        char prop_val[PROP_VALUE_MAX];
        int prop_len = 0;
        int prop_val_len;

        c = strchr(src_ptr, '$');
        if (!c) {
@@ -307,14 +305,14 @@ int expand_props(char *dst, const char *src, int dst_size)
            goto err;
        }

        prop_val_len = property_get(prop, prop_val);
        if (!prop_val_len) {
        std::string prop_val = property_get(prop);
        if (prop_val.empty()) {
            ERROR("property '%s' doesn't exist while expanding '%s'\n",
                  prop, src);
            goto err;
        }

        ret = push_chars(&dst_ptr, &left, prop_val, prop_val_len);
        ret = push_chars(&dst_ptr, &left, prop_val.c_str(), prop_val.size());
        if (ret < 0)
            goto err_nospace;
        src_ptr = c;
@@ -586,17 +584,13 @@ void queue_property_triggers(const char *name, const char *value)
                } else {
                     const char* equals = strchr(test, '=');
                     if (equals) {
                         char prop_name[PROP_NAME_MAX + 1];
                         char value[PROP_VALUE_MAX];
                         int length = equals - test;
                         if (length <= PROP_NAME_MAX) {
                             int ret;
                             memcpy(prop_name, test, length);
                             prop_name[length] = 0;
                             std::string prop_name(test, length);
                             std::string value = property_get(prop_name.c_str());

                             /* does the property exist, and match the trigger value? */
                             ret = property_get(prop_name, value);
                             if (ret > 0 && (!strcmp(equals + 1, value) ||
                             if (!value.empty() && (!strcmp(equals + 1, value.c_str()) ||
                                !strcmp(equals + 1, "*"))) {
                                 continue;
                             }
+3 −4
Original line number Diff line number Diff line
@@ -64,19 +64,18 @@ void add_service_keycodes(struct service *svc)

static void handle_keychord() {
    struct service *svc;
    char adb_enabled[PROP_VALUE_MAX];
    int ret;
    __u16 id;

    // Only handle keychords if adb is enabled.
    property_get("init.svc.adbd", adb_enabled);
    ret = read(keychord_fd, &id, sizeof(id));
    if (ret != sizeof(id)) {
        ERROR("could not read keychord id\n");
        return;
    }

    if (!strcmp(adb_enabled, "running")) {
    // Only handle keychords if adb is enabled.
    std::string adb_enabled = property_get("init.svc.adbd");
    if (adb_enabled == "running") {
        svc = service_find_by_keychord(id);
        if (svc) {
            INFO("Starting service %s from keychord\n", svc->name);
Loading