Merge "init: logd: Allow Developer settings to adjust logd size"
This commit is contained in:
commit
8b2d46a5fc
3 changed files with 64 additions and 10 deletions
|
@ -90,6 +90,7 @@ struct {
|
|||
{ "log.", AID_SHELL, 0 },
|
||||
{ "service.adb.root", AID_SHELL, 0 },
|
||||
{ "service.adb.tcp.port", AID_SHELL, 0 },
|
||||
{ "persist.logd.size",AID_SYSTEM, 0 },
|
||||
{ "persist.sys.", AID_SYSTEM, 0 },
|
||||
{ "persist.service.", AID_SYSTEM, 0 },
|
||||
{ "persist.security.", AID_SYSTEM, 0 },
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/user.h>
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
|
||||
|
@ -32,6 +33,34 @@
|
|||
// Default
|
||||
#define LOG_BUFFER_SIZE (256 * 1024) // Tuned on a per-platform basis here?
|
||||
#define log_buffer_size(id) mMaxSize[id]
|
||||
#define LOG_BUFFER_MIN_SIZE (64 * 1024UL)
|
||||
#define LOG_BUFFER_MAX_SIZE (256 * 1024 * 1024UL)
|
||||
|
||||
static bool valid_size(unsigned long value) {
|
||||
if ((value < LOG_BUFFER_MIN_SIZE) || (LOG_BUFFER_MAX_SIZE < value)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
long pages = sysconf(_SC_PHYS_PAGES);
|
||||
if (pages < 1) {
|
||||
return true;
|
||||
}
|
||||
|
||||
long pagesize = sysconf(_SC_PAGESIZE);
|
||||
if (pagesize <= 1) {
|
||||
pagesize = PAGE_SIZE;
|
||||
}
|
||||
|
||||
// maximum memory impact a somewhat arbitrary ~3%
|
||||
pages = (pages + 31) / 32;
|
||||
unsigned long maximum = pages * pagesize;
|
||||
|
||||
if ((maximum < LOG_BUFFER_MIN_SIZE) || (LOG_BUFFER_MAX_SIZE < maximum)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return value <= maximum;
|
||||
}
|
||||
|
||||
static unsigned long property_get_size(const char *key) {
|
||||
char property[PROPERTY_VALUE_MAX];
|
||||
|
@ -56,6 +85,10 @@ static unsigned long property_get_size(const char *key) {
|
|||
value = 0;
|
||||
}
|
||||
|
||||
if (!valid_size(value)) {
|
||||
value = 0;
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
|
@ -64,18 +97,38 @@ LogBuffer::LogBuffer(LastLogTimes *times)
|
|||
pthread_mutex_init(&mLogElementsLock, NULL);
|
||||
dgram_qlen_statistics = false;
|
||||
|
||||
static const char global_default[] = "persist.logd.size";
|
||||
unsigned long default_size = property_get_size(global_default);
|
||||
static const char global_tuneable[] = "persist.logd.size"; // Settings App
|
||||
static const char global_default[] = "ro.logd.size"; // BoardConfig.mk
|
||||
|
||||
unsigned long default_size = property_get_size(global_tuneable);
|
||||
if (!default_size) {
|
||||
default_size = property_get_size(global_default);
|
||||
}
|
||||
|
||||
log_id_for_each(i) {
|
||||
setSize(i, LOG_BUFFER_SIZE);
|
||||
setSize(i, default_size);
|
||||
|
||||
char key[PROP_NAME_MAX];
|
||||
snprintf(key, sizeof(key), "%s.%s",
|
||||
global_default, android_log_id_to_name(i));
|
||||
|
||||
setSize(i, property_get_size(key));
|
||||
snprintf(key, sizeof(key), "%s.%s",
|
||||
global_tuneable, android_log_id_to_name(i));
|
||||
unsigned long property_size = property_get_size(key);
|
||||
|
||||
if (!property_size) {
|
||||
snprintf(key, sizeof(key), "%s.%s",
|
||||
global_default, android_log_id_to_name(i));
|
||||
property_size = property_get_size(key);
|
||||
}
|
||||
|
||||
if (!property_size) {
|
||||
property_size = default_size;
|
||||
}
|
||||
|
||||
if (!property_size) {
|
||||
property_size = LOG_BUFFER_SIZE;
|
||||
}
|
||||
|
||||
if (setSize(i, property_size)) {
|
||||
setSize(i, LOG_BUFFER_MIN_SIZE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -339,7 +392,7 @@ unsigned long LogBuffer::getSizeUsed(log_id_t id) {
|
|||
// set the total space allocated to "id"
|
||||
int LogBuffer::setSize(log_id_t id, unsigned long size) {
|
||||
// Reasonable limits ...
|
||||
if ((size < (64 * 1024)) || ((256 * 1024 * 1024) < size)) {
|
||||
if (!valid_size(size)) {
|
||||
return -1;
|
||||
}
|
||||
pthread_mutex_lock(&mLogElementsLock);
|
||||
|
|
|
@ -64,7 +64,7 @@ bool clientHasLogCredentials(SocketClient * cli) {
|
|||
}
|
||||
|
||||
gid_t gid = cli->getGid();
|
||||
if ((gid == AID_ROOT) || (gid == AID_LOG)) {
|
||||
if ((gid == AID_ROOT) || (gid == AID_SYSTEM) || (gid == AID_LOG)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue