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 | |
| 17 | #ifndef _LOGD_LOG_KLOG_H__ |
| 18 | #define _LOGD_LOG_KLOG_H__ |
| 19 | |
Mark Salyzyn | aeaaf81 | 2016-09-30 13:30:33 -0700 | [diff] [blame] | 20 | #include <private/android_logger.h> |
Mark Salyzyn | ae4d928 | 2014-10-15 08:49:39 -0700 | [diff] [blame] | 21 | #include <sysutils/SocketListener.h> |
Mark Salyzyn | ae4d928 | 2014-10-15 08:49:39 -0700 | [diff] [blame] | 22 | |
Mark Salyzyn | ea1a241 | 2015-09-02 07:39:53 -0700 | [diff] [blame] | 23 | char *log_strntok_r(char *s, size_t *len, char **saveptr, size_t *sublen); |
Mark Salyzyn | 2c3b300 | 2015-05-22 15:23:44 -0700 | [diff] [blame] | 24 | |
Mark Salyzyn | 317bfb9 | 2016-02-23 08:55:43 -0800 | [diff] [blame] | 25 | class LogBuffer; |
| 26 | class LogReader; |
| 27 | |
Mark Salyzyn | ae4d928 | 2014-10-15 08:49:39 -0700 | [diff] [blame] | 28 | class LogKlog : public SocketListener { |
| 29 | LogBuffer *logbuf; |
| 30 | LogReader *reader; |
| 31 | const log_time signature; |
Mark Salyzyn | ae4d928 | 2014-10-15 08:49:39 -0700 | [diff] [blame] | 32 | // 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 | |
| 43 | public: |
| 44 | LogKlog(LogBuffer *buf, LogReader *reader, int fdWrite, int fdRead, bool auditd); |
Mark Salyzyn | 151beac | 2015-09-04 11:37:42 -0700 | [diff] [blame] | 45 | int log(const char *buf, size_t len); |
| 46 | void synchronize(const char *buf, size_t len); |
Mark Salyzyn | ae4d928 | 2014-10-15 08:49:39 -0700 | [diff] [blame] | 47 | |
Mark Salyzyn | b6bee33 | 2015-09-08 08:56:32 -0700 | [diff] [blame] | 48 | bool isMonotonic() { return logbuf->isMonotonic(); } |
Mark Salyzyn | ae4d928 | 2014-10-15 08:49:39 -0700 | [diff] [blame] | 49 | static void convertMonotonicToReal(log_time &real) { real += correction; } |
Mark Salyzyn | b6bee33 | 2015-09-08 08:56:32 -0700 | [diff] [blame] | 50 | static void convertRealToMonotonic(log_time &real) { real -= correction; } |
Mark Salyzyn | ae4d928 | 2014-10-15 08:49:39 -0700 | [diff] [blame] | 51 | |
| 52 | protected: |
Mark Salyzyn | 151beac | 2015-09-04 11:37:42 -0700 | [diff] [blame] | 53 | void sniffTime(log_time &now, const char **buf, size_t len, bool reverse); |
Mark Salyzyn | 0b4a63d | 2016-07-15 08:54:03 -0700 | [diff] [blame] | 54 | pid_t sniffPid(const char **buf, size_t len); |
Mark Salyzyn | 151beac | 2015-09-04 11:37:42 -0700 | [diff] [blame] | 55 | void calculateCorrection(const log_time &monotonic, |
| 56 | const char *real_string, size_t len); |
Mark Salyzyn | ae4d928 | 2014-10-15 08:49:39 -0700 | [diff] [blame] | 57 | virtual bool onDataAvailable(SocketClient *cli); |
| 58 | |
| 59 | }; |
| 60 | |
| 61 | #endif |