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

Commit f86b5a6b authored by Elliott Hughes's avatar Elliott Hughes
Browse files

Move init to libbase logging.

Change-Id: Ibfbefeff587a69e948978a037c555fd12a5ade6a
parent 90db709a
Loading
Loading
Loading
Loading
+6 −9
Original line number Diff line number Diff line
@@ -42,7 +42,7 @@ int Command::InvokeFunc() const {
    expanded_args[0] = args_[0];
    for (std::size_t i = 1; i < args_.size(); ++i) {
        if (!expand_props(args_[i], &expanded_args[i])) {
            ERROR("%s: cannot expand '%s'\n", args_[0].c_str(), args_[i].c_str());
            LOG(ERROR) << args_[0] << ": cannot expand '" << args_[i] << "'";
            return -EINVAL;
        }
    }
@@ -123,9 +123,8 @@ void Action::ExecuteCommand(const Command& command) const {
        std::string cmd_str = command.BuildCommandString();
        std::string source = command.BuildSourceString();

        INFO("Command '%s' action=%s%s returned %d took %.2fs\n",
             cmd_str.c_str(), trigger_name.c_str(), source.c_str(),
             result, t.duration());
        LOG(INFO) << "Command '" << cmd_str << "' action=" << trigger_name << source
                  << " returned " << result << " took " << t.duration() << "s";
    }
}

@@ -253,13 +252,12 @@ std::string Action::BuildTriggersString() const {

void Action::DumpState() const {
    std::string trigger_name = BuildTriggersString();
    INFO("on %s\n", trigger_name.c_str());
    LOG(INFO) << "on " << trigger_name;

    for (const auto& c : commands_) {
        std::string cmd_str = c.BuildCommandString();
        INFO(" %s\n", cmd_str.c_str());
        LOG(INFO) << "  %s" << cmd_str;
    }
    INFO("\n");
}

class EventTrigger : public Trigger {
@@ -366,7 +364,7 @@ void ActionManager::ExecuteOneCommand() {

    if (current_command_ == 0) {
        std::string trigger_name = action->BuildTriggersString();
        INFO("processing action (%s)\n", trigger_name.c_str());
        LOG(INFO) << "processing action (" << trigger_name << ")";
    }

    action->ExecuteOneCommand(current_command_);
@@ -395,7 +393,6 @@ void ActionManager::DumpState() const {
    for (const auto& a : actions_) {
        a->DumpState();
    }
    INFO("\n");
}

bool ActionParser::ParseSection(const std::vector<std::string>& args,
+4 −4
Original line number Diff line number Diff line
@@ -206,12 +206,12 @@ static int bootchart_init() {
int do_bootchart_init(const std::vector<std::string>& args) {
    g_remaining_samples = bootchart_init();
    if (g_remaining_samples < 0) {
        ERROR("Bootcharting init failure: %s\n", strerror(errno));
        PLOG(ERROR) << "Bootcharting initialization failed";
    } else if (g_remaining_samples > 0) {
        NOTICE("Bootcharting started (will run for %d s).\n",
               (g_remaining_samples * BOOTCHART_POLLING_MS) / 1000);
        LOG(INFO) << "Bootcharting started (will run for "
                  << ((g_remaining_samples * BOOTCHART_POLLING_MS) / 1000) << " s).";
    } else {
        NOTICE("Not bootcharting.\n");
        LOG(VERBOSE) << "Not bootcharting.";
    }
    return 0;
}
+19 −19
Original line number Diff line number Diff line
@@ -71,12 +71,12 @@ static const int kTerminateServiceDelayMicroSeconds = 50000;
static int insmod(const char *filename, const char *options, int flags) {
    int fd = open(filename, O_RDONLY | O_NOFOLLOW | O_CLOEXEC);
    if (fd == -1) {
        ERROR("insmod: open(\"%s\") failed: %s", filename, strerror(errno));
        PLOG(ERROR) << "insmod: open(\"" << filename << "\") failed";
        return -1;
    }
    int rc = syscall(__NR_finit_module, fd, options, flags);
    if (rc == -1) {
        ERROR("finit_module for \"%s\" failed: %s", filename, strerror(errno));
        PLOG(ERROR) << "finit_module for \"" << filename << "\" failed";
    }
    close(fd);
    return rc;
@@ -201,13 +201,13 @@ static void unmount_and_fsck(const struct mntent *entry) {
        const char *f2fs_argv[] = {
            "/system/bin/fsck.f2fs", "-f", entry->mnt_fsname,
        };
        android_fork_execvp_ext(ARRAY_SIZE(f2fs_argv), (char **)f2fs_argv,
        android_fork_execvp_ext(arraysize(f2fs_argv), (char **)f2fs_argv,
                                &st, true, LOG_KLOG, true, NULL, NULL, 0);
    } else if (!strcmp(entry->mnt_type, "ext4")) {
        const char *ext4_argv[] = {
            "/system/bin/e2fsck", "-f", "-y", entry->mnt_fsname,
        };
        android_fork_execvp_ext(ARRAY_SIZE(ext4_argv), (char **)ext4_argv,
        android_fork_execvp_ext(arraysize(ext4_argv), (char **)ext4_argv,
                                &st, true, LOG_KLOG, true, NULL, NULL, 0);
    }
}
@@ -421,7 +421,7 @@ static int do_mount(const std::vector<std::string>& args) {
        }

        close(fd);
        ERROR("out of loopback devices");
        LOG(ERROR) << "out of loopback devices";
        return -1;
    } else {
        if (wait)
@@ -445,7 +445,7 @@ static int wipe_data_via_recovery() {
        write(fd, "--reason=wipe_data_via_recovery\n", strlen("--reason=wipe_data_via_recovery\n") + 1);
        close(fd);
    } else {
        ERROR("could not open /cache/recovery/command\n");
        PLOG(ERROR) << "could not open /cache/recovery/command";
        return -1;
    }
    android_reboot(ANDROID_RB_RESTART2, 0, "recovery");
@@ -499,9 +499,9 @@ static int do_mount_all(const std::vector<std::string>& args) {
    if (pid > 0) {
        /* Parent.  Wait for the child to return */
        int wp_ret = TEMP_FAILURE_RETRY(waitpid(pid, &status, 0));
        if (wp_ret < 0) {
            /* Unexpected error code. We will continue anyway. */
            NOTICE("waitpid failed rc=%d: %s\n", wp_ret, strerror(errno));
        if (wp_ret == -1) {
            // Unexpected error code. We will continue anyway.
            PLOG(WARNING) << "waitpid failed";
        }

        if (WIFEXITED(status)) {
@@ -516,7 +516,7 @@ static int do_mount_all(const std::vector<std::string>& args) {
        child_ret = fs_mgr_mount_all(fstab);
        fs_mgr_free_fstab(fstab);
        if (child_ret == -1) {
            ERROR("fs_mgr_mount_all returned an error\n");
            PLOG(ERROR) << "fs_mgr_mount_all returned an error";
        }
        _exit(child_ret);
    } else {
@@ -541,7 +541,7 @@ static int do_mount_all(const std::vector<std::string>& args) {
        ActionManager::GetInstance().QueueEventTrigger("nonencrypted");
    } else if (ret == FS_MGR_MNTALL_DEV_NEEDS_RECOVERY) {
        /* Setup a wipe via recovery, and reboot into recovery */
        ERROR("fs_mgr_mount_all suggested recovery, so wiping data via recovery.\n");
        PLOG(ERROR) << "fs_mgr_mount_all suggested recovery, so wiping data via recovery.";
        ret = wipe_data_via_recovery();
        /* If reboot worked, there is no return. */
    } else if (ret == FS_MGR_MNTALL_DEV_DEFAULT_FILE_ENCRYPTED) {
@@ -562,7 +562,7 @@ static int do_mount_all(const std::vector<std::string>& args) {
        property_set("ro.crypto.type", "file");
        property_set("vold.decrypt", "trigger_restart_min_framework");
    } else if (ret > 0) {
        ERROR("fs_mgr_mount_all returned unexpected error %d\n", ret);
        PLOG(ERROR) << "fs_mgr_mount_all returned unexpected error " << ret;
    }
    /* else ... < 0: error */

@@ -599,7 +599,7 @@ static int do_setrlimit(const std::vector<std::string>& args) {
static int do_start(const std::vector<std::string>& args) {
    Service* svc = ServiceManager::GetInstance().FindServiceByName(args[1]);
    if (!svc) {
        ERROR("do_start: Service %s not found\n", args[1].c_str());
        LOG(ERROR) << "do_start: Service " << args[1] << " not found";
        return -1;
    }
    if (!svc->Start())
@@ -610,7 +610,7 @@ static int do_start(const std::vector<std::string>& args) {
static int do_stop(const std::vector<std::string>& args) {
    Service* svc = ServiceManager::GetInstance().FindServiceByName(args[1]);
    if (!svc) {
        ERROR("do_stop: Service %s not found\n", args[1].c_str());
        LOG(ERROR) << "do_stop: Service " << args[1] << " not found";
        return -1;
    }
    svc->Stop();
@@ -620,7 +620,7 @@ static int do_stop(const std::vector<std::string>& args) {
static int do_restart(const std::vector<std::string>& args) {
    Service* svc = ServiceManager::GetInstance().FindServiceByName(args[1]);
    if (!svc) {
        ERROR("do_restart: Service %s not found\n", args[1].c_str());
        LOG(ERROR) << "do_restart: Service " << args[1] << " not found";
        return -1;
    }
    svc->Restart();
@@ -641,7 +641,7 @@ static int do_powerctl(const std::vector<std::string>& args) {
        cmd = ANDROID_RB_RESTART2;
        len = 6;
    } else {
        ERROR("powerctl: unrecognized command '%s'\n", command);
        LOG(ERROR) << "powerctl: unrecognized command '" << command << "'";
        return -EINVAL;
    }

@@ -655,7 +655,7 @@ static int do_powerctl(const std::vector<std::string>& args) {
            reboot_target = &command[len + 1];
        }
    } else if (command[len] != '\0') {
        ERROR("powerctl: unrecognized reboot target '%s'\n", &command[len]);
        LOG(ERROR) << "powerctl: unrecognized reboot target '" << &command[len] << "'";
        return -EINVAL;
    }

@@ -692,7 +692,7 @@ static int do_powerctl(const std::vector<std::string>& args) {
            // Wait a bit before recounting the number or running services.
            usleep(kTerminateServiceDelayMicroSeconds);
        }
        NOTICE("Terminating running services took %.02f seconds", t.duration());
        LOG(VERBOSE) << "Terminating running services took " << t.duration() << " seconds";
    }

    return android_reboot_with_callback(cmd, 0, reboot_target,
@@ -868,7 +868,7 @@ static int do_restorecon_recursive(const std::vector<std::string>& args) {
static int do_loglevel(const std::vector<std::string>& args) {
    int log_level = std::stoi(args[1]);
    if (log_level < KLOG_ERROR_LEVEL || log_level > KLOG_DEBUG_LEVEL) {
        ERROR("loglevel: invalid log level'%d'\n", log_level);
        LOG(ERROR) << "loglevel: invalid log level " << log_level;
        return -EINVAL;
    }
    klog_set_level(log_level);
+33 −38
Original line number Diff line number Diff line
@@ -174,13 +174,14 @@ static void fixup_sys_perms(const char* upath, const char* subsystem) {
        }

        std::string attr_file = path + "/" + dp->attr;
        INFO("fixup %s %d %d 0%o\n", attr_file.c_str(), dp->uid, dp->gid, dp->perm);
        LOG(INFO) << "fixup " << attr_file
                  << " " << dp->uid << " " << dp->gid << " " << std::oct << dp->perm;
        chown(attr_file.c_str(), dp->uid, dp->gid);
        chmod(attr_file.c_str(), dp->perm);
    }

    if (access(path.c_str(), F_OK) == 0) {
        INFO("restorecon_recursive: %s\n", path.c_str());
        LOG(INFO) << "restorecon_recursive: " << path;
        restorecon_recursive(path.c_str());
    }
}
@@ -241,8 +242,7 @@ static void make_device(const char *path,
    mode = get_device_perm(path, links, &uid, &gid) | (block ? S_IFBLK : S_IFCHR);

    if (selabel_lookup_best_match(sehandle, &secontext, path, links, mode)) {
        ERROR("Device '%s' not created; cannot find SELinux label (%s)\n",
                path, strerror(errno));
        PLOG(ERROR) << "Device '" << path << "' not created; cannot find SELinux label";
        return;
    }
    setfscreatecon(secontext);
@@ -261,8 +261,7 @@ static void make_device(const char *path,
        char* fcon = nullptr;
        int rc = lgetfilecon(path, &fcon);
        if (rc < 0) {
            ERROR("Cannot get SELinux label on '%s' device (%s)\n",
                    path, strerror(errno));
            PLOG(ERROR) << "Cannot get SELinux label on '" << path << "' device";
            goto out;
        }

@@ -270,8 +269,7 @@ static void make_device(const char *path,
        freecon(fcon);

        if (different && lsetfilecon(path, secontext)) {
            ERROR("Cannot set '%s' SELinux label on '%s' device (%s)\n",
                    secontext, path, strerror(errno));
            PLOG(ERROR) << "Cannot set '" << secontext << "' SELinux label on '" << path << "' device";
        }
    }

@@ -295,7 +293,7 @@ static void add_platform_device(const char *path)
            name += 9;
    }

    INFO("adding platform device %s (%s)\n", name, path);
    LOG(INFO) << "adding platform device " << name << " (" << path << ")";

    bus = (platform_node*) calloc(1, sizeof(struct platform_node));
    bus->path = strdup(path);
@@ -334,7 +332,7 @@ static void remove_platform_device(const char *path)
    list_for_each_reverse(node, &platform_names) {
        bus = node_to_item(node, struct platform_node, list);
        if (!strcmp(path, bus->path)) {
            INFO("removing platform device %s\n", bus->name);
            LOG(INFO) << "removing platform device " << bus->name;
            free(bus->path);
            list_remove(node);
            free(bus);
@@ -423,7 +421,7 @@ static void parse_event(const char *msg, struct uevent *uevent)
    }

    if (LOG_UEVENTS) {
        INFO("event { '%s', '%s', '%s', '%s', %d, %d }\n",
        LOG(INFO) << android::base::StringPrintf("event { '%s', '%s', '%s', '%s', %d, %d }",
                                                 uevent->action, uevent->path, uevent->subsystem,
                                                 uevent->firmware, uevent->major, uevent->minor);
    }
@@ -509,15 +507,16 @@ static char **get_block_device_symlinks(struct uevent *uevent)
        return NULL;
    memset(links, 0, sizeof(char *) * 4);

    INFO("found %s device %s\n", type, device);
    LOG(INFO) << "found " << type << " device " << device;

    snprintf(link_path, sizeof(link_path), "/dev/block/%s/%s", type, device);

    if (uevent->partition_name) {
        p = strdup(uevent->partition_name);
        sanitize(p);
        if (strcmp(uevent->partition_name, p))
            NOTICE("Linking partition '%s' as '%s'\n", uevent->partition_name, p);
        if (strcmp(uevent->partition_name, p)) {
            LOG(VERBOSE) << "Linking partition '" << uevent->partition_name << "' as '" << p << "'";
        }
        if (asprintf(&links[link_num], "%s/by-name/%s", link_path, p) > 0)
            link_num++;
        else
@@ -595,8 +594,7 @@ static const char *parse_device_name(struct uevent *uevent, unsigned int len)

    /* too-long names would overrun our buffer */
    if(strlen(name) > len) {
        ERROR("DEVPATH=%s exceeds %u-character limit on filename; ignoring event\n",
                name, len);
        LOG(ERROR) << "DEVPATH=" << name << " exceeds " << len << "-character limit on filename; ignoring event";
        return NULL;
    }

@@ -631,12 +629,11 @@ static bool assemble_devpath(char *devpath, const char *dirname,
{
    int s = snprintf(devpath, DEVPATH_LEN, "%s/%s", dirname, devname);
    if (s < 0) {
        ERROR("failed to assemble device path (%s); ignoring event\n",
                strerror(errno));
        PLOG(ERROR) << "failed to assemble device path; ignoring event";
        return false;
    } else if (s >= DEVPATH_LEN) {
        ERROR("%s/%s exceeds %u-character limit on path; ignoring event\n",
                dirname, devname, DEVPATH_LEN);
        LOG(ERROR) << dirname << "/" << devname
                   << " exceeds " << DEVPATH_LEN << "-character limit on path; ignoring event";
        return false;
    }
    return true;
@@ -680,8 +677,7 @@ static void handle_generic_device_event(struct uevent *uevent)
            break;

        default:
            ERROR("%s subsystem's devpath option is not set; ignoring event\n",
                    uevent->subsystem);
            LOG(ERROR) << uevent->subsystem << " subsystem's devpath option is not set; ignoring event";
            return;
        }

@@ -737,9 +733,8 @@ static void handle_generic_device_event(struct uevent *uevent)
     } else if(!strncmp(uevent->subsystem, "sound", 5)) {
         base = "/dev/snd/";
         make_dir(base, 0755);
     } else if(!strncmp(uevent->subsystem, "misc", 4) &&
                 !strncmp(name, "log_", 4)) {
         INFO("kernel logger is deprecated\n");
     } else if(!strncmp(uevent->subsystem, "misc", 4) && !strncmp(name, "log_", 4)) {
         LOG(INFO) << "kernel logger is deprecated";
         base = "/dev/log/";
         make_dir(base, 0755);
         name += 4;
@@ -818,8 +813,7 @@ static void process_firmware_event(struct uevent *uevent)
    size_t i;
    int booting = is_booting();

    INFO("firmware: loading '%s' for '%s'\n",
         uevent->firmware, uevent->path);
    LOG(INFO) << "firmware: loading '" << uevent->firmware << "' for '" << uevent->path << "'";

    l = asprintf(&root, SYSFS_PREFIX"%s/", uevent->path);
    if (l == -1)
@@ -842,7 +836,7 @@ static void process_firmware_event(struct uevent *uevent)
        goto loading_close_out;

try_loading_again:
    for (i = 0; i < ARRAY_SIZE(firmware_dirs); i++) {
    for (i = 0; i < arraysize(firmware_dirs); i++) {
        char *file = NULL;
        l = asprintf(&file, "%s/%s", firmware_dirs[i], uevent->firmware);
        if (l == -1)
@@ -850,10 +844,11 @@ try_loading_again:
        fw_fd = open(file, O_RDONLY|O_CLOEXEC);
        free(file);
        if (fw_fd >= 0) {
            if(!load_firmware(fw_fd, loading_fd, data_fd))
                INFO("firmware: copy success { '%s', '%s' }\n", root, uevent->firmware);
            else
                INFO("firmware: copy failure { '%s', '%s' }\n", root, uevent->firmware);
            if (!load_firmware(fw_fd, loading_fd, data_fd)) {
                LOG(INFO) << "firmware: copy success { '" << root << "', '" << uevent->firmware << "' }";
            } else {
                LOG(ERROR) << "firmware: copy failure { '" << root << "', '" << uevent->firmware << "' }";
            }
            break;
        }
    }
@@ -866,7 +861,7 @@ try_loading_again:
            booting = is_booting();
            goto try_loading_again;
        }
        INFO("firmware: could not open '%s': %s\n", uevent->firmware, strerror(errno));
        PLOG(ERROR) << "firmware: could not open '" << uevent->firmware << "'";
        write(loading_fd, "-1", 2);
        goto data_close_out;
    }
@@ -900,7 +895,7 @@ static void handle_firmware_event(struct uevent *uevent)
        process_firmware_event(uevent);
        _exit(EXIT_SUCCESS);
    } else if (pid < 0) {
        ERROR("could not fork to process firmware event: %s\n", strerror(errno));
        PLOG(ERROR) << "could not fork to process firmware event";
    }
}

@@ -996,7 +991,7 @@ void device_init() {
    fcntl(device_fd, F_SETFL, O_NONBLOCK);

    if (access(COLDBOOT_DONE, F_OK) == 0) {
        NOTICE("Skipping coldboot, already done!\n");
        LOG(VERBOSE) << "Skipping coldboot, already done!";
        return;
    }

@@ -1005,7 +1000,7 @@ void device_init() {
    coldboot("/sys/block");
    coldboot("/sys/devices");
    close(open(COLDBOOT_DONE, O_WRONLY|O_CREAT|O_CLOEXEC, 0000));
    NOTICE("Coldboot took %.2fs.\n", t.duration());
    LOG(INFO) << "Coldboot took " << t.duration() << "s.";
}

int get_device_fd()
+2 −3
Original line number Diff line number Diff line
@@ -38,7 +38,7 @@ bool ImportParser::ParseSection(const std::vector<std::string>& args,
        return false;
    }

    INFO("Added '%s' to import list\n", conf_file.c_str());
    LOG(INFO) << "Added '" << conf_file << "' to import list";
    imports_.emplace_back(std::move(conf_file));
    return true;
}
@@ -48,8 +48,7 @@ void ImportParser::EndFile(const std::string& filename) {
    imports_.clear();
    for (const auto& s : current_imports) {
        if (!Parser::GetInstance().ParseConfig(s)) {
            ERROR("could not import file '%s' from '%s': %s\n",
                  s.c_str(), filename.c_str(), strerror(errno));
            PLOG(ERROR) << "could not import file '" << s << "' from '" << filename << "'";
        }
    }
}
Loading