Loading include/private/android_logger.h 0 → 100644 +34 −0 Original line number Diff line number Diff line /* * Copyright (C) 2015 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. */ /* This file is used to define the internal protocol for the Android Logger */ #ifndef _SYSTEM_CORE_INCLUDE_PRIVATE_ANDROID_LOGGER_H_ #define _SYSTEM_CORE_INCLUDE_PRIVATE_ANDROID_LOGGER_H_ #include <stdint.h> #include <log/log.h> #include <log/log_read.h> /* Header Structure to logd */ typedef struct __attribute__((__packed__)) { typeof_log_id_t id; uint16_t tid; log_time realtime; } android_log_header_t; #endif logd/LogListener.cpp +8 −16 Original line number Diff line number Diff line Loading @@ -23,6 +23,7 @@ #include <cutils/sockets.h> #include <log/logger.h> #include <private/android_logger.h> #include "LogListener.h" Loading Loading @@ -54,7 +55,7 @@ bool LogListener::onDataAvailable(SocketClient *cli) { int socket = cli->getSocket(); ssize_t n = recvmsg(socket, &hdr, 0); if (n <= (ssize_t)(sizeof_log_id_t + sizeof(uint16_t) + sizeof(log_time))) { if (n <= (ssize_t)(sizeof(android_log_header_t))) { return false; } Loading @@ -81,28 +82,19 @@ bool LogListener::onDataAvailable(SocketClient *cli) { return false; } // First log element is always log_id. log_id_t log_id = (log_id_t) *((typeof_log_id_t *) buffer); if (log_id < 0 || log_id >= LOG_ID_MAX) { android_log_header_t *header = reinterpret_cast<android_log_header_t *>(buffer); if (/* header->id < LOG_ID_MIN || */ header->id >= LOG_ID_MAX) { return false; } char *msg = ((char *)buffer) + sizeof_log_id_t; n -= sizeof_log_id_t; // second element is the thread id of the caller pid_t tid = (pid_t) *((uint16_t *) msg); msg += sizeof(uint16_t); n -= sizeof(uint16_t); // third element is the realtime at point of caller log_time realtime(msg); msg += sizeof(log_time); n -= sizeof(log_time); char *msg = ((char *)buffer) + sizeof(android_log_header_t); n -= sizeof(android_log_header_t); // NB: hdr.msg_flags & MSG_TRUNC is not tested, silently passing a // truncated message to the logs. logbuf->log(log_id, realtime, cred->uid, cred->pid, tid, msg, logbuf->log((log_id_t)header->id, header->realtime, cred->uid, cred->pid, header->tid, msg, ((size_t) n <= USHRT_MAX) ? (unsigned short) n : USHRT_MAX); reader->notifyNewLog(); Loading Loading
include/private/android_logger.h 0 → 100644 +34 −0 Original line number Diff line number Diff line /* * Copyright (C) 2015 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. */ /* This file is used to define the internal protocol for the Android Logger */ #ifndef _SYSTEM_CORE_INCLUDE_PRIVATE_ANDROID_LOGGER_H_ #define _SYSTEM_CORE_INCLUDE_PRIVATE_ANDROID_LOGGER_H_ #include <stdint.h> #include <log/log.h> #include <log/log_read.h> /* Header Structure to logd */ typedef struct __attribute__((__packed__)) { typeof_log_id_t id; uint16_t tid; log_time realtime; } android_log_header_t; #endif
logd/LogListener.cpp +8 −16 Original line number Diff line number Diff line Loading @@ -23,6 +23,7 @@ #include <cutils/sockets.h> #include <log/logger.h> #include <private/android_logger.h> #include "LogListener.h" Loading Loading @@ -54,7 +55,7 @@ bool LogListener::onDataAvailable(SocketClient *cli) { int socket = cli->getSocket(); ssize_t n = recvmsg(socket, &hdr, 0); if (n <= (ssize_t)(sizeof_log_id_t + sizeof(uint16_t) + sizeof(log_time))) { if (n <= (ssize_t)(sizeof(android_log_header_t))) { return false; } Loading @@ -81,28 +82,19 @@ bool LogListener::onDataAvailable(SocketClient *cli) { return false; } // First log element is always log_id. log_id_t log_id = (log_id_t) *((typeof_log_id_t *) buffer); if (log_id < 0 || log_id >= LOG_ID_MAX) { android_log_header_t *header = reinterpret_cast<android_log_header_t *>(buffer); if (/* header->id < LOG_ID_MIN || */ header->id >= LOG_ID_MAX) { return false; } char *msg = ((char *)buffer) + sizeof_log_id_t; n -= sizeof_log_id_t; // second element is the thread id of the caller pid_t tid = (pid_t) *((uint16_t *) msg); msg += sizeof(uint16_t); n -= sizeof(uint16_t); // third element is the realtime at point of caller log_time realtime(msg); msg += sizeof(log_time); n -= sizeof(log_time); char *msg = ((char *)buffer) + sizeof(android_log_header_t); n -= sizeof(android_log_header_t); // NB: hdr.msg_flags & MSG_TRUNC is not tested, silently passing a // truncated message to the logs. logbuf->log(log_id, realtime, cred->uid, cred->pid, tid, msg, logbuf->log((log_id_t)header->id, header->realtime, cred->uid, cred->pid, header->tid, msg, ((size_t) n <= USHRT_MAX) ? (unsigned short) n : USHRT_MAX); reader->notifyNewLog(); Loading