| Mark Salyzyn | ae4d928 | 2014-10-15 08:49:39 -0700 | [diff] [blame] | 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 |  | 
| Tom Cherry | 64e9016 | 2020-05-07 14:44:43 -0700 | [diff] [blame] | 17 | #pragma once | 
| Mark Salyzyn | ae4d928 | 2014-10-15 08:49:39 -0700 | [diff] [blame] | 18 |  | 
| Mark Salyzyn | aeaaf81 | 2016-09-30 13:30:33 -0700 | [diff] [blame] | 19 | #include <private/android_logger.h> | 
| Mark Salyzyn | ae4d928 | 2014-10-15 08:49:39 -0700 | [diff] [blame] | 20 | #include <sysutils/SocketListener.h> | 
| Mark Salyzyn | ae4d928 | 2014-10-15 08:49:39 -0700 | [diff] [blame] | 21 |  | 
| Tom Cherry | 283c9a1 | 2020-05-14 19:25:05 -0700 | [diff] [blame] | 22 | #include "LogBuffer.h" | 
| Tom Cherry | 64e9016 | 2020-05-07 14:44:43 -0700 | [diff] [blame] | 23 | #include "LogStatistics.h" | 
|  | 24 |  | 
| Mark Salyzyn | ae4d928 | 2014-10-15 08:49:39 -0700 | [diff] [blame] | 25 | class LogKlog : public SocketListener { | 
| Mark Salyzyn | 501c373 | 2017-03-10 14:31:54 -0800 | [diff] [blame] | 26 | LogBuffer* logbuf; | 
| Mark Salyzyn | ae4d928 | 2014-10-15 08:49:39 -0700 | [diff] [blame] | 27 | const log_time signature; | 
| Mark Salyzyn | ae4d928 | 2014-10-15 08:49:39 -0700 | [diff] [blame] | 28 | // Set once thread is started, separates KLOG_ACTION_READ_ALL | 
|  | 29 | // and KLOG_ACTION_READ phases. | 
|  | 30 | bool initialized; | 
|  | 31 | // Used during each of the above phases to control logging. | 
|  | 32 | bool enableLogging; | 
|  | 33 | // set if we are also running auditd, to filter out audit reports from | 
|  | 34 | // our copy of the kernel log | 
|  | 35 | bool auditd; | 
|  | 36 |  | 
|  | 37 | static log_time correction; | 
|  | 38 |  | 
| Tom Cherry | 64e9016 | 2020-05-07 14:44:43 -0700 | [diff] [blame] | 39 | public: | 
| Tom Cherry | 68630a0 | 2020-05-11 16:29:29 -0700 | [diff] [blame] | 40 | LogKlog(LogBuffer* buf, int fdWrite, int fdRead, bool auditd, LogStatistics* stats); | 
| Mark Salyzyn | 0484b3b | 2016-08-11 08:02:06 -0700 | [diff] [blame] | 41 | int log(const char* buf, ssize_t len); | 
| Mark Salyzyn | ae4d928 | 2014-10-15 08:49:39 -0700 | [diff] [blame] | 42 |  | 
| Tom Cherry | 64e9016 | 2020-05-07 14:44:43 -0700 | [diff] [blame] | 43 | static void convertMonotonicToReal(log_time& real) { real += correction; } | 
| Mark Salyzyn | ae4d928 | 2014-10-15 08:49:39 -0700 | [diff] [blame] | 44 |  | 
| Tom Cherry | 64e9016 | 2020-05-07 14:44:43 -0700 | [diff] [blame] | 45 | protected: | 
|  | 46 | log_time sniffTime(const char*& buf, ssize_t len, bool reverse); | 
|  | 47 | pid_t sniffPid(const char*& buf, ssize_t len); | 
|  | 48 | void calculateCorrection(const log_time& monotonic, const char* real_string, ssize_t len); | 
|  | 49 | virtual bool onDataAvailable(SocketClient* cli); | 
|  | 50 |  | 
|  | 51 | private: | 
|  | 52 | LogStatistics* stats_; | 
| Mark Salyzyn | ae4d928 | 2014-10-15 08:49:39 -0700 | [diff] [blame] | 53 | }; |