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

Commit edc1abf1 authored by Nick Kralevich's avatar Nick Kralevich Committed by Android Git Automerger
Browse files

am 1bb3489e: resolved conflicts for merge of e9c8fb90 to klp-modular-dev-plus-aosp

* commit '1bb3489e':
  logd: initial checkin.
parents ce72e6c4 1bb3489e
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -23,12 +23,12 @@
#ifdef __cplusplus
struct log_time : public timespec {
public:
    log_time(timespec &T)
    log_time(const timespec &T)
    {
        tv_sec = T.tv_sec;
        tv_nsec = T.tv_nsec;
    }
    log_time(void)
    log_time()
    {
    }
    log_time(clockid_t id)
@@ -67,7 +67,7 @@ public:
    {
        return !(*this > T);
    }
    uint64_t nsec(void) const
    uint64_t nsec() const
    {
        return static_cast<uint64_t>(tv_sec) * NS_PER_SEC + tv_nsec;
    }
+17 −5
Original line number Diff line number Diff line
@@ -35,7 +35,7 @@ struct logger_entry {
/*
 * The userspace structure for version 2 of the logger_entry ABI.
 * This structure is returned to userspace if ioctl(LOGGER_SET_VERSION)
 * is called with version==2
 * is called with version==2; or used with the user space log daemon.
 */
struct logger_entry_v2 {
    uint16_t    len;       /* length of the payload */
@@ -48,6 +48,17 @@ struct logger_entry_v2 {
    char        msg[0];    /* the entry's payload */
};

struct logger_entry_v3 {
    uint16_t    len;       /* length of the payload */
    uint16_t    hdr_size;  /* sizeof(struct logger_entry_v2) */
    int32_t     pid;       /* generating process's pid */
    int32_t     tid;       /* generating process's tid */
    int32_t     sec;       /* seconds since Epoch */
    int32_t     nsec;      /* nanoseconds */
    uint32_t    lid;       /* log id of the payload */
    char        msg[0];    /* the entry's payload */
};

/*
 * The maximum size of the log entry payload that can be
 * written to the kernel logger driver. An attempt to write
@@ -69,6 +80,7 @@ struct log_msg {
    union {
        unsigned char buf[LOGGER_ENTRY_MAX_LEN + 1];
        struct logger_entry_v2 entry;
        struct logger_entry_v3 entry_v3;
        struct logger_entry_v2 entry_v2;
        struct logger_entry    entry_v1;
        struct {
@@ -106,21 +118,21 @@ struct log_msg {
    {
        return !(*this > T);
    }
    uint64_t nsec(void) const
    uint64_t nsec() const
    {
        return static_cast<uint64_t>(entry.sec) * NS_PER_SEC + entry.nsec;
    }

    /* packet methods */
    log_id_t id(void)
    log_id_t id()
    {
        return extra.id;
    }
    char *msg(void)
    char *msg()
    {
        return entry.hdr_size ? (char *) buf + entry.hdr_size : entry_v1.msg;
    }
    unsigned int len(void)
    unsigned int len()
    {
        return (entry.hdr_size ? entry.hdr_size : sizeof(entry_v1)) + entry.len;
    }
+2 −0
Original line number Diff line number Diff line
@@ -76,6 +76,7 @@
#define AID_SDCARD_PICS   1033  /* external storage photos access */
#define AID_SDCARD_AV     1034  /* external storage audio/video access */
#define AID_SDCARD_ALL    1035  /* access all users external storage */
#define AID_LOGD          1036  /* log daemon */

#define AID_SHELL         2000  /* adb and debug shell user */
#define AID_CACHE         2001  /* cache access */
@@ -151,6 +152,7 @@ static const struct android_id_info android_ids[] = {
    { "sdcard_pics",   AID_SDCARD_PICS, },
    { "sdcard_av",     AID_SDCARD_AV, },
    { "sdcard_all",    AID_SDCARD_ALL, },
    { "logd",          AID_LOGD, },

    { "shell",         AID_SHELL, },
    { "cache",         AID_CACHE, },

logd/Android.mk

0 → 100644
+28 −0
Original line number Diff line number Diff line
LOCAL_PATH:= $(call my-dir)

include $(CLEAR_VARS)

LOCAL_MODULE:= logd

LOCAL_SRC_FILES := \
    main.cpp \
    LogCommand.cpp \
    CommandListener.cpp \
    LogListener.cpp \
    LogReader.cpp \
    FlushCommand.cpp \
    LogBuffer.cpp \
    LogBufferElement.cpp \
    LogTimes.cpp

LOCAL_C_INCLUDES := $(KERNEL_HEADERS)

LOCAL_SHARED_LIBRARIES := \
    libsysutils \
    liblog \
    libcutils

LOCAL_MODULE_TAGS := optional

include $(BUILD_EXECUTABLE)
+137 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2012-2013 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 <arpa/inet.h>
#include <dirent.h>
#include <errno.h>
#include <fcntl.h>
#include <netinet/in.h>
#include <string.h>
#include <stdlib.h>
#include <sys/socket.h>
#include <sys/types.h>

#include <sysutils/SocketClient.h>
#include <private/android_filesystem_config.h>

#include "CommandListener.h"

CommandListener::CommandListener(LogBuffer *buf, LogReader * /*reader*/,
                                 LogListener * /*swl*/)
        : FrameworkListener("logd")
        , mBuf(*buf) {
    // registerCmd(new ShutdownCmd(buf, writer, swl));
    registerCmd(new ClearCmd(buf));
    registerCmd(new GetBufSizeCmd(buf));
    registerCmd(new GetBufSizeUsedCmd(buf));
}

CommandListener::ShutdownCmd::ShutdownCmd(LogBuffer *buf, LogReader *reader,
                                          LogListener *swl)
        : LogCommand("shutdown")
        , mBuf(*buf)
        , mReader(*reader)
        , mSwl(*swl)
{ }

int CommandListener::ShutdownCmd::runCommand(SocketClient * /*cli*/,
                                             int /*argc*/,
                                             char ** /*argv*/) {
    mSwl.stopListener();
    mReader.stopListener();
    exit(0);
}

CommandListener::ClearCmd::ClearCmd(LogBuffer *buf)
        : LogCommand("clear")
        , mBuf(*buf)
{ }

int CommandListener::ClearCmd::runCommand(SocketClient *cli,
                                         int argc, char **argv) {
    if ((cli->getUid() != AID_ROOT)
            && (cli->getGid() != AID_ROOT)
            && (cli->getGid() != AID_LOG)) {
        cli->sendMsg("Permission Denied");
        return 0;
    }

    if (argc < 2) {
        cli->sendMsg("Missing Argument");
        return 0;
    }

    int id = atoi(argv[1]);
    if ((id < LOG_ID_MIN) || (id >= LOG_ID_MAX)) {
        cli->sendMsg("Range Error");
        return 0;
    }

    mBuf.clear((log_id_t) id);
    cli->sendMsg("success");
    return 0;
}


CommandListener::GetBufSizeCmd::GetBufSizeCmd(LogBuffer *buf)
        : LogCommand("getLogSize")
        , mBuf(*buf)
{ }

int CommandListener::GetBufSizeCmd::runCommand(SocketClient *cli,
                                         int argc, char **argv) {
    if (argc < 2) {
        cli->sendMsg("Missing Argument");
        return 0;
    }

    int id = atoi(argv[1]);
    if ((id < LOG_ID_MIN) || (id >= LOG_ID_MAX)) {
        cli->sendMsg("Range Error");
        return 0;
    }

    unsigned long size = mBuf.getSize((log_id_t) id);
    char buf[512];
    snprintf(buf, sizeof(buf), "%lu", size);
    cli->sendMsg(buf);
    return 0;
}

CommandListener::GetBufSizeUsedCmd::GetBufSizeUsedCmd(LogBuffer *buf)
        : LogCommand("getLogSizeUsed")
        , mBuf(*buf)
{ }

int CommandListener::GetBufSizeUsedCmd::runCommand(SocketClient *cli,
                                         int argc, char **argv) {
    if (argc < 2) {
        cli->sendMsg("Missing Argument");
        return 0;
    }

    int id = atoi(argv[1]);
    if ((id < LOG_ID_MIN) || (id >= LOG_ID_MAX)) {
        cli->sendMsg("Range Error");
        return 0;
    }

    unsigned long size = mBuf.getSizeUsed((log_id_t) id);
    char buf[512];
    snprintf(buf, sizeof(buf), "%lu", size);
    cli->sendMsg(buf);
    return 0;
}
Loading