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

Commit c9fa42c0 authored by Tom Cherry's avatar Tom Cherry
Browse files

logd: wait for timeout via CLOCK_MONOTONIC

There are well known issues with CLOCK_REALTIME jumping drastically.

Test: --wrap works successfully
Change-Id: I5676274783ac9aa9374d2b9254e0109d883cc5a8
parent cda0ee3d
Loading
Loading
Loading
Loading
+1 −2
Original line number Diff line number Diff line
@@ -89,8 +89,7 @@ bool LogReader::onDataAvailable(SocketClient* cli) {
    static const char _timeout[] = " timeout=";
    cp = strstr(buffer, _timeout);
    if (cp) {
        timeout = atol(cp + sizeof(_timeout) - 1) * NS_PER_SEC +
                  log_time(CLOCK_REALTIME).nsec();
        timeout = atol(cp + sizeof(_timeout) - 1) * NS_PER_SEC + log_time(CLOCK_MONOTONIC).nsec();
    }

    unsigned int logMask = -1;
+6 −7
Original line number Diff line number Diff line
@@ -27,9 +27,9 @@

pthread_mutex_t LogTimeEntry::timesLock = PTHREAD_MUTEX_INITIALIZER;

LogTimeEntry::LogTimeEntry(LogReader& reader, SocketClient* client,
                           bool nonBlock, unsigned long tail, log_mask_t logMask,
                           pid_t pid, log_time start, uint64_t timeout)
LogTimeEntry::LogTimeEntry(LogReader& reader, SocketClient* client, bool nonBlock,
                           unsigned long tail, log_mask_t logMask, pid_t pid, log_time start,
                           uint64_t timeout)
    : leadingDropped(false),
      mReader(reader),
      mLogMask(logMask),
@@ -39,8 +39,7 @@ LogTimeEntry::LogTimeEntry(LogReader& reader, SocketClient* client,
      mIndex(0),
      mClient(client),
      mStart(start),
      mNonBlock(nonBlock),
      mEnd(log_time(android_log_clockid())) {
      mNonBlock(nonBlock) {
    mTimeout.tv_sec = timeout / NS_PER_SEC;
    mTimeout.tv_nsec = timeout % NS_PER_SEC;
    memset(mLastTid, 0, sizeof(mLastTid));
@@ -85,8 +84,8 @@ void* LogTimeEntry::threadStart(void* obj) {

    while (!me->mRelease) {
        if (me->mTimeout.tv_sec || me->mTimeout.tv_nsec) {
            if (pthread_cond_timedwait(&me->threadTriggeredCondition,
                                       &timesLock, &me->mTimeout) == ETIMEDOUT) {
            if (pthread_cond_clockwait(&me->threadTriggeredCondition, &timesLock, CLOCK_MONOTONIC,
                                       &me->mTimeout) == ETIMEDOUT) {
                me->mTimeout.tv_sec = 0;
                me->mTimeout.tv_nsec = 0;
            }
+1 −2
Original line number Diff line number Diff line
@@ -56,9 +56,8 @@ class LogTimeEntry {

    SocketClient* mClient;
    log_time mStart;
    struct timespec mTimeout;
    struct timespec mTimeout;  // CLOCK_MONOTONIC based timeout used for log wrapping.
    const bool mNonBlock;
    const log_time mEnd;  // only relevant if mNonBlock

    // Protect List manipulations
    static void wrlock(void) {