summaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorMark Salyzyn <salyzyn@google.com>2014-03-05 07:41:49 -0800
committerMark Salyzyn <salyzyn@google.com>2014-03-05 16:12:28 -0800
commit7e2f83c0bcc3ad8a2840a48be14d302ed79d671c (patch)
treee2d2ed4a9a9e218e046cb0796607cca8fc5ed97f /include
parent51ebffd8a5536af09b60950bf7cf6f020c962f8a (diff)
downloadsystem_core-7e2f83c0bcc3ad8a2840a48be14d302ed79d671c.zip
system_core-7e2f83c0bcc3ad8a2840a48be14d302ed79d671c.tar.gz
system_core-7e2f83c0bcc3ad8a2840a48be14d302ed79d671c.tar.bz2
logd: liblog: 64-bit issues
- structure packing - move towards log_time from struct timespec - extend log_time to cover differences between log_time and struct timespec Change-Id: I106ed0b609917306d170044054b5b32645f2a295
Diffstat (limited to 'include')
-rw-r--r--include/log/log_read.h59
-rw-r--r--include/log/logger.h8
2 files changed, 59 insertions, 8 deletions
diff --git a/include/log/log_read.h b/include/log/log_read.h
index 2601622..7edfe3c 100644
--- a/include/log/log_read.h
+++ b/include/log/log_read.h
@@ -19,21 +19,38 @@
#include <time.h>
+/* struct log_time is a wire-format variant of struct timespec */
#define NS_PER_SEC 1000000000ULL
#ifdef __cplusplus
-struct log_time : public timespec {
+struct log_time {
public:
+ uint32_t tv_sec; // good to Feb 5 2106
+ uint32_t tv_nsec;
+
log_time(const timespec &T)
{
tv_sec = T.tv_sec;
tv_nsec = T.tv_nsec;
}
+ log_time(const log_time &T)
+ {
+ tv_sec = T.tv_sec;
+ tv_nsec = T.tv_nsec;
+ }
+ log_time(uint32_t sec, uint32_t nsec)
+ {
+ tv_sec = sec;
+ tv_nsec = nsec;
+ }
log_time()
{
}
log_time(clockid_t id)
{
- clock_gettime(id, (timespec *) this);
+ timespec T;
+ clock_gettime(id, &T);
+ tv_sec = T.tv_sec;
+ tv_nsec = T.tv_nsec;
}
log_time(const char *T)
{
@@ -41,6 +58,8 @@ public:
tv_sec = c[0] | (c[1] << 8) | (c[2] << 16) | (c[3] << 24);
tv_nsec = c[4] | (c[5] << 8) | (c[6] << 16) | (c[7] << 24);
}
+
+ // timespec
bool operator== (const timespec &T) const
{
return (tv_sec == T.tv_sec) && (tv_nsec == T.tv_nsec);
@@ -67,13 +86,45 @@ public:
{
return !(*this > T);
}
+
+ // log_time
+ bool operator== (const log_time &T) const
+ {
+ return (tv_sec == T.tv_sec) && (tv_nsec == T.tv_nsec);
+ }
+ bool operator!= (const log_time &T) const
+ {
+ return !(*this == T);
+ }
+ bool operator< (const log_time &T) const
+ {
+ return (tv_sec < T.tv_sec)
+ || ((tv_sec == T.tv_sec) && (tv_nsec < T.tv_nsec));
+ }
+ bool operator>= (const log_time &T) const
+ {
+ return !(*this < T);
+ }
+ bool operator> (const log_time &T) const
+ {
+ return (tv_sec > T.tv_sec)
+ || ((tv_sec == T.tv_sec) && (tv_nsec > T.tv_nsec));
+ }
+ bool operator<= (const log_time &T) const
+ {
+ return !(*this > T);
+ }
+
uint64_t nsec() const
{
return static_cast<uint64_t>(tv_sec) * NS_PER_SEC + tv_nsec;
}
-};
+} __attribute__((__packed__));
#else
-typedef struct timespec log_time;
+typedef struct log_time {
+ uint32_t tv_sec;
+ uint32_t tv_nsec;
+} __attribute__((__packed__)) log_time;
#endif
#endif /* define _LIBS_LOG_LOG_READ_H */
diff --git a/include/log/logger.h b/include/log/logger.h
index bea0022..8810615 100644
--- a/include/log/logger.h
+++ b/include/log/logger.h
@@ -30,7 +30,7 @@ struct logger_entry {
int32_t sec; /* seconds since Epoch */
int32_t nsec; /* nanoseconds */
char msg[0]; /* the entry's payload */
-};
+} __attribute__((__packed__));
/*
* The userspace structure for version 2 of the logger_entry ABI.
@@ -46,18 +46,18 @@ struct logger_entry_v2 {
int32_t nsec; /* nanoseconds */
uint32_t euid; /* effective UID of logger */
char msg[0]; /* the entry's payload */
-};
+} __attribute__((__packed__));
struct logger_entry_v3 {
uint16_t len; /* length of the payload */
- uint16_t hdr_size; /* sizeof(struct logger_entry_v2) */
+ uint16_t hdr_size; /* sizeof(struct logger_entry_v3) */
int32_t pid; /* generating process's pid */
int32_t tid; /* generating process's tid */
int32_t sec; /* seconds since Epoch */
int32_t nsec; /* nanoseconds */
uint32_t lid; /* log id of the payload */
char msg[0]; /* the entry's payload */
-};
+} __attribute__((__packed__));
/*
* The maximum size of the log entry payload that can be