blob: a898c63ae1de26fcf13ed09c177423e7ea796cf5 [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
20#include <sysutils/SocketListener.h>
21#include <log/log_read.h>
22#include "LogReader.h"
23
Mark Salyzyn2c3b3002015-05-22 15:23:44 -070024char *log_strtok_r(char *str, char **saveptr);
25
Mark Salyzynae4d9282014-10-15 08:49:39 -070026class LogKlog : public SocketListener {
27 LogBuffer *logbuf;
28 LogReader *reader;
29 const log_time signature;
30 const int fdWrite; // /dev/kmsg
31 const int fdRead; // /proc/kmsg
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
43public:
44 LogKlog(LogBuffer *buf, LogReader *reader, int fdWrite, int fdRead, bool auditd);
45 int log(const char *buf);
46 void synchronize(const char *buf);
47
48 static void convertMonotonicToReal(log_time &real) { real += correction; }
49
50protected:
51 void sniffTime(log_time &now, const char **buf, bool reverse);
52 void calculateCorrection(const log_time &monotonic, const char *real_string);
53 virtual bool onDataAvailable(SocketClient *cli);
54
55};
56
57#endif