adb: clean up debug tracing a little.
Always use LOG() for debug tracing.
Remove useless D_lock. I believe it is useless to lock just before and after fprintf.
I verified the log output both on host and on device. The output looks fine to me.
Change-Id: I96ccfe408ff56864361551afe9ad464d197ae104
diff --git a/adb_auth_host.cpp b/adb_auth_host.cpp
index e7f82a9..749fec2 100644
--- a/adb_auth_host.cpp
+++ b/adb_auth_host.cpp
@@ -164,26 +164,26 @@
if (snprintf(path, sizeof(path), "%s.pub", private_key_path) >=
(int)sizeof(path)) {
- D("Path too long while writing public key\n");
+ D("Path too long while writing public key");
return 0;
}
if (!RSA_to_RSAPublicKey(private_key, &pkey)) {
- D("Failed to convert to publickey\n");
+ D("Failed to convert to publickey");
return 0;
}
outfile = fopen(path, "w");
if (!outfile) {
- D("Failed to open '%s'\n", path);
+ D("Failed to open '%s'", path);
return 0;
}
- D("Writing public key to '%s'\n", path);
+ D("Writing public key to '%s'", path);
#if defined(OPENSSL_IS_BORINGSSL)
if (!EVP_EncodedLength(&encoded_length, sizeof(pkey))) {
- D("Public key too large to base64 encode\n");
+ D("Public key too large to base64 encode");
goto out;
}
#else
@@ -194,7 +194,7 @@
encoded = new uint8_t[encoded_length];
if (encoded == nullptr) {
- D("Allocation failure\n");
+ D("Allocation failure");
goto out;
}
@@ -203,7 +203,7 @@
if (fwrite(encoded, encoded_length, 1, outfile) != 1 ||
fwrite(info, strlen(info), 1, outfile) != 1) {
- D("Write error while writing public key\n");
+ D("Write error while writing public key");
goto out;
}
@@ -226,10 +226,10 @@
FILE *f = NULL;
int ret = 0;
- D("generate_key '%s'\n", file);
+ D("generate_key '%s'", file);
if (!pkey || !exponent || !rsa) {
- D("Failed to allocate key\n");
+ D("Failed to allocate key");
goto out;
}
@@ -241,7 +241,7 @@
f = fopen(file, "w");
if (!f) {
- D("Failed to open '%s'\n", file);
+ D("Failed to open '%s'", file);
umask(old_mask);
goto out;
}
@@ -249,12 +249,12 @@
umask(old_mask);
if (!PEM_write_PrivateKey(f, pkey, NULL, NULL, 0, NULL, NULL)) {
- D("Failed to write key\n");
+ D("Failed to write key");
goto out;
}
if (!write_public_keyfile(rsa, file)) {
- D("Failed to write public key\n");
+ D("Failed to write public key");
goto out;
}
@@ -271,11 +271,11 @@
static int read_key(const char *file, struct listnode *list)
{
- D("read_key '%s'\n", file);
+ D("read_key '%s'", file);
FILE* fp = fopen(file, "r");
if (!fp) {
- D("Failed to open '%s': %s\n", file, strerror(errno));
+ D("Failed to open '%s': %s", file, strerror(errno));
return 0;
}
@@ -283,7 +283,7 @@
key->rsa = RSA_new();
if (!PEM_read_RSAPrivateKey(fp, &key->rsa, NULL, NULL)) {
- D("Failed to read key\n");
+ D("Failed to read key");
fclose(fp);
RSA_free(key->rsa);
delete key;
@@ -307,7 +307,7 @@
WCHAR path[MAX_PATH];
const HRESULT hr = SHGetFolderPathW(NULL, CSIDL_PROFILE, NULL, 0, path);
if (FAILED(hr)) {
- D("SHGetFolderPathW failed: %s\n",
+ D("SHGetFolderPathW failed: %s",
SystemErrorCodeToString(hr).c_str());
return -1;
}
@@ -322,7 +322,7 @@
format = "%s/%s";
#endif
- D("home '%s'\n", home);
+ D("home '%s'", home);
if (snprintf(android_dir, sizeof(android_dir), format, home,
ANDROID_PATH) >= (int)sizeof(android_dir))
@@ -330,7 +330,7 @@
if (stat(android_dir, &buf)) {
if (adb_mkdir(android_dir, 0750) < 0) {
- D("Cannot mkdir '%s'\n", android_dir);
+ D("Cannot mkdir '%s'", android_dir);
return -1;
}
}
@@ -346,15 +346,15 @@
ret = get_user_keyfilepath(path, sizeof(path));
if (ret < 0 || ret >= (signed)sizeof(path)) {
- D("Error getting user key filename\n");
+ D("Error getting user key filename");
return 0;
}
- D("user key '%s'\n", path);
+ D("user key '%s'", path);
if (stat(path, &buf) == -1) {
if (!generate_key(path)) {
- D("Failed to generate new key\n");
+ D("Failed to generate new key");
return 0;
}
}
@@ -370,7 +370,7 @@
for (auto& path : android::base::Split(adb_keys_path, ENV_PATH_SEPARATOR_STR)) {
if (!read_key(path.c_str(), key_list)) {
- D("Failed to read '%s'\n", path.c_str());
+ D("Failed to read '%s'", path.c_str());
}
}
}
@@ -382,7 +382,7 @@
struct adb_private_key *key = node_to_item(node, struct adb_private_key, node);
if (token_size != TOKEN_SIZE) {
- D("Unexpected token size %zd\n", token_size);
+ D("Unexpected token size %zd", token_size);
return 0;
}
@@ -390,7 +390,7 @@
return 0;
}
- D("adb_auth_sign len=%d\n", len);
+ D("adb_auth_sign len=%d", len);
return (int)len;
}
@@ -421,7 +421,7 @@
char path[PATH_MAX];
int ret = get_user_keyfilepath(path, sizeof(path) - 4);
if (ret < 0 || ret >= (signed)(sizeof(path) - 4)) {
- D("Error getting user key filename\n");
+ D("Error getting user key filename");
return 0;
}
strcat(path, ".pub");
@@ -433,12 +433,12 @@
unsigned size;
char* file_data = reinterpret_cast<char*>(load_file(path, &size));
if (file_data == nullptr) {
- D("Can't load '%s'\n", path);
+ D("Can't load '%s'", path);
return 0;
}
if (len < (size_t)(size + 1)) {
- D("%s: Content too large ret=%d\n", path, size);
+ D("%s: Content too large ret=%d", path, size);
free(file_data);
return 0;
}
@@ -460,13 +460,13 @@
{
int ret;
- D("adb_auth_init\n");
+ D("adb_auth_init");
list_init(&key_list);
ret = get_user_key(&key_list);
if (!ret) {
- D("Failed to get user key\n");
+ D("Failed to get user key");
return;
}