blob: 976afc8af46a3f7a4e5194f15dc4072d778d2f53 [file] [log] [blame]
Mark Salyzynae4d9282014-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 Salyzynaeaaf812016-09-30 13:30:33 -070020#include <private/android_logger.h>
Mark Salyzynae4d9282014-10-15 08:49:39 -070021#include <sysutils/SocketListener.h>
Mark Salyzynae4d9282014-10-15 08:49:39 -070022
Mark Salyzyn501c3732017-03-10 14:31:54 -080023char* log_strntok_r(char* s, size_t* len, char** saveptr, size_t* sublen);
Mark Salyzyn2c3b3002015-05-22 15:23:44 -070024
Mark Salyzyn317bfb92016-02-23 08:55:43 -080025class LogBuffer;
26class LogReader;
27
Mark Salyzynae4d9282014-10-15 08:49:39 -070028class LogKlog : public SocketListener {
Mark Salyzyn501c3732017-03-10 14:31:54 -080029 LogBuffer* logbuf;
30 LogReader* reader;
Mark Salyzynae4d9282014-10-15 08:49:39 -070031 const log_time signature;
Mark Salyzynae4d9282014-10-15 08:49:39 -070032 // Set once thread is started, separates KLOG_ACTION_READ_ALL
33 // and KLOG_ACTION_READ phases.
34 bool initialized;
35 // Used during each of the above phases to control logging.
36 bool enableLogging;
37 // set if we are also running auditd, to filter out audit reports from
38 // our copy of the kernel log
39 bool auditd;
40
41 static log_time correction;
42
Mark Salyzyn501c3732017-03-10 14:31:54 -080043 public:
44 LogKlog(LogBuffer* buf, LogReader* reader, int fdWrite, int fdRead,
45 bool auditd);
46 int log(const char* buf, size_t len);
47 void synchronize(const char* buf, size_t len);
Mark Salyzynae4d9282014-10-15 08:49:39 -070048
Mark Salyzyn501c3732017-03-10 14:31:54 -080049 bool isMonotonic() {
50 return logbuf->isMonotonic();
51 }
52 static void convertMonotonicToReal(log_time& real) {
53 real += correction;
54 }
55 static void convertRealToMonotonic(log_time& real) {
56 real -= correction;
57 }
Mark Salyzynae4d9282014-10-15 08:49:39 -070058
Mark Salyzyn501c3732017-03-10 14:31:54 -080059 protected:
60 void sniffTime(log_time& now, const char** buf, size_t len, bool reverse);
61 pid_t sniffPid(const char** buf, size_t len);
62 void calculateCorrection(const log_time& monotonic, const char* real_string,
63 size_t len);
64 virtual bool onDataAvailable(SocketClient* cli);
Mark Salyzynae4d9282014-10-15 08:49:39 -070065};
66
67#endif