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

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

Merge changes Iec369a50,I78959464,I3f9f8d56 into oc-dev

* changes:
  logd: instrument tests better for failure
  logd: iterator corruption paranoia
  liblog: log_time add explicit to some constructors.
parents 1b089530 0a0a4652
Loading
Loading
Loading
Loading
+7 −8
Original line number Diff line number Diff line
@@ -41,13 +41,12 @@ struct log_time {
  static const uint32_t tv_sec_max = 0xFFFFFFFFUL;
  static const uint32_t tv_nsec_max = 999999999UL;

  log_time(const timespec& T) {
    tv_sec = static_cast<uint32_t>(T.tv_sec);
    tv_nsec = static_cast<uint32_t>(T.tv_nsec);
  log_time(const timespec& T)
      : tv_sec(static_cast<uint32_t>(T.tv_sec)),
        tv_nsec(static_cast<uint32_t>(T.tv_nsec)) {
  }
  log_time(uint32_t sec, uint32_t nsec) {
    tv_sec = sec;
    tv_nsec = nsec;
  explicit log_time(uint32_t sec, uint32_t nsec = 0)
      : tv_sec(sec), tv_nsec(nsec) {
  }
#ifdef _SYSTEM_CORE_INCLUDE_PRIVATE_ANDROID_LOGGER_H_
#define __struct_log_time_private_defined
@@ -56,14 +55,14 @@ struct log_time {
  log_time() {
  }
#ifdef __linux__
  log_time(clockid_t id) {
  explicit log_time(clockid_t id) {
    timespec T;
    clock_gettime(id, &T);
    tv_sec = static_cast<uint32_t>(T.tv_sec);
    tv_nsec = static_cast<uint32_t>(T.tv_nsec);
  }
#endif
  log_time(const char* T) {
  explicit log_time(const char* T) {
    const uint8_t* c = reinterpret_cast<const uint8_t*>(T);
    tv_sec = c[0] | (static_cast<uint32_t>(c[1]) << 8) |
             (static_cast<uint32_t>(c[2]) << 16) |
+14 −0
Original line number Diff line number Diff line
@@ -1120,9 +1120,22 @@ log_time LogBuffer::flushTo(SocketClient* reader, const log_time& start,

    log_time max = start;

    LogBufferElement* lastElement = nullptr;  // iterator corruption paranoia
    static const size_t maxSkip = 4194304;    // maximum entries to skip
    size_t skip = maxSkip;
    for (; it != mLogElements.end(); ++it) {
        LogBufferElement* element = *it;

        if (!--skip) {
            android::prdebug("reader.per: too many elements skipped");
            break;
        }
        if (element == lastElement) {
            android::prdebug("reader.per: identical elements");
            break;
        }
        lastElement = element;

        if (!privileged && (element->getUid() != uid)) {
            continue;
        }
@@ -1167,6 +1180,7 @@ log_time LogBuffer::flushTo(SocketClient* reader, const log_time& start,
            return max;
        }

        skip = maxSkip;
        pthread_mutex_lock(&mLogElementsLock);
    }
    pthread_mutex_unlock(&mLogElementsLock);
+12 −4
Original line number Diff line number Diff line
@@ -668,8 +668,12 @@ TEST(logd, timeout) {
    while (--i) {
        int fd = socket_local_client("logdr", ANDROID_SOCKET_NAMESPACE_RESERVED,
                                     SOCK_SEQPACKET);
        EXPECT_LT(0, fd);
        if (fd < 0) _exit(fd);
        int save_errno = errno;
        if (fd < 0) {
            fprintf(stderr, "failed to open /dev/socket/logdr %s\n",
                    strerror(save_errno));
            _exit(fd);
        }

        std::string ask = android::base::StringPrintf(
            "dumpAndClose lids=0,1,2,3,4,5 timeout=6 start=%" PRIu32
@@ -721,8 +725,12 @@ TEST(logd, timeout) {
        // active _or_ inactive during the test.
        if (content_timeout) {
            log_time msg(msg_timeout.entry.sec, msg_timeout.entry.nsec);
            EXPECT_FALSE(msg < now);
            if (msg < now) _exit(-1);
            if (msg < now) {
                fprintf(stderr, "%u.%09u < %u.%09u\n", msg_timeout.entry.sec,
                        msg_timeout.entry.nsec, (unsigned)now.tv_sec,
                        (unsigned)now.tv_nsec);
                _exit(-1);
            }
            if (msg > now) {
                now = msg;
                now.tv_sec += 30;