Merge "adb: improve logging of key loading slightly."

This commit is contained in:
Treehugger Robot 2020-03-09 18:00:25 +00:00 committed by Gerrit Code Review
commit 9da07506de
1 changed files with 12 additions and 10 deletions

View File

@ -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;
}