Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1cd4102a authored by Mark Salyzyn's avatar Mark Salyzyn Committed by Gerrit Code Review
Browse files

Merge "logd: add getEventTag command and service"

parents 3dfe4012 61e9ce67
Loading
Loading
Loading
Loading
+13 −1
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ LOCAL_SRC_FILES := \
    libaudit.c \
    LogAudit.cpp \
    LogKlog.cpp \
    LogTags.cpp \
    event.logtags

LOCAL_SHARED_LIBRARIES := \
@@ -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))
+37 −0
Original line number Diff line number Diff line
@@ -15,6 +15,7 @@
 */

#include <arpa/inet.h>
#include <ctype.h>
#include <dirent.h>
#include <errno.h>
#include <fcntl.h>
@@ -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));
}
@@ -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") {
}

+1 −0
Original line number Diff line number Diff line
@@ -61,6 +61,7 @@ private:
    LogBufferCmd(GetStatistics);
    LogBufferCmd(GetPruneList);
    LogBufferCmd(SetPruneList);
    LogBufferCmd(GetEventTag);

#define LogCmd(name)                                             \
    class name##Cmd : public LogCommand {                        \
+2 −4
Original line number Diff line number Diff line
@@ -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);
+9 −0
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@
#include <sysutils/SocketClient.h>

#include "LogBufferElement.h"
#include "LogTags.h"
#include "LogTimes.h"
#include "LogStatistics.h"
#include "LogWhiteBlackList.h"
@@ -99,6 +100,8 @@ class LogBuffer {

    bool monotonic;

    LogTags tags;

    LogBufferElement* lastLoggedElements[LOG_ID_MAX];
    LogBufferElement* droppedElements[LOG_ID_MAX];
    void log(LogBufferElement* elem);
@@ -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