blob: 145c01b7f2731ca1078e46890238bf2be7bfc524 [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
Tom Cherry479b5032020-05-07 14:44:43 -070017#pragma once
Mark Salyzyne73a18b2014-10-15 08:49:39 -070018
Mark Salyzyn8b8bfd22016-09-30 13:30:33 -070019#include <private/android_logger.h>
Mark Salyzyne73a18b2014-10-15 08:49:39 -070020#include <sysutils/SocketListener.h>
Mark Salyzyne73a18b2014-10-15 08:49:39 -070021
Tom Cherryadf2e442020-05-14 19:25:05 -070022#include "LogBuffer.h"
Tom Cherry479b5032020-05-07 14:44:43 -070023#include "LogStatistics.h"
24
Mark Salyzyne73a18b2014-10-15 08:49:39 -070025class LogKlog : public SocketListener {
Mark Salyzyn65059532017-03-10 14:31:54 -080026 LogBuffer* logbuf;
Mark Salyzyne73a18b2014-10-15 08:49:39 -070027 const log_time signature;
Mark Salyzyne73a18b2014-10-15 08:49:39 -070028 // Set once thread is started, separates KLOG_ACTION_READ_ALL
29 // and KLOG_ACTION_READ phases.
30 bool initialized;
Mark Salyzyne73a18b2014-10-15 08:49:39 -070031 // set if we are also running auditd, to filter out audit reports from
32 // our copy of the kernel log
33 bool auditd;
34
35 static log_time correction;
36
Tom Cherry479b5032020-05-07 14:44:43 -070037 public:
Tom Cherry5ecfbf02020-05-11 16:29:29 -070038 LogKlog(LogBuffer* buf, int fdWrite, int fdRead, bool auditd, LogStatistics* stats);
Mark Salyzyn530bd6c2016-08-11 08:02:06 -070039 int log(const char* buf, ssize_t len);
Mark Salyzyne73a18b2014-10-15 08:49:39 -070040
Tom Cherry479b5032020-05-07 14:44:43 -070041 static void convertMonotonicToReal(log_time& real) { real += correction; }
Mark Salyzyne73a18b2014-10-15 08:49:39 -070042
Tom Cherry479b5032020-05-07 14:44:43 -070043 protected:
44 log_time sniffTime(const char*& buf, ssize_t len, bool reverse);
45 pid_t sniffPid(const char*& buf, ssize_t len);
46 void calculateCorrection(const log_time& monotonic, const char* real_string, ssize_t len);
47 virtual bool onDataAvailable(SocketClient* cli);
48
49 private:
50 LogStatistics* stats_;
Mark Salyzyne73a18b2014-10-15 08:49:39 -070051};