summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--logd/Android.mk39
-rw-r--r--logd/LogBuffer.h7
-rw-r--r--logd/LogBufferInterface.cpp22
-rw-r--r--logd/LogBufferInterface.h40
-rw-r--r--logd/LogListener.cpp15
-rw-r--r--logd/LogListener.h4
6 files changed, 106 insertions, 21 deletions
diff --git a/logd/Android.mk b/logd/Android.mk
index 9211037bb..fb51992ef 100644
--- a/logd/Android.mk
+++ b/logd/Android.mk
@@ -2,12 +2,9 @@ LOCAL_PATH:= $(call my-dir)
2 2
3include $(CLEAR_VARS) 3include $(CLEAR_VARS)
4 4
5LOCAL_MODULE:= logd 5LOCAL_MODULE:= liblogd
6
7LOCAL_INIT_RC := logd.rc
8 6
9LOCAL_SRC_FILES := \ 7LOCAL_SRC_FILES := \
10 main.cpp \
11 LogCommand.cpp \ 8 LogCommand.cpp \
12 CommandListener.cpp \ 9 CommandListener.cpp \
13 LogListener.cpp \ 10 LogListener.cpp \
@@ -15,6 +12,7 @@ LOCAL_SRC_FILES := \
15 FlushCommand.cpp \ 12 FlushCommand.cpp \
16 LogBuffer.cpp \ 13 LogBuffer.cpp \
17 LogBufferElement.cpp \ 14 LogBufferElement.cpp \
15 LogBufferInterface.cpp \
18 LogTimes.cpp \ 16 LogTimes.cpp \
19 LogStatistics.cpp \ 17 LogStatistics.cpp \
20 LogWhiteBlackList.cpp \ 18 LogWhiteBlackList.cpp \
@@ -25,12 +23,9 @@ LOCAL_SRC_FILES := \
25 event.logtags 23 event.logtags
26 24
27LOCAL_SHARED_LIBRARIES := \ 25LOCAL_SHARED_LIBRARIES := \
28 libsysutils \ 26 libbase
29 liblog \ 27
30 libcutils \ 28LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH)
31 libbase \
32 libpackagelistparser \
33 libcap
34 29
35# This is what we want to do: 30# This is what we want to do:
36# event_logtags = $(shell \ 31# event_logtags = $(shell \
@@ -46,6 +41,30 @@ event_flag += -DLIBLOG_LOG_TAG=1006
46 41
47LOCAL_CFLAGS := -Werror $(event_flag) 42LOCAL_CFLAGS := -Werror $(event_flag)
48 43
44include $(BUILD_STATIC_LIBRARY)
45
46include $(CLEAR_VARS)
47
48LOCAL_MODULE:= logd
49
50LOCAL_INIT_RC := logd.rc
51
52LOCAL_SRC_FILES := \
53 main.cpp
54
55LOCAL_STATIC_LIBRARIES := \
56 liblogd
57
58LOCAL_SHARED_LIBRARIES := \
59 libsysutils \
60 liblog \
61 libcutils \
62 libbase \
63 libpackagelistparser \
64 libcap
65
66LOCAL_CFLAGS := -Werror
67
49include $(BUILD_EXECUTABLE) 68include $(BUILD_EXECUTABLE)
50 69
51include $(CLEAR_VARS) 70include $(CLEAR_VARS)
diff --git a/logd/LogBuffer.h b/logd/LogBuffer.h
index 51edd8628..e59775488 100644
--- a/logd/LogBuffer.h
+++ b/logd/LogBuffer.h
@@ -27,6 +27,7 @@
27#include <sysutils/SocketClient.h> 27#include <sysutils/SocketClient.h>
28 28
29#include "LogBufferElement.h" 29#include "LogBufferElement.h"
30#include "LogBufferInterface.h"
30#include "LogStatistics.h" 31#include "LogStatistics.h"
31#include "LogTags.h" 32#include "LogTags.h"
32#include "LogTimes.h" 33#include "LogTimes.h"
@@ -74,7 +75,7 @@ static bool isMonotonic(const log_time& mono) {
74 75
75typedef std::list<LogBufferElement*> LogBufferElementCollection; 76typedef std::list<LogBufferElement*> LogBufferElementCollection;
76 77
77class LogBuffer { 78class LogBuffer : public LogBufferInterface {
78 LogBufferElementCollection mLogElements; 79 LogBufferElementCollection mLogElements;
79 pthread_rwlock_t mLogElementsLock; 80 pthread_rwlock_t mLogElementsLock;
80 81
@@ -107,14 +108,14 @@ class LogBuffer {
107 LastLogTimes& mTimes; 108 LastLogTimes& mTimes;
108 109
109 explicit LogBuffer(LastLogTimes* times); 110 explicit LogBuffer(LastLogTimes* times);
110 ~LogBuffer(); 111 ~LogBuffer() override;
111 void init(); 112 void init();
112 bool isMonotonic() { 113 bool isMonotonic() {
113 return monotonic; 114 return monotonic;
114 } 115 }
115 116
116 int log(log_id_t log_id, log_time realtime, uid_t uid, pid_t pid, pid_t tid, 117 int log(log_id_t log_id, log_time realtime, uid_t uid, pid_t pid, pid_t tid,
117 const char* msg, unsigned short len); 118 const char* msg, unsigned short len) override;
118 // lastTid is an optional context to help detect if the last previous 119 // lastTid is an optional context to help detect if the last previous
119 // valid message was from the same source so we can differentiate chatty 120 // valid message was from the same source so we can differentiate chatty
120 // filter types (identical or expired) 121 // filter types (identical or expired)
diff --git a/logd/LogBufferInterface.cpp b/logd/LogBufferInterface.cpp
new file mode 100644
index 000000000..3cb2b898f
--- /dev/null
+++ b/logd/LogBufferInterface.cpp
@@ -0,0 +1,22 @@
1/*
2 * Copyright (C) 2017 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#include "LogBufferInterface.h"
18
19LogBufferInterface::LogBufferInterface() {
20}
21LogBufferInterface::~LogBufferInterface() {
22} \ No newline at end of file
diff --git a/logd/LogBufferInterface.h b/logd/LogBufferInterface.h
new file mode 100644
index 000000000..7d82b91f3
--- /dev/null
+++ b/logd/LogBufferInterface.h
@@ -0,0 +1,40 @@
1/*
2 * Copyright (C) 2012-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_BUFFER_INTERFACE_H__
18#define _LOGD_LOG_BUFFER_INTERFACE_H__
19
20#include <sys/types.h>
21
22#include <android-base/macros.h>
23#include <log/log_id.h>
24#include <log/log_time.h>
25
26// Abstract interface that handles log when log available.
27class LogBufferInterface {
28 public:
29 LogBufferInterface();
30 virtual ~LogBufferInterface();
31 // Handles a log entry when available in LogListener.
32 // Returns the size of the handled log message.
33 virtual int log(log_id_t log_id, log_time realtime, uid_t uid, pid_t pid,
34 pid_t tid, const char* msg, unsigned short len) = 0;
35
36 private:
37 DISALLOW_COPY_AND_ASSIGN(LogBufferInterface);
38};
39
40#endif // _LOGD_LOG_BUFFER_INTERFACE_H__
diff --git a/logd/LogListener.cpp b/logd/LogListener.cpp
index dadc75f4c..709646e37 100644
--- a/logd/LogListener.cpp
+++ b/logd/LogListener.cpp
@@ -30,7 +30,7 @@
30#include "LogListener.h" 30#include "LogListener.h"
31#include "LogUtils.h" 31#include "LogUtils.h"
32 32
33LogListener::LogListener(LogBuffer* buf, LogReader* reader) 33LogListener::LogListener(LogBufferInterface* buf, LogReader* reader)
34 : SocketListener(getLogSocket(), false), logbuf(buf), reader(reader) { 34 : SocketListener(getLogSocket(), false), logbuf(buf), reader(reader) {
35} 35}
36 36
@@ -102,11 +102,14 @@ bool LogListener::onDataAvailable(SocketClient* cli) {
102 // NB: hdr.msg_flags & MSG_TRUNC is not tested, silently passing a 102 // NB: hdr.msg_flags & MSG_TRUNC is not tested, silently passing a
103 // truncated message to the logs. 103 // truncated message to the logs.
104 104
105 if (logbuf->log((log_id_t)header->id, header->realtime, cred->uid, 105 if (logbuf != nullptr) {
106 cred->pid, header->tid, msg, 106 int res = logbuf->log(
107 ((size_t)n <= USHRT_MAX) ? (unsigned short)n : USHRT_MAX) >= 107 (log_id_t)header->id, header->realtime, cred->uid, cred->pid,
108 0) { 108 header->tid, msg,
109 reader->notifyNewLog(); 109 ((size_t)n <= USHRT_MAX) ? (unsigned short)n : USHRT_MAX);
110 if (res > 0 && reader != nullptr) {
111 reader->notifyNewLog();
112 }
110 } 113 }
111 114
112 return true; 115 return true;
diff --git a/logd/LogListener.h b/logd/LogListener.h
index 2973b8bd3..e16c5fb62 100644
--- a/logd/LogListener.h
+++ b/logd/LogListener.h
@@ -21,11 +21,11 @@
21#include "LogReader.h" 21#include "LogReader.h"
22 22
23class LogListener : public SocketListener { 23class LogListener : public SocketListener {
24 LogBuffer* logbuf; 24 LogBufferInterface* logbuf;
25 LogReader* reader; 25 LogReader* reader;
26 26
27 public: 27 public:
28 LogListener(LogBuffer* buf, LogReader* reader); 28 LogListener(LogBufferInterface* buf, LogReader* reader /* nullable */);
29 29
30 protected: 30 protected:
31 virtual bool onDataAvailable(SocketClient* cli); 31 virtual bool onDataAvailable(SocketClient* cli);