Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2ee4371c authored by Yao Chen's avatar Yao Chen
Browse files

Handle return value 0 from android_logger_list_read

This fixes the bug that sometimes statsd is running at 99% cpu.
Connection to logd can be reset for various reasons, and android_logger_list_read
will return 0 when that happens. We didn't handle 0 before, and that leads to reading
empty logs and processing them in a infinite loop.

Bug: 71833883
Test: manual test by killing logd, forcing return 0.
Change-Id: I5a9c89fc58959d6593028a14f70a8fe8d10b40f1
parent 1776fa33
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -98,7 +98,10 @@ int LogReader::connect_and_read() {

            // Read a message
            err = android_logger_list_read(loggers, &msg);
            if (err < 0) {
            // err = 0 - no content, unexpected connection drop or EOF.
            // err = +ive number - size of retrieved data from logger
            // err = -ive number, OS supplied error _except_ for -EAGAIN
            if (err <= 0) {
                fprintf(stderr, "logcat read failure: %s\n", strerror(err));
                break;
            }