Merge "liblog: logprint, error return and truncated data"
am: 07169227e1
Change-Id: I2adb74fe54dfb6a4a6cc4b3f1a2898d7e0650560
This commit is contained in:
commit
f7f0b53aec
1 changed files with 29 additions and 20 deletions
|
|
@ -20,9 +20,6 @@
|
||||||
#define HAVE_STRSEP
|
#define HAVE_STRSEP
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
//#ifndef __MINGW32__
|
|
||||||
//#include <arpa/inet.h>
|
|
||||||
//#endif
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|
@ -117,7 +114,7 @@ static android_LogPriority filterCharToPri (char c)
|
||||||
c = tolower(c);
|
c = tolower(c);
|
||||||
|
|
||||||
if (c >= '0' && c <= '9') {
|
if (c >= '0' && c <= '9') {
|
||||||
if (c >= ('0'+ANDROID_LOG_SILENT)) {
|
if (c >= ('0' + ANDROID_LOG_SILENT)) {
|
||||||
pri = ANDROID_LOG_VERBOSE;
|
pri = ANDROID_LOG_VERBOSE;
|
||||||
} else {
|
} else {
|
||||||
pri = (android_LogPriority)(c - '0');
|
pri = (android_LogPriority)(c - '0');
|
||||||
|
|
@ -397,7 +394,7 @@ LIBLOG_ABI_PUBLIC int android_log_addFilterRule(
|
||||||
}
|
}
|
||||||
|
|
||||||
if(filterExpression[tagNameLength] == ':') {
|
if(filterExpression[tagNameLength] == ':') {
|
||||||
pri = filterCharToPri(filterExpression[tagNameLength+1]);
|
pri = filterCharToPri(filterExpression[tagNameLength + 1]);
|
||||||
|
|
||||||
if (pri == ANDROID_LOG_UNKNOWN) {
|
if (pri == ANDROID_LOG_UNKNOWN) {
|
||||||
goto error;
|
goto error;
|
||||||
|
|
@ -521,6 +518,9 @@ LIBLOG_ABI_PUBLIC int android_log_processLogBuffer(
|
||||||
struct logger_entry *buf,
|
struct logger_entry *buf,
|
||||||
AndroidLogEntry *entry)
|
AndroidLogEntry *entry)
|
||||||
{
|
{
|
||||||
|
entry->message = NULL;
|
||||||
|
entry->messageLen = 0;
|
||||||
|
|
||||||
entry->tv_sec = buf->sec;
|
entry->tv_sec = buf->sec;
|
||||||
entry->tv_nsec = buf->nsec;
|
entry->tv_nsec = buf->nsec;
|
||||||
entry->uid = -1;
|
entry->uid = -1;
|
||||||
|
|
@ -621,7 +621,7 @@ static inline uint64_t get8LE(const uint8_t* src)
|
||||||
|
|
||||||
low = src[0] | (src[1] << 8) | (src[2] << 16) | (src[3] << 24);
|
low = src[0] | (src[1] << 8) | (src[2] << 16) | (src[3] << 24);
|
||||||
high = src[4] | (src[5] << 8) | (src[6] << 16) | (src[7] << 24);
|
high = src[4] | (src[5] << 8) | (src[6] << 16) | (src[7] << 24);
|
||||||
return ((uint64_t) high << 32) | (uint64_t) low;
|
return ((uint64_t)high << 32) | (uint64_t)low;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool findChar(const char** cp, size_t* len, int c) {
|
static bool findChar(const char** cp, size_t* len, int c) {
|
||||||
|
|
@ -829,7 +829,10 @@ static int android_log_printBinaryEvent(const unsigned char** pEventData,
|
||||||
eventData += 4;
|
eventData += 4;
|
||||||
eventDataLen -= 4;
|
eventDataLen -= 4;
|
||||||
|
|
||||||
if (eventDataLen < strLen) return -1;
|
if (eventDataLen < strLen) {
|
||||||
|
result = -1; /* mark truncated */
|
||||||
|
strLen = eventDataLen;
|
||||||
|
}
|
||||||
|
|
||||||
if (cp && (strLen == 0)) {
|
if (cp && (strLen == 0)) {
|
||||||
/* reset the format if no content */
|
/* reset the format if no content */
|
||||||
|
|
@ -840,15 +843,18 @@ static int android_log_printBinaryEvent(const unsigned char** pEventData,
|
||||||
memcpy(outBuf, eventData, strLen);
|
memcpy(outBuf, eventData, strLen);
|
||||||
outBuf += strLen;
|
outBuf += strLen;
|
||||||
outBufLen -= strLen;
|
outBufLen -= strLen;
|
||||||
} else if (outBufLen > 0) {
|
} else {
|
||||||
/* copy what we can */
|
if (outBufLen > 0) {
|
||||||
memcpy(outBuf, eventData, outBufLen);
|
/* copy what we can */
|
||||||
outBuf += outBufLen;
|
memcpy(outBuf, eventData, outBufLen);
|
||||||
outBufLen -= outBufLen;
|
outBuf += outBufLen;
|
||||||
goto no_room;
|
outBufLen -= outBufLen;
|
||||||
|
}
|
||||||
|
if (!result) result = 1; /* if not truncated, return no room */
|
||||||
}
|
}
|
||||||
eventData += strLen;
|
eventData += strLen;
|
||||||
eventDataLen -= strLen;
|
eventDataLen -= strLen;
|
||||||
|
if (result != 0) goto bail;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case EVENT_TYPE_LIST:
|
case EVENT_TYPE_LIST:
|
||||||
|
|
@ -991,13 +997,16 @@ no_room:
|
||||||
LIBLOG_ABI_PUBLIC int android_log_processBinaryLogBuffer(
|
LIBLOG_ABI_PUBLIC int android_log_processBinaryLogBuffer(
|
||||||
struct logger_entry *buf,
|
struct logger_entry *buf,
|
||||||
AndroidLogEntry *entry,
|
AndroidLogEntry *entry,
|
||||||
const EventTagMap *map __unused, // only on !__ANDROID__
|
const EventTagMap *map __unused, /* only on !__ANDROID__ */
|
||||||
char *messageBuf, int messageBufLen)
|
char *messageBuf, int messageBufLen)
|
||||||
{
|
{
|
||||||
size_t inCount;
|
size_t inCount;
|
||||||
uint32_t tagIndex;
|
uint32_t tagIndex;
|
||||||
const unsigned char* eventData;
|
const unsigned char* eventData;
|
||||||
|
|
||||||
|
entry->message = NULL;
|
||||||
|
entry->messageLen = 0;
|
||||||
|
|
||||||
entry->tv_sec = buf->sec;
|
entry->tv_sec = buf->sec;
|
||||||
entry->tv_nsec = buf->nsec;
|
entry->tv_nsec = buf->nsec;
|
||||||
entry->priority = ANDROID_LOG_INFO;
|
entry->priority = ANDROID_LOG_INFO;
|
||||||
|
|
@ -1009,7 +1018,7 @@ LIBLOG_ABI_PUBLIC int android_log_processBinaryLogBuffer(
|
||||||
* Pull the tag out, fill in some additional details based on incoming
|
* Pull the tag out, fill in some additional details based on incoming
|
||||||
* buffer version (v3 adds lid, v4 adds uid).
|
* buffer version (v3 adds lid, v4 adds uid).
|
||||||
*/
|
*/
|
||||||
eventData = (const unsigned char*) buf->msg;
|
eventData = (const unsigned char*)buf->msg;
|
||||||
struct logger_entry_v2 *buf2 = (struct logger_entry_v2 *)buf;
|
struct logger_entry_v2 *buf2 = (struct logger_entry_v2 *)buf;
|
||||||
if (buf2->hdr_size) {
|
if (buf2->hdr_size) {
|
||||||
if ((buf2->hdr_size < sizeof(((struct log_msg *)NULL)->entry_v1)) ||
|
if ((buf2->hdr_size < sizeof(((struct log_msg *)NULL)->entry_v1)) ||
|
||||||
|
|
@ -1122,7 +1131,7 @@ LIBLOG_ABI_PUBLIC int android_log_processBinaryLogBuffer(
|
||||||
*/
|
*/
|
||||||
*outBuf = '\0';
|
*outBuf = '\0';
|
||||||
entry->messageLen = outBuf - messageBuf;
|
entry->messageLen = outBuf - messageBuf;
|
||||||
assert(entry->messageLen == (messageBufLen-1) - outRemaining);
|
assert(entry->messageLen == (messageBufLen - 1) - outRemaining);
|
||||||
|
|
||||||
entry->message = messageBuf;
|
entry->message = messageBuf;
|
||||||
|
|
||||||
|
|
@ -1217,7 +1226,7 @@ static size_t convertPrintable(char *p, const char *message, size_t messageLen)
|
||||||
} else if (*message == '\b') {
|
} else if (*message == '\b') {
|
||||||
strcpy(buf, "\\b");
|
strcpy(buf, "\\b");
|
||||||
} else if (*message == '\t') {
|
} else if (*message == '\t') {
|
||||||
strcpy(buf, "\t"); // Do not escape tabs
|
strcpy(buf, "\t"); /* Do not escape tabs */
|
||||||
} else if (*message == '\v') {
|
} else if (*message == '\v') {
|
||||||
strcpy(buf, "\\v");
|
strcpy(buf, "\\v");
|
||||||
} else if (*message == '\f') {
|
} else if (*message == '\f') {
|
||||||
|
|
@ -1574,7 +1583,7 @@ LIBLOG_ABI_PUBLIC char *android_log_formatLogLine (
|
||||||
nsec = entry->tv_nsec;
|
nsec = entry->tv_nsec;
|
||||||
#if __ANDROID__
|
#if __ANDROID__
|
||||||
if (p_format->monotonic_output) {
|
if (p_format->monotonic_output) {
|
||||||
// prevent convertMonotonic from being called if logd is monotonic
|
/* prevent convertMonotonic from being called if logd is monotonic */
|
||||||
if (android_log_clockid() != CLOCK_MONOTONIC) {
|
if (android_log_clockid() != CLOCK_MONOTONIC) {
|
||||||
struct timespec time;
|
struct timespec time;
|
||||||
convertMonotonic(&time, entry);
|
convertMonotonic(&time, entry);
|
||||||
|
|
@ -1648,7 +1657,7 @@ LIBLOG_ABI_PUBLIC char *android_log_formatLogLine (
|
||||||
} else
|
} else
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
// Not worth parsing package list, names all longer than 5
|
/* Not worth parsing package list, names all longer than 5 */
|
||||||
snprintf(uid, sizeof(uid), "%5d:", entry->uid);
|
snprintf(uid, sizeof(uid), "%5d:", entry->uid);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -1758,7 +1767,7 @@ LIBLOG_ABI_PUBLIC char *android_log_formatLogLine (
|
||||||
if (*pm++ == '\n') numLines++;
|
if (*pm++ == '\n') numLines++;
|
||||||
}
|
}
|
||||||
/* plus one line for anything not newline-terminated at the end */
|
/* plus one line for anything not newline-terminated at the end */
|
||||||
if (pm > entry->message && *(pm-1) != '\n') numLines++;
|
if (pm > entry->message && *(pm - 1) != '\n') numLines++;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue