liblog: remove the rest of the log reader transport
This is simplified down to the point there are only two branches that
need to be made, so remove the rest of the transport structs and
simply branch where needed.
Test: liblog-unit-tests
Change-Id: Ic82e7e70eb7b4e40b381a4d8066629c5b7d4f827
diff --git a/liblog/pmsg_reader.cpp b/liblog/pmsg_reader.cpp
index 9f603e9..9390fec 100644
--- a/liblog/pmsg_reader.cpp
+++ b/liblog/pmsg_reader.cpp
@@ -14,6 +14,8 @@
* limitations under the License.
*/
+#include "pmsg_reader.h"
+
#include <ctype.h>
#include <errno.h>
#include <fcntl.h>
@@ -26,31 +28,7 @@
#include "logger.h"
-static int PmsgAvailable(log_id_t logId);
-static int PmsgRead(struct logger_list* logger_list, struct android_log_transport_context* transp,
- struct log_msg* log_msg);
-static void PmsgClose(struct logger_list* logger_list,
- struct android_log_transport_context* transp);
-
-struct android_log_transport_read pmsgLoggerRead = {
- .name = "pmsg",
- .available = PmsgAvailable,
- .close = PmsgClose,
- .read = PmsgRead,
-};
-
-static int PmsgAvailable(log_id_t logId) {
- if (logId > LOG_ID_SECURITY) {
- return -EINVAL;
- }
- if (access("/dev/pmsg0", W_OK) == 0) {
- return 0;
- }
- return -EBADF;
-}
-
-static int PmsgRead(struct logger_list* logger_list, struct android_log_transport_context* transp,
- struct log_msg* log_msg) {
+int PmsgRead(struct logger_list* logger_list, struct log_msg* log_msg) {
ssize_t ret;
off_t current, next;
struct __attribute__((__packed__)) {
@@ -62,7 +40,7 @@
memset(log_msg, 0, sizeof(*log_msg));
- if (atomic_load(&transp->context.fd) <= 0) {
+ if (atomic_load(&logger_list->fd) <= 0) {
int i, fd = open("/sys/fs/pstore/pmsg-ramoops-0", O_RDONLY | O_CLOEXEC);
if (fd < 0) {
@@ -75,7 +53,7 @@
return -errno;
}
}
- i = atomic_exchange(&transp->context.fd, fd);
+ i = atomic_exchange(&logger_list->fd, fd);
if ((i > 0) && (i != fd)) {
close(i);
}
@@ -86,7 +64,7 @@
int fd;
if (preread_count < sizeof(buf)) {
- fd = atomic_load(&transp->context.fd);
+ fd = atomic_load(&logger_list->fd);
if (fd <= 0) {
return -EBADF;
}
@@ -120,7 +98,7 @@
(!logger_list->pid || (logger_list->pid == buf.p.pid))) {
char* msg = log_msg->entry.msg;
*msg = buf.prio;
- fd = atomic_load(&transp->context.fd);
+ fd = atomic_load(&logger_list->fd);
if (fd <= 0) {
return -EBADF;
}
@@ -144,7 +122,7 @@
return ret + sizeof(buf.prio) + log_msg->entry.hdr_size;
}
- fd = atomic_load(&transp->context.fd);
+ fd = atomic_load(&logger_list->fd);
if (fd <= 0) {
return -EBADF;
}
@@ -152,7 +130,7 @@
if (current < 0) {
return -errno;
}
- fd = atomic_load(&transp->context.fd);
+ fd = atomic_load(&logger_list->fd);
if (fd <= 0) {
return -EBADF;
}
@@ -166,8 +144,8 @@
}
}
-static void PmsgClose(struct logger_list*, struct android_log_transport_context* transp) {
- int fd = atomic_exchange(&transp->context.fd, 0);
+void PmsgClose(struct logger_list* logger_list) {
+ int fd = atomic_exchange(&logger_list->fd, 0);
if (fd > 0) {
close(fd);
}
@@ -185,7 +163,6 @@
__android_log_pmsg_file_read_fn fn, void* arg) {
ssize_t ret;
struct logger_list logger_list;
- struct android_log_transport_context transp;
struct content {
struct listnode node;
struct logger_entry entry;
@@ -207,7 +184,6 @@
/* Add just enough clues in logger_list and transp to make API function */
memset(&logger_list, 0, sizeof(logger_list));
- memset(&transp, 0, sizeof(transp));
logger_list.mode = ANDROID_LOG_PSTORE | ANDROID_LOG_NONBLOCK | ANDROID_LOG_RDONLY;
logger_list.log_mask = (unsigned)-1;
@@ -241,7 +217,7 @@
/* Read the file content */
log_msg log_msg;
- while (PmsgRead(&logger_list, &transp, &log_msg) > 0) {
+ while (PmsgRead(&logger_list, &log_msg) > 0) {
const char* cp;
size_t hdr_size = log_msg.entry.hdr_size;
@@ -399,7 +375,7 @@
}
list_add_head(node, &content->node);
}
- PmsgClose(&logger_list, &transp);
+ PmsgClose(&logger_list);
/* Progress through all the collected files */
list_for_each_safe(node, n, &name_list) {