summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMark Salyzyn2015-01-16 15:38:07 -0600
committerMark Salyzyn2015-01-23 17:32:11 -0600
commitb5f6e45d6bddd2f6262bf387c3314dc744896320 (patch)
tree6b866998680afb3dde2db6b1f9d8e2e57852b73c /logd/LogListener.cpp
parent2c7f05d88c3d59eea5ce82a4762cf3c6477565c7 (diff)
downloadplatform-system-core-b5f6e45d6bddd2f6262bf387c3314dc744896320.tar.gz
platform-system-core-b5f6e45d6bddd2f6262bf387c3314dc744896320.tar.xz
platform-system-core-b5f6e45d6bddd2f6262bf387c3314dc744896320.zip
logd: create private/android_logger.h
- create a structure to depict the private header expected at logd end of socket. - utilize this new structure instead of unscalable byte stream technique used to unpack in logd. Change-Id: I2d0e5c3531c279f2dc1fbd74807210ff8d804de0
Diffstat (limited to 'logd/LogListener.cpp')
-rw-r--r--logd/LogListener.cpp24
1 files changed, 8 insertions, 16 deletions
diff --git a/logd/LogListener.cpp b/logd/LogListener.cpp
index 8186cea97..fc9e30ff4 100644
--- a/logd/LogListener.cpp
+++ b/logd/LogListener.cpp
@@ -23,6 +23,7 @@
23 23
24#include <cutils/sockets.h> 24#include <cutils/sockets.h>
25#include <log/logger.h> 25#include <log/logger.h>
26#include <private/android_logger.h>
26 27
27#include "LogListener.h" 28#include "LogListener.h"
28 29
@@ -54,7 +55,7 @@ bool LogListener::onDataAvailable(SocketClient *cli) {
54 int socket = cli->getSocket(); 55 int socket = cli->getSocket();
55 56
56 ssize_t n = recvmsg(socket, &hdr, 0); 57 ssize_t n = recvmsg(socket, &hdr, 0);
57 if (n <= (ssize_t)(sizeof_log_id_t + sizeof(uint16_t) + sizeof(log_time))) { 58 if (n <= (ssize_t)(sizeof(android_log_header_t))) {
58 return false; 59 return false;
59 } 60 }
60 61
@@ -81,28 +82,19 @@ bool LogListener::onDataAvailable(SocketClient *cli) {
81 return false; 82 return false;
82 } 83 }
83 84
84 // First log element is always log_id. 85 android_log_header_t *header = reinterpret_cast<android_log_header_t *>(buffer);
85 log_id_t log_id = (log_id_t) *((typeof_log_id_t *) buffer); 86 if (/* header->id < LOG_ID_MIN || */ header->id >= LOG_ID_MAX) {
86 if (log_id < 0 || log_id >= LOG_ID_MAX) {
87 return false; 87 return false;
88 } 88 }
89 char *msg = ((char *)buffer) + sizeof_log_id_t;
90 n -= sizeof_log_id_t;
91 89
92 // second element is the thread id of the caller 90 char *msg = ((char *)buffer) + sizeof(android_log_header_t);
93 pid_t tid = (pid_t) *((uint16_t *) msg); 91 n -= sizeof(android_log_header_t);
94 msg += sizeof(uint16_t);
95 n -= sizeof(uint16_t);
96
97 // third element is the realtime at point of caller
98 log_time realtime(msg);
99 msg += sizeof(log_time);
100 n -= sizeof(log_time);
101 92
102 // NB: hdr.msg_flags & MSG_TRUNC is not tested, silently passing a 93 // NB: hdr.msg_flags & MSG_TRUNC is not tested, silently passing a
103 // truncated message to the logs. 94 // truncated message to the logs.
104 95
105 logbuf->log(log_id, realtime, cred->uid, cred->pid, tid, msg, 96 logbuf->log((log_id_t)header->id, header->realtime,
97 cred->uid, cred->pid, header->tid, msg,
106 ((size_t) n <= USHRT_MAX) ? (unsigned short) n : USHRT_MAX); 98 ((size_t) n <= USHRT_MAX) ? (unsigned short) n : USHRT_MAX);
107 reader->notifyNewLog(); 99 reader->notifyNewLog();
108 100