Incidentd needs to access /data/misc/logd to get persisted logs for
debugging purposes. Relax permissions on /data/misc/logd to allow
group (log) to access the dir and read its files. Effectively change
to:
drwxr-x--- logd log /data/misc/logd
-rw-r----- logd log /data/misc/logd/logcat*
Since this dir stores the past output of logcat, anyone that can run
logcat can be granted access to this dir. Access to this dir is further
guarded by SELinux. So it is safe.
Bug: 147924172
Test: Build, flash, reboot. Verify that the files have the right
permissions.
Change-Id: I4d2aa9d5883d1ef14411b2b3902f0ca7c641dd7e
package_string() isn't readable in its current form and a loop is
unnecessary, so let's replace that with the direct calculations. The
new and old functions are identical in results except an edge case
where the old function incorrectly believes it needs to round up to
'10' for the size prefix, when '9' would be ok, specifically:
10\naaaaa\n\f vs 9\naaaaa\n\f. This is true for all powers of 10.
Clean up the calling side in logcat as well.
Test: printing log statistics and prune list works
Change-Id: Ib62ab2badab59040215b130ec9e3efbc7c95af3f
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
* The --help text is way too long to print after each error, so simply
print the errors and exit.
* Report errno in a few cases where it was previously not reported
* Fix more punctuation
* Fix '?' and ':' getopt_long() return cases for long options.
Test: errors look better
Change-Id: I57058a2250e9f3c3431f104e43f0eb5ec60d8c8a
* Print an error if -c is provided with -f and -L since it is ambiguous
* Move the clear operation when -f is provided to a stand alone
location, since there is no need to loop
* Prevent -g/-G, -S, and -p/-P with -f, since that combination doesn't
make sense
Test: logpersist works
Change-Id: I6d8709bd61c898c47835470e99b0acff8c2692e4
Makes slight improvements to the --help text:
- Fix whitespace formatting and punctuation.
- Divide options into categories
- Clarify how the logd control functions work.
- Clarify --print.
Add additional text to the EOF error message that is returned when
logd disconnects the logcat instance, to clarify that this is intended
behavior if the logcat instance is reading too slowly.
Bug: 144311420
Test: view these messages
Change-Id: Icc12d278a8e8cb483918c0637b6fb529949cc33f
Logcat dup-es STDOUT and used the dup-ed file descriptor to write logging
information. Because of this writes happen on that fd and not on stdout.
This in turn causes no output in the LogcatService in the emulator.
The qemu-pipe forwarder now dup-es the same fd as logcat is using so
that we receive data again.
Bug: b/145214141
Test: Logcat works again in emulator 29.2.10
Change-Id: Ia6e2430f1d7a0476a5b438d315a9ea337c13806d
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
Removing the rest of liblogcat broke logcatd since LogcatPanic() now
actually calls exit(), whereas logcatd relied on it to return
normally.
We can achieve the expected behavior with a small shell script, so
this change does that as well.
Test: logcatd / logpersist work
Change-Id: Icde36a4811a0db987a801978485e1af1dfc3d38c
1) Use libbase parsing functions instead of our own versions
2) Remove log_device_t, as it's an unneeded wrapper around log buffers
3) Do not report 'unexpected' if we get a log from a buffer that we
didn't reqest. I checked and I don't see any references to this
happening in practice, so the code is mostly superfluous. It seems
reasonable enough to report the actual buffer name instead of
'unexpected' in any case.
4) Print all buffers that experience an error, not just the first one
seen.
Test: logcat works, logcat-unit-tests
Change-Id: Ic50074cfb716f63f3eda261f1cd236d7afaf453a
There were big changes made to support liblogcat, which has long since
been removed. This change removes the rest of those changes.
It moves the rest of the global state into a class, particularly for
the logcatd case. The original code re-uses the same context, but
that doesn't seem right or safe.
Test: logcat works, logcat-unit-tests
Test: logpersist works, including last log cat and log rotation
Change-Id: Iee6a2a0319265e87be0bc8fec2b11e8fd2b65ed4
logger_entry and logger_entry_v2 were used for the kernel logger,
which we have long since deprecated. logger_entry_v3 is the same as
logger_entry_v4 without a uid field, so it is trivially removable,
especially since we're now always providing uids in log messages.
liblog and logd already get updated in sync with each other, so we
have no reason for backwards compatibility with their format.
Test: build, unit tests
Change-Id: I27c90609f28c8d826e5614fdb3fe59bde22b5042
I'm asked at least once a week or more why a new service isn't starting.
Usually, the reason is that "File ... has incorrect label or no domain
transition from ... to another SELinux domain defined. ..." from init.
Even in permissive mode, this is required.
Bug: 63014404
Test: boot, check logcat
Change-Id: I7244a56fc46f84e9592e1eccf2d23461691965b3
Add FALLTHROUGH_INTENDED for clang compiler.
Bug: 112564944
Test: build with global -Wimplicit-fallthrough.
Change-Id: I40f8bbf94e207c9dd90921e9b762ba51abab5777
The units should be byte instead of bit and multiplier are kibibyte
mebibyte gibibyte respectively.
Bug: 114062206
Test: Build and logcat -g
Test: ./logcat-unit-tests
Change-Id: I995faa9a340bb63f48d117a1b8590e5d74ac1bba
Parsing logs isn't an API, and even if you want to do that, popen(3)
already exists.
Bug: N/A
Test: ran tests
Change-Id: I53c40be49141483da0a844a7af47da0b38d29781
* Use const reference parameter type to avoid unnecessary copy.
* Use more efficient overloaded string methods.
Bug: 30407689
Bug: 30411878
Test: build with WITH_TIDY=1
Change-Id: Ia5a00581e718d412255d6177e5a7c286cdfbec11
If -h or --help argument was supplied, logcat would report the help
message but also return an error. Officially add -h and --help as
recognized flags, report all help with a (zero) success error code.
Adding this, and the associated test, was split off as a stepping
stone to resolving an issue with logcat -L or --last flag operations.
Test: gTest logcat-unit-tests --gtest_filter=*.help
Bug: 28788401
Bug: 30041146
Bug: 30612424
Bug: 35326290
Change-Id: I948e7fa4e92bd23f52717758ffd96bbd068c53d4
Upon opening, qemu pipe (a.k.a. goldfish pipe) requires a purpose
string so that emulator can route the content to the right channel
on the host.
This CL will ask emulator to send the content to pipe based 'logcat'
service on the host.
Change-Id: Icc71f81d5b95b64ea315fe10da82ff704416e449
Was leaking log_device_t in command path. Cleanup leak in command
path and add thorough clean up on destroy for insurance.
Start grouping related like-type variables in the context structure
for more effective layout.
Test: gTest logcat-unit-tests
Bug: 35326290
Change-Id: Ibfbddec2d0e1bce24b87b035d67726cac1395574
Resolve one of the threading issues by creating a private C++ified
copy of getopt_long_r that started out its life as the bionic
getopt_long, but is reentrant. Adds a new state context for the
stderr stream called optstderr. Utilize this new function in logcat.
Control opterr and optstderr to match liblogcat expectations. Correct
and fortify const.
Alternative would be to lock around _all_ getopt callers. This has
the advantage of requiring _no_ locks that could get in the way of
using liblogcat in a signal handler. The log reader interface does
run the risk of incurring locks and heap allocations though, so there
is more work to be done for that final goal.
Test: gTest logcat-unit-tests
Bug: 35326290
Change-Id: Ibb1b374c55d357d5d7fa5ad00bfaf07ae0bc4ba5
Deal with yet another reentrancy issue with strtok() and do not
treat optarg as fungible data, allocate a temporary copy. Add
support in the -v flag and environmental variable ANDROID_PRINTF_LOG
for a comma-separated list of format and format modifiers.
Test: manual + gTest logcat-unit-tests
Bug: 35326290
Change-Id: I073e5676d59ba41bfd36df86942342766ef730f1
- Replace all NULL, macro defined to 0, with nullptr. nullptr is a
keyword of type nullptr_t, with a value of (nullptr_t)0, a pointer
type of sizeof(void*) that can not confusingly promote to an int.
- Replace all boolean evaluations of values against 0, NULL, and
nullptr with direct, ! or !! as appropriate.
- Note that thread_stopped should be semaphore, defer that to
a non-code-quality improvement patch.
- Check for null context in android_logcat_destroy.
- Run clang-format to realign format with setting.
Test: compile and gTest logcat-unit-tests
Bug: 35326290
Change-Id: Iaf729cd7899c6cece78431536ed325604f0e353f
Provide minimal redirection functionality, adding stdout redirection
to the existing stderr redirection parsing.
- stderr and stdout redirection do _not_ support append, will treat
like write only.
- stderr redirection does _not_ support filename. Only 2>&1 to
join stderr and stdout and 2>/dev/null to drop content on floor.
- stdout redirection supports filename only.
- stderr 2>&1 redirection must be last for shell compatibility.
- preserve 2>&1 through file rotation (bugfix)
Test: logcat-benchmarks --benchmark_filter='BM_logcat_popen*|BM_logcat_system*'
Bug: 35326290
Change-Id: Id36b59358167f21381bd1dbf0bd7a7e10e2a2ed9
The -Q option is used in emulator and it fails to redirect the
output of logcat to the desired file.
This CL fixes that problem.
There is no gTest because of /proc/cmdline sniffing for this option.
manually tested on /dev/qemu_pipe inside emulator
Test: manual
Bug: 35326290
Change-Id: I282da685e90450aadb2a989a0517dc3b1bb6634d
A non-blocking API to run a logcat function in a background thread.
Returns a read end of a pipe to collect the output.
Test: gTest logcat-unit-tests
Bug: 35326290
Change-Id: Idc14e4ad955e0b2b9fafa5d3aeed8cd7fb4069fb
Try to leverage as much of logcat as-is and produce a viable
library API that others can use for their own logcat execution.
Added a test to check ANDROID_PRINTF_LOG environment variable.
Test: gTest logcat-unit-tests
Bug: 35326290
Change-Id: I30de692ea9d83e6fd6e5d9e7cf93d31401a88a40
- Android coding standard compliance with an eye to reducing merge
impact.
- resolve a few misbehaviors in logcat_test.
SideEffects: none
Test: gTest logcat-unit-tests
Bug: 35326290
Change-Id: I63d0667ad34c0df11086a6ffe94b7030430b865b
Add a hidden -v nsec flag to logcat (actually logprint in liblog.so)
so that we can do more exacting tests of logcat.tail_time. Halve the
spam pressure of logcat.tail_* in inject() routine, and give us a few
more retries at the higher counts. Add instrumentation to
logcat.logrotate failures. Add inject for logcat.year test.
Test: gTest logcat-unit-tests
Bug: 34454772
Change-Id: If6f3bd21892c8a2b9ccee8c8bbf592a1ae0b2a57
Do not report security buffer errors if not specifically
named in the buffer list.
Test: gTest logcat-unit-test --gtest_filter=logcat.security
Bug: 34511645
Change-Id: I028d51abad0329fcf42e467b135d035b06c1d2e3
NULL represents system default. In the future, NULL could represent
static and dynamic tags, which can come from multiple files based on
implementation details in the liblog library.
Test: gTest logd-unit-tests & liblog-unit-tests
Bug: 31456426
Change-Id: I0e3d296de81ca299ae63d7b83781639ee67ec298
Expand logprint feature to pull out the log tag description
fields, parse them and merge into the logging content. Add
-v descriptive, -v colour(british, hidden) and -v help. Also
added a unit test for the descriptive format borrowing from
event tags that have been unchanged since 2009.
Had to add -v help because we have too many undocumented
formats and format adverbs.
Test: gTest logcat-unit-tests --gtest_filter=logcat.descriptive
Bug: 31456426
Change-Id: I93a1c003b7a3f4c332544946fdedb7277919cec3
Commit 807e40ecc9 'liblog: logd: Add
android_lookupEventTag_len()' which addressed a Dirty Shared memory
leak resulted in a regression. Most notably logcat <tag> stopped
working for the events log buffer.
AndroidLogEntry::tag also requires callers to check out
AndroidLogEntry::tagLen as tag is no longer guaranteed to be
nul terminated.
Test: logcat-unit-tests --gtest_filter=logcat.event_tag_filter
Bug: 31456426
Change-Id: Ibe5236131b640eb5b7e3df0ab4b5f3e25b85ad45
log/logger.h pieces moved into log/log.h. Correct for some
minor Android Coding standards.
Test: gTests liblog-unit-tests, logd-unit-tests and logcat-unit-tests
Bug: 19235719
Bug: 26552300
Bug: 31289077
Bug: 31456426
Change-Id: I0a19fd8788eec20a582e72e4c62c04534bdb1b9a