Loading logd/Android.mk +13 −1 Original line number Diff line number Diff line Loading @@ -21,6 +21,7 @@ LOCAL_SRC_FILES := \ libaudit.c \ LogAudit.cpp \ LogKlog.cpp \ LogTags.cpp \ event.logtags LOCAL_SHARED_LIBRARIES := \ Loading @@ -38,12 +39,23 @@ LOCAL_SHARED_LIBRARIES := \ # $(LOCAL_PATH)/$2/event.logtags) # event_flag := $(call event_logtags,auditd) # event_flag += $(call event_logtags,logd) # event_flag += $(call event_logtags,tag_def) # so make sure we do not regret hard-coding it as follows: event_flag := -DAUDITD_LOG_TAG=1003 -DCHATTY_LOG_TAG=1004 event_flag := -DAUDITD_LOG_TAG=1003 -DCHATTY_LOG_TAG=1004 -DTAG_DEF_LOG_TAG=1005 event_flag += -DLIBLOG_LOG_TAG=1006 LOCAL_CFLAGS := -Werror $(event_flag) include $(BUILD_EXECUTABLE) include $(CLEAR_VARS) LOCAL_MODULE := logtagd.rc LOCAL_SRC_FILES := $(LOCAL_MODULE) LOCAL_MODULE_CLASS := ETC LOCAL_MODULE_TAGS := debug LOCAL_MODULE_PATH := $(TARGET_OUT_ETC)/init include $(BUILD_PREBUILT) include $(call first-makefiles-under,$(LOCAL_PATH)) logd/CommandListener.cpp +37 −0 Original line number Diff line number Diff line Loading @@ -15,6 +15,7 @@ */ #include <arpa/inet.h> #include <ctype.h> #include <dirent.h> #include <errno.h> #include <fcntl.h> Loading Loading @@ -47,6 +48,7 @@ CommandListener::CommandListener(LogBuffer *buf, LogReader * /*reader*/, registerCmd(new GetStatisticsCmd(buf)); registerCmd(new SetPruneListCmd(buf)); registerCmd(new GetPruneListCmd(buf)); registerCmd(new GetEventTagCmd(buf)); registerCmd(new ReinitCmd()); registerCmd(new ExitCmd(this)); } Loading Loading @@ -284,6 +286,41 @@ int CommandListener::SetPruneListCmd::runCommand(SocketClient *cli, return 0; } CommandListener::GetEventTagCmd::GetEventTagCmd(LogBuffer *buf) : LogCommand("getEventTag"), mBuf(*buf) { } int CommandListener::GetEventTagCmd::runCommand(SocketClient *cli, int argc, char ** argv) { setname(); uid_t uid = cli->getUid(); if (clientHasLogCredentials(cli)) { uid = AID_ROOT; } const char *name = NULL; const char *format = NULL; for (int i = 1; i < argc; ++i) { static const char _name[] = "name="; if (!strncmp(argv[i], _name, strlen(_name))) { name = argv[i] + strlen(_name); continue; } static const char _format[] = "format="; if (!strncmp(argv[i], _format, strlen(_format))) { format = argv[i] + strlen(_format); continue; } } cli->sendMsg(package_string(mBuf.formatGetEventTag(uid, name, format)).c_str()); return 0; } CommandListener::ReinitCmd::ReinitCmd() : LogCommand("reinit") { } Loading logd/CommandListener.h +1 −0 Original line number Diff line number Diff line Loading @@ -61,6 +61,7 @@ private: LogBufferCmd(GetStatistics); LogBufferCmd(GetPruneList); LogBufferCmd(SetPruneList); LogBufferCmd(GetEventTag); #define LogCmd(name) \ class name##Cmd : public LogCommand { \ Loading logd/LogBuffer.cpp +2 −4 Original line number Diff line number Diff line Loading @@ -199,15 +199,13 @@ int LogBuffer::log(log_id_t log_id, log_time realtime, if (log_id != LOG_ID_SECURITY) { int prio = ANDROID_LOG_INFO; const char *tag = NULL; size_t len = 0; if (log_id == LOG_ID_EVENTS) { tag = android::tagToName(&len, elem->getTag()); tag = tagToName(elem->getTag()); } else { prio = *msg; tag = msg + 1; len = strlen(tag); } if (!__android_log_is_loggable_len(prio, tag, len, ANDROID_LOG_VERBOSE)) { if (!__android_log_is_loggable(prio, tag, ANDROID_LOG_VERBOSE)) { // Log traffic received to total pthread_mutex_lock(&mLogElementsLock); stats.add(elem); Loading logd/LogBuffer.h +9 −0 Original line number Diff line number Diff line Loading @@ -27,6 +27,7 @@ #include <sysutils/SocketClient.h> #include "LogBufferElement.h" #include "LogTags.h" #include "LogTimes.h" #include "LogStatistics.h" #include "LogWhiteBlackList.h" Loading Loading @@ -99,6 +100,8 @@ class LogBuffer { bool monotonic; LogTags tags; LogBufferElement* lastLoggedElements[LOG_ID_MAX]; LogBufferElement* droppedElements[LOG_ID_MAX]; void log(LogBufferElement* elem); Loading Loading @@ -133,6 +136,12 @@ public: int initPrune(const char *cp) { return mPrune.init(cp); } std::string formatPrune() { return mPrune.format(); } std::string formatGetEventTag(uid_t uid, const char *name, const char *format) { return tags.formatGetEventTag(uid, name, format); } const char *tagToName(uint32_t tag) { return tags.tagToName(tag); } // helper must be protected directly or implicitly by lock()/unlock() const char *pidToName(pid_t pid) { return stats.pidToName(pid); } uid_t pidToUid(pid_t pid) { return stats.pidToUid(pid); } Loading Loading
logd/Android.mk +13 −1 Original line number Diff line number Diff line Loading @@ -21,6 +21,7 @@ LOCAL_SRC_FILES := \ libaudit.c \ LogAudit.cpp \ LogKlog.cpp \ LogTags.cpp \ event.logtags LOCAL_SHARED_LIBRARIES := \ Loading @@ -38,12 +39,23 @@ LOCAL_SHARED_LIBRARIES := \ # $(LOCAL_PATH)/$2/event.logtags) # event_flag := $(call event_logtags,auditd) # event_flag += $(call event_logtags,logd) # event_flag += $(call event_logtags,tag_def) # so make sure we do not regret hard-coding it as follows: event_flag := -DAUDITD_LOG_TAG=1003 -DCHATTY_LOG_TAG=1004 event_flag := -DAUDITD_LOG_TAG=1003 -DCHATTY_LOG_TAG=1004 -DTAG_DEF_LOG_TAG=1005 event_flag += -DLIBLOG_LOG_TAG=1006 LOCAL_CFLAGS := -Werror $(event_flag) include $(BUILD_EXECUTABLE) include $(CLEAR_VARS) LOCAL_MODULE := logtagd.rc LOCAL_SRC_FILES := $(LOCAL_MODULE) LOCAL_MODULE_CLASS := ETC LOCAL_MODULE_TAGS := debug LOCAL_MODULE_PATH := $(TARGET_OUT_ETC)/init include $(BUILD_PREBUILT) include $(call first-makefiles-under,$(LOCAL_PATH))
logd/CommandListener.cpp +37 −0 Original line number Diff line number Diff line Loading @@ -15,6 +15,7 @@ */ #include <arpa/inet.h> #include <ctype.h> #include <dirent.h> #include <errno.h> #include <fcntl.h> Loading Loading @@ -47,6 +48,7 @@ CommandListener::CommandListener(LogBuffer *buf, LogReader * /*reader*/, registerCmd(new GetStatisticsCmd(buf)); registerCmd(new SetPruneListCmd(buf)); registerCmd(new GetPruneListCmd(buf)); registerCmd(new GetEventTagCmd(buf)); registerCmd(new ReinitCmd()); registerCmd(new ExitCmd(this)); } Loading Loading @@ -284,6 +286,41 @@ int CommandListener::SetPruneListCmd::runCommand(SocketClient *cli, return 0; } CommandListener::GetEventTagCmd::GetEventTagCmd(LogBuffer *buf) : LogCommand("getEventTag"), mBuf(*buf) { } int CommandListener::GetEventTagCmd::runCommand(SocketClient *cli, int argc, char ** argv) { setname(); uid_t uid = cli->getUid(); if (clientHasLogCredentials(cli)) { uid = AID_ROOT; } const char *name = NULL; const char *format = NULL; for (int i = 1; i < argc; ++i) { static const char _name[] = "name="; if (!strncmp(argv[i], _name, strlen(_name))) { name = argv[i] + strlen(_name); continue; } static const char _format[] = "format="; if (!strncmp(argv[i], _format, strlen(_format))) { format = argv[i] + strlen(_format); continue; } } cli->sendMsg(package_string(mBuf.formatGetEventTag(uid, name, format)).c_str()); return 0; } CommandListener::ReinitCmd::ReinitCmd() : LogCommand("reinit") { } Loading
logd/CommandListener.h +1 −0 Original line number Diff line number Diff line Loading @@ -61,6 +61,7 @@ private: LogBufferCmd(GetStatistics); LogBufferCmd(GetPruneList); LogBufferCmd(SetPruneList); LogBufferCmd(GetEventTag); #define LogCmd(name) \ class name##Cmd : public LogCommand { \ Loading
logd/LogBuffer.cpp +2 −4 Original line number Diff line number Diff line Loading @@ -199,15 +199,13 @@ int LogBuffer::log(log_id_t log_id, log_time realtime, if (log_id != LOG_ID_SECURITY) { int prio = ANDROID_LOG_INFO; const char *tag = NULL; size_t len = 0; if (log_id == LOG_ID_EVENTS) { tag = android::tagToName(&len, elem->getTag()); tag = tagToName(elem->getTag()); } else { prio = *msg; tag = msg + 1; len = strlen(tag); } if (!__android_log_is_loggable_len(prio, tag, len, ANDROID_LOG_VERBOSE)) { if (!__android_log_is_loggable(prio, tag, ANDROID_LOG_VERBOSE)) { // Log traffic received to total pthread_mutex_lock(&mLogElementsLock); stats.add(elem); Loading
logd/LogBuffer.h +9 −0 Original line number Diff line number Diff line Loading @@ -27,6 +27,7 @@ #include <sysutils/SocketClient.h> #include "LogBufferElement.h" #include "LogTags.h" #include "LogTimes.h" #include "LogStatistics.h" #include "LogWhiteBlackList.h" Loading Loading @@ -99,6 +100,8 @@ class LogBuffer { bool monotonic; LogTags tags; LogBufferElement* lastLoggedElements[LOG_ID_MAX]; LogBufferElement* droppedElements[LOG_ID_MAX]; void log(LogBufferElement* elem); Loading Loading @@ -133,6 +136,12 @@ public: int initPrune(const char *cp) { return mPrune.init(cp); } std::string formatPrune() { return mPrune.format(); } std::string formatGetEventTag(uid_t uid, const char *name, const char *format) { return tags.formatGetEventTag(uid, name, format); } const char *tagToName(uint32_t tag) { return tags.tagToName(tag); } // helper must be protected directly or implicitly by lock()/unlock() const char *pidToName(pid_t pid) { return stats.pidToName(pid); } uid_t pidToUid(pid_t pid) { return stats.pidToUid(pid); } Loading