blob: 77b24bc31f299be65ac10beec935474e235ecbb1 [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
Tom Cherry64e90162020-05-07 14:44:43 -070017#pragma once
Mark Salyzynae4d9282014-10-15 08:49:39 -070018
Mark Salyzynaeaaf812016-09-30 13:30:33 -070019#include <private/android_logger.h>
Mark Salyzynae4d9282014-10-15 08:49:39 -070020#include <sysutils/SocketListener.h>
Mark Salyzynae4d9282014-10-15 08:49:39 -070021
Tom Cherry64e90162020-05-07 14:44:43 -070022#include "LogStatistics.h"
23
Mark Salyzyn317bfb92016-02-23 08:55:43 -080024class LogBuffer;
Mark Salyzyn317bfb92016-02-23 08:55:43 -080025
Mark Salyzynae4d9282014-10-15 08:49:39 -070026class LogKlog : public SocketListener {
Mark Salyzyn501c3732017-03-10 14:31:54 -080027 LogBuffer* logbuf;
Mark Salyzynae4d9282014-10-15 08:49:39 -070028 const log_time signature;
Mark Salyzynae4d9282014-10-15 08:49:39 -070029 // Set once thread is started, separates KLOG_ACTION_READ_ALL
30 // and KLOG_ACTION_READ phases.
31 bool initialized;
32 // Used during each of the above phases to control logging.
33 bool enableLogging;
34 // set if we are also running auditd, to filter out audit reports from
35 // our copy of the kernel log
36 bool auditd;
37
38 static log_time correction;
39
Tom Cherry64e90162020-05-07 14:44:43 -070040 public:
Tom Cherry68630a02020-05-11 16:29:29 -070041 LogKlog(LogBuffer* buf, int fdWrite, int fdRead, bool auditd, LogStatistics* stats);
Mark Salyzyn0484b3b2016-08-11 08:02:06 -070042 int log(const char* buf, ssize_t len);
Mark Salyzynae4d9282014-10-15 08:49:39 -070043
Tom Cherry64e90162020-05-07 14:44:43 -070044 static void convertMonotonicToReal(log_time& real) { real += correction; }
Mark Salyzynae4d9282014-10-15 08:49:39 -070045
Tom Cherry64e90162020-05-07 14:44:43 -070046 protected:
47 log_time sniffTime(const char*& buf, ssize_t len, bool reverse);
48 pid_t sniffPid(const char*& buf, ssize_t len);
49 void calculateCorrection(const log_time& monotonic, const char* real_string, ssize_t len);
50 virtual bool onDataAvailable(SocketClient* cli);
51
52 private:
53 LogStatistics* stats_;
Mark Salyzynae4d9282014-10-15 08:49:39 -070054};