summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMark Salyzyn2017-03-10 16:31:54 -0600
committerMark Salyzyn2017-03-13 12:31:09 -0500
commit501c373916e292764400dbae735f44b33378400f (patch)
tree56946d23a00461d2a462658f36689faa1d9d71a3 /logd/LogListener.cpp
parent488525b47ba23b2548f3bf6aa2f4ce6267b2d9b5 (diff)
downloadplatform-system-core-501c373916e292764400dbae735f44b33378400f.tar.gz
platform-system-core-501c373916e292764400dbae735f44b33378400f.tar.xz
platform-system-core-501c373916e292764400dbae735f44b33378400f.zip
logd: specify clang format
Switch _all_ file's coding style to match to ease all future changes. SideEffects: None Test: compile Bug: 35373582 Change-Id: I470cb17f64fa48f14aafc02f574e296bffe3a3f3
Diffstat (limited to 'logd/LogListener.cpp')
-rw-r--r--logd/LogListener.cpp54
1 files changed, 24 insertions, 30 deletions
diff --git a/logd/LogListener.cpp b/logd/LogListener.cpp
index 4a30e6dac..dadc75f4c 100644
--- a/logd/LogListener.cpp
+++ b/logd/LogListener.cpp
@@ -30,32 +30,24 @@
30#include "LogListener.h" 30#include "LogListener.h"
31#include "LogUtils.h" 31#include "LogUtils.h"
32 32
33LogListener::LogListener(LogBuffer *buf, LogReader *reader) : 33LogListener::LogListener(LogBuffer* buf, LogReader* reader)
34 SocketListener(getLogSocket(), false), 34 : SocketListener(getLogSocket(), false), logbuf(buf), reader(reader) {
35 logbuf(buf),
36 reader(reader) {
37} 35}
38 36
39bool LogListener::onDataAvailable(SocketClient *cli) { 37bool LogListener::onDataAvailable(SocketClient* cli) {
40 static bool name_set; 38 static bool name_set;
41 if (!name_set) { 39 if (!name_set) {
42 prctl(PR_SET_NAME, "logd.writer"); 40 prctl(PR_SET_NAME, "logd.writer");
43 name_set = true; 41 name_set = true;
44 } 42 }
45 43
46 char buffer[sizeof_log_id_t + sizeof(uint16_t) + sizeof(log_time) 44 char buffer[sizeof_log_id_t + sizeof(uint16_t) + sizeof(log_time) +
47 + LOGGER_ENTRY_MAX_PAYLOAD]; 45 LOGGER_ENTRY_MAX_PAYLOAD];
48 struct iovec iov = { buffer, sizeof(buffer) }; 46 struct iovec iov = { buffer, sizeof(buffer) };
49 47
50 alignas(4) char control[CMSG_SPACE(sizeof(struct ucred))]; 48 alignas(4) char control[CMSG_SPACE(sizeof(struct ucred))];
51 struct msghdr hdr = { 49 struct msghdr hdr = {
52 NULL, 50 NULL, 0, &iov, 1, control, sizeof(control), 0,
53 0,
54 &iov,
55 1,
56 control,
57 sizeof(control),
58 0,
59 }; 51 };
60 52
61 int socket = cli->getSocket(); 53 int socket = cli->getSocket();
@@ -68,13 +60,13 @@ bool LogListener::onDataAvailable(SocketClient *cli) {
68 return false; 60 return false;
69 } 61 }
70 62
71 struct ucred *cred = NULL; 63 struct ucred* cred = NULL;
72 64
73 struct cmsghdr *cmsg = CMSG_FIRSTHDR(&hdr); 65 struct cmsghdr* cmsg = CMSG_FIRSTHDR(&hdr);
74 while (cmsg != NULL) { 66 while (cmsg != NULL) {
75 if (cmsg->cmsg_level == SOL_SOCKET 67 if (cmsg->cmsg_level == SOL_SOCKET &&
76 && cmsg->cmsg_type == SCM_CREDENTIALS) { 68 cmsg->cmsg_type == SCM_CREDENTIALS) {
77 cred = (struct ucred *)CMSG_DATA(cmsg); 69 cred = (struct ucred*)CMSG_DATA(cmsg);
78 break; 70 break;
79 } 71 }
80 cmsg = CMSG_NXTHDR(&hdr, cmsg); 72 cmsg = CMSG_NXTHDR(&hdr, cmsg);
@@ -91,26 +83,29 @@ bool LogListener::onDataAvailable(SocketClient *cli) {
91 return false; 83 return false;
92 } 84 }
93 85
94 android_log_header_t *header = reinterpret_cast<android_log_header_t *>(buffer); 86 android_log_header_t* header =
95 if (/* header->id < LOG_ID_MIN || */ header->id >= LOG_ID_MAX || header->id == LOG_ID_KERNEL) { 87 reinterpret_cast<android_log_header_t*>(buffer);
88 if (/* header->id < LOG_ID_MIN || */ header->id >= LOG_ID_MAX ||
89 header->id == LOG_ID_KERNEL) {
96 return false; 90 return false;
97 } 91 }
98 92
99 if ((header->id == LOG_ID_SECURITY) && 93 if ((header->id == LOG_ID_SECURITY) &&
100 (!__android_log_security() || 94 (!__android_log_security() ||
101 !clientHasLogCredentials(cred->uid, cred->gid, cred->pid))) { 95 !clientHasLogCredentials(cred->uid, cred->gid, cred->pid))) {
102 return false; 96 return false;
103 } 97 }
104 98
105 char *msg = ((char *)buffer) + sizeof(android_log_header_t); 99 char* msg = ((char*)buffer) + sizeof(android_log_header_t);
106 n -= sizeof(android_log_header_t); 100 n -= sizeof(android_log_header_t);
107 101
108 // NB: hdr.msg_flags & MSG_TRUNC is not tested, silently passing a 102 // NB: hdr.msg_flags & MSG_TRUNC is not tested, silently passing a
109 // truncated message to the logs. 103 // truncated message to the logs.
110 104
111 if (logbuf->log((log_id_t)header->id, header->realtime, 105 if (logbuf->log((log_id_t)header->id, header->realtime, cred->uid,
112 cred->uid, cred->pid, header->tid, msg, 106 cred->pid, header->tid, msg,
113 ((size_t) n <= USHRT_MAX) ? (unsigned short) n : USHRT_MAX) >= 0) { 107 ((size_t)n <= USHRT_MAX) ? (unsigned short)n : USHRT_MAX) >=
108 0) {
114 reader->notifyNewLog(); 109 reader->notifyNewLog();
115 } 110 }
116 111
@@ -122,9 +117,8 @@ int LogListener::getLogSocket() {
122 int sock = android_get_control_socket(socketName); 117 int sock = android_get_control_socket(socketName);
123 118
124 if (sock < 0) { 119 if (sock < 0) {
125 sock = socket_local_server(socketName, 120 sock = socket_local_server(
126 ANDROID_SOCKET_NAMESPACE_RESERVED, 121 socketName, ANDROID_SOCKET_NAMESPACE_RESERVED, SOCK_DGRAM);
127 SOCK_DGRAM);
128 } 122 }
129 123
130 int on = 1; 124 int on = 1;