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

Commit 4046c132 authored by Mark Salyzyn's avatar Mark Salyzyn Committed by Android (Google) Code Review
Browse files

Merge changes I929dddc7,Ice88b141,I243b1338

* changes:
  logd: prune more aggressively when over the top
  logd: initial checkin.
  logcat: test: add clear and blocking check
parents d4446607 63c15d50
Loading
Loading
Loading
Loading
+3 −3
Original line number Original line Diff line number Diff line
@@ -23,12 +23,12 @@
#ifdef __cplusplus
#ifdef __cplusplus
struct log_time : public timespec {
struct log_time : public timespec {
public:
public:
    log_time(timespec &T)
    log_time(const timespec &T)
    {
    {
        tv_sec = T.tv_sec;
        tv_sec = T.tv_sec;
        tv_nsec = T.tv_nsec;
        tv_nsec = T.tv_nsec;
    }
    }
    log_time(void)
    log_time()
    {
    {
    }
    }
    log_time(clockid_t id)
    log_time(clockid_t id)
@@ -67,7 +67,7 @@ public:
    {
    {
        return !(*this > T);
        return !(*this > T);
    }
    }
    uint64_t nsec(void) const
    uint64_t nsec() const
    {
    {
        return static_cast<uint64_t>(tv_sec) * NS_PER_SEC + tv_nsec;
        return static_cast<uint64_t>(tv_sec) * NS_PER_SEC + tv_nsec;
    }
    }
+17 −5
Original line number Original line Diff line number Diff line
@@ -35,7 +35,7 @@ struct logger_entry {
/*
/*
 * The userspace structure for version 2 of the logger_entry ABI.
 * The userspace structure for version 2 of the logger_entry ABI.
 * This structure is returned to userspace if ioctl(LOGGER_SET_VERSION)
 * This structure is returned to userspace if ioctl(LOGGER_SET_VERSION)
 * is called with version==2
 * is called with version==2; or used with the user space log daemon.
 */
 */
struct logger_entry_v2 {
struct logger_entry_v2 {
    uint16_t    len;       /* length of the payload */
    uint16_t    len;       /* length of the payload */
@@ -48,6 +48,17 @@ struct logger_entry_v2 {
    char        msg[0];    /* the entry's payload */
    char        msg[0];    /* the entry's payload */
};
};


struct logger_entry_v3 {
    uint16_t    len;       /* length of the payload */
    uint16_t    hdr_size;  /* sizeof(struct logger_entry_v2) */
    int32_t     pid;       /* generating process's pid */
    int32_t     tid;       /* generating process's tid */
    int32_t     sec;       /* seconds since Epoch */
    int32_t     nsec;      /* nanoseconds */
    uint32_t    lid;       /* log id of the payload */
    char        msg[0];    /* the entry's payload */
};

/*
/*
 * The maximum size of the log entry payload that can be
 * The maximum size of the log entry payload that can be
 * written to the kernel logger driver. An attempt to write
 * written to the kernel logger driver. An attempt to write
@@ -69,6 +80,7 @@ struct log_msg {
    union {
    union {
        unsigned char buf[LOGGER_ENTRY_MAX_LEN + 1];
        unsigned char buf[LOGGER_ENTRY_MAX_LEN + 1];
        struct logger_entry_v2 entry;
        struct logger_entry_v2 entry;
        struct logger_entry_v3 entry_v3;
        struct logger_entry_v2 entry_v2;
        struct logger_entry_v2 entry_v2;
        struct logger_entry    entry_v1;
        struct logger_entry    entry_v1;
        struct {
        struct {
@@ -106,21 +118,21 @@ struct log_msg {
    {
    {
        return !(*this > T);
        return !(*this > T);
    }
    }
    uint64_t nsec(void) const
    uint64_t nsec() const
    {
    {
        return static_cast<uint64_t>(entry.sec) * NS_PER_SEC + entry.nsec;
        return static_cast<uint64_t>(entry.sec) * NS_PER_SEC + entry.nsec;
    }
    }


    /* packet methods */
    /* packet methods */
    log_id_t id(void)
    log_id_t id()
    {
    {
        return extra.id;
        return extra.id;
    }
    }
    char *msg(void)
    char *msg()
    {
    {
        return entry.hdr_size ? (char *) buf + entry.hdr_size : entry_v1.msg;
        return entry.hdr_size ? (char *) buf + entry.hdr_size : entry_v1.msg;
    }
    }
    unsigned int len(void)
    unsigned int len()
    {
    {
        return (entry.hdr_size ? entry.hdr_size : sizeof(entry_v1)) + entry.len;
        return (entry.hdr_size ? entry.hdr_size : sizeof(entry_v1)) + entry.len;
    }
    }
+2 −0
Original line number Original line Diff line number Diff line
@@ -76,6 +76,7 @@
#define AID_SDCARD_PICS   1033  /* external storage photos access */
#define AID_SDCARD_PICS   1033  /* external storage photos access */
#define AID_SDCARD_AV     1034  /* external storage audio/video access */
#define AID_SDCARD_AV     1034  /* external storage audio/video access */
#define AID_SDCARD_ALL    1035  /* access all users external storage */
#define AID_SDCARD_ALL    1035  /* access all users external storage */
#define AID_LOGD          1036  /* log daemon */


#define AID_SHELL         2000  /* adb and debug shell user */
#define AID_SHELL         2000  /* adb and debug shell user */
#define AID_CACHE         2001  /* cache access */
#define AID_CACHE         2001  /* cache access */
@@ -151,6 +152,7 @@ static const struct android_id_info android_ids[] = {
    { "sdcard_pics",   AID_SDCARD_PICS, },
    { "sdcard_pics",   AID_SDCARD_PICS, },
    { "sdcard_av",     AID_SDCARD_AV, },
    { "sdcard_av",     AID_SDCARD_AV, },
    { "sdcard_all",    AID_SDCARD_ALL, },
    { "sdcard_all",    AID_SDCARD_ALL, },
    { "logd",          AID_LOGD, },


    { "shell",         AID_SHELL, },
    { "shell",         AID_SHELL, },
    { "cache",         AID_CACHE, },
    { "cache",         AID_CACHE, },
+95 −9
Original line number Original line Diff line number Diff line
@@ -319,12 +319,16 @@ static void caught_blocking(int signum)


TEST(logcat, blocking) {
TEST(logcat, blocking) {
    FILE *fp;
    FILE *fp;
    unsigned long long v = 0xDEADBEEFA55A0000ULL;
    unsigned long long v = 0xDEADBEEFA55F0000ULL;


    pid_t pid = getpid();
    pid_t pid = getpid();


    v += pid & 0xFFFF;
    v += pid & 0xFFFF;


    LOG_FAILURE_RETRY(__android_log_btwrite(0, EVENT_TYPE_LONG, &v, sizeof(v)));

    v &= 0xFFFFFFFFFFFAFFFFULL;

    ASSERT_EQ(0, NULL == (fp = popen(
    ASSERT_EQ(0, NULL == (fp = popen(
      "( trap exit HUP QUIT INT PIPE KILL ; sleep 6; echo DONE )&"
      "( trap exit HUP QUIT INT PIPE KILL ; sleep 6; echo DONE )&"
      " logcat -b events 2>&1",
      " logcat -b events 2>&1",
@@ -341,12 +345,12 @@ TEST(logcat, blocking) {
    while (fgets(buffer, sizeof(buffer), fp)) {
    while (fgets(buffer, sizeof(buffer), fp)) {
        alarm(2);
        alarm(2);


        ++count;

        if (!strncmp(buffer, "DONE", 4)) {
        if (!strncmp(buffer, "DONE", 4)) {
            break;
            break;
        }
        }


        ++count;

        int p;
        int p;
        unsigned long long l;
        unsigned long long l;


@@ -369,7 +373,7 @@ TEST(logcat, blocking) {


    pclose(fp);
    pclose(fp);


    ASSERT_LT(10, count);
    ASSERT_LE(2, count);


    ASSERT_EQ(1, signals);
    ASSERT_EQ(1, signals);
}
}
@@ -385,12 +389,16 @@ static void caught_blocking_tail(int signum)


TEST(logcat, blocking_tail) {
TEST(logcat, blocking_tail) {
    FILE *fp;
    FILE *fp;
    unsigned long long v = 0xA55ADEADBEEF0000ULL;
    unsigned long long v = 0xA55FDEADBEEF0000ULL;


    pid_t pid = getpid();
    pid_t pid = getpid();


    v += pid & 0xFFFF;
    v += pid & 0xFFFF;


    LOG_FAILURE_RETRY(__android_log_btwrite(0, EVENT_TYPE_LONG, &v, sizeof(v)));

    v &= 0xFFFAFFFFFFFFFFFFULL;

    ASSERT_EQ(0, NULL == (fp = popen(
    ASSERT_EQ(0, NULL == (fp = popen(
      "( trap exit HUP QUIT INT PIPE KILL ; sleep 6; echo DONE )&"
      "( trap exit HUP QUIT INT PIPE KILL ; sleep 6; echo DONE )&"
      " logcat -b events -T 5 2>&1",
      " logcat -b events -T 5 2>&1",
@@ -407,12 +415,12 @@ TEST(logcat, blocking_tail) {
    while (fgets(buffer, sizeof(buffer), fp)) {
    while (fgets(buffer, sizeof(buffer), fp)) {
        alarm(2);
        alarm(2);


        ++count;

        if (!strncmp(buffer, "DONE", 4)) {
        if (!strncmp(buffer, "DONE", 4)) {
            break;
            break;
        }
        }


        ++count;

        int p;
        int p;
        unsigned long long l;
        unsigned long long l;


@@ -431,13 +439,91 @@ TEST(logcat, blocking_tail) {
    alarm(0);
    alarm(0);
    signal(SIGALRM, SIG_DFL);
    signal(SIGALRM, SIG_DFL);


    /* Generate SIGPIPE */
    // Generate SIGPIPE
    fclose(fp);
    fclose(fp);
    caught_blocking_tail(0);
    caught_blocking_tail(0);


    pclose(fp);
    pclose(fp);


    ASSERT_LT(5, count);
    ASSERT_LE(2, count);

    ASSERT_EQ(1, signals);
}

static void caught_blocking_clear(int signum)
{
    unsigned long long v = 0xDEADBEEFA55C0000ULL;

    v += getpid() & 0xFFFF;

    LOG_FAILURE_RETRY(__android_log_btwrite(0, EVENT_TYPE_LONG, &v, sizeof(v)));
}

TEST(logcat, blocking_clear) {
    FILE *fp;
    unsigned long long v = 0xDEADBEEFA55C0000ULL;

    pid_t pid = getpid();

    v += pid & 0xFFFF;

    // This test is racey; an event occurs between clear and dump.
    // We accept that we will get a false positive, but never a false negative.
    ASSERT_EQ(0, NULL == (fp = popen(
      "( trap exit HUP QUIT INT PIPE KILL ; sleep 6; echo DONE )&"
      " logcat -b events -c 2>&1 ;"
      " logcat -b events 2>&1",
      "r")));

    char buffer[5120];

    int count = 0;

    int signals = 0;

    signal(SIGALRM, caught_blocking_clear);
    alarm(2);
    while (fgets(buffer, sizeof(buffer), fp)) {
        alarm(2);

        if (!strncmp(buffer, "clearLog: ", 10)) {
            fprintf(stderr, "WARNING: Test lacks permission to run :-(\n");
            count = signals = 1;
            break;
        }

        if (!strncmp(buffer, "DONE", 4)) {
            break;
        }

        ++count;

        int p;
        unsigned long long l;

        if ((2 != sscanf(buffer, "I/[0] ( %u): %lld", &p, &l))
         || (p != pid)) {
            continue;
        }

        if (l == v) {
            if (count > 1) {
                fprintf(stderr, "WARNING: Possible false positive\n");
            }
            ++signals;
            break;
        }
    }
    alarm(0);
    signal(SIGALRM, SIG_DFL);

    // Generate SIGPIPE
    fclose(fp);
    caught_blocking_clear(0);

    pclose(fp);

    ASSERT_LE(1, count);


    ASSERT_EQ(1, signals);
    ASSERT_EQ(1, signals);
}
}

logd/Android.mk

0 → 100644
+28 −0
Original line number Original line Diff line number Diff line
LOCAL_PATH:= $(call my-dir)

include $(CLEAR_VARS)

LOCAL_MODULE:= logd

LOCAL_SRC_FILES := \
    main.cpp \
    LogCommand.cpp \
    CommandListener.cpp \
    LogListener.cpp \
    LogReader.cpp \
    FlushCommand.cpp \
    LogBuffer.cpp \
    LogBufferElement.cpp \
    LogTimes.cpp

LOCAL_C_INCLUDES := $(KERNEL_HEADERS)

LOCAL_SHARED_LIBRARIES := \
    libsysutils \
    liblog \
    libcutils

LOCAL_MODULE_TAGS := optional

include $(BUILD_EXECUTABLE)
Loading