blob: 4c0975155256c7612b98901cf3c6a6d7ba0ecdaf [file] [log] [blame]
Mark Salyzyne73a18b2014-10-15 08:49:39 -07001/*
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
Mark Salyzyn8b8bfd22016-09-30 13:30:33 -070020#include <private/android_logger.h>
Mark Salyzyne73a18b2014-10-15 08:49:39 -070021#include <sysutils/SocketListener.h>
Mark Salyzyne73a18b2014-10-15 08:49:39 -070022
Mark Salyzyna92051d2016-02-23 08:55:43 -080023class LogBuffer;
24class LogReader;
25
Mark Salyzyne73a18b2014-10-15 08:49:39 -070026class LogKlog : public SocketListener {
Mark Salyzyn65059532017-03-10 14:31:54 -080027 LogBuffer* logbuf;
28 LogReader* reader;
Mark Salyzyne73a18b2014-10-15 08:49:39 -070029 const log_time signature;
Mark Salyzyne73a18b2014-10-15 08:49:39 -070030 // 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
Mark Salyzyn65059532017-03-10 14:31:54 -080041 public:
42 LogKlog(LogBuffer* buf, LogReader* reader, int fdWrite, int fdRead,
43 bool auditd);
Mark Salyzyn530bd6c2016-08-11 08:02:06 -070044 int log(const char* buf, ssize_t len);
Mark Salyzyne73a18b2014-10-15 08:49:39 -070045
Mark Salyzyn65059532017-03-10 14:31:54 -080046 static void convertMonotonicToReal(log_time& real) {
47 real += correction;
48 }
Mark Salyzyne73a18b2014-10-15 08:49:39 -070049
Mark Salyzyn65059532017-03-10 14:31:54 -080050 protected:
Bernie Innocenti440e0352019-01-16 15:25:18 +090051 log_time sniffTime(const char*& buf, ssize_t len, bool reverse);
52 pid_t sniffPid(const char*& buf, ssize_t len);
53 void calculateCorrection(const log_time& monotonic, const char* real_string, ssize_t len);
54 virtual bool onDataAvailable(SocketClient* cli);
Mark Salyzyne73a18b2014-10-15 08:49:39 -070055};
56
57#endif