Commit graph

18 commits

Author SHA1 Message Date
Tom Cherry
ed860ff4bf Make android_logger_set_prune_list() sane
The current version requires callers to supply a string with 32 extra
bytes for liblog to internally prepend "setPruneList ", and to have
enough space to parse logd's return string.  That is an unacceptable
requirement on callers.

This change removes that requirement by having liblog allocate the
needed std::string in any case.

It also stops writing back the 'success' or 'Invalid' string to the
caller's buffer, since that is redundant as well.

Test: changing prune settings works.
Change-Id: Ic0f03a229f0b9a77d03adcb91288370c3bd42903
2019-12-06 11:23:58 -08:00
Tom Cherry
4023938914 Merge "liblog: remove the rest of the log reader transport" 2019-11-19 20:21:42 +00:00
Tom Cherry
1a75a8cd4b liblog: remove memset() before recv().
This is unneeded, since we're already checking the length returned by
recv() and log_msg that is read for validity.

It costs ~4% of CPU with `logcat -s` and ~2% of CPU when running
simpleperf for 1 second on walleye on master.

Bug: 144311420
Test: logcat works, simpleperf doesn't show memset() costing as much.
Change-Id: I986e7e96518774034340f1b1201a2071a904e3bb
2019-11-19 10:10:37 -08:00
Tom Cherry
026ddde6e4 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
2019-11-19 09:41:49 -08:00
Tom Cherry
9156c534e0 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
2019-11-18 07:16:40 -08:00
Tom Cherry
828db1a901 liblog: cleanup opaque type usage
There's a lot of unnecessary boilerplate around these opaque types,
and this change simplifies it.

Test: liblog-unit-tests
Change-Id: I0c4e133037fd5f04157ac22175181a6a496e18c4
2019-11-14 10:40:42 -08:00
Tom Cherry
e3fc9ac7e3 Merge "liblog: remove alarm in logd_reader.cpp" 2019-10-09 14:48:38 +00:00
Tom Cherry
5398021b9e liblog: remove alarm in logd_reader.cpp
There is an alarm() call that provides a 30 second timeout in case
logd is unavailable.  The main reason for this is in the case that logd
is crashing, debuggerd is ptrace'ing logd, and tombstoned is
attempting to dump log messages.  In this case, with no other checks
and without this alarm, tombstoned will deadlock when dumping log
messages.

However, tombstoned already has two mechanisms to prevent the above
situation from happening:
1) It checks that the thread name that is is dumping is either logd or
   starts with "logd." and skips dumping logs in this case.
2) It does not dump logs if it is running in process for any process.

Calling alarm() or modifying signal handlers from general purpose
libraries is not recommended either, so without a strong reason to
keep this, this change removes it.

This also shortens the liblog.wrap_mode_blocks test time, since the 30
second issue that it ensures does not happen has been fundamentally
removed.

Test: `kill -8 `pidof logd`` succeeds without delay
Test: liblog, logd unit tests
Change-Id: Id8a40544645d220e49f7ba299201af80a0c44de9
2019-10-08 13:05:55 -07:00
Tom Cherry
5d7969b58a Merge "liblog: remove code checking for fd = 0" 2019-10-08 19:24:02 +00:00
Tom Cherry
29d0e89364 liblog: remove code checking for fd = 0
Fix a typo where I check socket()'s return value for 0 instead of -1
as an error.

Remove code that checks if socket() returns 0 as the actual fd that it
returns.  This should not happen in any well formed program.

Test: liblog unit tests
Change-Id: I1d878e85d9a39155d68c6c84e9cf9b0db8d1b3a4
2019-10-08 10:18:20 -07:00
Nick Desaulniers
34282df8bb [liblog] fix -Wreorder-init-list
Bug: 139945549
Test: mm
Change-Id: I57de1a650d2c85dfb4f8817bbc80eb2296eaf568
Signed-off-by: Nick Desaulniers <ndesaulniers@google.com>
2019-10-07 21:28:43 -07:00
Elliott Hughes
6efbda7309 liblog: replace crufty min macro with existing MIN.
The "branchless" macro generates slightly worse code than std::min or
<sys/param.h>'s MIN.

Test: treehugger
Change-Id: I92c17325383bd6116c7b4736d42f01f7a9bb81a3
2019-10-02 12:27:03 -07:00
Tom Cherry
0f6ea6e8b6 liblog: remove a few unused items
Test: build
Change-Id: I8a31ad3a9fcd6f74f3a0221d38b64e8e2ea7ea2d
2019-10-01 17:29:13 -07:00
Tom Cherry
4c63e04f2a liblog: remove endianness functions
Android is little endian.

Test: liblog unit tests
Change-Id: Ieea7af39013a97f9f0d138a6d1ada3524d94e710
2019-09-30 14:39:37 -07:00
Tom Cherry
f7e1b1ebd4 liblog: only allow one transport for reading
liblog has left over code from local_logger that allows for reading
from multiple sources and merging the contents.  Since we've already
removed local_logger, this change removes the rest of this code.

Test: liblog-unit-tests
Change-Id: I5685ad6c1e7cbcaa0a660ed10f47714784a40791
2019-08-26 19:50:32 -07:00
Tom Cherry
05de1ba38e liblog: simplify socket_local_client() and always use CLOEXEC
socket_local_client() was copied from libcutils, but we only need a
small subset of its functionality.  We instead create our own version
with just the needed parts.

Importantly, use CLOEXEC in this new function and other places where
it was missing previously.

Test: logging works, liblog-unit-tests
Change-Id: Ifb929227af67bafa13e391eab92358d9f6fe6450
2019-02-12 12:53:19 -08:00
Tom Cherry
2d9779e87b liblog: remove visibility macros
Visibility is managed through version scripts now.

Bug: 123349183
Test: build
Change-Id: Ia388611a2ec14d0ff9c3896cfe97ccdce17dbb8b
2019-02-08 11:48:19 -08:00
Tom Cherry
71ba16488b liblog: convert to C++
Bug: 119867234
Test: liblog, logcat, logd unit tests

Change-Id: I2a33b6fc37f9860c0041e3573bfb59ea389f623c
2019-01-15 15:57:33 -08:00
Renamed from liblog/logd_reader.c (Browse further)