Commit graph

342 commits

Author SHA1 Message Date
Tom Cherry
500c25cb61 logcat: fix tests broken from new formatting
1) `logcat -g` now contains 'readable', so fix sscanf() appropriately
2) Remove tests that the security buffer isn't returned as an error,
since it's not important to hide this buffer from the logging front
end, and more importantly: the expected failures no longer happen.
3) Update invalid_buffer for the new error format.

Test: logcat-unit-tests
Change-Id: I1a607815bdc7b1135e9a0e97f8b7334f2d259e31
2020-09-01 21:33:34 +00:00
Tom Cherry
d11f2371e1 Remove android_lookupEventTagNum() and related code
This was introduced years ago but never gained any users.

Test: build
Merged-In: Id2deb6de1839f995970c6350a1970a872f0b51cf
Change-Id: Id2deb6de1839f995970c6350a1970a872f0b51cf
2020-08-17 18:04:00 +00:00
Tom Cherry
3e970d430f logcat: replace write() calls with WriteFully()
There is a possibility of data loss if an interrupt occurs in the
middle of these write() calls.

Test: logcat -g/-S/-B work correctly
Change-Id: I2dd4ec10771714fc49b61538d3028983516e106c
2020-08-05 14:01:11 -07:00
Tom Cherry
06e111a148 Add android_logger_get_log_consumed_size() and report it in logcat
There is an existing API, android_logger_get_log_readable_size() which
historically reported the consumed amount of data for the chatty log
buffer, since consumed and readable are synonymous with that buffer
type.

With log compression, readable and consumed are not synonymous, since
the readable log size is the uncompressed log size whereas the
consumed log size is the compressed log size.

This change adds android_logger_get_log_consumed_size() which returns
the consumed log size and makes android_logger_get_log_readable_size()
return the readable log size.  Note that these values are identical if
compression is not used.

It adds both statistics to logcat:

    main: ring buffer is 1 MiB (429 KiB consumed, 817 KiB readable)
    radio: ring buffer is 1 MiB (339 KiB consumed, 715 KiB readable)
    ...

Test: logcat prints the right values with compression and chatty
Change-Id: I8b9688a987736204e2e6026e8635fbd1a5e68bb7
2020-08-05 13:43:31 -07:00
Tom Cherry
2d451663be Cleanup for #inclusivefixit.
Test: build
Change-Id: If11a32c130367560394eccf442de95d941918073
2020-07-27 11:37:19 -07:00
Treehugger Robot
7382be402a Merge "Use standard colors in logcat color output" 2020-06-22 21:43:14 +00:00
Peter Kalauskas
8b477b6d10 Use standard colors in logcat color output
Previously, colors were specified from the 216 additional colors, which
typically specify an exact RGB color value. Instead, use escape codes
for standard colors (default foreground, red, green, yellow, etc.),
which are commonly adjusted by terminal emulators user preferences.

Bug: 159503129
Test: adb logcat --format color
Test: atest liblog
Change-Id: I0b10a70a76a29d896d04d6c49e716b09cb09b19a
2020-06-20 03:26:12 +00:00
Tom Cherry
0efb410013 logging: Use more inclusive language.
Also generic syntax clean up and removing some unused aspects (sorting
the list and the TODO increasing performance based on this sorting).

Test: logging unit tests
Change-Id: I56bb3866c13cb4c28bd48665bf32ec620cf0278e
2020-06-16 14:31:31 -07:00
Treehugger Robot
cbe630dbc6 Merge "Logtags for input flinger" 2020-06-08 17:47:31 +00:00
Siarhei Vishniakou
9243090395 Logtags for input flinger
Reserve logtags 62000 -> 62199 for inputflinger

Bug: 153092301
Test: build with ag/10998853
Change-Id: If87f8e8e39bd445dfa7c96a542482c9ff3bf3fd3
2020-06-05 12:37:43 -07:00
Tom Cherry
9291f0f566 logcat: filter based on UID
Bug: 153761317
Test: logging works normally without --uid
Test: logging filters based on uid with --uid
Change-Id: I6843fa635831c727c0236ac5534862e11447484b
2020-06-05 10:02:44 -07:00
Tom Cherry
bd80e5678f liblog: remove unused log_time functions, inline the others
One of the reasons that logcat and logd statically include liblog is
to access the symbols in log_time.cpp, which we do not expose
otherwise.  Except for strptime(), which will be handled in a separate
CL, these symbols are either small enough to inline in the header or
unused and can be removed.

Test: logging unit tests
Change-Id: I1f8cfbb779aef79fc7d5b6d0050438fe5f0e0e2c
2020-05-18 15:40:26 -07:00
Tom Cherry
f2c2746aba Remove the monotonic option for logging
This has been around for ~5 years but there has been roughly no
adoption, so remove this as we clean up the logging code.

Future efforts may track the monotonic timestamp in all cases.

Test: logging unit tests
Change-Id: I55ed565669f923988e741f6b384141bba893630d
2020-05-06 13:37:33 -07:00
Jaegeuk Kim
2e5b7c425f logcatd: unset pinning log files
commit 5327d931ac ("logcatd: fallocate and fadvise to logcat files")
introduced pinning log files in order to avoid f2fs fragmentation.

But, logcatd does not guarantee to write data within fallocated 2MB space.
So, we can see some bytes written beyond 2MB boundary which results in
pinning small chunks across the filesystem. This makes F2FS GC have to unset
the pinning blocks via GC loop. If this happens during checkpoint=disable
at booting time, we can see long delay to mount /data accordingly.

Bug: 136483670
Bug: 137180754
Bug: 149418646
Fixes: 5327d931ac ("logcatd: fallocate and fadvise to logcat files")
Signed-off-by: Jaegeuk Kim <jaegeuk@google.com>
Change-Id: I986221d6d1da9b8e46e63d1be98ddf0ce4cb099f
2020-04-23 20:52:11 +00:00
Tom Cherry
c5c6d7d326 Don't include log/log_read.h in log/log.h
log/log.h primarily concerns itself with writing logs.  The few users
who read logs should directly include log/log_read.h.

Bug: 78370064
Test: build
Change-Id: Ie95c55ea2ffc76fc95768323d445ada6ad4f2520
2020-04-17 15:31:34 -07:00
Felipe Leme
76024d755a Documented range of event logtags used by Android Automotive.
Test: N/A
Bug: 153900032

Change-Id: I2e35d56f89becea33c4a4b7fb6af8de3ccbb087a
2020-04-15 14:40:21 -07:00
Tom Cherry
907b2d0349 Remove ANDROID_LOG_RDONLY, etc
These macros haven't been meaningful in years.

Test: logging unit tests
Change-Id: I796ec6d9b450f8a84bc85c3f15ddd988724c5e08
2020-03-23 13:43:27 -07:00
Tom Cherry
26d712eef1 logcat: add 'device shut down' to error message upon EOF
Turns out this is the actual most likely cause of EOF.

Test: n/a
Change-Id: I00b89fea9e7069493e7143be443c520ea3cb3c89
2020-02-14 10:10:44 -08:00
Mike Ma
a7fb095207 Relax permissions on /data/misc/logd
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
2020-01-21 18:39:19 -08:00
Tom Cherry
4b4154be30 logcat: remove unused enum and #def
Test: build
Change-Id: Ie43b4eb39c85b2a8edad4a5a73696dc97f43be68
2019-12-09 13:29:39 -08:00
Tom Cherry
e17b4f62df Cleanup package_string() and its users
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
2019-12-06 13:55:08 -08:00
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
72a4e08864 logcat: more error printing clean-up
* 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
2019-12-06 10:27:07 -08:00
Tom Cherry
c30a3eede5 logcat: clean up handling of logd control commands with -f and -L
* 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
2019-12-05 13:39:34 -08:00
Tom Cherry
416973276e logcat: improve --help and error messages
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
2019-12-04 14:00:50 -08:00
Erwin Jansen
4f138b2ce8 Dup the correct fd for qemu pipe.
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
2019-12-02 18:56:27 +00: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
2249b07eb8 logcat: fix logpersist.stop and logpersist.clear
Test: these work
Change-Id: Ib0b0b5408c93a05f39d1b585256a2c7c34736e7e
2019-10-31 06:43:47 -07:00
Tom Cherry
98c6c3304a logcat: fix logcatd / logpersist
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
2019-10-31 06:43:47 -07:00
Tom Cherry
6f061e8d64 logcat: modernize the code
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
2019-10-29 16:07:51 -07:00
Tom Cherry
d162f14d6c logcat: remove the rest of liblogcat
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
2019-10-25 15:00:16 -07:00
Tom Cherry
441054aa1e Remove old logger_entry_v* formats
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
2019-10-24 10:53:14 -07:00
Rashed Abdel-Tawab
a726e460aa
Change logpersist.start to sh_binary
This is a script, should be sh_binary

Test: m -j logpersist.start, check symlinks
Change-Id: I724abab898285c308291091ea8c76f5b93e4aaa5
2019-10-04 20:42:39 -07:00
Jaegeuk Kim
5327d931ac logcatd: fallocate and fadvise to logcat files
1. Pinning and fallocating blocks can avoid filesystem fragmentation.
2. Dropping caches can avoid memory pressure.
3. Use 2MB files

Bug: 136483670
Bug: 137180754
Change-Id: I0827bd903a677cbcbf3688983e847301cd541cdd
Signed-off-by: Jaegeuk Kim <jaegeuk@google.com>
2019-09-04 22:45:48 +00:00
Elliott Hughes
addd852165 logcat: switch to <regex>.
This was the only user of the google3 additions to external/pcre.

Test: adb logcat --grep camera
Change-Id: Iaa9dae38d30f60470f6a65b0a0fdd93e01abfc99
2019-08-08 08:53:59 -07:00
Steven Moreland
b0e867a1e6 logcat: error on multiple PID argument
Since they are dropped.

Bug: N/A
Test: manual try w/ 1 and 2 --pid arguments
Change-Id: I5945c12dc080a8c046b8071106f7d87ecb2b018c
2019-08-02 10:14:37 -07:00
Tian Baofeng
8415a5c45e Logcatd: remove some extra logic
There will be some unnecessary error logs caused
by extra logic was reported by init when some properties
were set default values. This patch remove these logic
codes to remove these avoidable error logs.

Bug: 137567691
Test: Can use logcat -r -n with configures

Change-Id: I9b8fa2025bcbef5d39438a8243f9ff5dc0a645df
Signed-off-by: Tian, Baofeng <baofeng.tian@intel.com>
Signed-off-by: Duan, YayongX <yayongx.duan@intel.com>
2019-07-25 06:27:36 +00:00
Steven Moreland
fe535f5e68 logcat: add 'kernel' to defaults
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
2019-07-08 15:59:25 -07:00
Tian, Baofeng
00813a585a Logcatd: Add new properties control logcat file size and file count.
Logcatd has capability to output logs to filesystem with certain size
and certain file count, however file size is not configurable, fixed
as 1024 kbytes, file count is configurable, but original property
name didn't match the logcat parameter well.
This patch add interface rotate_kbytes and count into logcatd.rc.
rotate_kbytes used to control each logcat file size.
count is another alias for logd.logpersistd.size to control file number.

Bug: 133362078
Test: Can use logcat -r -n with configures

Change-Id: I9954c9c125a4ab4e49310986f81c734bf8ee96b3
Signed-off-by: Tian, Baofeng <baofeng.tian@intel.com>
Signed-off-by: Duan, YayongX <yayongx.duan@intel.com>
2019-05-24 07:23:22 +00:00
Treehugger Robot
29d2b05194 Merge "Logtags for com.android.server.policy" 2019-03-27 14:41:12 +00:00
Siarhei Vishniakou
6bd71b979c Logtags for com.android.server.policy
The definitions for event log tags are currently in system/core. Instead
of keeping them there, reserve a range for these event tags and move
them into com.android.server.policy.

Currently it is only used by PhoneWindowManager.

Bug: 128933363
Test: build only
Change-Id: Ida903499e9af8650299e3965787b4ac966b66915
Merged-In: Ida903499e9af8650299e3965787b4ac966b66915
2019-03-26 12:36:53 -07:00
Josh Gao
c6ad69d1d4 liblog: don't return 0xFFFFFFFF as an invalid log id.
There are a bunch of branches that check "id >= LOG_ID_MAX", but because
C++ hates you, this does a promotion to signed int despite the
fact that both sides of the comparison are the same enum with an
underlying type of unsigned int. (C++17 §7.6.3)

Return LOG_ID_MAX instead of a value that gets promoted to signed -1, to
avoid this.

Bug: http://b/129272512
Test: /data/nativetest64/logcat-unit-tests/logcat-unit-tests
Change-Id: I4b3ee662d76d5cc80d9a9625d17f7e5b5980de41
2019-03-25 16:41:39 -07:00
Suren Baghdasaryan
9491078300 DO NOT MERGE: Revert "Revert "Add dependencies on libprocessgroup for sched_policy users""
This reverts commit 1bef8c550c.

Reason for revert: AOSP is fixed with new vendor image

Change-Id: Ib341ac80e2f88c13a7815a490ea2d9422ebdf55f
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
2019-01-25 16:49:18 +00:00
Suren Baghdasaryan
1bef8c550c DO NOT MERGE: Revert "Add dependencies on libprocessgroup for sched_policy users"
This reverts commit 02843339f9.

Reason for revert: Broke AOSP

Change-Id: I62f91c0adf440b5da0a145862b04dd27a7016faf
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
2019-01-23 20:43:28 -08:00
Suren Baghdasaryan
02843339f9 Add dependencies on libprocessgroup for sched_policy users
After moving sched_policy functions into libprocessgroup its users require
additional dependency and inclusion of sched_policy_ctrl.h header.

Exempt-From-Owner-Approval: janitorial

Bug: 111307099
Test: builds, boots

Merged-In: Icc052080e1bce46ce06f7264446950cab0490a95
Change-Id: Icc052080e1bce46ce06f7264446950cab0490a95
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
2019-01-22 18:19:45 +00:00
Tom Cherry
9e12433760 Statically link liblog to logd/logcat and their tests
logd/logcat use more symbols than the rest of the platform, so let's
statically link them for now while we understand the API that the
platform overall uses.

Test: build
Change-Id: I21ae1bd3ff9b310f099612fbe790f769712661df
2019-01-17 11:37:22 -08:00
Elliott Hughes
da94ca4d28 Stop using __STRING unnecessarily.
Bug: N/A
Test: builds
Change-Id: I8748abf834ec3a808eb2fc6ee0f288562fb0b4ea
2018-11-14 14:27:22 -08:00
Dan Willemsen
3e963f9df7 Convert more modules to Android.bp
Test: cd system/core; mma
Test: check for mkbootfs in build artifacts
Test: out/host/linux-x86/nativetest64/libcrypto_utils_test/libcrypto_utils_test
Test: out/host/linux-x86/nativetest64/libnativebridge-tests/*_test
Change-Id: I71141bd85f052d5d86763a8b79b219cc4c46aafb
2018-10-31 21:53:37 -07:00
Tom Cherry
d2c7613fc0 logcat: include 'kernel' and 'security' buffers in logcat --help
Bug: 115798272
Test: documentation looks right
Change-Id: I35dcc51e6779e7382843d4d92fb6182ddf0e0202
2018-10-22 11:16:07 -07:00
Chih-Hung Hsieh
502f4864d6 Suppress implicit-fallthrough warnings.
Add FALLTHROUGH_INTENDED for clang compiler.

Bug: 112564944
Test: build with global -Wimplicit-fallthrough.
Change-Id: I40f8bbf94e207c9dd90921e9b762ba51abab5777
2018-09-17 16:50:11 +00:00