Loading include/log/log_read.h +3 −3 Original line number Original line Diff line number Diff line Loading @@ -23,12 +23,12 @@ #ifdef __cplusplus #ifdef __cplusplus struct log_time : public timespec { struct log_time : public timespec { public: public: log_time(timespec &T) log_time(const timespec &T) { { tv_sec = T.tv_sec; tv_sec = T.tv_sec; tv_nsec = T.tv_nsec; tv_nsec = T.tv_nsec; } } log_time(void) log_time() { { } } log_time(clockid_t id) log_time(clockid_t id) Loading Loading @@ -67,7 +67,7 @@ public: { { return !(*this > T); return !(*this > T); } } uint64_t nsec(void) const uint64_t nsec() const { { return static_cast<uint64_t>(tv_sec) * NS_PER_SEC + tv_nsec; return static_cast<uint64_t>(tv_sec) * NS_PER_SEC + tv_nsec; } } Loading include/log/logger.h +17 −5 Original line number Original line Diff line number Diff line Loading @@ -35,7 +35,7 @@ struct logger_entry { /* /* * The userspace structure for version 2 of the logger_entry ABI. * The userspace structure for version 2 of the logger_entry ABI. * This structure is returned to userspace if ioctl(LOGGER_SET_VERSION) * 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 { struct logger_entry_v2 { uint16_t len; /* length of the payload */ uint16_t len; /* length of the payload */ Loading @@ -48,6 +48,17 @@ struct logger_entry_v2 { char msg[0]; /* the entry's payload */ 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 * The maximum size of the log entry payload that can be * written to the kernel logger driver. An attempt to write * written to the kernel logger driver. An attempt to write Loading @@ -69,6 +80,7 @@ struct log_msg { union { union { unsigned char buf[LOGGER_ENTRY_MAX_LEN + 1]; unsigned char buf[LOGGER_ENTRY_MAX_LEN + 1]; struct logger_entry_v2 entry; struct logger_entry_v2 entry; struct logger_entry_v3 entry_v3; struct logger_entry_v2 entry_v2; struct logger_entry_v2 entry_v2; struct logger_entry entry_v1; struct logger_entry entry_v1; struct { struct { Loading Loading @@ -106,21 +118,21 @@ struct log_msg { { { return !(*this > T); return !(*this > T); } } uint64_t nsec(void) const uint64_t nsec() const { { return static_cast<uint64_t>(entry.sec) * NS_PER_SEC + entry.nsec; return static_cast<uint64_t>(entry.sec) * NS_PER_SEC + entry.nsec; } } /* packet methods */ /* packet methods */ log_id_t id(void) log_id_t id() { { return extra.id; return extra.id; } } char *msg(void) char *msg() { { return entry.hdr_size ? (char *) buf + entry.hdr_size : entry_v1.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; return (entry.hdr_size ? entry.hdr_size : sizeof(entry_v1)) + entry.len; } } Loading include/private/android_filesystem_config.h +2 −0 Original line number Original line Diff line number Diff line Loading @@ -76,6 +76,7 @@ #define AID_SDCARD_PICS 1033 /* external storage photos access */ #define AID_SDCARD_PICS 1033 /* external storage photos access */ #define AID_SDCARD_AV 1034 /* external storage audio/video access */ #define AID_SDCARD_AV 1034 /* external storage audio/video access */ #define AID_SDCARD_ALL 1035 /* access all users external storage */ #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_SHELL 2000 /* adb and debug shell user */ #define AID_CACHE 2001 /* cache access */ #define AID_CACHE 2001 /* cache access */ Loading Loading @@ -151,6 +152,7 @@ static const struct android_id_info android_ids[] = { { "sdcard_pics", AID_SDCARD_PICS, }, { "sdcard_pics", AID_SDCARD_PICS, }, { "sdcard_av", AID_SDCARD_AV, }, { "sdcard_av", AID_SDCARD_AV, }, { "sdcard_all", AID_SDCARD_ALL, }, { "sdcard_all", AID_SDCARD_ALL, }, { "logd", AID_LOGD, }, { "shell", AID_SHELL, }, { "shell", AID_SHELL, }, { "cache", AID_CACHE, }, { "cache", AID_CACHE, }, Loading logd/Android.mk 0 → 100644 +28 −0 Original line number Original line 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) logd/CommandListener.cpp 0 → 100644 +137 −0 Original line number Original line 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
include/log/log_read.h +3 −3 Original line number Original line Diff line number Diff line Loading @@ -23,12 +23,12 @@ #ifdef __cplusplus #ifdef __cplusplus struct log_time : public timespec { struct log_time : public timespec { public: public: log_time(timespec &T) log_time(const timespec &T) { { tv_sec = T.tv_sec; tv_sec = T.tv_sec; tv_nsec = T.tv_nsec; tv_nsec = T.tv_nsec; } } log_time(void) log_time() { { } } log_time(clockid_t id) log_time(clockid_t id) Loading Loading @@ -67,7 +67,7 @@ public: { { return !(*this > T); return !(*this > T); } } uint64_t nsec(void) const uint64_t nsec() const { { return static_cast<uint64_t>(tv_sec) * NS_PER_SEC + tv_nsec; return static_cast<uint64_t>(tv_sec) * NS_PER_SEC + tv_nsec; } } Loading
include/log/logger.h +17 −5 Original line number Original line Diff line number Diff line Loading @@ -35,7 +35,7 @@ struct logger_entry { /* /* * The userspace structure for version 2 of the logger_entry ABI. * The userspace structure for version 2 of the logger_entry ABI. * This structure is returned to userspace if ioctl(LOGGER_SET_VERSION) * 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 { struct logger_entry_v2 { uint16_t len; /* length of the payload */ uint16_t len; /* length of the payload */ Loading @@ -48,6 +48,17 @@ struct logger_entry_v2 { char msg[0]; /* the entry's payload */ 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 * The maximum size of the log entry payload that can be * written to the kernel logger driver. An attempt to write * written to the kernel logger driver. An attempt to write Loading @@ -69,6 +80,7 @@ struct log_msg { union { union { unsigned char buf[LOGGER_ENTRY_MAX_LEN + 1]; unsigned char buf[LOGGER_ENTRY_MAX_LEN + 1]; struct logger_entry_v2 entry; struct logger_entry_v2 entry; struct logger_entry_v3 entry_v3; struct logger_entry_v2 entry_v2; struct logger_entry_v2 entry_v2; struct logger_entry entry_v1; struct logger_entry entry_v1; struct { struct { Loading Loading @@ -106,21 +118,21 @@ struct log_msg { { { return !(*this > T); return !(*this > T); } } uint64_t nsec(void) const uint64_t nsec() const { { return static_cast<uint64_t>(entry.sec) * NS_PER_SEC + entry.nsec; return static_cast<uint64_t>(entry.sec) * NS_PER_SEC + entry.nsec; } } /* packet methods */ /* packet methods */ log_id_t id(void) log_id_t id() { { return extra.id; return extra.id; } } char *msg(void) char *msg() { { return entry.hdr_size ? (char *) buf + entry.hdr_size : entry_v1.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; return (entry.hdr_size ? entry.hdr_size : sizeof(entry_v1)) + entry.len; } } Loading
include/private/android_filesystem_config.h +2 −0 Original line number Original line Diff line number Diff line Loading @@ -76,6 +76,7 @@ #define AID_SDCARD_PICS 1033 /* external storage photos access */ #define AID_SDCARD_PICS 1033 /* external storage photos access */ #define AID_SDCARD_AV 1034 /* external storage audio/video access */ #define AID_SDCARD_AV 1034 /* external storage audio/video access */ #define AID_SDCARD_ALL 1035 /* access all users external storage */ #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_SHELL 2000 /* adb and debug shell user */ #define AID_CACHE 2001 /* cache access */ #define AID_CACHE 2001 /* cache access */ Loading Loading @@ -151,6 +152,7 @@ static const struct android_id_info android_ids[] = { { "sdcard_pics", AID_SDCARD_PICS, }, { "sdcard_pics", AID_SDCARD_PICS, }, { "sdcard_av", AID_SDCARD_AV, }, { "sdcard_av", AID_SDCARD_AV, }, { "sdcard_all", AID_SDCARD_ALL, }, { "sdcard_all", AID_SDCARD_ALL, }, { "logd", AID_LOGD, }, { "shell", AID_SHELL, }, { "shell", AID_SHELL, }, { "cache", AID_CACHE, }, { "cache", AID_CACHE, }, Loading
logd/Android.mk 0 → 100644 +28 −0 Original line number Original line 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)
logd/CommandListener.cpp 0 → 100644 +137 −0 Original line number Original line 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; }