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

Commit 401c7878 authored by Elliott Hughes's avatar Elliott Hughes
Browse files

adb: improve logging of key loading slightly.

In particular, always include the file name in the log.

Bug: http://b/144462309
Test: adb kill-server && adb devices -l && cat /tmp/adb.*.log
Change-Id: I66b5e063b00381f9dfa9ace222cad3e415e4f43b
parent cc642ec7
Loading
Loading
Loading
Loading
+12 −10
Original line number Diff line number Diff line
@@ -145,12 +145,12 @@ static bool load_key(const std::string& file) {

    std::lock_guard<std::mutex> lock(g_keys_mutex);
    std::string fingerprint = hash_key(key.get());
    if (g_keys.find(fingerprint) != g_keys.end()) {
        LOG(INFO) << "ignoring already-loaded key: " << file;
    } else {
        LOG(INFO) << "Loaded fingerprint=[" << SHA256BitsToHexString(fingerprint) << "]";
    bool already_loaded = (g_keys.find(fingerprint) != g_keys.end());
    if (!already_loaded) {
        g_keys[fingerprint] = std::move(key);
    }
    LOG(INFO) << (already_loaded ? "ignored already-loaded" : "loaded new") << " key from '" << file
              << "' with fingerprint " << SHA256BitsToHexString(fingerprint);
    return true;
}

@@ -159,23 +159,25 @@ static bool load_keys(const std::string& path, bool allow_dir = true) {

    struct stat st;
    if (stat(path.c_str(), &st) != 0) {
        PLOG(ERROR) << "failed to stat '" << path << "'";
        PLOG(ERROR) << "load_keys: failed to stat '" << path << "'";
        return false;
    }

    if (S_ISREG(st.st_mode)) {
        return load_key(path);
    } else if (S_ISDIR(st.st_mode)) {
    }

    if (S_ISDIR(st.st_mode)) {
        if (!allow_dir) {
            // inotify isn't recursive. It would break expectations to load keys in nested
            // directories but not monitor them for new keys.
            LOG(WARNING) << "refusing to recurse into directory '" << path << "'";
            LOG(WARNING) << "load_keys: refusing to recurse into directory '" << path << "'";
            return false;
        }

        std::unique_ptr<DIR, decltype(&closedir)> dir(opendir(path.c_str()), closedir);
        if (!dir) {
            PLOG(ERROR) << "failed to open directory '" << path << "'";
            PLOG(ERROR) << "load_keys: failed to open directory '" << path << "'";
            return false;
        }

@@ -189,7 +191,7 @@ static bool load_keys(const std::string& path, bool allow_dir = true) {
            }

            if (!android::base::EndsWith(name, ".adb_key")) {
                LOG(INFO) << "skipping non-adb_key '" << path << "/" << name << "'";
                LOG(INFO) << "skipped non-adb_key '" << path << "/" << name << "'";
                continue;
            }

@@ -198,7 +200,7 @@ static bool load_keys(const std::string& path, bool allow_dir = true) {
        return result;
    }

    LOG(ERROR) << "unexpected type for '" << path << "': 0x" << std::hex << st.st_mode;
    LOG(ERROR) << "load_keys: unexpected type for '" << path << "': 0x" << std::hex << st.st_mode;
    return false;
}