summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMark Salyzyn2015-06-12 16:59:42 -0500
committerMark Salyzyn2015-06-15 16:22:02 -0500
commitd5600fd40fac5e90532ea08e22940965cfdd7710 (patch)
tree469cfcb4f1f6718fa4a82f7c5aeaa456eb1010be /logd/main.cpp
parentbd1ef90448c32e2beec4c66f08fe613bcc632cc8 (diff)
downloadplatform-system-core-d5600fd40fac5e90532ea08e22940965cfdd7710.tar.gz
platform-system-core-d5600fd40fac5e90532ea08e22940965cfdd7710.tar.xz
platform-system-core-d5600fd40fac5e90532ea08e22940965cfdd7710.zip
logd: missing klogd content
(cherry pick from commit ee49c6a670a54e0636f81f39ddc93c87c9a4d766) - regression in log_strtok_r (part deux) In commit 'logd: fix kernel logline stutter' 2c3b300fd8307e8da13608197d0a89bc613de5fb we introduced log_strtok_r. as a replacement for strtok_r that dealt with a problem with some kernel log messages. Fix is to refine definition of is_timestamp to not match on patterns like [0], requiring a single period. Another fix is to refine definition of is_prio to properly escape non-digit content. - Missing content because SYSLOG_ACTION_SIZE_BUFFER with added logging is too short for full read of SYSLOG_ACTION_READ_ALL dropping initial content. Add a margin for additional 1024 bytes. - Absolute _first_ log entry has sequence number of 1, which is specifically dropped, start sequence count at 1 rather than 0. - Remove trailing space for efficiency. - If tag exists but no content, trick into kernel logging. Bug: 21851884 Change-Id: I0867a555a3bca09bbf18d18e75e41dffffe57a23
Diffstat (limited to 'logd/main.cpp')
-rw-r--r--logd/main.cpp80
1 files changed, 48 insertions, 32 deletions
diff --git a/logd/main.cpp b/logd/main.cpp
index a876c99cb..9b889838d 100644
--- a/logd/main.cpp
+++ b/logd/main.cpp
@@ -33,6 +33,8 @@
33#include <syslog.h> 33#include <syslog.h>
34#include <unistd.h> 34#include <unistd.h>
35 35
36#include <memory>
37
36#include <cutils/properties.h> 38#include <cutils/properties.h>
37#include <cutils/sched_policy.h> 39#include <cutils/sched_policy.h>
38#include <cutils/sockets.h> 40#include <cutils/sockets.h>
@@ -275,6 +277,45 @@ static bool property_get_bool_svelte(const char *key) {
275 && !property_get_bool("ro.config.low_ram", false)); 277 && !property_get_bool("ro.config.low_ram", false));
276} 278}
277 279
280static void readDmesg(LogAudit *al, LogKlog *kl) {
281 if (!al && !kl) {
282 return;
283 }
284
285 int len = klogctl(KLOG_SIZE_BUFFER, NULL, 0);
286 if (len <= 0) {
287 return;
288 }
289
290 len += 1024; // Margin for additional input race or trailing nul
291 std::unique_ptr<char []> buf(new char[len]);
292
293 int rc = klogctl(KLOG_READ_ALL, buf.get(), len);
294 if (rc <= 0) {
295 return;
296 }
297
298 if (rc < len) {
299 len = rc + 1;
300 }
301 buf[len - 1] = '\0';
302
303 if (kl) {
304 kl->synchronize(buf.get());
305 }
306
307 for (char *ptr = NULL, *tok = buf.get();
308 (rc >= 0) && ((tok = log_strtok_r(tok, &ptr)));
309 tok = NULL) {
310 if (al) {
311 rc = al->log(tok);
312 }
313 if (kl) {
314 rc = kl->log(tok);
315 }
316 }
317}
318
278// Foreground waits for exit of the main persistent threads 319// Foreground waits for exit of the main persistent threads
279// that are started here. The threads are created to manage 320// that are started here. The threads are created to manage
280// UNIX domain client sockets for writing, reading and 321// UNIX domain client sockets for writing, reading and
@@ -410,41 +451,16 @@ int main(int argc, char *argv[]) {
410 kl = new LogKlog(logBuf, reader, fdDmesg, fdPmesg, al != NULL); 451 kl = new LogKlog(logBuf, reader, fdDmesg, fdPmesg, al != NULL);
411 } 452 }
412 453
413 if (al || kl) { 454 readDmesg(al, kl);
414 int len = klogctl(KLOG_SIZE_BUFFER, NULL, 0);
415 if (len > 0) {
416 len++;
417 char buf[len];
418
419 int rc = klogctl(KLOG_READ_ALL, buf, len);
420
421 buf[len - 1] = '\0';
422
423 if ((rc >= 0) && kl) {
424 kl->synchronize(buf);
425 }
426
427 for (char *ptr = NULL, *tok = buf;
428 (rc >= 0) && ((tok = log_strtok_r(tok, &ptr)));
429 tok = NULL) {
430 if (al) {
431 rc = al->log(tok);
432 }
433 if (kl) {
434 rc = kl->log(tok);
435 }
436 }
437 }
438 455
439 // failure is an option ... messages are in dmesg (required by standard) 456 // failure is an option ... messages are in dmesg (required by standard)
440 457
441 if (kl && kl->startListener()) { 458 if (kl && kl->startListener()) {
442 delete kl; 459 delete kl;
443 } 460 }
444 461
445 if (al && al->startListener()) { 462 if (al && al->startListener()) {
446 delete al; 463 delete al;
447 }
448 } 464 }
449 465
450 TEMP_FAILURE_RETRY(pause()); 466 TEMP_FAILURE_RETRY(pause());