logd: refine is_prio

(cherry pick from commit 618d0dec50)

- Heuristics associated with translation of kernel messages to
  Android user space logs.
- Limit is_prio to 4 characters, we got false positives on hex
  values like <register contents> with no alpha chars.
- x11 and other register definitions are not valid tags, en0 is
- fix some Android coding standard issues

Change-Id: Idc3dcc53a2cb75ac38628c8ef7a5d5b53f12587a
This commit is contained in:
Mark Salyzyn 2015-07-13 10:19:34 -07:00
parent 8bc53c125a
commit cb19b08dac

View file

@ -43,8 +43,10 @@ static char *is_prio(char *s) {
if (!isdigit(*s++)) { if (!isdigit(*s++)) {
return NULL; return NULL;
} }
static const size_t max_prio_len = 4;
size_t len = 0;
char c; char c;
while ((c = *s++)) { while (((c = *s++)) && (++len <= max_prio_len)) {
if (!isdigit(c)) { if (!isdigit(c)) {
return (c == '>') ? s : NULL; return (c == '>') ? s : NULL;
} }
@ -73,7 +75,7 @@ static char *is_timestamp(char *s) {
} }
// Like strtok_r with "\r\n" except that we look for log signatures (regex) // Like strtok_r with "\r\n" except that we look for log signatures (regex)
// \(\(<[0-9]+>\)\([[] *[0-9]+[.][0-9]+[]] \)\{0,1\}\|[[] *[0-9]+[.][0-9]+[]] \) // \(\(<[0-9]\{1,4\}>\)\([[] *[0-9]+[.][0-9]+[]] \)\{0,1\}\|[[] *[0-9]+[.][0-9]+[]] \)
// and split if we see a second one without a newline. // and split if we see a second one without a newline.
#define SIGNATURE_MASK 0xF0 #define SIGNATURE_MASK 0xF0
@ -165,7 +167,7 @@ char *log_strtok_r(char *s, char **last) {
break; break;
} }
} }
/* NOTREACHED */ // NOTREACHED
} }
log_time LogKlog::correction = log_time(CLOCK_REALTIME) - log_time(CLOCK_MONOTONIC); log_time LogKlog::correction = log_time(CLOCK_REALTIME) - log_time(CLOCK_MONOTONIC);
@ -465,7 +467,7 @@ int LogKlog::log(const char *buf) {
if (strncmp(bt, cp, size)) { if (strncmp(bt, cp, size)) {
// <PRI>[<TIME>] <tag>_host '<tag>.<num>' : message // <PRI>[<TIME>] <tag>_host '<tag>.<num>' : message
if (!strncmp(bt + size - 5, "_host", 5) if (!strncmp(bt + size - 5, "_host", 5)
&& !strncmp(bt, cp, size - 5)) { && !strncmp(bt, cp, size - 5)) {
const char *b = cp; const char *b = cp;
cp += size - 5; cp += size - 5;
if (*cp == '.') { if (*cp == '.') {
@ -535,11 +537,15 @@ int LogKlog::log(const char *buf) {
} }
size = etag - tag; size = etag - tag;
if ((size <= 1) if ((size <= 1)
|| ((size == 2) && (isdigit(tag[0]) || isdigit(tag[1]))) // register names like x9
|| ((size == 3) && !strncmp(tag, "CPU", 3)) || ((size == 2) && (isdigit(tag[0]) || isdigit(tag[1])))
|| ((size == 7) && !strncmp(tag, "WARNING", 7)) // register names like x18 but not driver names like en0
|| ((size == 5) && !strncmp(tag, "ERROR", 5)) || ((size == 3) && (isdigit(tag[1]) && isdigit(tag[2])))
|| ((size == 4) && !strncmp(tag, "INFO", 4))) { // blacklist
|| ((size == 3) && !strncmp(tag, "CPU", 3))
|| ((size == 7) && !strncmp(tag, "WARNING", 7))
|| ((size == 5) && !strncmp(tag, "ERROR", 5))
|| ((size == 4) && !strncmp(tag, "INFO", 4))) {
buf = start; buf = start;
etag = tag = ""; etag = tag = "";
} }