Commit graph

719 commits

Author SHA1 Message Date
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
6a391e9eda liblog: remove useless #define
Neither android_logger_free nor android_logger_close exist.

Test: build
Change-Id: Ieb4d740c234b54db9278a21f07b0533c28b76baf
2020-05-12 10:44:22 -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
Tom Cherry
20d4d23f8c liblog: mark tests as require_root: true
Some tests require root to be run, so we require_root to run all of
them.

Test: tests pass as root
Change-Id: I5b3ca4f08e41f16e81c5d5995043ab55d379a882
2020-04-30 14:39:10 -07:00
Tom Cherry
710825ce47 liblog: require root for multi_connect_dgram_socket test
Bug: 65062446
Test: multi_connect_dgram_socket is skipped for non-root
Test: multi_connect_dgram_socket passes for root
Change-Id: I610bed5987580e0c5a01952efc2e32e7d8cdf9b4
2020-04-30 14:28:13 -07:00
Tom Cherry
09eae5024e Merge "liblog: clean up log_id.h includes" 2020-04-29 18:43:15 +00:00
Tom Cherry
da399f3a47 Merge "liblog: fix header copyrights" 2020-04-28 22:09:24 +00:00
Tom Cherry
3e86e250bb Merge "liblog: remove Rwlocks for logd_socket and pmsg_fd" 2020-04-28 21:10:29 +00:00
Tom Cherry
dd1d42664f liblog: clean up log_id.h includes
This header is not needed in many of the places it is included.  It
contains functions that are duplicated from the <android/log.h>
header.

Test: build
Change-Id: I6ba41d596bcc956cfed13f1d3b21e023591bce0f
2020-04-28 12:34:45 -07:00
Tom Cherry
b629ed9679 liblog: fix header copyrights
There is no reason to dual license this.

Test: builds
Change-Id: I93e6f75758edc32dbeeb55354cf0b1b327561716
2020-04-28 09:52:33 -07:00
Tom Cherry
7acfba274c liblog: remove Rwlocks for logd_socket and pmsg_fd
These historically used atomics to manage their lifetime.  They were
unfortunately unsafe and later replace with a RwLock.  A lock is
also problematic as it is too heavy weight for the typical use case
and implies that logging is neither async nor fork safe.

This change returns us to using atomics with two key changes:
1) compare_exchange_strong() is used instead of atomic_exchange().
   The latter has a race condition where a separate thread could have
   read the atomic value into a register, while the thread performing
   the atomic_exchange closes that FD.  The new code only changes the
   FD in the atomic if it is uninitialized.
2) Using the fact that DGRAM sockets can have connect() called on them
   multiple times, it uses a single logd_socket for the duration of
   the program.

These sockets are thread/async/fork safely created and accessed.

The one caveat is __android_log_close(), which is intended only to be
used by zygote when it is single threaded and is therefore not thread
safe.  It will close this socket and reset the underlying variable,
such that the next log message will go through the above
initialization.

Bug: 65062446
Test: logging works, logging unit tests
Test: new unit test
Change-Id: Ia4dbf7479dbe50683d124558ab2f83bff53b8f5f
2020-04-27 18:24:38 -07:00
Jooyung Han
8c2056f747 Merge "libbase/liblog: set min_sdk_version" 2020-04-27 23:00:58 +00:00
Tom Cherry
efe9defc65 Merge "Don't include log/log_read.h in log/log.h" 2020-04-23 14:58:44 +00:00
Jooyung Han
3851f7e836 libbase/liblog: set min_sdk_version
Modules contributing mainline modules (APK/APEX) should set
min_sdk_version as well as apex_available.

For now setting min_sdk_version doesn't change build outputs.
But build-time checks will be added soon.

Bug: 152655956
Test: m
Change-Id: If4ff1fbc31e5be3f5611a4713ae4032aba4ee5f2
2020-04-23 23:40:14 +09:00
Treehugger Robot
7d503c5bc9 Merge changes I9f382dab,I97225d4b,Iad113f44
* changes:
  Fix doxygen links in log.h.
  Fix docs for __android_log_is_loggable.
  Fix doxygen comments for __android_log_message.
2020-04-23 04:00:22 +00:00
Dan Albert
1891b863f8 Fix doxygen links in log.h.
`@{link blah}` != `{@link blah}`. The latter defines a link to blah,
the former defines a custom group that is never closed. This was doing
really exciting things to devsite.

Most identifiers do not need to be explicitly linked. The two in the
struct do need to be for some reason (maybe typedef vs function, or
maybe because it's a struct, idk). I've left those two but removed all
the ones that work implicitly.

Test: staged to devsite
Bug: None
Change-Id: I9f382dab499abb27945d178e17ae8c810c619898
2020-04-22 17:09:21 -07:00
Dan Albert
6e0eead1df Fix docs for __android_log_is_loggable.
len is not a parameter for the function this comment was attached to.
It seems to be that the documentation was meant to apply to both
functions, so copy it and remove the incorrect parameter from the one
that does not take it.

Test: build_ndk_docs.py
Bug: None
Change-Id: I97225d4ba925a33c73b6c7f81bb7b18def363489
2020-04-22 17:09:21 -07:00
Dan Albert
9e9a35e066 Fix doxygen comments for __android_log_message.
There's a different syntax for putting the comments _after_ the
members, but IMO more readable to just move them before the member.

Test: development/tools/ndk/build_ndk_docs.py
Bug: None
Change-Id: Iad113f449f9cb0996efc4b9d184d8e5b0ed5da85
2020-04-22 17:09:17 -07:00
Tom Cherry
538bac2e97 Merge "Remove thread safety from libbase logging / liblog" 2020-04-22 23:17:57 +00:00
Tom Cherry
53d301c29b Remove thread safety from libbase logging / liblog
There are no libbase users that require thread safety for SetLogger,
SetAborter, or SetDefaultTag  and the equivalent liblog symbols are
unreleased, thus have effectively no users.

It is hard to imagine a scenario where a user would need to use these
functions in a multi-threaded program, and it is unreasonable for all
users to pay for thread safety for a vast minority of potential
scenarios. Thread safety implies less efficiency and necessarily means
that these functions are neither fork safe nor async-signal safe, and
we do have users who depend on those characteristics.

It is always possible for users of the non-thread safe versions of
these functions to build thread safe versions on top of them.  For
example, if a user needs a thread safe SetLogger(), they can use the
non-thread safe SetLogger at the start of their program to register a
logger that has its own lock and pointer to a logger function.

Bug: 119867234
Test: logging unit tests
Change-Id: I8afffec1a6957d3bda95502a4c59493e0c5049ce
2020-04-22 13:12:11 -07:00
Tom Cherry
576e83429c liblog: remove more unneeded #define's
Test: build
Change-Id: I44f1d051e5438e38d7c14f79a7e72dd18cd3df83
2020-04-20 13:17:02 -07: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
Tom Cherry
6b76de04f7 Merge "liblog: return -EPERM if a log_is_loggable() returns false" 2020-04-16 20:13:04 +00:00
Tom Cherry
1ff17fcebb liblog: return -EPERM if a log_is_loggable() returns false
This was the previous behavior, so retain it.

Bug: 119867234
Test: logging unit tests
Change-Id: I088f760cc274a4a42d72477eb4e2e8d23c613a8a
2020-04-16 12:55:30 -07:00
Tom Cherry
f0dafccb38 Merge "liblog: cleanup log_read.h header" 2020-04-16 15:19:29 +00:00
Tom Cherry
715a58e24d liblog: cleanup log_read.h header
There's no need to pull in <fcntl.h> to get O_NONBLOCK, since the
ANDROID_LOG_* macros are better standalone.

Also note that 0x00000003 should be reserved since these corresponded
to previously used values.

Test: build
Change-Id: Icaee6ee0250fe97d8324b3b340f7e196767b2711
2020-04-14 08:59:41 -07:00
Tom Cherry
0ca9bd2bcd liblog: remove operator overloads from log_msg
No one's using them and it's not intuitive how they would be used.

Test: build
Change-Id: I8d49825be2e7ecee9834060260b1c59c30664f1d
2020-04-13 13:48:58 -07:00
Tom Cherry
5f4c79f510 liblog: cleanup TODOs in tests
1) log_msg.msg() will never be nullptr, unless logd sends an invalid
   response, so it's the right idea to ASSERT() that this is true
   instead of just checking and continuing.
2) Even though liblog.too_big_payload is tautological, there's no
   reason not to test it, in case the assumptions that make it
   tautological change.
3) We're not too worried about the return value of logging functions
   or that liblog prevents them from being written (anyone can write
   their own values to logd after all).

Test: liblog-unit-tests
Change-Id: I144cc7cf45c164ea5f04e0786ff0e298fd626f07
2020-04-10 13:48:05 -07:00
Tom Cherry
d3ecc66b9c liblog: support extended logger_entry headers
logger_entry has a hdr_size field meant for backwards compatibility,
however there are a few checks that expect it to be a specific size.
More problematically, it has a variable length array element, msg[0]
at the end, that would be incorrect if the header size was not kept
static.

This change fixes up those issues to facilitate future additions.

Bug: 119867234
Test: logging works with extended size headers, logging unit tests
Test: newly added unit tests with extended size header
Change-Id: I14b2b0855d219d11f374b53a5aa8e05cd6a65eef
2020-04-09 15:48:44 -07:00
Dan Shi
45efd5a27b Merge "Remove vts10 tests from vts suite" 2020-04-06 21:24:46 +00:00
Tom Cherry
97deb299df liblog: include all structures in README.protocol.md
We are stating that these structures will be stable, so include them
in the documentation directly.

Bug: 152466437
Test: n/a
Change-Id: I52a05f61163aa35b99869d722284ff3f98d7f010
2020-04-03 14:34:58 -07:00
Peter Collingbourne
e2b76c5b00 Merge "Move crash_dump into the runtime APEX." 2020-03-30 19:03:41 +00:00
Dan Shi
96f29ead9c Remove vts10 tests from vts suite
The tests are only needed in vts10 suite.

Bug: 151896491
Test: local build
Exempt-From-Owner-Approval: This CL removes vts10 tests from vts suite.
It won't change test logic or behavior.

Change-Id: I4d468be075b54213b56c7e1aa94af94f2bdce9ff
2020-03-27 10:07:44 -07:00
Tom Cherry
3e4c8acfdb Reland: "Fixed a typo in the version name""
This reverts commit e6e87fd705.

Bug: 150949964
Test: build
Change-Id: Ia2f04700fcd9b8e2e3bef7ab5084d36444161939
2020-03-25 18:36:26 +00:00
Tom Cherry
ebf43ad2d8 liblog: correct new APIs per the API review
1) Rename __android_logger_data to __android_log_message and rename
   __android_log_write_logger_data to
   __android_log_write_log_message. Move the const char* message
   argument into __android_log_message.
2) Add @param, @return, and "Available since API level 30." to the
   documentation of new functions.
3) Document that the user defined aborter should but may not abort.
4) Document the line separation is the responsibility of the log
   function provided to __android_log_set_logger().

Bug: 150898477
Test: build, liblog and libbase unit tests
Change-Id: I07c41011ef25b3e7cc4943f3f1e240a2f6aa2802
2020-03-25 18:36:10 +00:00
Treehugger Robot
2d90168f80 Merge "Add vts10 suite to existing vts tests" 2020-03-24 21:49:44 +00:00
Tom Cherry
7581e86a72 Merge "Remove ANDROID_LOG_RDONLY, etc" 2020-03-24 21:00:57 +00:00
Dan Shi
5d8d73c440 Add vts10 suite to existing vts tests
This is to prepare renaming vts to vts10.

Bug: 151896491
Test: local build
Exempt-From-Owner-Approval: This CL adds all tests in vts to a new
suite vts10. vts10 will be the new name of existing vts suite. This CL
won't change test logic or behavior.

Change-Id: I3c7ccef142de30f02a59046cecba121480f6e436
2020-03-24 13:04:53 -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
986bd0c7c8 Skip pmsg related tests if /dev/pmsg0 is not found
These test use fopen() with append which includes O_CREAT.  If these
tests are run in the 'su' SELinux domain (aka through `adb root`) then
they'll create a blank text file when opening /dev/pmsg0 if it does
not exist.  Other tests and processes will attempt to write to this
file, either succeeding (for 'su' domain processes) and wasting memory,
or failing due to SELinux and generating audits (for typical
processes).

This isn't a problem for user builds, since without `adb root`, the
tests simply fail when pmsg0 does not exist.

Test: no excess denials or /dev/pmsg0 creation when running
      liblog-unit-tests as root
Change-Id: I06e0f308c72db5a53c5f9e4a29bd23f56352c7e2
2020-03-23 13:15:05 -07:00
Peter Collingbourne
b72e74810c Move crash_dump into the runtime APEX.
A future change will introduce a version lock between linker and
crash_dump. Move crash_dump into the runtime APEX alongside linker in order to
ensure that they will be the same version even if the runtime APEX is updated.

Bug: 135772972
Change-Id: Ic2eae31b6927eb0e8a62315ac141f50933c00bcc
Merged-In: Ic2eae31b6927eb0e8a62315ac141f50933c00bcc
2020-03-18 10:38:04 -07:00
Tom Cherry
c74afeaa8b Merge changes Id67203bb,I0c1dd57f
* changes:
  liblog: move LOG_ID_DEFAULT into the log_id enum
  liblog: use int32_t and uint32_t for new NDK APIs
2020-03-13 16:10:35 +00:00
Tom Cherry
cd61376986 Merge "liblog: fix header guards ordering" 2020-03-13 15:48:19 +00:00
Tom Cherry
6085cd5a64 liblog: move LOG_ID_DEFAULT into the log_id enum
As requested during the API review.

Bug: 150898477
Test: liblog and libbase unit tests
Change-Id: Id67203bbfbc3e116b6b6efd40428afe48203dcfc
2020-03-12 11:14:19 -07:00
Tom Cherry
f1a975bece liblog: use int32_t and uint32_t for new NDK APIs
As requested during the API review.

Bug: 150898477
Test: liblog and libbase unit tests
Change-Id: I0c1dd57f7499e432bb881e1da1beb55f1ff7de05
2020-03-12 11:11:24 -07:00
Tom Cherry
227ac56454 liblog: fix header guards ordering
__ANDROID_API__ isn't defined on host, so this check will fail due to
-Wundef.  The || is short circuited through, so we can check for host
first and only have the right side of the || evaluated for device
builds.

Bug: 150898477
Bug: 151255209
Test: build
Change-Id: I2e0bc055ac0c7ba8262875801cdaed9cc30d2cef
2020-03-12 09:37:05 -07:00
Jiyong Park
95b6f45b0e don't include liblog to APEXes
liblog is a platform library that provides stable C API. There is no
need to include the library, especialy by statically linking to it, in
any APEX. It not only wastes the storage/ram, but also is incorrect
because the socket interface to logd which is implemented in liblog is
not guaranteed to be stable.

Fixing this issue by converting static_libs: ["liblog"] into
shared_libs: ["liblog"], in which case the dependency to the library
is satisfied via the stub variant of the library.

As a result, we could restrict the availablity of the library to
the platform and the runtime APEX.

Exempt-From-Owner-Approval: already approved when this was in internal
master (ag/10572699)

Bug: http://b/151051671
Bug: http://b/150827719
Test: m
Change-Id: I5aab863cb12b8767b6979255c247000a59355b0e
2020-03-11 09:20:08 +00:00
Tom Cherry
59e93a55fc liblog: add API level guard to NDK log.h header
Bug: 119867234
Test: build
Change-Id: I6fdd7c070af06f04314b9bf7bbfede2a106e0d7c
2020-03-10 08:50:46 -07:00
Treehugger Robot
2401f5f2cc Merge "Set apex_available property" 2020-03-10 07:30:36 +00:00
Tom Cherry
bbb16022c7 liblog: minimum_log_priority should be atomic
In case multiple threads try to reference this variable while it is
being set, it should be atomic so that all threads always see a valid
value.

Bug: 150898477
Test: liblog, libbase unit tests
Change-Id: If6c9e291f2471b96a752dc6e76e3e63458b71391
2020-03-09 12:43:18 -07:00