summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMark Salyzyn2015-03-03 18:21:27 -0600
committerMark Salyzyn2015-03-04 15:21:41 -0600
commit29eb57066c37bf667a56bb4a7143b50664d5eb44 (patch)
treeaf2101fdf3c2037ad9625f50b029b3a994b84bf5
parent4487c605eaeea2b85c8511fe915a286c3aaf4da4 (diff)
downloadplatform-system-core-29eb57066c37bf667a56bb4a7143b50664d5eb44.tar.gz
platform-system-core-29eb57066c37bf667a56bb4a7143b50664d5eb44.tar.xz
platform-system-core-29eb57066c37bf667a56bb4a7143b50664d5eb44.zip
logd: use <endian.h>
Change-Id: Iba843c054ea4fbe1a26c7821b5613fdb5e8001a1
-rw-r--r--logd/LogAudit.cpp33
1 files changed, 15 insertions, 18 deletions
diff --git a/logd/LogAudit.cpp b/logd/LogAudit.cpp
index c7c024995..af0b77595 100644
--- a/logd/LogAudit.cpp
+++ b/logd/LogAudit.cpp
@@ -15,6 +15,7 @@
15 */ 15 */
16 16
17#include <ctype.h> 17#include <ctype.h>
18#include <endian.h>
18#include <errno.h> 19#include <errno.h>
19#include <limits.h> 20#include <limits.h>
20#include <stdarg.h> 21#include <stdarg.h>
@@ -23,6 +24,8 @@
23#include <sys/uio.h> 24#include <sys/uio.h>
24#include <syslog.h> 25#include <syslog.h>
25 26
27#include <private/android_logger.h>
28
26#include "libaudit.h" 29#include "libaudit.h"
27#include "LogAudit.h" 30#include "LogAudit.h"
28 31
@@ -138,29 +141,23 @@ int LogAudit::logPrint(const char *fmt, ...) {
138 // log to events 141 // log to events
139 142
140 size_t l = strlen(str); 143 size_t l = strlen(str);
141 size_t n = l + sizeof(uint32_t) + sizeof(uint8_t) + sizeof(uint32_t); 144 size_t n = l + sizeof(android_log_event_string_t);
142 145
143 bool notify = false; 146 bool notify = false;
144 147
145 char *newstr = reinterpret_cast<char *>(malloc(n)); 148 android_log_event_string_t *event = static_cast<android_log_event_string_t *>(malloc(n));
146 if (!newstr) { 149 if (!event) {
147 rc = -ENOMEM; 150 rc = -ENOMEM;
148 } else { 151 } else {
149 cp = newstr; 152 event->header.tag = htole32(AUDITD_LOG_TAG);
150 *cp++ = AUDITD_LOG_TAG & 0xFF; 153 event->payload.type = EVENT_TYPE_STRING;
151 *cp++ = (AUDITD_LOG_TAG >> 8) & 0xFF; 154 event->payload.length = htole32(l);
152 *cp++ = (AUDITD_LOG_TAG >> 16) & 0xFF; 155 memcpy(event->payload.data, str, l);
153 *cp++ = (AUDITD_LOG_TAG >> 24) & 0xFF; 156
154 *cp++ = EVENT_TYPE_STRING; 157 logbuf->log(LOG_ID_EVENTS, now, uid, pid, tid,
155 *cp++ = l & 0xFF; 158 reinterpret_cast<char *>(event),
156 *cp++ = (l >> 8) & 0xFF;
157 *cp++ = (l >> 16) & 0xFF;
158 *cp++ = (l >> 24) & 0xFF;
159 memcpy(cp, str, l);
160
161 logbuf->log(LOG_ID_EVENTS, now, uid, pid, tid, newstr,
162 (n <= USHRT_MAX) ? (unsigned short) n : USHRT_MAX); 159 (n <= USHRT_MAX) ? (unsigned short) n : USHRT_MAX);
163 free(newstr); 160 free(event);
164 161
165 notify = true; 162 notify = true;
166 } 163 }
@@ -190,7 +187,7 @@ int LogAudit::logPrint(const char *fmt, ...) {
190 } 187 }
191 n = (estr - str) + strlen(ecomm) + l + 2; 188 n = (estr - str) + strlen(ecomm) + l + 2;
192 189
193 newstr = reinterpret_cast<char *>(malloc(n)); 190 char *newstr = static_cast<char *>(malloc(n));
194 if (!newstr) { 191 if (!newstr) {
195 rc = -ENOMEM; 192 rc = -ENOMEM;
196 } else { 193 } else {