Home | History | Annotate | Download | only in logd
      1 /*
      2  * Copyright (C) 2014 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 #ifndef _LOGD_LOG_KLOG_H__
     18 #define _LOGD_LOG_KLOG_H__
     19 
     20 #include <private/android_logger.h>
     21 #include <sysutils/SocketListener.h>
     22 
     23 class LogBuffer;
     24 class LogReader;
     25 
     26 class LogKlog : public SocketListener {
     27     LogBuffer* logbuf;
     28     LogReader* reader;
     29     const log_time signature;
     30     // Set once thread is started, separates KLOG_ACTION_READ_ALL
     31     // and KLOG_ACTION_READ phases.
     32     bool initialized;
     33     // Used during each of the above phases to control logging.
     34     bool enableLogging;
     35     // set if we are also running auditd, to filter out audit reports from
     36     // our copy of the kernel log
     37     bool auditd;
     38 
     39     static log_time correction;
     40 
     41    public:
     42     LogKlog(LogBuffer* buf, LogReader* reader, int fdWrite, int fdRead,
     43             bool auditd);
     44     int log(const char* buf, ssize_t len);
     45     void synchronize(const char* buf, ssize_t len);
     46 
     47     bool isMonotonic() {
     48         return logbuf->isMonotonic();
     49     }
     50     static void convertMonotonicToReal(log_time& real) {
     51         real += correction;
     52     }
     53     static void convertRealToMonotonic(log_time& real) {
     54         real -= correction;
     55     }
     56 
     57    protected:
     58     void sniffTime(log_time& now, const char*& buf, ssize_t len, bool reverse);
     59     pid_t sniffPid(const char*& buf, ssize_t len);
     60     void calculateCorrection(const log_time& monotonic, const char* real_string,
     61                              ssize_t len);
     62     virtual bool onDataAvailable(SocketClient* cli);
     63 };
     64 
     65 #endif
     66