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

Commit 30edbdce authored by Mark Salyzyn's avatar Mark Salyzyn Committed by Gerrit Code Review
Browse files

Merge changes I598c8c5c,I672b0f4d,Id882978b,Idff5e080,Ib124eca1, ...

* changes:
  logger.h: reduce maximum payload so sum is page size
  liblog: test for maximum payload can not survive change
  liblog: logprint use uid name if length less then 5
  liblog: logprint add uid format modifier
  liblog: readlog apps get logger_entry_v4 for pstore
  logd: readlog apps get logger_entry_v4
  logger.h: Add definition for logger_entry_v4
parents ad9dac1c b6a8d41e
Loading
Loading
Loading
Loading
+15 −2
Original line number Diff line number Diff line
@@ -64,12 +64,24 @@ struct logger_entry_v3 {
    char        msg[0];    /* the entry's payload */
} __attribute__((__packed__));

struct logger_entry_v4 {
    uint16_t    len;       /* length of the payload */
    uint16_t    hdr_size;  /* sizeof(struct logger_entry_v4) */
    int32_t     pid;       /* generating process's pid */
    uint32_t    tid;       /* generating process's tid */
    uint32_t    sec;       /* seconds since Epoch */
    uint32_t    nsec;      /* nanoseconds */
    uint32_t    lid;       /* log id of the payload, bottom 4 bits currently */
    uint32_t    uid;       /* generating process's uid */
    char        msg[0];    /* the entry's payload */
} __attribute__((__packed__));

/*
 * The maximum size of the log entry payload that can be
 * written to the logger. An attempt to write more than
 * this amount will result in a truncated log entry.
 */
#define LOGGER_ENTRY_MAX_PAYLOAD	4076
#define LOGGER_ENTRY_MAX_PAYLOAD	4068

/*
 * The maximum size of a log entry which can be read from the
@@ -83,7 +95,8 @@ struct logger_entry_v3 {
struct log_msg {
    union {
        unsigned char buf[LOGGER_ENTRY_MAX_LEN + 1];
        struct logger_entry_v3 entry;
        struct logger_entry_v4 entry;
        struct logger_entry_v4 entry_v4;
        struct logger_entry_v3 entry_v3;
        struct logger_entry_v2 entry_v2;
        struct logger_entry    entry_v1;
+2 −0
Original line number Diff line number Diff line
@@ -44,6 +44,7 @@ typedef enum {
    FORMAT_MODIFIER_ZONE,      /* Adds zone to date */
    FORMAT_MODIFIER_EPOCH,     /* Print time as seconds since Jan 1 1970 */
    FORMAT_MODIFIER_MONOTONIC, /* Print cpu time as seconds since start */
    FORMAT_MODIFIER_UID,       /* Adds uid */
} AndroidLogPrintFormat;

typedef struct AndroidLogFormat_t AndroidLogFormat;
@@ -52,6 +53,7 @@ typedef struct AndroidLogEntry_t {
    time_t tv_sec;
    long tv_nsec;
    android_LogPriority priority;
    int32_t uid;
    int32_t pid;
    int32_t tid;
    const char * tag;
+18 −9
Original line number Diff line number Diff line
@@ -634,6 +634,7 @@ static int android_logger_list_read_pstore(struct logger_list *logger_list,
        android_log_header_t l;
    } buf;
    static uint8_t preread_count;
    bool is_system;

    memset(log_msg, 0, sizeof(*log_msg));

@@ -690,11 +691,14 @@ static int android_logger_list_read_pstore(struct logger_list *logger_list,
            }

            uid = get_best_effective_uid();
            if (!uid_has_log_permission(uid) && (uid != buf.p.uid)) {
            is_system = uid_has_log_permission(uid);
            if (!is_system && (uid != buf.p.uid)) {
                break;
            }

            ret = TEMP_FAILURE_RETRY(read(logger_list->sock,
                                          is_system ?
                                              log_msg->entry_v4.msg :
                                              log_msg->entry_v3.msg,
                                          buf.p.len - sizeof(buf)));
            if (ret < 0) {
@@ -704,13 +708,18 @@ static int android_logger_list_read_pstore(struct logger_list *logger_list,
                return -EIO;
            }

            log_msg->entry_v3.len = buf.p.len - sizeof(buf);
            log_msg->entry_v3.hdr_size = sizeof(log_msg->entry_v3);
            log_msg->entry_v3.pid = buf.p.pid;
            log_msg->entry_v3.tid = buf.l.tid;
            log_msg->entry_v3.sec = buf.l.realtime.tv_sec;
            log_msg->entry_v3.nsec = buf.l.realtime.tv_nsec;
            log_msg->entry_v3.lid = buf.l.id;
            log_msg->entry_v4.len = buf.p.len - sizeof(buf);
            log_msg->entry_v4.hdr_size = is_system ?
                sizeof(log_msg->entry_v4) :
                sizeof(log_msg->entry_v3);
            log_msg->entry_v4.pid = buf.p.pid;
            log_msg->entry_v4.tid = buf.l.tid;
            log_msg->entry_v4.sec = buf.l.realtime.tv_sec;
            log_msg->entry_v4.nsec = buf.l.realtime.tv_nsec;
            log_msg->entry_v4.lid = buf.l.id;
            if (is_system) {
                log_msg->entry_v4.uid = buf.p.uid;
            }

            return ret;
        }
+53 −9
Original line number Diff line number Diff line
@@ -32,6 +32,7 @@
#include <cutils/list.h>
#include <log/logd.h>
#include <log/logprint.h>
#include <private/android_filesystem_config.h>

#define MS_PER_NSEC 1000000
#define US_PER_NSEC 1000
@@ -56,6 +57,7 @@ struct AndroidLogFormat_t {
    bool zone_output;
    bool epoch_output;
    bool monotonic_output;
    bool uid_output;
};

/*
@@ -204,6 +206,7 @@ AndroidLogFormat *android_log_format_new()
    p_ret->zone_output = false;
    p_ret->epoch_output = false;
    p_ret->monotonic_output = android_log_clockid() == CLOCK_MONOTONIC;
    p_ret->uid_output = false;

    return p_ret;
}
@@ -258,6 +261,9 @@ int android_log_setPrintFormat(AndroidLogFormat *p_format,
    case FORMAT_MODIFIER_MONOTONIC:
        p_format->monotonic_output = true;
        return 0;
    case FORMAT_MODIFIER_UID:
        p_format->uid_output = true;
        return 0;
    default:
        break;
    }
@@ -290,6 +296,7 @@ AndroidLogPrintFormat android_log_formatFromString(const char * formatString)
    else if (strcmp(formatString, "zone") == 0) format = FORMAT_MODIFIER_ZONE;
    else if (strcmp(formatString, "epoch") == 0) format = FORMAT_MODIFIER_EPOCH;
    else if (strcmp(formatString, "monotonic") == 0) format = FORMAT_MODIFIER_MONOTONIC;
    else if (strcmp(formatString, "uid") == 0) format = FORMAT_MODIFIER_UID;
    else {
        extern char *tzname[2];
        static const char gmt[] = "GMT";
@@ -451,6 +458,7 @@ int android_log_processLogBuffer(struct logger_entry *buf,
{
    entry->tv_sec = buf->sec;
    entry->tv_nsec = buf->nsec;
    entry->uid = -1;
    entry->pid = buf->pid;
    entry->tid = buf->tid;

@@ -482,6 +490,9 @@ int android_log_processLogBuffer(struct logger_entry *buf,
    struct logger_entry_v2 *buf2 = (struct logger_entry_v2 *)buf;
    if (buf2->hdr_size) {
        msg = ((char *)buf2) + buf2->hdr_size;
        if (buf2->hdr_size >= sizeof(struct logger_entry_v4)) {
            entry->uid = ((struct logger_entry_v4 *)buf)->uid;
        }
    }
    for (i = 1; i < buf->len; i++) {
        if (msg[i] == '\0') {
@@ -734,6 +745,7 @@ int android_log_processBinaryLogBuffer(struct logger_entry *buf,
    entry->tv_sec = buf->sec;
    entry->tv_nsec = buf->nsec;
    entry->priority = ANDROID_LOG_INFO;
    entry->uid = -1;
    entry->pid = buf->pid;
    entry->tid = buf->tid;

@@ -744,6 +756,9 @@ int android_log_processBinaryLogBuffer(struct logger_entry *buf,
    struct logger_entry_v2 *buf2 = (struct logger_entry_v2 *)buf;
    if (buf2->hdr_size) {
        eventData = ((unsigned char *)buf2) + buf2->hdr_size;
        if (buf2->hdr_size >= sizeof(struct logger_entry_v4)) {
            entry->uid = ((struct logger_entry_v4 *)buf)->uid;
        }
    }
    inCount = buf->len;
    if (inCount < 4)
@@ -1238,7 +1253,7 @@ char *android_log_formatLogLine (
    char prefixBuf[128], suffixBuf[128];
    char priChar;
    int prefixSuffixIsHeaderFooter = 0;
    char *ret = NULL;
    char *ret;
    time_t now;
    unsigned long nsec;

@@ -1310,6 +1325,30 @@ char *android_log_formatLogLine (
        suffixLen = MIN(suffixLen, sizeof(suffixBuf));
    }

    char uid[16];
    uid[0] = '\0';
    if (p_format->uid_output) {
        if (entry->uid >= 0) {
            const struct android_id_info *info = android_ids;
            size_t i;

            for (i = 0; i < android_id_count; ++i) {
                if (info->aid == (unsigned int)entry->uid) {
                    break;
                }
                ++info;
            }
            if ((i < android_id_count) && (strlen(info->name) <= 5)) {
                 snprintf(uid, sizeof(uid), "%5s:", info->name);
            } else {
                 // Not worth parsing package list, names all longer than 5
                 snprintf(uid, sizeof(uid), "%5d:", entry->uid);
            }
        } else {
            snprintf(uid, sizeof(uid), "      ");
        }
    }

    switch (p_format->format) {
        case FORMAT_TAG:
            len = snprintf(prefixBuf + prefixLen, sizeof(prefixBuf) - prefixLen,
@@ -1322,11 +1361,11 @@ char *android_log_formatLogLine (
                "  (%s)\n", entry->tag);
            suffixLen += MIN(len, sizeof(suffixBuf) - suffixLen);
            len = snprintf(prefixBuf + prefixLen, sizeof(prefixBuf) - prefixLen,
                "%c(%5d) ", priChar, entry->pid);
                "%c(%s%5d) ", priChar, uid, entry->pid);
            break;
        case FORMAT_THREAD:
            len = snprintf(prefixBuf + prefixLen, sizeof(prefixBuf) - prefixLen,
                "%c(%5d:%5d) ", priChar, entry->pid, entry->tid);
                "%c(%s%5d:%5d) ", priChar, uid, entry->pid, entry->tid);
            strcpy(suffixBuf + suffixLen, "\n");
            ++suffixLen;
            break;
@@ -1338,21 +1377,26 @@ char *android_log_formatLogLine (
            break;
        case FORMAT_TIME:
            len = snprintf(prefixBuf + prefixLen, sizeof(prefixBuf) - prefixLen,
                "%s %c/%-8s(%5d): ", timeBuf, priChar, entry->tag, entry->pid);
                "%s %c/%-8s(%s%5d): ", timeBuf, priChar, entry->tag,
                uid, entry->pid);
            strcpy(suffixBuf + suffixLen, "\n");
            ++suffixLen;
            break;
        case FORMAT_THREADTIME:
            ret = strchr(uid, ':');
            if (ret) {
                *ret = ' ';
            }
            len = snprintf(prefixBuf + prefixLen, sizeof(prefixBuf) - prefixLen,
                "%s %5d %5d %c %-8s: ", timeBuf,
                entry->pid, entry->tid, priChar, entry->tag);
                "%s %s%5d %5d %c %-8s: ", timeBuf,
                uid, entry->pid, entry->tid, priChar, entry->tag);
            strcpy(suffixBuf + suffixLen, "\n");
            ++suffixLen;
            break;
        case FORMAT_LONG:
            len = snprintf(prefixBuf + prefixLen, sizeof(prefixBuf) - prefixLen,
                "[ %s %5d:%5d %c/%-8s ]\n",
                timeBuf, entry->pid, entry->tid, priChar, entry->tag);
                "[ %s %s%5d:%5d %c/%-8s ]\n",
                timeBuf, uid, entry->pid, entry->tid, priChar, entry->tag);
            strcpy(suffixBuf + suffixLen, "\n\n");
            suffixLen += 2;
            prefixSuffixIsHeaderFooter = 1;
@@ -1360,7 +1404,7 @@ char *android_log_formatLogLine (
        case FORMAT_BRIEF:
        default:
            len = snprintf(prefixBuf + prefixLen, sizeof(prefixBuf) - prefixLen,
                "%c/%-8s(%5d): ", priChar, entry->tag, entry->pid);
                "%c/%-8s(%s%5d): ", priChar, entry->tag, uid, entry->pid);
            strcpy(suffixBuf + suffixLen, "\n");
            ++suffixLen;
            break;
+8 −7
Original line number Diff line number Diff line
@@ -342,8 +342,9 @@ TEST(liblog, android_logger_list_read__cpu) {
}

static const char max_payload_tag[] = "TEST_max_payload_XXXX";
static const char max_payload_buf[LOGGER_ENTRY_MAX_PAYLOAD
    - sizeof(max_payload_tag) - 1] = "LEONATO\n\
#define SIZEOF_MAX_PAYLOAD_BUF (LOGGER_ENTRY_MAX_PAYLOAD - \
                                sizeof(max_payload_tag) - 1)
static const char max_payload_buf[] = "LEONATO\n\
I learn in this letter that Don Peter of Arragon\n\
comes this night to Messina\n\
MESSENGER\n\
@@ -469,7 +470,7 @@ Good Signior Leonato, you are come to meet your\n\
trouble: the fashion of the world is to avoid\n\
cost, and you encounter it\n\
LEONATO\n\
Never came trouble to my house in the likeness";
Never came trouble to my house in the likeness of your grace";

TEST(liblog, max_payload) {
    pid_t pid = getpid();
@@ -528,7 +529,7 @@ TEST(liblog, max_payload) {

    EXPECT_EQ(true, matches);

    EXPECT_LE(sizeof(max_payload_buf), static_cast<size_t>(max_len));
    EXPECT_LE(SIZEOF_MAX_PAYLOAD_BUF, static_cast<size_t>(max_len));
}

TEST(liblog, too_big_payload) {
@@ -1005,7 +1006,7 @@ TEST(liblog, android_errorWriteWithInfoLog__android_logger_list_read__data_too_l
    const int TAG = 123456782;
    const char SUBTAG[] = "test-subtag";
    const int UID = -1;
    const int DATA_LEN = sizeof(max_payload_buf);
    const int DATA_LEN = SIZEOF_MAX_PAYLOAD_BUF;
    struct logger_list *logger_list;

    pid_t pid = getpid();
@@ -1076,8 +1077,8 @@ TEST(liblog, android_errorWriteWithInfoLog__android_logger_list_read__data_too_l
        }
        eventData += dataLen;

        // 4 bytes for the tag, and 512 bytes for the log since the max_payload_buf should be
        // truncated.
        // 4 bytes for the tag, and 512 bytes for the log since the
        // max_payload_buf should be truncated.
        ASSERT_EQ(4 + 512, eventData - original);

        ++count;
Loading