Merge "Modularize logd." am: ab28acef76
am: c955d890de
Change-Id: I2ab27da508f2a1212d3c0617bbf5037665cf3737
This commit is contained in:
commit
e49500a041
6 changed files with 106 additions and 21 deletions
|
|
@ -2,12 +2,9 @@ LOCAL_PATH:= $(call my-dir)
|
||||||
|
|
||||||
include $(CLEAR_VARS)
|
include $(CLEAR_VARS)
|
||||||
|
|
||||||
LOCAL_MODULE:= logd
|
LOCAL_MODULE:= liblogd
|
||||||
|
|
||||||
LOCAL_INIT_RC := logd.rc
|
|
||||||
|
|
||||||
LOCAL_SRC_FILES := \
|
LOCAL_SRC_FILES := \
|
||||||
main.cpp \
|
|
||||||
LogCommand.cpp \
|
LogCommand.cpp \
|
||||||
CommandListener.cpp \
|
CommandListener.cpp \
|
||||||
LogListener.cpp \
|
LogListener.cpp \
|
||||||
|
|
@ -15,6 +12,7 @@ LOCAL_SRC_FILES := \
|
||||||
FlushCommand.cpp \
|
FlushCommand.cpp \
|
||||||
LogBuffer.cpp \
|
LogBuffer.cpp \
|
||||||
LogBufferElement.cpp \
|
LogBufferElement.cpp \
|
||||||
|
LogBufferInterface.cpp \
|
||||||
LogTimes.cpp \
|
LogTimes.cpp \
|
||||||
LogStatistics.cpp \
|
LogStatistics.cpp \
|
||||||
LogWhiteBlackList.cpp \
|
LogWhiteBlackList.cpp \
|
||||||
|
|
@ -25,12 +23,9 @@ LOCAL_SRC_FILES := \
|
||||||
event.logtags
|
event.logtags
|
||||||
|
|
||||||
LOCAL_SHARED_LIBRARIES := \
|
LOCAL_SHARED_LIBRARIES := \
|
||||||
libsysutils \
|
libbase
|
||||||
liblog \
|
|
||||||
libcutils \
|
LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH)
|
||||||
libbase \
|
|
||||||
libpackagelistparser \
|
|
||||||
libcap
|
|
||||||
|
|
||||||
# This is what we want to do:
|
# This is what we want to do:
|
||||||
# event_logtags = $(shell \
|
# event_logtags = $(shell \
|
||||||
|
|
@ -46,6 +41,30 @@ event_flag += -DLIBLOG_LOG_TAG=1006
|
||||||
|
|
||||||
LOCAL_CFLAGS := -Werror $(event_flag)
|
LOCAL_CFLAGS := -Werror $(event_flag)
|
||||||
|
|
||||||
|
include $(BUILD_STATIC_LIBRARY)
|
||||||
|
|
||||||
|
include $(CLEAR_VARS)
|
||||||
|
|
||||||
|
LOCAL_MODULE:= logd
|
||||||
|
|
||||||
|
LOCAL_INIT_RC := logd.rc
|
||||||
|
|
||||||
|
LOCAL_SRC_FILES := \
|
||||||
|
main.cpp
|
||||||
|
|
||||||
|
LOCAL_STATIC_LIBRARIES := \
|
||||||
|
liblogd
|
||||||
|
|
||||||
|
LOCAL_SHARED_LIBRARIES := \
|
||||||
|
libsysutils \
|
||||||
|
liblog \
|
||||||
|
libcutils \
|
||||||
|
libbase \
|
||||||
|
libpackagelistparser \
|
||||||
|
libcap
|
||||||
|
|
||||||
|
LOCAL_CFLAGS := -Werror
|
||||||
|
|
||||||
include $(BUILD_EXECUTABLE)
|
include $(BUILD_EXECUTABLE)
|
||||||
|
|
||||||
include $(CLEAR_VARS)
|
include $(CLEAR_VARS)
|
||||||
|
|
|
||||||
|
|
@ -27,6 +27,7 @@
|
||||||
#include <sysutils/SocketClient.h>
|
#include <sysutils/SocketClient.h>
|
||||||
|
|
||||||
#include "LogBufferElement.h"
|
#include "LogBufferElement.h"
|
||||||
|
#include "LogBufferInterface.h"
|
||||||
#include "LogStatistics.h"
|
#include "LogStatistics.h"
|
||||||
#include "LogTags.h"
|
#include "LogTags.h"
|
||||||
#include "LogTimes.h"
|
#include "LogTimes.h"
|
||||||
|
|
@ -74,7 +75,7 @@ static bool isMonotonic(const log_time& mono) {
|
||||||
|
|
||||||
typedef std::list<LogBufferElement*> LogBufferElementCollection;
|
typedef std::list<LogBufferElement*> LogBufferElementCollection;
|
||||||
|
|
||||||
class LogBuffer {
|
class LogBuffer : public LogBufferInterface {
|
||||||
LogBufferElementCollection mLogElements;
|
LogBufferElementCollection mLogElements;
|
||||||
pthread_rwlock_t mLogElementsLock;
|
pthread_rwlock_t mLogElementsLock;
|
||||||
|
|
||||||
|
|
@ -107,14 +108,14 @@ class LogBuffer {
|
||||||
LastLogTimes& mTimes;
|
LastLogTimes& mTimes;
|
||||||
|
|
||||||
explicit LogBuffer(LastLogTimes* times);
|
explicit LogBuffer(LastLogTimes* times);
|
||||||
~LogBuffer();
|
~LogBuffer() override;
|
||||||
void init();
|
void init();
|
||||||
bool isMonotonic() {
|
bool isMonotonic() {
|
||||||
return monotonic;
|
return monotonic;
|
||||||
}
|
}
|
||||||
|
|
||||||
int log(log_id_t log_id, log_time realtime, uid_t uid, pid_t pid, pid_t tid,
|
int log(log_id_t log_id, log_time realtime, uid_t uid, pid_t pid, pid_t tid,
|
||||||
const char* msg, unsigned short len);
|
const char* msg, unsigned short len) override;
|
||||||
// lastTid is an optional context to help detect if the last previous
|
// lastTid is an optional context to help detect if the last previous
|
||||||
// valid message was from the same source so we can differentiate chatty
|
// valid message was from the same source so we can differentiate chatty
|
||||||
// filter types (identical or expired)
|
// filter types (identical or expired)
|
||||||
|
|
|
||||||
22
logd/LogBufferInterface.cpp
Normal file
22
logd/LogBufferInterface.cpp
Normal file
|
|
@ -0,0 +1,22 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2017 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "LogBufferInterface.h"
|
||||||
|
|
||||||
|
LogBufferInterface::LogBufferInterface() {
|
||||||
|
}
|
||||||
|
LogBufferInterface::~LogBufferInterface() {
|
||||||
|
}
|
||||||
40
logd/LogBufferInterface.h
Normal file
40
logd/LogBufferInterface.h
Normal file
|
|
@ -0,0 +1,40 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2012-2014 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _LOGD_LOG_BUFFER_INTERFACE_H__
|
||||||
|
#define _LOGD_LOG_BUFFER_INTERFACE_H__
|
||||||
|
|
||||||
|
#include <sys/types.h>
|
||||||
|
|
||||||
|
#include <android-base/macros.h>
|
||||||
|
#include <log/log_id.h>
|
||||||
|
#include <log/log_time.h>
|
||||||
|
|
||||||
|
// Abstract interface that handles log when log available.
|
||||||
|
class LogBufferInterface {
|
||||||
|
public:
|
||||||
|
LogBufferInterface();
|
||||||
|
virtual ~LogBufferInterface();
|
||||||
|
// Handles a log entry when available in LogListener.
|
||||||
|
// Returns the size of the handled log message.
|
||||||
|
virtual int log(log_id_t log_id, log_time realtime, uid_t uid, pid_t pid,
|
||||||
|
pid_t tid, const char* msg, unsigned short len) = 0;
|
||||||
|
|
||||||
|
private:
|
||||||
|
DISALLOW_COPY_AND_ASSIGN(LogBufferInterface);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // _LOGD_LOG_BUFFER_INTERFACE_H__
|
||||||
|
|
@ -30,7 +30,7 @@
|
||||||
#include "LogListener.h"
|
#include "LogListener.h"
|
||||||
#include "LogUtils.h"
|
#include "LogUtils.h"
|
||||||
|
|
||||||
LogListener::LogListener(LogBuffer* buf, LogReader* reader)
|
LogListener::LogListener(LogBufferInterface* buf, LogReader* reader)
|
||||||
: SocketListener(getLogSocket(), false), logbuf(buf), reader(reader) {
|
: SocketListener(getLogSocket(), false), logbuf(buf), reader(reader) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -102,11 +102,14 @@ bool LogListener::onDataAvailable(SocketClient* cli) {
|
||||||
// NB: hdr.msg_flags & MSG_TRUNC is not tested, silently passing a
|
// NB: hdr.msg_flags & MSG_TRUNC is not tested, silently passing a
|
||||||
// truncated message to the logs.
|
// truncated message to the logs.
|
||||||
|
|
||||||
if (logbuf->log((log_id_t)header->id, header->realtime, cred->uid,
|
if (logbuf != nullptr) {
|
||||||
cred->pid, header->tid, msg,
|
int res = logbuf->log(
|
||||||
((size_t)n <= USHRT_MAX) ? (unsigned short)n : USHRT_MAX) >=
|
(log_id_t)header->id, header->realtime, cred->uid, cred->pid,
|
||||||
0) {
|
header->tid, msg,
|
||||||
reader->notifyNewLog();
|
((size_t)n <= USHRT_MAX) ? (unsigned short)n : USHRT_MAX);
|
||||||
|
if (res > 0 && reader != nullptr) {
|
||||||
|
reader->notifyNewLog();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
|
||||||
|
|
@ -21,11 +21,11 @@
|
||||||
#include "LogReader.h"
|
#include "LogReader.h"
|
||||||
|
|
||||||
class LogListener : public SocketListener {
|
class LogListener : public SocketListener {
|
||||||
LogBuffer* logbuf;
|
LogBufferInterface* logbuf;
|
||||||
LogReader* reader;
|
LogReader* reader;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
LogListener(LogBuffer* buf, LogReader* reader);
|
LogListener(LogBufferInterface* buf, LogReader* reader /* nullable */);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual bool onDataAvailable(SocketClient* cli);
|
virtual bool onDataAvailable(SocketClient* cli);
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue