Merge "Fs_mgr: Fix format code"
diff --git a/include/private/android_logger.h b/include/private/android_logger.h
index cc7ba30..724ca51 100644
--- a/include/private/android_logger.h
+++ b/include/private/android_logger.h
@@ -41,4 +41,46 @@
log_time realtime;
} android_log_header_t;
+/* Event Header Structure to logd */
+typedef struct __attribute__((__packed__)) {
+ int32_t tag; // Little Endian Order
+} android_event_header_t;
+
+/* Event payload EVENT_TYPE_INT */
+typedef struct __attribute__((__packed__)) {
+ int8_t type; // EVENT_TYPE_INT
+ int32_t data; // Little Endian Order
+} android_event_int_t;
+
+/* Event with single EVENT_TYPE_INT */
+typedef struct __attribute__((__packed__)) {
+ android_event_header_t header;
+ android_event_int_t payload;
+} android_log_event_int_t;
+
+/* Event payload EVENT_TYPE_LONG */
+typedef struct __attribute__((__packed__)) {
+ int8_t type; // EVENT_TYPE_LONG
+ int64_t data; // Little Endian Order
+} android_event_long_t;
+
+/* Event with single EVENT_TYPE_LONG */
+typedef struct __attribute__((__packed__)) {
+ android_event_header_t header;
+ android_event_long_t payload;
+} android_log_event_long_t;
+
+/* Event payload EVENT_TYPE_STRING */
+typedef struct __attribute__((__packed__)) {
+ int8_t type; // EVENT_TYPE_STRING;
+ int32_t length; // Little Endian Order
+ char data[];
+} android_event_string_t;
+
+/* Event with single EVENT_TYPE_STRING */
+typedef struct __attribute__((__packed__)) {
+ android_event_header_t header;
+ android_event_string_t payload;
+} android_log_event_string_t;
+
#endif
diff --git a/liblog/logprint.c b/liblog/logprint.c
index 7ba4c8e..8093a4c 100644
--- a/liblog/logprint.c
+++ b/liblog/logprint.c
@@ -416,27 +416,6 @@
}
/*
- * Extract a 4-byte value from a byte stream.
- */
-static inline uint32_t get4LE(const uint8_t* src)
-{
- return src[0] | (src[1] << 8) | (src[2] << 16) | (src[3] << 24);
-}
-
-/*
- * Extract an 8-byte value from a byte stream.
- */
-static inline uint64_t get8LE(const uint8_t* src)
-{
- uint32_t low, high;
-
- low = src[0] | (src[1] << 8) | (src[2] << 16) | (src[3] << 24);
- high = src[4] | (src[5] << 8) | (src[6] << 16) | (src[7] << 24);
- return ((long long) high << 32) | (long long) low;
-}
-
-
-/*
* Recursively convert binary log data to printable form.
*
* This needs to be recursive because you can have lists of lists.
@@ -473,7 +452,7 @@
if (eventDataLen < 4)
return -1;
- ival = get4LE(eventData);
+ ival = le32toh(*((int32_t *)eventData));
eventData += 4;
eventDataLen -= 4;
@@ -494,7 +473,7 @@
if (eventDataLen < 8)
return -1;
- lval = get8LE(eventData);
+ lval = le64toh(*((int64_t *)eventData));
eventData += 8;
eventDataLen -= 8;
@@ -515,7 +494,7 @@
if (eventDataLen < 4)
return -1;
- strLen = get4LE(eventData);
+ strLen = le32toh(*((int32_t *)eventData));
eventData += 4;
eventDataLen -= 4;
@@ -630,7 +609,7 @@
inCount = buf->len;
if (inCount < 4)
return -1;
- tagIndex = get4LE(eventData);
+ tagIndex = le32toh(*((int32_t *)eventData));
eventData += 4;
inCount -= 4;
diff --git a/logd/LogAudit.cpp b/logd/LogAudit.cpp
index c7c0249..af0b775 100644
--- a/logd/LogAudit.cpp
+++ b/logd/LogAudit.cpp
@@ -15,6 +15,7 @@
*/
#include <ctype.h>
+#include <endian.h>
#include <errno.h>
#include <limits.h>
#include <stdarg.h>
@@ -23,6 +24,8 @@
#include <sys/uio.h>
#include <syslog.h>
+#include <private/android_logger.h>
+
#include "libaudit.h"
#include "LogAudit.h"
@@ -138,29 +141,23 @@
// log to events
size_t l = strlen(str);
- size_t n = l + sizeof(uint32_t) + sizeof(uint8_t) + sizeof(uint32_t);
+ size_t n = l + sizeof(android_log_event_string_t);
bool notify = false;
- char *newstr = reinterpret_cast<char *>(malloc(n));
- if (!newstr) {
+ android_log_event_string_t *event = static_cast<android_log_event_string_t *>(malloc(n));
+ if (!event) {
rc = -ENOMEM;
} else {
- cp = newstr;
- *cp++ = AUDITD_LOG_TAG & 0xFF;
- *cp++ = (AUDITD_LOG_TAG >> 8) & 0xFF;
- *cp++ = (AUDITD_LOG_TAG >> 16) & 0xFF;
- *cp++ = (AUDITD_LOG_TAG >> 24) & 0xFF;
- *cp++ = EVENT_TYPE_STRING;
- *cp++ = l & 0xFF;
- *cp++ = (l >> 8) & 0xFF;
- *cp++ = (l >> 16) & 0xFF;
- *cp++ = (l >> 24) & 0xFF;
- memcpy(cp, str, l);
+ event->header.tag = htole32(AUDITD_LOG_TAG);
+ event->payload.type = EVENT_TYPE_STRING;
+ event->payload.length = htole32(l);
+ memcpy(event->payload.data, str, l);
- logbuf->log(LOG_ID_EVENTS, now, uid, pid, tid, newstr,
+ logbuf->log(LOG_ID_EVENTS, now, uid, pid, tid,
+ reinterpret_cast<char *>(event),
(n <= USHRT_MAX) ? (unsigned short) n : USHRT_MAX);
- free(newstr);
+ free(event);
notify = true;
}
@@ -190,7 +187,7 @@
}
n = (estr - str) + strlen(ecomm) + l + 2;
- newstr = reinterpret_cast<char *>(malloc(n));
+ char *newstr = static_cast<char *>(malloc(n));
if (!newstr) {
rc = -ENOMEM;
} else {