liblog: simplify logd 'command' functions and struct logger
There are a set of functions, such as android_logger_get_log_size()
and android_logger_get_prune_list() that talk to the logd command
socket to perform their activities. There's a transport abstraction
layer that handles these symbols to optionally route them to other
transports, originally designed for pstore or local logger; however
these functions fundamentally only make sense for logd.
Ideally, these functions would be removed and new functions would be
added that do not depend on struct logger_list or struct logger and
more clearly indicate that they only work with logd. For example:
android_logger_get_size(struct logger*) could be
logd_get_buffer_size(log_id_t log_id). We would remove the need to
'open' the struct logger and make it clear that it only operates on
logd.
Since liblog is an llndk library however, we cannot change or remove
these symbols. Since these symbols are not frequently used, it seems
acceptable to keep them as is and not introduce improved versions.
We, however, do want to simplify the code that handles them and this
change removes the transport abstraction layer that handles them.
They retain the behavior that unless the struct logger_list was opened
for logd, that the functions return -EINVAL.
The one exception to this is android_logger_clear(). If the struct
logger provided to this function was opened from a struct logger_list
that used pstore for its mode argument, this function will clear the
entire pstore log. This function does not respect the 'logId'
parameter of the struct logger, since that would not be possible.
This change removes this android_logger_clear() behavior and makes it
strictly for logd, for symmetry with the rest of the functions and due
to the lack of clarity regarding the 'logId' parameter of its input.
The only caller of this function, logcat, will clear pstore directly.
struct logger was built to encapsulate the information needed to
connect to a logger device from the old kernel logger. Now that we
only support reading from pstore and from logd, there is much less
information needed to be captured. Specifically, we only need to know
the log_id and whether or not it was opened as part of a pstore or
logd 'list'.
Test: liblog-unit-test
Test: logcat -c/-g/-G/-p/-P/-S work
Test: logcat -c works with -L
Test: logcat -g/-G/-p/-P/-S continue to fail with -L
Change-Id: I2c549b6f8539de94510e223949ab209ecc40e2d0
diff --git a/liblog/logger.h b/liblog/logger.h
index 9c488b6..d2251e5 100644
--- a/liblog/logger.h
+++ b/liblog/logger.h
@@ -53,7 +53,6 @@
/* Does not cause resources to be taken */
int (*available)(log_id_t logId);
- int (*version)(struct logger* logger, struct android_log_transport_context* transp);
/* Release resources taken by the following interfaces */
void (*close)(struct logger_list* logger_list, struct android_log_transport_context* transp);
/*
@@ -62,53 +61,37 @@
*/
int (*read)(struct logger_list* logger_list, struct android_log_transport_context* transp,
struct log_msg* log_msg);
- /* Must only be called if not ANDROID_LOG_NONBLOCK (blocking) */
- int (*poll)(struct logger_list* logger_list, struct android_log_transport_context* transp);
-
- int (*clear)(struct logger* logger, struct android_log_transport_context* transp);
- ssize_t (*setSize)(struct logger* logger, struct android_log_transport_context* transp,
- size_t size);
- ssize_t (*getSize)(struct logger* logger, struct android_log_transport_context* transp);
- ssize_t (*getReadableSize)(struct logger* logger, struct android_log_transport_context* transp);
-
- ssize_t (*getPrune)(struct logger_list* logger_list, struct android_log_transport_context* transp,
- char* buf, size_t len);
- ssize_t (*setPrune)(struct logger_list* logger_list, struct android_log_transport_context* transp,
- char* buf, size_t len);
- ssize_t (*getStats)(struct logger_list* logger_list, struct android_log_transport_context* transp,
- char* buf, size_t len);
};
struct android_log_transport_context {
union android_log_context_union context; /* zero init per-transport context */
struct android_log_transport_read* transport;
- unsigned logMask; /* mask of requested log buffers */
};
struct logger_list {
- struct listnode logger;
android_log_transport_context transport_context;
bool transport_initialized;
int mode;
unsigned int tail;
log_time start;
pid_t pid;
+ uint32_t log_mask;
};
-struct logger {
- struct listnode node;
- struct logger_list* parent;
+// Format for a 'logger' entry: uintptr_t where only the bottom 32 bits are used.
+// bit 31: Set if this 'logger' is for logd.
+// bit 30: Set if this 'logger' is for pmsg
+// bits 0-2: the decimal value of the log buffer.
+// Other bits are unused.
- log_id_t logId;
-};
+#define LOGGER_LOGD (1 << 31)
+#define LOGGER_PMSG (1 << 30)
+#define LOGGER_LOG_ID_MASK ((1 << 3) - 1)
-/* assumes caller has structures read-locked, single threaded, or fenced */
-#define logger_for_each(logp, logger_list) \
- for ((logp) = node_to_item((logger_list)->logger.next, struct logger, node); \
- ((logp) != node_to_item(&(logger_list)->logger, struct logger, node)) && \
- ((logp)->parent == (logger_list)); \
- (logp) = node_to_item((logp)->node.next, struct logger, node))
+inline bool android_logger_is_logd(struct logger* logger) {
+ return reinterpret_cast<uintptr_t>(logger) & LOGGER_LOGD;
+}
/* OS specific dribs and drabs */