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
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
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
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
There's a lot of unnecessary boilerplate around these opaque types,
and this change simplifies it.
Test: liblog-unit-tests
Change-Id: I0c4e133037fd5f04157ac22175181a6a496e18c4
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
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
The "branchless" macro generates slightly worse code than std::min or
<sys/param.h>'s MIN.
Test: treehugger
Change-Id: I92c17325383bd6116c7b4736d42f01f7a9bb81a3
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
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