Merge "logd: consolidate command handling and fix an error check" am: 2666aaba84 am: 6252e97df4
Original change: https://android-review.googlesource.com/c/platform/system/core/+/1393638 Change-Id: Ib6ac8cde20b8177b542d31eaf9ca3b268173dcd6
This commit is contained in:
commit
73c52ce2d4
1 changed files with 46 additions and 95 deletions
|
|
@ -32,6 +32,7 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include <android-base/logging.h>
|
#include <android-base/logging.h>
|
||||||
|
#include <android-base/parseint.h>
|
||||||
#include <android-base/stringprintf.h>
|
#include <android-base/stringprintf.h>
|
||||||
#include <cutils/sockets.h>
|
#include <cutils/sockets.h>
|
||||||
#include <log/log_properties.h>
|
#include <log/log_properties.h>
|
||||||
|
|
@ -64,53 +65,58 @@ static void setname() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int CommandListener::ClearCmd::runCommand(SocketClient* cli, int argc,
|
template <typename F>
|
||||||
char** argv) {
|
static int LogIdCommand(SocketClient* cli, int argc, char** argv, F&& function) {
|
||||||
setname();
|
setname();
|
||||||
|
if (argc < 2) {
|
||||||
|
cli->sendMsg("Missing Argument");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int log_id;
|
||||||
|
if (!android::base::ParseInt(argv[1], &log_id, static_cast<int>(LOG_ID_MAIN),
|
||||||
|
static_cast<int>(LOG_ID_KERNEL))) {
|
||||||
|
cli->sendMsg("Range Error");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
function(static_cast<log_id_t>(log_id));
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int CommandListener::ClearCmd::runCommand(SocketClient* cli, int argc, char** argv) {
|
||||||
uid_t uid = cli->getUid();
|
uid_t uid = cli->getUid();
|
||||||
if (clientHasLogCredentials(cli)) {
|
if (clientHasLogCredentials(cli)) {
|
||||||
uid = AID_ROOT;
|
uid = AID_ROOT;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (argc < 2) {
|
return LogIdCommand(cli, argc, argv, [&](log_id_t id) {
|
||||||
cli->sendMsg("Missing Argument");
|
cli->sendMsg(buf()->Clear(id, uid) ? "success" : "busy");
|
||||||
return 0;
|
});
|
||||||
}
|
|
||||||
|
|
||||||
int id = atoi(argv[1]);
|
|
||||||
if ((id < LOG_ID_MIN) || (LOG_ID_MAX <= id)) {
|
|
||||||
cli->sendMsg("Range Error");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
cli->sendMsg(buf()->Clear((log_id_t)id, uid) ? "success" : "busy");
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int CommandListener::GetBufSizeCmd::runCommand(SocketClient* cli, int argc,
|
template <typename F>
|
||||||
char** argv) {
|
static int LogSizeCommand(SocketClient* cli, int argc, char** argv, F&& size_function) {
|
||||||
setname();
|
return LogIdCommand(cli, argc, argv, [&](log_id_t log_id) {
|
||||||
if (argc < 2) {
|
cli->sendMsg(std::to_string(size_function(log_id)).c_str());
|
||||||
cli->sendMsg("Missing Argument");
|
});
|
||||||
return 0;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
int id = atoi(argv[1]);
|
int CommandListener::GetBufSizeCmd::runCommand(SocketClient* cli, int argc, char** argv) {
|
||||||
if ((id < LOG_ID_MIN) || (LOG_ID_MAX <= id)) {
|
return LogSizeCommand(cli, argc, argv, [this](log_id_t id) { return buf()->GetSize(id); });
|
||||||
cli->sendMsg("Range Error");
|
}
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t size = buf()->GetSize(static_cast<log_id_t>(id));
|
int CommandListener::GetBufSizeReadableCmd::runCommand(SocketClient* cli, int argc, char** argv) {
|
||||||
char buf[512];
|
return LogSizeCommand(cli, argc, argv,
|
||||||
snprintf(buf, sizeof(buf), "%zu", size);
|
[this](log_id_t id) { return stats()->SizeReadable(id); });
|
||||||
cli->sendMsg(buf);
|
}
|
||||||
return 0;
|
|
||||||
|
int CommandListener::GetBufSizeUsedCmd::runCommand(SocketClient* cli, int argc, char** argv) {
|
||||||
|
return LogSizeCommand(cli, argc, argv, [this](log_id_t id) { return stats()->Sizes(id); });
|
||||||
}
|
}
|
||||||
|
|
||||||
int CommandListener::SetBufSizeCmd::runCommand(SocketClient* cli, int argc,
|
int CommandListener::SetBufSizeCmd::runCommand(SocketClient* cli, int argc,
|
||||||
char** argv) {
|
char** argv) {
|
||||||
setname();
|
|
||||||
if (!clientHasLogCredentials(cli)) {
|
if (!clientHasLogCredentials(cli)) {
|
||||||
cli->sendMsg("Permission Denied");
|
cli->sendMsg("Permission Denied");
|
||||||
return 0;
|
return 0;
|
||||||
|
|
@ -120,62 +126,11 @@ int CommandListener::SetBufSizeCmd::runCommand(SocketClient* cli, int argc,
|
||||||
cli->sendMsg("Missing Argument");
|
cli->sendMsg("Missing Argument");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int id = atoi(argv[1]);
|
|
||||||
if ((id < LOG_ID_MIN) || (LOG_ID_MAX <= id)) {
|
|
||||||
cli->sendMsg("Range Error");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t size = atol(argv[2]);
|
size_t size = atol(argv[2]);
|
||||||
if (!buf()->SetSize(static_cast<log_id_t>(id), size)) {
|
|
||||||
cli->sendMsg("Range Error");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
cli->sendMsg("success");
|
return LogIdCommand(cli, argc, argv, [&](log_id_t log_id) {
|
||||||
return 0;
|
cli->sendMsg(buf()->SetSize(log_id, size) ? "success" : "busy");
|
||||||
}
|
});
|
||||||
|
|
||||||
int CommandListener::GetBufSizeReadableCmd::runCommand(SocketClient* cli, int argc, char** argv) {
|
|
||||||
setname();
|
|
||||||
if (argc < 2) {
|
|
||||||
cli->sendMsg("Missing Argument");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int id = atoi(argv[1]);
|
|
||||||
if (id < LOG_ID_MIN || LOG_ID_MAX <= id) {
|
|
||||||
cli->sendMsg("Range Error");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t size = stats()->SizeReadable(static_cast<log_id_t>(id));
|
|
||||||
char buf[512];
|
|
||||||
snprintf(buf, sizeof(buf), "%zu", size);
|
|
||||||
cli->sendMsg(buf);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int CommandListener::GetBufSizeUsedCmd::runCommand(SocketClient* cli, int argc,
|
|
||||||
char** argv) {
|
|
||||||
setname();
|
|
||||||
if (argc < 2) {
|
|
||||||
cli->sendMsg("Missing Argument");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int id = atoi(argv[1]);
|
|
||||||
if ((id < LOG_ID_MIN) || (LOG_ID_MAX <= id)) {
|
|
||||||
cli->sendMsg("Range Error");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t size = stats()->Sizes(static_cast<log_id_t>(id));
|
|
||||||
char buf[512];
|
|
||||||
snprintf(buf, sizeof(buf), "%zu", size);
|
|
||||||
cli->sendMsg(buf);
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// This returns a string with a length prefix with the format <length>\n<data>\n\f. The length
|
// This returns a string with a length prefix with the format <length>\n<data>\n\f. The length
|
||||||
|
|
@ -200,8 +155,7 @@ static std::string PackageString(const std::string& str) {
|
||||||
return android::base::StringPrintf("%zu\n%s\n\f", total_size, str.c_str());
|
return android::base::StringPrintf("%zu\n%s\n\f", total_size, str.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
int CommandListener::GetStatisticsCmd::runCommand(SocketClient* cli, int argc,
|
int CommandListener::GetStatisticsCmd::runCommand(SocketClient* cli, int argc, char** argv) {
|
||||||
char** argv) {
|
|
||||||
setname();
|
setname();
|
||||||
uid_t uid = cli->getUid();
|
uid_t uid = cli->getUid();
|
||||||
if (clientHasLogCredentials(cli)) {
|
if (clientHasLogCredentials(cli)) {
|
||||||
|
|
@ -266,8 +220,7 @@ int CommandListener::SetPruneListCmd::runCommand(SocketClient* cli, int argc, ch
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int CommandListener::GetEventTagCmd::runCommand(SocketClient* cli, int argc,
|
int CommandListener::GetEventTagCmd::runCommand(SocketClient* cli, int argc, char** argv) {
|
||||||
char** argv) {
|
|
||||||
setname();
|
setname();
|
||||||
uid_t uid = cli->getUid();
|
uid_t uid = cli->getUid();
|
||||||
if (clientHasLogCredentials(cli)) {
|
if (clientHasLogCredentials(cli)) {
|
||||||
|
|
@ -311,8 +264,7 @@ int CommandListener::GetEventTagCmd::runCommand(SocketClient* cli, int argc,
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int CommandListener::ReinitCmd::runCommand(SocketClient* cli, int /*argc*/,
|
int CommandListener::ReinitCmd::runCommand(SocketClient* cli, int, char**) {
|
||||||
char** /*argv*/) {
|
|
||||||
setname();
|
setname();
|
||||||
|
|
||||||
LOG(INFO) << "logd reinit";
|
LOG(INFO) << "logd reinit";
|
||||||
|
|
@ -335,8 +287,7 @@ int CommandListener::ReinitCmd::runCommand(SocketClient* cli, int /*argc*/,
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int CommandListener::ExitCmd::runCommand(SocketClient* cli, int /*argc*/,
|
int CommandListener::ExitCmd::runCommand(SocketClient* cli, int, char**) {
|
||||||
char** /*argv*/) {
|
|
||||||
setname();
|
setname();
|
||||||
|
|
||||||
cli->sendMsg("success");
|
cli->sendMsg("success");
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue