Merge "Make android_logger_set_prune_list() sane"
This commit is contained in:
commit
d1ac612879
3 changed files with 8 additions and 24 deletions
|
|
@ -139,8 +139,7 @@ ssize_t android_logger_get_statistics(struct logger_list* logger_list,
|
|||
char* buf, size_t len);
|
||||
ssize_t android_logger_get_prune_list(struct logger_list* logger_list,
|
||||
char* buf, size_t len);
|
||||
int android_logger_set_prune_list(struct logger_list* logger_list, char* buf,
|
||||
size_t len);
|
||||
int android_logger_set_prune_list(struct logger_list* logger_list, const char* buf, size_t len);
|
||||
|
||||
#define ANDROID_LOG_RDONLY O_RDONLY
|
||||
#define ANDROID_LOG_WRONLY O_WRONLY
|
||||
|
|
|
|||
|
|
@ -33,6 +33,8 @@
|
|||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
#include <cutils/sockets.h>
|
||||
#include <private/android_filesystem_config.h>
|
||||
#include <private/android_logger.h>
|
||||
|
|
@ -249,22 +251,14 @@ ssize_t android_logger_get_prune_list(struct logger_list* logger_list, char* buf
|
|||
return SendLogdControlMessage(buf, len);
|
||||
}
|
||||
|
||||
int android_logger_set_prune_list(struct logger_list* logger_list, char* buf, size_t len) {
|
||||
int android_logger_set_prune_list(struct logger_list* logger_list, const char* buf, size_t len) {
|
||||
if (logger_list->mode & ANDROID_LOG_PSTORE) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
const char cmd[] = "setPruneList ";
|
||||
const size_t cmdlen = sizeof(cmd) - 1;
|
||||
std::string cmd = "setPruneList " + std::string{buf, len};
|
||||
|
||||
if (strlen(buf) > (len - cmdlen)) {
|
||||
return -ENOMEM; /* KISS */
|
||||
}
|
||||
memmove(buf + cmdlen, buf, len - cmdlen);
|
||||
buf[len - 1] = '\0';
|
||||
memcpy(buf, cmd, cmdlen);
|
||||
|
||||
return check_log_success(buf, SendLogdControlMessage(buf, len));
|
||||
return check_log_success(cmd.data(), SendLogdControlMessage(cmd.data(), cmd.size()));
|
||||
}
|
||||
|
||||
static int logdOpen(struct logger_list* logger_list) {
|
||||
|
|
|
|||
|
|
@ -1075,17 +1075,8 @@ int Logcat::Run(int argc, char** argv) {
|
|||
|
||||
if (setPruneList) {
|
||||
size_t len = strlen(setPruneList);
|
||||
// extra 32 bytes are needed by android_logger_set_prune_list
|
||||
size_t bLen = len + 32;
|
||||
char* buf = nullptr;
|
||||
if (asprintf(&buf, "%-*s", (int)(bLen - 1), setPruneList) > 0) {
|
||||
buf[len] = '\0';
|
||||
if (android_logger_set_prune_list(logger_list.get(), buf, bLen)) {
|
||||
error(EXIT_FAILURE, 0, "Failed to set the prune list.");
|
||||
}
|
||||
free(buf);
|
||||
} else {
|
||||
error(EXIT_FAILURE, 0, "Failed to set the prune list (alloc).");
|
||||
if (android_logger_set_prune_list(logger_list.get(), setPruneList, len)) {
|
||||
error(EXIT_FAILURE, 0, "Failed to set the prune list.");
|
||||
}
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue