Commit graph

552 commits

Author SHA1 Message Date
Evgenii Stepanov
f38ae34bbc Merge "Don't disable all sanitizers in liblog, just asan." 2017-01-24 23:00:54 +00:00
Evgenii Stepanov
ffdabdc6f2 Don't disable all sanitizers in liblog, just asan.
ASan runtime library depends on liblog, so we have to disable ASan,
but nothing else.

Bug: 33091541
Test: SANITIZE_TARGET=address keeps working
Change-Id: I6e22925b7f1d5ec86fe1bd8c00dba4c3e86ddf3f
2017-01-24 12:57:23 -08:00
Vijay Venkatraman
3c6763ca21 Exporting C headers from system/core
Moved headers from include/libcutils and include/liblog to
libcutils/include and liblog/include respectively, so they can be
exported via these libs. They needed to be moved since Soong does
not allow export from external folder.

Added symlink from old locations. They are needed since Soong
includes system/core/include by default. Once all modules are
cleaned up to explicitly add the required libs, the symlinks will be
removed.

Also added liblog_vndk_headers that exports a special log/log.h for
VNDK.

Moved headers of libcutils to libcutils_headers. They should be used
by modules for header-only inlines. Added libcutils_headers as
dependency of libcutils.

Added libcutils_vndk_headers that exports a special cutils/log.h
deprecating usage of the file. A later CL will deprecate the one in
libcutils_headers

Test: Add above libs to shared lib of local module
Change-Id: I6e1f9c5f23d8b6eae13dc3b7e5dfe7fae93b8510
2017-01-22 19:45:38 -08:00
Mark Salyzyn
142b43d4ab liblog: BM_log_latency improvement
This reduces BM_log_latency from ~300ns to ~100ns.  Because, well, we
read the clock earlier and that is what BM_log_latency tries to
measure.  The one major improvement in the switch from kernel logger
to user space logger was that we picked up the timestamp in the
context of the caller before doing anything else, but alas changes
over time neglected this fact and placed isloggable checking ahead
of this important fact.

Test: liblog_benchmarks, check results
Change-Id: I4bc9fc3cf8b1659e88417d967b1d0f3743f9e456
2017-01-20 17:53:27 +00:00
Jorge Lucangeli Obes
f4ae42f6a8 Check the return value of setuid(2).
I'd like to mark setuid() WARN_UNUSED_RESULT to prevent security bugs.
This line would break because the file is compiled with -Werror.

Bug: 34251640
Test: Build, run unit test.
Change-Id: Ibb6fa5e5b899d47f77f2a32da762165de310101d
2017-01-13 15:43:45 +00:00
Mark Salyzyn
65e1e6284c liblog: retry -ENOTCONN | -ECONNREFUSED | -ENOENT indefinitely
Deal with recovering after transitory failures surrounding logd
crash or recovery.  Improve the chances that the logging functions
can work in a signal handler, not officially supported, but making
sure logging is not blamed for system lockups when misused.

Reorder gTests so that setuid(AID_SYSTEM) is performed after
liblog.enoent test, and that this occurs after other tests that
like to see buffers with content in them as we stop logd.

Test: gTest liblog-unit-tests --gtest_filter=liblog.enoent
Bug: 33755074
Change-Id: I66f88599534614b7b61da6b2ae5fe099ebaced3a
2017-01-09 15:51:09 +00:00
Mark Salyzyn
b52f445dbb liblog: test: switch to private event structures
Some tests use hard-coded offsets to interpret the binary
events buffers.  Switch to using the private event structures
to access the components of common event messages.

Test: gTest liblog-unit-tests
Bug: 33755074
Change-Id: I17447814583099d5ec417a54389e962158456005
2017-01-06 22:13:34 +00:00
Dan Albert
9a41bcecc6 Unversion NDK stub libraries.
The system versions of these libraries aren't versioned yet.

Bug: https://github.com/android-ndk/ndk/issues/278
Test: make ndk
Change-Id: Icf5ff9921441d3e252771aef37002c772c08cbd0
2017-01-06 11:04:15 -08:00
Elliott Hughes
9b3b119912 Don't use bare noreturn in log.h.
toybox has a #define noreturn that trips over this.

Also move `format` out of the way, just in case.

Bug: https://github.com/android-ndk/ndk/issues/271
Test: builds
Change-Id: Ib8811136b4b422ff74625509539a5464a3c9af18
2017-01-03 13:17:42 -08:00
Mark Salyzyn
af3503cff4 liblog: test failures due to permission issues
Test: gTest liblog-unit-tests passes
Change-Id: Ia9452b3ee9e6068723e8bef48c4d88d3769951a8
2016-12-27 10:01:42 -08:00
Mark Salyzyn
fc148f7f33 liblog: add IF_ALOG_RATELIMIT
IF_ALOG_RATELIMIT()
    ALOGE("Only one message globally using IF_ALOG_RATELIMIT()"
          " in the process may appear ever ten seconds,"
          " (%s)", strerror(errno));

static time_t last; /* initial state zero */
IF_ALOG_RATELIMIT_LOCAL(60, &last)
    ALOGE("Only one message locally may appear every minute,"
          " (%s)", strerror(errno));

These new calls are guaranteed not to affect the value of a
non-zero errno to simplify logging of errors.  However, the
ALOGE calls in the above examples may update the errno value
upon their return.

Test: gTest liblog-unit-tests --gtest_filter=liblog.__android_log_ratelimit
Bug: 33535908
Change-Id: Id8cc192fc7d14504ffd418933cf88ae945c089f2
2016-12-21 21:36:14 +00:00
Mark Salyzyn
5bd8f2d956 liblog: pmsg read permissions for AID_LOGD
Test: gTest liblog-unit-test and logd-unit-tests
Bug: 31456426
Change-Id: I7a2fe8245ecd651883f7851ce71b6c45e373af82
2016-12-19 15:57:01 +00:00
Mark Salyzyn
774e04f779 liblog: move log_is_loggable.c to properties.c
Just makes sense cleanup

Test: gTest liblog-unit-tests
Bug: 33535908
Change-Id: I85de049f3cd73a473d56db5970d42eee5f9f70a8
2016-12-16 08:43:56 -08:00
Treehugger Robot
8b99ef6c21 Merge "liblog: event_tag_map use unordered_map" 2016-12-16 01:57:03 +00:00
Mark Salyzyn
700fb87648 liblog: event_tag_map use unordered_map
>3 times faster access for lookup functions.  Code simplification and
C++ coding style conversion.  android_lookupEventTagNum has been
expanded to utilize the Format match, and then drops down to just
Tag match.

Performance testing on Hikey, all services stopped, shell only access,
CPU not locked had good repeatability.

$ adb reboot ; adb wait-for-device ; adb shell su root stop

Before this adjustment using binary search:

$ /data/nativetest64/liblog-benchmarks/liblog-benchmarks BM_lookupEvent*
                          iterations      ns/op
Precharge: start
Precharge: stop 231
BM_lookupEventTag           10000000        153
BM_lookupEventTag_NOT       20000000        139
BM_lookupEventFormat        10000000        153

After this adjustment strictly using std::unordered_map lookup:

$ /data/nativetest64/liblog-benchmarks/liblog-benchmarks BM_lookupEvent*
                          iterations      ns/op
Precharge: start
Precharge: stop 231
BM_lookupEventTag           50000000         56
BM_lookupEventTag_NOT      100000000         21
BM_lookupEventFormat        50000000         56

Test: gTest logd-unit-tests and liblog-unit-tests, liblog-benchmarks.
Bug: 31456426
Change-Id: I1cfc3d641c3ea9ab08d455efe0c844d3a6381440
2016-12-15 22:32:37 +00:00
Mark Salyzyn
a91b426268 liblog: clean up SafetyNet unit tests
Move active code into helpers.

Test: gTest liblog-unit-tests
Change-Id: I5ade96edd71b7d773386f4d99eddbad076d10405
2016-12-13 13:47:48 -08:00
Mark Salyzyn
ed9dc8abe2 liblog: switch event_tag_map.c to event_tag_map.cpp
NB: recent activities on event_tag_map.c were to allow
    this transition to be unremarkable.

Test: compile
Bug: 31456426
Change-Id: I13e1771a001874244711a5ac3023861c2a5f8c7d
2016-12-01 15:42:03 -08:00
Mark Salyzyn
3cd9e31446 liblog: fortify event_log_tags test
Robustness fortification.  Deal with gtest failure if event-log-tags
file is updated, adb sync for example, and thus will report
Shared_Dirty instead of Shared_Clear.  Add check for Private_Dirty
and Private_Clean being clear at zero too as a bonus.

Test: gTest liblog-unit-tests --gtest_filter=liblog.event_log_tags
Bug: 31456426
Change-Id: Id912929fdd65499aa532a15653ef387a997a5054
2016-11-30 11:08:46 -08:00
Treehugger Robot
f1f7333e7c Merge "liblog: CTS test" 2016-11-30 16:25:11 +00:00
Treehugger Robot
4afb3ef952 Merge "liblog: event_tag_map benchmark" 2016-11-30 15:31:11 +00:00
Treehugger Robot
1abc3cd641 Merge changes Ia0ca36fc,Ib42c0635
* changes:
  Enable liblog on host bionic
  Enable libbase/libutils/libziparchive on host bionic
2016-11-30 05:59:53 +00:00
Dan Willemsen
0910d2dbb9 Enable liblog on host bionic
Some of the __BIONIC__ checks were actually looking for an android
device. Host bionic has __BIONIC__, but not __ANDROID__.

Bug: 31559095
Test: Test linux_bionic compile
Change-Id: Ia0ca36fc9486fe8ea7e5d1b2e26ab0491903723c
2016-11-29 13:39:55 -08:00
Treehugger Robot
9bfd9f558b Merge "system/core: replace EVENT_TAG_MAP_FILE with NULL" 2016-11-29 19:37:48 +00:00
Mark Salyzyn
52ed8c68ee liblog: CTS test
Utilize liblog-unit-tests as a CTS test

Replacement for EventLogTest#testWriteEventWithOversizeValue
along with some other mandatory logging functionality.

Test: run cts tests
Bug: 26235244
Change-Id: I71f549bd0b93f6c41e1f91565b0fbddf042e4991
2016-11-29 08:40:16 -08:00
Mark Salyzyn
0b37d01f72 liblog: event_tag_map benchmark
Tested on Hikey, all services stopped, shell only access, CPUs not
locked.

$ /data/nativetest64/liblog-benchmarks/liblog-benchmarks BM_lookupEvent*
                          iterations      ns/op
Precharge: start
Precharge: stop 231
BM_lookupEventTag           10000000        153
BM_lookupEventTag_NOT       20000000        139
BM_lookupEventFormat        10000000        153

Test: run benchmarks
Bug: 31456426
Change-Id: Ice3ffa0b061d9a6b917718b2d9aedcc2348b7005
2016-11-28 15:15:58 -08:00
Mark Salyzyn
1179eb8048 system/core: replace EVENT_TAG_MAP_FILE with NULL
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
2016-11-21 11:13:02 -08:00
Mark Salyzyn
2ca4f49476 liblog: add private android_log_write_list_buffer()
Allows us to compose an event message for our own in-memory purposes.
Will be used to compose an event message in logd and directly write
it to just the pmsg buffer.  Provide an internal enhanced C++ wrapper
for event handling.

Test: gTest liblog-unit-tests --gtest_filter=liblog.android_log_write_list_buffer
Bug: 31456426
Change-Id: I98246898ba580f9e506baba8af2fd1b26a2a8aae
2016-11-21 09:46:39 -08:00
Mark Salyzyn
472245d962 liblog: move android_log_event_context class to log/log_event_list.h
rename class from android_log_event_context to android_log_event_list

Test: gTest logcat-unit-tests
Bug: 31992412
Bug: 31456426
Change-Id: Ib61cbca7d453837d64959c56b0e11f8c5edbfbdd
2016-11-21 09:46:34 -08:00
Mark Salyzyn
538bc12c08 logcat: add hidden --debug flag and cleanup
Allow us to debug corrupted log messages. Fix liblog to propagate
errors correctly and repair a gtest that failed.

Test: liblog-unit-tests --gtest_filter=liblog.__android_log_bswrite_and_print___max
      logcat -b events --debug -t 50
Bug: 32903864
Change-Id: Ib4eb9f466777cd23b8b54728d36354590d07869a
2016-11-16 15:46:42 -08:00
Mark Salyzyn
1a57ae3a7d liblog: logprint: report truncated event log contents if error
We need to accept that a log tag can contain no payload.  For those
that are corrupted, and to aid debugging, report what we did manage
to interpret.  Report last character as a ! for corruption, and ^
for truncation.  Fix a few Android Coding standard issues.

Test: gTest logcat-unit-tests
Bug: 32903864
Change-Id: Id11bef3a7b6569305c51701dd66c45d2038d6628
2016-11-15 14:46:34 -08:00
Mark Salyzyn
53e9fc7915 liblog: android_closeEventTagMap pointer check
Followup to c/278768 where failure to open tag map can
result in segment violation in android_closeEventTagMap.
Add check for pointer value = -1 to bypass call to close.

Test: gTest liblog-unit-tests, logcat-unit-tests & logd-unit-tests
Bug: 30963384
Bug: 31456426
Change-Id: I20547e55d7e29682fde4538bc1fc6d83b4535d49
2016-11-09 10:16:38 -08:00
Mark Salyzyn
4fd0507b20 liblog: logcat: logprint support -v descriptive
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
2016-11-04 15:22:52 -07:00
Mark Salyzyn
530711b39e liblog: add android_lookupEventFormat_len
Test: compile
Bug: 31456426
Change-Id: I283fec89431c18af788fa0477a2ab78792221878
2016-11-04 15:22:52 -07:00
Mark Salyzyn
5febc51318 liblog: test report pmsg not configured if ENOMEM return
NB: bionic stdio is broken when providing appropriate errno value(s)
    on failure so libc.__pstore_append will not report pmsg
    misconfigured correctly on android for now.

Test: misconfigured kernel, watch for this message in liblog-unit-tests
Change-Id: Ifb1b550c7d3a3888000459c2f68c392cc23c379f
2016-11-03 11:20:59 -07:00
Mark Salyzyn
a28525293d liblog: remove reference to log/logger.h
Test: compile
Bug: 31992412
Change-Id: Idd52072d0f8c657ac53dc3e6b505a66c47a94357
2016-10-26 14:59:42 -07:00
Mark Salyzyn
aeaaf81c2c liblog: logd: logcat: Split out log/logger.h into public and private.
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
2016-10-24 11:12:49 -07:00
Mark Salyzyn
749a298dfd liblog: restructure log/log.h and android/log.h
We went too far, so this is a partial revert, part deux.

Keep general purpose logging macros in android/log.h for the NDK.
More internal features like Radio, System and Events logging are
moved back to log/log.h.  Correct liblog ndk symbols.  Correct for
some Android Coding standards.

Test: compile
Bug: 31992412
Change-Id: Id3731496fa226e8c170305d0d2a1859e8cf67e14
2016-10-24 11:03:49 -07:00
Treehugger Robot
c741dd4838 Merge "Add license to ndk_headers." 2016-10-20 22:12:40 +00:00
Dan Albert
286b2eaa52 Add license to ndk_headers.
Test: make ndk
Bug: None
Change-Id: Iaba7368b89ec446b5c65c7c127a98914bd949496
2016-10-20 10:18:27 -07:00
Mark Salyzyn
cfd5b080af system/core: preparation to pull back interfaces from android/log.h
Point to log/log.h where necessary, define LOG_TAG where necessary.
Accept that private/android_logger.h is suitable replacement for
log/logger.h and android/log.h.

Correct liblog/README

Effectively a cleanup and controlled select revert of
'system/core: drop or replace log/logger.h' and
'system/core: Replace log/log.h with android/log.h'.

Test: compile
Bug: 30465923
Change-Id: Ic2ad157bad6f5efe2c6af293a73bb753300b17a2
2016-10-20 08:11:39 -07:00
Mark Salyzyn
e455373b57 liblog: Add private interfaces for buffer size properties
Add private function __android_logger_get_buffer_size() to read
properties and compose the default buffer size.  This interface
complements the existing android_looger_get_size() which returns
the logd setting which can differ at runtime.  For use in logd
and dumpstate.  Side effect is we also add the private functions
__android_logger_property_get_bool() and
__android_logger_valid_buffer_size() for reuse in logd.

Test: gTest liblog-unit-test, logd-unit-tests and logcat-unit-tests in
      combination with commit 'logd: Use private interfaces for
      buffer size properties'
Bug: 31750617
Change-Id: Id95cb68f775ef6b427c122e10f6f8291d336d184
2016-10-18 09:48:55 -07:00
Treehugger Robot
915d620359 Merge "liblog: LIBLOG_ABI_PRIVATE __android_log_is_debuggable()" 2016-10-17 21:46:37 +00:00
Treehugger Robot
6da1ea0e48 Merge "liblog: __android_log_pmsg_file_write() cleanup" 2016-10-17 14:16:46 +00:00
Dan Albert
b7c3996f7c Continue using the legacy NDK android/log.h.
system/core/android/log.h needs some work before it can be included in
the NDK. It defines a *lot* of macros that previously were usable
names in NDK sources that used android/log.h. As an example, the
following file defines LOG_TAG as a variable, but the variable name
gets macro replaced if we use the current android/log.h.
4adc1515f8/framework/platform/android/tcuTestLogParserJNI.cpp (41)

For now, we keep a copy of the old NDK android/log.h in
legacy-ndk-includes.

Test: make checkbuild
Bug: http://b/30465923
Change-Id: I8ce942d1ee2f8f0d4c27130802c03992a1b85ec4
2016-10-14 13:12:29 -07:00
Mark Salyzyn
9ea359fce0 liblog: LIBLOG_ABI_PRIVATE __android_log_is_debuggable()
Allow our own libraries to use this privately instead of
running the less efficient get_properties and doing the math.

Test: compile and boot smoke test
Bug: 27566046
Bug: 31456426
Change-Id: I2f677276d27fbcb6af01b600ac1d9891c8938d43
2016-10-14 08:00:41 -07:00
Treehugger Robot
955648a915 Merge "Rely on the platform -std default." 2016-10-14 02:28:38 +00:00
Mark Salyzyn
db8a266aea liblog: __android_log_pmsg_file_write() cleanup
__android_log_pmsg_file_write() will open /dev/pmsg0 if not
already, and will close it if we opened it.

Added atomic access to the android_log_context as insurance.

Fortify and correct pmsg tests.

Test: gTest liblog-unit-tests --gtest_filter=liblog.__android_log_pmsg_file_*
Bug: 31958686
Change-Id: I2cf6f971b6968938f471fda67367efe20dae3004
2016-10-13 21:43:42 +00:00
Elliott Hughes
36e0d390a2 Rely on the platform -std default.
Bug: http://b/32019064
Test: builds
Change-Id: I18a1d816d63b64601485045070851f32d44e85eb
2016-10-10 14:31:12 -07:00
Mark Salyzyn
6debf985aa liblog: adb: move security interfaces to private
Test: Compile & adb functioning
Bug: 19235719
Bug: 26552300
Bug: 31289077
Bug: 31456426
Change-Id: I7ad8963bcca3d8b5c37b547c11d163b652d35556
2016-10-10 15:15:45 +00:00
Mark Salyzyn
37c9451349 system/core: drop or replace log/logger.h
debuggerd does not require log/logger.h, can use android/log.h
In some cases, mark why log/logger.h was required.

Test: Compile and boot smoke test
Bug: 26552300
Bug: 31289077
Bug: 31456426
Change-Id: Ia34987e25a01d81971ec8d785415f732b8376c4f
2016-10-04 09:09:10 -07:00
Mark Salyzyn
807e40ecc9 liblog: logd: Add android_lookupEventTag_len()
Allows us to mitigate the impact of MAP_PRIVATE and copy on write by
calling android_lookupEventTag_len instead of android_lookupEventTag,
and delaying the copy on write impact to the later.  We return a
string length in a supplied location along with the string pointer
with android_lookupEventTag_len(const EventTagMap* map, size_t* len,
int tag).  The string is not guaranteed to be nul terminated.  Since
android_lookupEventTag() called even once can cause the memory
impact, we will mark it as deprecated, but we currently have no
timeframe for removal since this is a very old interface.

Add an API for __android_log_is_loggable_len() that accepts the non
null terminated content and fixup callers that would gain because the
length is known prior to the call either in the compiler or at
runtime.  Tackle transition to android_lookupEventTag_len() and
fixup callers.

On any application that performs logging (eg: com.android.phone)

/proc/<pid>/smaps before:

xxxxxxxxxx-xxxxxxxxxx rw-p 00000000 fd:00 463 /system/etc/event-log-tags
Size:                 20 kB
Rss:                  20 kB
Pss:                   1 kB
Shared_Clean:          0 kB
Shared_Dirty:         20 kB
Private_Clean:         0 kB
Private_Dirty:         0 kB
Referenced:            0 kB
Anonymous:            20 kB
AnonHugePages:         0 kB
Swap:                  0 kB
SwapPss:               0 kB
KernelPageSize:        4 kB
MMUPageSize:           4 kB
Locked:                0 kB
VmFlags: rd wr mr mw me ac

/proc/<pid>/smaps after:

xxxxxxxxxx-xxxxxxxxxx rw-p 00000000 fd:00 1773 /system/etc/event-log-tags
Size:                 20 kB
Rss:                  20 kB
Pss:                   1 kB
Shared_Clean:         20 kB  (was 0kB)
Shared_Dirty:          0 kB  (was 20kB)
Private_Clean:         0 kB
Private_Dirty:         0 kB
Referenced:           20 kB  (was 0kB)
Anonymous:             0 kB  (was 20kB)
AnonHugePages:         0 kB
Swap:                  0 kB
SwapPss:               0 kB
KernelPageSize:        4 kB
MMUPageSize:           4 kB
Locked:                0 kB
VmFlags: rd wr mr mw me ac

Added liblog-unit-tests --gtest_filter=liblog.event_log_tags to
check for Shared_Clean: to not be 0 and Anonymous: to be 0 for
all processes referencing event-log-tags.  Which can include multiple
references to /system/etc/event-log-tags and future possible refs to
/data/misc/logd/event-log-tags and /dev/event-log-tags.  We want
failure messages to help point to errant code using the deprecated
interface.

This change saves 1/4MB of memory or more on a typical system.

Test: gTest liblog-unit-tests
Bug: 31456426
Change-Id: I9e08e44d9092bd96fe704b5709242e7195281d33
2016-10-03 11:08:34 -07:00
Mark Salyzyn
9633b919d7 liblog: Move liblog tag from 1005 to 1006
Allow logd to add another "consecutive" log tag

Test: gTest liblog-unit-tests, check for liblog in logcat afterwards
Bug: 31456426
Change-Id: I0c25e038878ec9a0cf368a33a63f8345c68749c3
2016-09-30 12:47:05 -07:00
Mark Salyzyn
6584d0a35a liblog: Replace log/log.h with android/log.h
Move all liblog related content into android/log.h, and make
log/log.h points to android/log.h.

Test: Compile
Bug: 26552300
Bug: 31289077
Change-Id: I858e0ebe047b86f2a8530a99bc9c380d3d58edbb
2016-09-30 12:47:05 -07:00
Mark Salyzyn
a166708d15 liblog: logcat: Replace log/logd.h with log/log.h
Should use log/log.h and in some cases android/log.h instead. Can
not remove file because still in use by partners, so log/logd.h
points to log/log.h.

Test: Compile
Bug: 26552300
Bug: 31289077
Change-Id: I3580d46154617abb7231027a44f4ab9ee023febf
2016-09-30 12:47:05 -07:00
Mark Salyzyn
004cd3c55d liblog: logd: logcat: deprecate log/log_read.h
Always used in combination with log/logger.h except in log_time.cpp,
and not used externally.  As a result liblog has to support stl, a
small price to pay since goal is to convert liblog to C++ internally.

Test: compile
Bug: 31456426
Bug: 26552300
Bug: 31289077
Change-Id: I72828ec807d0a2c8e40bbdebd7a69f147a7ca5a9
2016-09-30 12:47:05 -07:00
Treehugger Robot
dfd30c4a16 Merge "liblog: fix errno issues with event tag map" 2016-09-28 18:07:09 +00:00
Treehugger Robot
1dfa8112ce Merge "liblog: free event tag map in __android_log_close()" 2016-09-28 14:58:39 +00:00
Mark Salyzyn
70a83dc7b3 liblog: fix errno issues with event tag map
Cleanup.

Save the errno for the calls that fail, and reinstate them for
return. Drop fprintf stutter, one succinct line. Solve a memory
leak in close.  Change android_lookupEventTag() to use an
unsigned int so that we can use the full range of uint32_t tags.

Make sure this file compiles clean in C++.

Test: gTest liblog-unit-tests
Bug: 30963384
Bug: 31456426
Change-Id: I6a5efa6fb7e991431caba75ef0971e111968f6bf
2016-09-26 09:23:55 -07:00
Mark Salyzyn
ba1a798fd8 liblog: free event tag map in __android_log_close()
There is no leak since a reference always remained and could get
reused.  It just makes sense to also close the event tag map as well
if logging is closed.  If we close we also have to fix a tagArray
leak in android_closeEventTagMap().

NB: __android_log_close() already makes an assumption that another
thread is not logging at the same time, which is true in all callers
at this time.  There are some partial mitigation strategies if
__android_log_close() is called asynchronously, but not completely
solved at the cost of a lock for every logging call.

Test: gTest liblog-unit-tests
Bug: 30963384
Bug: 31456426
Change-Id: Ib76ad9302dba4d3f35250213f4dfef22498af238
2016-09-26 08:21:13 -07:00
Dan Albert
ddce8c70c4 Migrate liblog to ndk_library.
Test: make native
Bug: http://b/30465923
Change-Id: I3db7ede817a57b3505c0556ea28f08b9e8331e1a
2016-09-23 15:43:23 -07:00
Narayan Kamath
b2f019ec1e liblog: don't bother keeping FD around once it's mapped.
Posix and linux explicitly state that this isn't necessary.

bug: 30963384
Change-Id: I2cc16ded04f0ebc909dc3027e02867594fb49d05
2016-09-01 19:31:08 +01:00
Mark Salyzyn
6322efe522 Merge "liblog: add __android_log_close()"
am: 812d1c7ea2

Change-Id: I2ba5ed22e78564a864bab6b550b6d2bd2609a629
2016-08-24 16:05:05 +00:00
Mark Salyzyn
2d562c9dce Merge "logger: validate hdr_size field in logger entry"
am: fcf7ab8b1b

Change-Id: Ic88fe616256ab4949040771d3bed1dfb823ab981
2016-08-24 16:05:04 +00:00
Treehugger Robot
812d1c7ea2 Merge "liblog: add __android_log_close()" 2016-08-24 15:58:48 +00:00
Mark Salyzyn
df7a4c6bae liblog: add __android_log_close()
Bug: 30963384
Change-Id: I901e6ac2cc3c601bbecc2d64e00a98e2ab448210
2016-08-23 15:25:03 -07:00
Mark Salyzyn
305374cf0f logger: validate hdr_size field in logger entry
- check hdr_size to make sure it is in the expected range
  from sizeof entry_v1 to entry (entry_v4).
- alter msg() method to report NULL on invalid hdr_size
- alter all users of msg() method.

Bug: 30947841
Change-Id: I9bc1740d7aa9f37df5be966c18de1fb9de63d5dd
2016-08-23 14:51:50 -07:00
Elliott Hughes
33f8c194f9 Merge "liblog: use SOCK_NONBLOCK directly."
am: fca43d3ec5

Change-Id: I4d959d9091adbf8bf2d7b68653a3c6064893a65a
2016-08-23 01:20:36 +00:00
Elliott Hughes
5ba3003467 liblog: use SOCK_NONBLOCK directly.
No need to have a race, even if it doesn't matter.

Change-Id: Ia79f2633643bc63618de0fd85953b3226415484f
2016-08-22 16:19:58 -07:00
Chih-Hung Hsieh
89cc78b77f Merge \"Fix google-explicit-constructor warnings in system/core.\"
am: 6dc68cb5f9

Change-Id: I5a010465364b6e14423b19e8c0f9cffa58ee3152
2016-07-29 17:01:17 +00:00
Chih-Hung Hsieh
034c475931 Fix google-explicit-constructor warnings in system/core.
* Declare explicit conversion constructors.
* Add NOLINT for implicit conversion constructors.
* Fix also some misaligned indendations.

Bug: 28341362
Change-Id: Idf911f35923b408d92285cc1a053f382ba08c63e
Test: build with clang-tidy
2016-07-26 11:26:01 -07:00
Mark Salyzyn
0d9ce37382 Merge \"liblog: pmsg_read add validity checking for prio\"
am: 73cc6edf0e

Change-Id: Iba5e7b7c2325e127eb9f040c8ab86ba24efd5b20
2016-07-15 19:04:48 +00:00
Mark Salyzyn
56da612ec4 Merge \"liblog: reset pid and uid cache after a vfork()\"
am: d4f6324176

Change-Id: I3b59f56b2b5f399b079ab9439600dc3a72c669a6
2016-07-14 15:55:55 +00:00
Mark Salyzyn
3d8afe9b01 liblog: pmsg_read add validity checking for prio
Improve pmsg data corruption detection.

Bug: 30085794
Change-Id: I215da4fff07797b8c0a3462f850bafb090adfc68
2016-07-14 07:34:53 -07:00
Mark Salyzyn
ec4f5c776d liblog: reset pid and uid cache after a vfork()
Bionic getuid() and getpid() calls cache to reduce the need to
perform a syscall, and also reset their own cache after a vfork().
No more need for liblog to be performing this flawed cache operation.

Bug: 30085794
Change-Id: I70feed8bff0ddd919c2885a348ba67b14ddc0e0d
2016-07-14 07:34:53 -07:00
Colin Cross
68bfe51348 Merge \"Rename Android.soong.mk to Android.mk\"
am: b07df4dd3f

Change-Id: I9d9a232539b9991ab935e143140a3b77d896ebc7
2016-07-12 16:20:21 +00:00
Colin Cross
b39e4025ae Rename Android.soong.mk to Android.mk
Soong is always on now, so we don't have to distinguish between
makefiles that should be ignored because Soong is handling them with an
Android.bp file, and makefiles that are still needed with Soong.  All
obsolete Android.mk files have been removed, rename all Android.soong.mk
files to Android.mk.

Change-Id: Iabbddcbfb2c837cfd4556241b570474452cc5d4d
2016-07-11 16:56:51 -07:00
Elliott Hughes
016ad16100 Merge "Use alignas for alignment." am: bb1e7977fb
am: 689b998ab2

* commit '689b998ab26f2a04e079312aee2f8e32fbe7f26c':
  Use alignas for alignment.

Change-Id: Ic81a88146df0f407849800c63d2edb7404efe0ac
2016-06-07 15:55:12 +00:00
Elliott Hughes
5f4a946c09 Use alignas for alignment.
Change-Id: I427c407a188682a360c74b2bd5a44dd62551ea66
2016-06-06 19:59:45 -07:00
Colin Cross
bfcb1b779f Merge "Remove deprecated Android.mk files" am: ce5b4fee23
am: 5806404e4d

* commit '5806404e4d693699fef2e710fd8ad836815f8852':
  Remove deprecated Android.mk files

Change-Id: I8a87996377bd53a16d330c0df9bfff84c92e10a2
2016-06-02 16:41:27 +00:00
Colin Cross
ce5b4fee23 Merge "Remove deprecated Android.mk files" 2016-06-02 16:31:42 +00:00
Dan Willemsen
9ce49be616 Merge "Fix liblog logtags" am: 59e6afc617
am: 6b5255722e

* commit '6b5255722e7497fc7c854cf1ae9e51322bc7ceae':
  Fix liblog logtags

Change-Id: I6225d8fd338b9ffc5b4406d5dbb92e2816bcaaad
2016-06-01 23:47:45 +00:00
Dan Willemsen
d119101807 Fix liblog logtags
This was broken because we didn't have logtags support in Soong.

Bug: 28989759
Change-Id: I8370a73cf14703b86aafd85e7ea74fc570c3ff0f
2016-06-01 15:32:35 -07:00
Colin Cross
b50216ed86 Remove deprecated Android.mk files
These directories all have Android.bp files that are always used now,
delete the Android.mk files.

Change-Id: I8b0c89072a660c4a7a30fcefc76a7bbe247df977
2016-05-26 16:58:28 -07:00
Chih-hung Hsieh
d581f2c47d Merge "Fix misc-macro-parentheses warnings in liblog." am: 2bd428e1f9
am: 1cff850bb3

* commit '1cff850bb383d75c395d4627086b6baa63639a18':
  Fix misc-macro-parentheses warnings in liblog.

Change-Id: I318ab4909ba59e7181b9ec9c3e73f58ea8b0c0d8
2016-05-19 01:02:34 +00:00
Chih-hung Hsieh
2bd428e1f9 Merge "Fix misc-macro-parentheses warnings in liblog." 2016-05-19 00:48:44 +00:00
Chih-Hung Hsieh
f0f94fe49b Fix misc-macro-parentheses warnings in liblog.
Bug: 28705665
Change-Id: Ib272a83cb93b09d986c19a40e23a2679b9e17558
2016-05-18 15:48:50 -07:00
Mark Salyzyn
5d32a9821d Merge "liblog: log reader validate headers" am: 0321476fe2
am: 0a7dec432c

* commit '0a7dec432ce3a72edcf5bf092871296225cd814b':
  liblog: log reader validate headers

Change-Id: Ic035cf9d3e765e95799a25c1441d5fa88ab3fda7
2016-05-18 14:27:54 +00:00
Mark Salyzyn
8fd1faa596 liblog: log reader validate headers
Ensure len and hdr_size fields are valid and match the return value.
Truncate or zero content as necessary, but do not drop the message.

Bug: 28610769
Change-Id: I10785fa5b03aa3da7d07b368188e3f7c36a84b4f
2016-05-17 13:54:42 -07:00
Mark Salyzyn
5d76be85a4 Merge "liblog: sleep 20ms before critical property_set" am: 1d560ff24a
am: 03ac8fe0be

* commit '03ac8fe0be882b09d7faba4d5f96e536a94198ab':
  liblog: sleep 20ms before critical property_set

Change-Id: I91d3262a478f83556851881208fb1f83de62f189
2016-05-12 16:48:21 +00:00
Mark Salyzyn
5cceee6404 liblog: sleep 20ms before critical property_set
Going too fast can result in the property not being set
and causing an extreme corner case failure being reported
and blamed on is_loggable functionality.

Bug: 25792367
Change-Id: Idda6f67d655d8a84d2809daf695394d5293e7431
2016-05-12 15:58:57 +00:00
Rubin Xu
7dcdd52cf6 Merge "Return correct length from pmsgRead()" am: fc2a8b2bd6
am: a76e171bf3

* commit 'a76e171bf351e3d26b3eb596188b6c9b2fcab3f4':
  Return correct length from pmsgRead()

Change-Id: I616c3c889e99292454b0a7c33f999a56ada2c939
2016-05-09 15:36:23 +00:00
Rubin Xu
9c2f803e9d Return correct length from pmsgRead()
Bug: 28610769
Change-Id: I38cac786ca43ef8d9530f4e2e5a0bdd4cc3bccef
2016-05-05 16:50:44 +01:00
Mark Salyzyn
9fd5df3816 Merge "liblog: O_CLOEXEC flag on opens" am: fc80b22752
am: a0afba8a87

* commit 'a0afba8a8721319233e788cf723e979d3f0781e2':
  liblog: O_CLOEXEC flag on opens

Change-Id: I4c018e556b645ab58477cc537d65489d904fa78b
2016-04-29 15:44:52 +00:00
Mark Salyzyn
a3692040fa Merge "liblog: logcat -g readable size wrong" am: 7f18790bd7
am: 7a5b8c7f53

* commit '7a5b8c7f53ca79f99e74655b2f68356c7184532a':
  liblog: logcat -g readable size wrong

Change-Id: I1461a41dc0b1bff3394caa5a107d7ad80cc7d068
2016-04-29 14:53:23 +00:00
Mark Salyzyn
78786da116 liblog: O_CLOEXEC flag on opens
Bug: 28455828
Change-Id: Ic00101a6192aab7271cb0c3461e249a77d7f29ed
2016-04-29 07:52:36 -07:00
Mark Salyzyn
ccfb244b36 liblog: logcat -g readable size wrong
Bug: 28451229
Change-Id: I4bbc2bed933d69416c23cc7af617be3fb55d0b62
2016-04-29 07:39:51 -07:00
Colin Cross
c4dcc38e44 Merge "Update sanitize property format" am: 0652728
am: 9ba3f6d

* commit '9ba3f6db392f0f9b25cc5b3ad03c984fdc76094f':
  Update sanitize property format

Change-Id: I7ac818440c50c7166921d74dfb3b6c10af19ee09
2016-04-19 22:51:08 +00:00
Colin Cross
0652728e2a Merge "Update sanitize property format" 2016-04-19 22:42:04 +00:00
Mark Salyzyn
ab162d6cb2 Merge "liblog: android_log_isloggable failing apct" am: 0d4661d
am: cee2ce6755

* commit 'cee2ce6755d032c494be4295e98064b3b40ffa51':
  liblog: android_log_isloggable failing apct

Change-Id: I2cddfa04aff9a39ec897a75408a3f63c38692f4a
2016-04-19 00:28:59 +00:00
Colin Cross
5d35ce649c Update sanitize property format
Change-Id: I81c299609ece7a1c7f27093f563d5df08efe989b
2016-04-15 16:33:21 -07:00
Mark Salyzyn
efe8ecc1d9 liblog: android_log_isloggable failing apct
- periodic failures in apct, dropped second serial test
  in refresh_cache, trusting check_cache or global.
- The retry loop to see if is_loggable recovers of 1000
  was hiding subsequent tests, drop to 10 retries.
- On the whole, the average performance remains the same.

Bug: 25792367
Change-Id: I4110440ef46671d7a1c128689bde623808bed04f
2016-04-15 11:04:24 -07:00
Mark Salyzyn
c1bfe53f76 Merge "liblog: remove android_ids and replace with getpwuid" am: f7040c8
am: 4a7d498

* commit '4a7d498e2ff0ee58112710c04f284a24a3f88cd2':
  liblog: remove android_ids and replace with getpwuid

Change-Id: Idb750dd8944807cc14c265b388e2c058e17bbe53
2016-04-11 16:01:13 +00:00
William Roberts
8a5b9caaa6 liblog: remove android_ids and replace with getpwuid
Note: This code makes the assumption that getpwuid is
thread safe, which it is ONLY ON BIONIC. Thus,
if you attempt to use this on a non-target build, you
may get burned. Thus, an ifndef checking on __BIONIC__
is used to produce a build error if you attempt to do
so.

Change-Id: I61038c428b71771edcfc76f18d8fc5cbe349238b
Bug: 27999086
Signed-off-by: William Roberts <william.c.roberts@intel.com>
2016-04-11 14:55:56 +00:00
Mark Salyzyn
33aecaa784 Merge "liblog: suppress pmsg on user builds" am: 0858071
am: 24967e5

* commit '24967e5f5e87e5079f416d3cbc3d6a5dba7e8865':
  liblog: suppress pmsg on user builds

Change-Id: Ic4f2c02e227ee3c0dc29eb11757dc024aae3b950
2016-03-31 21:07:32 +00:00
Mark Salyzyn
7ef5249afa liblog: suppress pmsg on user builds
- add optimized & cached LIBLOG_HIDDEN __android_log_is_debuggable()
- check when writing, either LOG_ID_SECURITY, SafetyNet or
  debuggable when pushing content to the pmsg buffer.

Bug: 27566046
Change-Id: I85f1b55ec329b38e00f4183836b6ed53046c323d
2016-03-29 13:52:21 -07:00
Mark Salyzyn
47cce8c410 Merge "liblog: gate write on log id available" am: fbdbf10
am: f44cb4c

* commit 'f44cb4c6cb11a4a2cd6af8f72d84a092bcfcf513':
  liblog: gate write on log id available

Change-Id: Ida839dd23ea2b3b1b860c6e8e2b32af61b2fea29
2016-03-29 20:00:52 +00:00
Mark Salyzyn
c33103c440 liblog: gate write on log id available
- Secure LOG_ID_KERNEL in writer
- Secure LOG_ID_SECURITY in reader and writer
- if writer transport says not available, do not write to that log id

Bug: 27566046
Bug: 27896341
Change-Id: If63a78a56fb94adfbf9979454c4cadb81af45c19
2016-03-29 12:29:04 -07:00
Mark Salyzyn
cca6f20341 Merge "liblog: update Android.bp" into nyc-dev
am: 033bc9f

* commit '033bc9f3e7175ece714c13258c2385d503c35dc8':
  liblog: update Android.bp
2016-03-25 19:59:25 +00:00
Mark Salyzyn
93101bea8b liblog: update Android.bp
Update Android.bp to match the version in AOSP.

Change-Id: I93aba0f93a7a8d255073661331f1d966a53e20aa
(cherry picked from commit c457a4b73e)
2016-03-24 13:45:00 -07:00
Mark Salyzyn
128c0f7081 liblog: logprint: deal with malformed log messages
am: 476b771

* commit '476b771bdaebf7aa72d41730557fce82cee7faf3':
  liblog: logprint: deal with malformed log messages
2016-03-24 19:25:32 +00:00
Mark Salyzyn
476b771bda liblog: logprint: deal with malformed log messages
(cherry picked from commit 083c53462a)

Try to print as much content as possible should the application
logging only submit content as part of a tag with an empty message.
We search for the first non-printable ascii character in the tag, in
order to split it up for printing.

Applications (such as com.yahoo.mobile.client.android.weather) that
malform their log messages will no longer be punished by truncating
the content, but this should never be considered advocacy for their
bad behavior.

Bug: 27585978
Change-Id: Idb0680e8d6a6ad2bef5150661905acccb5b70afb
2016-03-24 12:21:53 -07:00
Mark Salyzyn
abdb758ef6 Merge "liblog: logprint: deal with malformed log messages" 2016-03-24 19:20:29 +00:00
Mark Salyzyn
574f2bb174 liblog: update Android.bp
Update Android.bp to match the version in AOSP.

(cherry picked from commit 018a96d03f)

Change-Id: I93aba0f93a7a8d255073661331f1d966a53e20aa
(cherry picked from commit c457a4b73e)
2016-03-23 05:19:11 +00:00
Mark Salyzyn
b8e596eb5a Merge changes If37ef423,If93df3ae,I01b38637 into nyc-dev
am: df4e31b

* commit 'df4e31b031e14aacd8b1435ddf7a32923e6e1427':
  liblog: add __android_log_pmsg_file_read
  liblog: add __android_log_pmsg_file_write
  liblog: split out transports into separate files
2016-03-22 23:24:21 +00:00
Mark Salyzyn
2b8157d9fd liblog: add __android_log_pmsg_file_read
(cherry pick from commit 864e8e80e4)

- This is considered an Android Private function, not exported
  for general use.
- goal is to retreive a file's content from a series of log
  messages from pmsg, to be retrieved after a reboot for
  transfer to a persistent location.
- files are presented in reverse sorted order, first based on
  _any_ numerical content, then by alphanumeric order.
- Add a gTest for this function, relies on gTest for
  liblog.__android_log_pmsg_file_write from prior to reboot.

Bug: 27176738
Change-Id: If37ef423009bd28b598b233af3bccef3429bdc22
2016-03-22 14:08:00 -07:00
Mark Salyzyn
10bdf61e5f liblog: add __android_log_pmsg_file_write
(cherry pick from commit d4b061bde2)

- This is considered an Android Private function, not exported
  for general use.
- goal is to record a file's content into a series of log
  messages into pmsg, to be retrieved after a reboot for
  transfer to a persistent location.
- filename reference is converted to a tag-unique
  "<dirbase>:<filebase>".
- buffer and length representing the filename contents are
  recorded, along with a sequence number placed into the nsec
  time field to ANDROID_LOG_PMSG_FILE_MAX_SEQUENCE.
- Add a gTest for this function.

Bug: 27176738
Change-Id: If93df3ae8bfc1bb75516d4a1fd8dae0301af644b
2016-03-22 14:07:54 -07:00
Mark Salyzyn
facf94c74a liblog: split out transports into separate files
(cherry pick from commit 018a96d03f)

Create config_logger, logger and logger_read to house the log
interfaces. Add fake_logger, logd_logger and pmsg_logger to
house the write and read transports. Allows for an easier and
direct path to add new transports to the library.

SideEffects: None, logger benchmark performance unaffected

Bug: 27176738
Bug: 27405083
Change-Id: I01b38637334a5242905c8c89f6ab0a92e2540008
2016-03-22 14:06:00 -07:00
Mark Salyzyn
864e8e80e4 liblog: add __android_log_pmsg_file_read
- This is considered an Android Private function, not exported
  for general use.
- goal is to retreive a file's content from a series of log
  messages from pmsg, to be retrieved after a reboot for
  transfer to a persistent location.
- files are presented in reverse sorted order, first based on
  _any_ numerical content, then by alphanumeric order.
- Add a gTest for this function, relies on gTest for
  liblog.__android_log_pmsg_file_write from prior to reboot.

Bug: 27176738
Change-Id: If37ef423009bd28b598b233af3bccef3429bdc22
2016-03-22 13:03:53 -07:00
Mark Salyzyn
d4b061bde2 liblog: add __android_log_pmsg_file_write
- This is considered an Android Private function, not exported
  for general use.
- goal is to record a file's content into a series of log
  messages into pmsg, to be retrieved after a reboot for
  transfer to a persistent location.
- filename reference is converted to a tag-unique
  "<dirbase>:<filebase>".
- buffer and length representing the filename contents are
  recorded, along with a sequence number placed into the nsec
  time field to ANDROID_LOG_PMSG_FILE_MAX_SEQUENCE.
- Add a gTest for this function.

Bug: 27176738
Change-Id: If93df3ae8bfc1bb75516d4a1fd8dae0301af644b
2016-03-22 13:03:36 -07:00
Mark Salyzyn
018a96d03f liblog: split out transports into separate files
Create config_logger, logger and logger_read to house the log
interfaces. Add fake_logger, logd_logger and pmsg_logger to
house the write and read transports. Allows for an easier and
direct path to add new transports to the library.

SideEffects: None, logger benchmark performance unaffected

Bug: 27176738
Bug: 27405083
Change-Id: I01b38637334a5242905c8c89f6ab0a92e2540008
2016-03-22 13:01:15 -07:00
Mark Salyzyn
083c53462a liblog: logprint: deal with malformed log messages
Try to print as much content as possible should the application
logging only submit content as part of a tag with an empty message.
We search for the first non-printable ascii character in the tag, in
order to split it up for printing.

Applications (such as com.yahoo.mobile.client.android.weather) that
malform their log messages will no longer be punished by truncating
the content, but this should never be considered advocacy for their
bad behavior.

Bug: 27585978
Change-Id: Idb0680e8d6a6ad2bef5150661905acccb5b70afb
2016-03-21 23:06:29 +00:00
Mark Salyzyn
2581a3e762 liblog: test: security buffer is allowed to be denied
am: 53263ff

* commit '53263ffa00b291de92dd4cb399b1cb5218d363f6':
  liblog: test: security buffer is allowed to be denied
2016-03-16 16:50:08 +00:00
Mark Salyzyn
04f5acd3a8 liblog: test: do not LOG in signal handler
am: a6f2f81

* commit 'a6f2f81d1ec81315f7b8395c17282b5f9d02bf0a':
  liblog: test: do not LOG in signal handler
2016-03-16 16:50:08 +00:00
Mark Salyzyn
53263ffa00 liblog: test: security buffer is allowed to be denied
(cherry pick from commit 29e70a98fe)

Bug: 27405083
Change-Id: I7cbc8fda326a2aea3bef5dabee9d3290cc818b24
2016-03-16 09:05:15 -07:00
Mark Salyzyn
a6f2f81d1e liblog: test: do not LOG in signal handler
(cherry pick from commit 50af7f8b1d)

- We actually are logging in a signal handler, the title is bluster
  to remind developers. It is not a reliable path though as it can
  lock up. Our goal is to minimize the chances of a lockup regardless
  in the name of stability only. The test remains to catch regression
  in the name of code quality and reliability. Expected to be
  >99.999% reliable.
- Add a new _correct_ duplicate test that uses signal to release a
  semaphore to a thread that performs the task. This path is expected
  to be 100% reliable.

Bug: 27405083
Change-Id: Ibb7cf4b13e34ebfac2db2af8724b7db7a27f81a8
2016-03-16 09:04:30 -07:00
Mark Salyzyn
c040600baf Merge changes I7cbc8fda,Ibb7cf4b1
* changes:
  liblog: test: security buffer is allowed to be denied
  liblog: test: do not LOG in signal handler
2016-03-16 16:02:48 +00:00
Mark Salyzyn
73207ce139 liblog: truncate logtags that overflow prefixBuf
(cherry pick from commit 2f83d679dd)

Bug: 27585978
Change-Id: If2f45e8787b05b46491a771702746cfc248b9ccd
2016-03-14 10:08:06 -07:00
Mark Salyzyn
29e70a98fe liblog: test: security buffer is allowed to be denied
Bug: 27405083
Change-Id: I7cbc8fda326a2aea3bef5dabee9d3290cc818b24
2016-03-14 09:18:55 -07:00
Mark Salyzyn
50af7f8b1d liblog: test: do not LOG in signal handler
- We actually are logging in a signal handler, the title is bluster
  to remind developers. It is not a reliable path though as it can
  lock up. Our goal is to minimize the chances of a lockup regardless
  in the name of stability only. The test remains to catch regression
  in the name of code quality and reliability. Expected to be
  >99.999% reliable.
- Add a new _correct_ duplicate test that uses signal to release a
  semaphore to a thread that performs the task. This path is expected
  to be 100% reliable.

Bug: 27405083
Change-Id: Ibb7cf4b13e34ebfac2db2af8724b7db7a27f81a8
2016-03-14 09:18:38 -07:00
Mark Salyzyn
2f83d679dd liblog: truncate logtags that overflow prefixBuf
Bug: 27585978
Change-Id: If2f45e8787b05b46491a771702746cfc248b9ccd
2016-03-14 09:12:24 -07:00
Mark Salyzyn
6d753faaf8 liblog: audit declare LIBLOG_ABI_PUBLIC
(cherry pick from commit be1d3c21b5)

- replace <sys/cdefs.h> with local "log_cdefs.h" which
  fortifies and expands definitions, adding LIBLOG_ABI_PUBLIC,
  LIBLOG_HIDDEN, LIBLOG_ABI_PRIVATE and LIBLOG_WEAK.
- clearly tag each interface as LIBLOG_ABI_PUBLIC, LIBLOG_HIDDEN,
  LIBLOG_ABI_PRIVATE, LIBLOG_WEAK or static depending on scope
- Add -fvisibility=hidden to ensure nothing else leaks
- some code standard adjustments

Bug: 27566046
Change-Id: Ic14033c4e6d833d973beb035ddc1c6134fb35a3f
2016-03-10 14:44:27 -08:00
Mark Salyzyn
029c737380 liblog: document fakeLogClose never to be called
(cherry pick from commit bc81b17e06)

Bug: 27107691
Change-Id: Ia699646ec2e83ca46f8b62b5d4f144e533b36074
2016-03-10 14:44:22 -08:00
Mark Salyzyn
8edbbe1dc1 fake_log_device: long lived allocations
(cherry pick from commit 0085a135b9)

Use static space for long lived allocations as they
will appear to act like a memory leak. Resort to a
larger on-stack iovec to reduce the chances of an
allocation. Fix bug in writer where not enough size
was available for "security" buffer name. Minor
transitions to more consistent coding style.

Bug: 27107691
Change-Id: I68c918e7b916b1ae3b04829d48b3eddaa0a7e739
2016-03-10 14:44:16 -08:00
Mark Salyzyn
be1d3c21b5 liblog: audit declare LIBLOG_ABI_PUBLIC
- replace <sys/cdefs.h> with local "log_cdefs.h" which
  fortifies and expands definitions, adding LIBLOG_ABI_PUBLIC,
  LIBLOG_HIDDEN, LIBLOG_ABI_PRIVATE and LIBLOG_WEAK.
- clearly tag each interface as LIBLOG_ABI_PUBLIC, LIBLOG_HIDDEN,
  LIBLOG_ABI_PRIVATE, LIBLOG_WEAK or static depending on scope
- Add -fvisibility=hidden to ensure nothing else leaks
- some code standard adjustments

Bug: 27566046
Change-Id: Ic14033c4e6d833d973beb035ddc1c6134fb35a3f
2016-03-10 13:49:38 -08:00
Dan Willemsen
7d5457e150 liblog: Update Android.bp for Android.mk changes
Change-Id: I5062583a45efa2774f01339e7601767b817f54ee
2016-02-29 10:46:18 -08:00
Elliott Hughes
74c9052fe4 Remove another test for a private API I'm about to remove.
Change-Id: I541d1de549aa62d43867889f41bd0757ed414636
2016-02-26 22:04:26 -08:00
Elliott Hughes
0962ecd4e3 Merge "Remove a test for an API I'm removing." 2016-02-27 01:26:30 +00:00
Elliott Hughes
9ce327200c Remove a test for an API I'm removing.
Change-Id: I44ee84b92fdbf561551e5cf90e0c44df535de83f
2016-02-26 16:57:54 -08:00
Dan Willemsen
9dddd137c7 Fix windows 64-bit builds
pid_t is 64-bit in 64-bit mingw, but the windows process/thread
functions return a DWORD(uint32_t). Instead of promoting to a pid_t and
fixing the format strings, just use a uint32_t to store the values.

android_thread_id also cannot be a 64-bit pointer, so for windows just
force it to be a uint32_t.

libutils/ProcessCallStack only works under Linux, since it makes heavy
use of /proc. Don't compile it under Windows or Darwin.

Bug: 26957718

(cherry picked from commit 86cf941c48)

Change-Id: I8d39d1951fea1b3011caf585c983e1da7959f7c0
2016-02-25 18:43:55 -08:00
Mark Salyzyn
a4f2ef1b05 liblog: __android_log_error_write use event list library
(cherry pick from commit 81f407be36)

Switch to the event list library to compose the associated event.

SideEffects: Instead of composing event on a stack buffer of 512
             bytes in size, a PAGE is allocated temporarily.

Bug: 27356456
Change-Id: Ic15a87f49385834c2287ed82c26439b2c5eb4f77
2016-02-25 15:54:28 -08:00
Mark Salyzyn
d9aee653d1 liblog: test: __android_log_error_write accuracy
(cherry pick from commit 5cecedc6e8)

Add a test to confirm exact expected content using the testframe
setup for the events log handler. Remove dependency on 512 truncation
in liblog->
android_errorWriteWithInfoLog__android_logger_list_read__data_too_large
to something more liberal.

Bug: 27356456
Change-Id: I8a53ad3a16cf16b14856efe5b95417e857c7e09b
2016-02-25 15:53:44 -08:00
Mark Salyzyn
1d5afc9e08 liblog: add android_log_write_string8_len
(cherry pick from commit 67d7eafd56)

android_log_write_string8_len(android_log_context ctx,
                              const char *value, size_t maxlen)

Caps the supplied string to a maxlen length. Alter API to handle
a NULL pointer for the value string for this and
android_log_write_string8() and instead of returning -EINVAL,
act like a null string "" was supplied to preserve the list
location. API is also changed to report the number of characters
actually placed into the android_log_context.

Bug: 27356456
Bug: 19235719
Change-Id: I6a03d405eac1d741555dd05555513ec691e7a46e
2016-02-25 15:53:00 -08:00
Mark Salyzyn
81f407be36 liblog: __android_log_error_write use event list library
Switch to the event list library to compose the associated event.

SideEffects: Instead of composing event on a stack buffer of 512
             bytes in size, a PAGE is allocated temporarily.

Bug: 27356456
Change-Id: Ic15a87f49385834c2287ed82c26439b2c5eb4f77
2016-02-25 12:29:32 -08:00
Mark Salyzyn
5cecedc6e8 liblog: test: __android_log_error_write accuracy
Add a test to confirm exact expected content using the testframe
setup for the events log handler. Remove dependency on 512 truncation
in liblog->
android_errorWriteWithInfoLog__android_logger_list_read__data_too_large
to something more liberal.

Bug: 27356456
Change-Id: I8a53ad3a16cf16b14856efe5b95417e857c7e09b
2016-02-25 12:29:32 -08:00
Mark Salyzyn
67d7eafd56 liblog: add android_log_write_string8_len
android_log_write_string8_len(android_log_context ctx,
                              const char *value, size_t maxlen)

Caps the supplied string to a maxlen length. Alter API to handle
a NULL pointer for the value string for this and
android_log_write_string8() and instead of returning -EINVAL,
act like a null string "" was supplied to preserve the list
location. API is also changed to report the number of characters
actually placed into the android_log_context.

Bug: 27356456
Bug: 19235719
Change-Id: I6a03d405eac1d741555dd05555513ec691e7a46e
2016-02-25 12:29:32 -08:00
Mark Salyzyn
9dd6510dd0 liblog: event log list logging handler
(cherry pick from commit bd1ad049b2)

Based off an initial request and effort by williamluh@google.com

- Added the following functions:

* Composing and Writing:

android_log_context create_android_logger(uint32_t tag)

int android_log_write_list_begin(android_log_context ctx)
int android_log_write_list_end(android_log_context ctx)

int android_log_write_int32(android_log_context ctx, int32_t value)
int android_log_write_int64(android_log_context ctx, int64_t value)
int android_log_write_string8(android_log_context ctx, const char *value)
int android_log_write_float32(android_log_context ctx, float value)

int android_log_write_list(android_log_context ctx, log_id_t id)

* Reading and Interpreting:

android_log_context create_android_log_parser(const char *msg, size_t len)

android_log_list_element android_log_read_next(android_log_context ctx)
android_log_list_element android_log_peek_next(android_log_context ctx)

* Destroy context used above:

int android_log_destroy(android_log_context *ctx);

- Added unit gTests

We moved implemented android_log_buffer_to_string() to the test since
it is an alternate for already existing logprint functionality.
Please move into liblog should it be of some common use, otherwise
as is it is a good means of stessing the reading and interpreting
handlers.

Signed-off-by: Mark Salyzyn <salyzyn@google.com>
Bug: 19235719
Change-Id: I4aa1927e8e6a75f0a129d15a27c891cf1ccd4f5c
2016-02-23 07:45:49 -08:00
Mark Salyzyn
bd1ad049b2 liblog: event log list logging handler
Based off an initial request and effort by williamluh@google.com

- Added the following functions:

* Composing and Writing:

android_log_context create_android_logger(uint32_t tag)

int android_log_write_list_begin(android_log_context ctx)
int android_log_write_list_end(android_log_context ctx)

int android_log_write_int32(android_log_context ctx, int32_t value)
int android_log_write_int64(android_log_context ctx, int64_t value)
int android_log_write_string8(android_log_context ctx, const char *value)
int android_log_write_float32(android_log_context ctx, float value)

int android_log_write_list(android_log_context ctx, log_id_t id)

* Reading and Interpreting:

android_log_context create_android_log_parser(const char *msg, size_t len)

android_log_list_element android_log_read_next(android_log_context ctx)
android_log_list_element android_log_peek_next(android_log_context ctx)

* Destroy context used above:

int android_log_destroy(android_log_context *ctx);

- Added unit gTests

We moved implemented android_log_buffer_to_string() to the test since
it is an alternate for already existing logprint functionality.
Please move into liblog should it be of some common use, otherwise
as is it is a good means of stessing the reading and interpreting
handlers.

Signed-off-by: Mark Salyzyn <salyzyn@google.com>
Bug: 19235719
Change-Id: I4aa1927e8e6a75f0a129d15a27c891cf1ccd4f5c
2016-02-22 16:04:41 -08:00
Mark Salyzyn
b7a0166b00 liblog: deal with warning messages
(cherry pick from commit b525884edb)

- Fix bug in fake_log_devices when it can not allocate memory
  failing to use the full on-stack buffer as backup.
- remove superfluous code.

Bug: 27265662
Change-Id: I97b6cca5f4ce8ecad9beb3a08353de596d6a4ad1
2016-02-22 15:46:22 -08:00
Mark Salyzyn
b525884edb liblog: deal with warning messages
- Fix bug in fake_log_devices when it can not allocate memory
  failing to use the full on-stack buffer as backup.
- remove superfluous code.

Bug: 27265662
Change-Id: I97b6cca5f4ce8ecad9beb3a08353de596d6a4ad1
2016-02-19 14:40:16 -08:00
Mark Salyzyn
0085a135b9 fake_log_device: long lived allocations
Use static space for long lived allocations as they
will appear to act like a memory leak. Resort to a
larger on-stack iovec to reduce the chances of an
allocation. Fix bug in writer where not enough size
was available for "security" buffer name. Minor
transitions to more consistent coding style.

Bug: 27107691
Change-Id: I68c918e7b916b1ae3b04829d48b3eddaa0a7e739
2016-02-17 12:22:18 -08:00
Mark Salyzyn
bc81b17e06 liblog: document fakeLogClose never to be called
Bug: 27107691
Change-Id: Ia699646ec2e83ca46f8b62b5d4f144e533b36074
2016-02-16 10:35:06 -08:00
Mark Salyzyn
663687270c liblog: test: newline space prefix and max length print tests
Add some more tests for logprint library

Bug: 27091726
Change-Id: I264c0607967e0121fefb1b8698f9b02b1463c662
2016-02-11 10:43:14 -08:00
Mark Salyzyn
3f94122ced liblog: add gTests for logging with leading newline
Bug: 27091726
Change-Id: Idff0e4e7c025426002c6381c3afb00e12d9fc1b5
2016-02-10 09:52:13 -08:00
Dan Willemsen
86cf941c48 Fix windows 64-bit builds
pid_t is 64-bit in 64-bit mingw, but the windows process/thread
functions return a DWORD(uint32_t). Instead of promoting to a pid_t and
fixing the format strings, just use a uint32_t to store the values.

android_thread_id also cannot be a 64-bit pointer, so for windows just
force it to be a uint32_t.

libutils/ProcessCallStack only works under Linux, since it makes heavy
use of /proc. Don't compile it under Windows or Darwin.

Bug: 26957718
Change-Id: I4e43e7cf18a96f22b3a9a08dbab8c3e960c12930
2016-02-05 16:10:10 -08:00
Colin Cross
a2dd73424f Merge "liblog: remove strdup from logging calls" 2016-02-03 21:48:37 +00:00
Colin Cross
7a106f7c12 liblog: remove strdup from logging calls
strdup to a static pointer is unnecessary, strlcpy into a static buffer
instead.  Avoids allocations in the ALOG* path, allowing liblog to be
used by libmemleak.

Change-Id: Ie0986da27c1fc5eb8ce4ebb076b513be8e1ee676
2016-02-02 13:55:42 -08:00
Mark Salyzyn
8fa8896d2e logd: security buffer only AID_SYSTEM reader
- limit AID_SYSTEM uid or gid to read security buffer messages
- adjust liblog tests to reflect the reality of this adjustment

To fully test all security buffer paths and modes

$ su 0,0,0 /data/nativetest/liblog-unit-tests/liblog-unit-tests --gtest_filter=liblog.__security*
$ su 1000,1000,1000 /data/nativetest/liblog-unit-tests/liblog-unit-tests --gtest_filter=liblog.__security*
$ su 2000,2000,2000 /data/nativetest/liblog-unit-tests/liblog-unit-tests --gtest_filter=liblog.__security*

ToDo: Integrate the above individually into the gTest Q/A testing

Bug: 26029733
Change-Id: Idcf5492db78fa6934ef6fb43f3ef861052675651
2016-02-01 13:29:06 -08:00
Mark Salyzyn
9107c462ce liblog: check getgroups for AID_LOG for AID_LOG_SECURITY
Bug: 26792035
Change-Id: I634d3c8f9f3175956bd70e80daa479af40180f90
2016-01-26 13:32:02 -08:00
Mark Salyzyn
7cc8013e37 liblog: fix android_log_printLogLine empty event string
Allow _one_ empty line to get through before evaluating
further. Add __android_log_bswrite testing for content
and contentless cases; checking for propagation and for
expected printing. As for printing which is fixed here,
security variants cover the same code paths as the events.

Bug: 26646213
Change-Id: I484718aa604e0a00afde4c34a00e87468ea93aa5
2016-01-20 14:15:19 -08:00
Rubin Xu
d545d2930e Add logd security buffer tag types and string write API.
Bug: 22860162
Change-Id: I1cceed3462eaebdd8208abf101b127f27f0023a7
2016-01-19 17:13:28 +00:00
Mark Salyzyn
1a5bac2069 Merge "Revert "logd: liblog: whitelist "snet_event_log""" 2016-01-06 21:22:04 +00:00
Mark Salyzyn
0ee8de3c2d Revert "logd: liblog: whitelist "snet_event_log""
Callers will not guarantee that they can or will ratelimit, we need to
retain the ability to blacklist snet_event_log as a result.

This reverts commit 6aa21b225d.

Bug: 26178938
Change-Id: Ibf47d2e23a84c56f5f72d02312c698df7ff2b601
2016-01-06 21:19:23 +00:00
Dan Willemsen
d68c35a9ce liblog: Update Android.bp to match Android.mk
Change-Id: Ic887493c03d133a566a96c1c5b65dcd67e5d7131
2016-01-05 13:09:35 -08:00
Mark Salyzyn
6aa21b225d logd: liblog: whitelist "snet_event_log"
Dangerous bridge to cross to whitelist, who is special, who is not?
Rationalized as these events are used to catch exploits on platform.
As it stands no one should be allowed to block any messages in the
security context, not even for development purposes.

Bug: 26178938
Change-Id: Ibdc76bc0fe29ba05be168b623af1c9f41d7edbd2
2015-12-30 10:07:19 -08:00
Mark Salyzyn
a014004752 liblog: add __android_log_is_loggable checking to writer
Add __android_log_is_loggable() checking for all buffers except
LOG_ID_SECURITY. Return -EPERM if blocked. Since we are sniffing
the log tag, check validity and return -EINVAL.

NB: Try not to call __android_log_is_loggable() in native code within
a signal handler. Both here, and in the system properties, there
are locking paths that are not guaranteed to play well in that
environment. This has also been the case for the log writer path
even before this change. All attempts have been made to use trylock,
and to use a more expensive code path when contention occurs rather
than lead to deadlock.

Bug: 19544788
Bug: 26178938
Change-Id: I98738c662f6328189a6703251eb8721a05e956f9
2015-12-30 10:03:37 -08:00
Mark Salyzyn
31ca3c3770 liblog: build break
Some compilers erroneously see uninitialized use, even despite all
accesses being behind !not_locked. Confirmed initialization does not
affect expected performance.

Bug: 26178938
Bug: 26029733
Bug: 17760225
Change-Id: Ib36ed8dd2c4b196ca84ef79a9531625dcee77e15
2015-12-22 10:49:35 -08:00
Mark Salyzyn
a67d8a53c7 liblog: is loggable is flaky
- Deal with __android_log_is_loggable inside signal handler by
  treating a lock contention system call as more costly than reading
  the associated property directly. Rather waiting around in a
  contended stat to hit cache.
- Check both the individual known __system_property_serial() and
  global __system_property_area_serial() to detect updates or
  additions to the properties to respond in the most aggressive and
  timely manner. __android_log_is_loggable() return at max CPU
  clockrate on a N9 in 61ns.
- Craft a common do_cache2 inline that adds the above to the other
  functions that utilize cache handling and preserves (within 3ns)
  performance in android_log_clockid() and __android_log_security().
  These functions return at max CPU clockrate on a N9 in 23ns.

Bug: 19544788
Bug: 25693940
Bug: 25792367
Bug: 26178938
Change-Id: I9cd94598f5c558e946b93977ad3714a4b03d0422
2015-12-22 10:06:22 -08:00
Mark Salyzyn
77c166b5dd liblog: test: instrument is_loggable failures
Bug: 25792367
Change-Id: Ia34f8e7ea0bd7f15bf705afd3a1c631a56d1c479
2015-12-18 15:17:51 -08:00
Mark Salyzyn
ee3b838e13 logd: statistics per-pid filter
Primarily gives access to the Chattiest TIDs and TAGs
associated with a pid.

Has a secondary effect of allowing us to pull out the
command line, comm and in some cases the associated
PACKAGE for a specific pid while the logs are still
present even if the executable is gone.

Bug: 26029733
Bug: 21615139
Change-Id: I1ea63165a680a9318360579b70b1512078ed5682
2015-12-18 13:17:37 -08:00
Mark Salyzyn
5d8742feb6 Merge "liblog: test: pmsg overhead measurement" 2015-12-18 20:34:55 +00:00
Mark Salyzyn
1d51753461 Merge "liblog: Remove paranoia regarding logd" 2015-12-18 18:51:24 +00:00
Mark Salyzyn
163ebdc7cd liblog: test: pmsg overhead measurement
This test tells us that scatter-gather (writev instead of write)
carries a small ~2% penalty. Unaligned buffer carry a similar
additional penalty. On N9 it takes 3us to 22us _just_ to write
the pmsg logs, depending on size. Some assumptions about the
socket read and write performance for the main logging can be made
from tracking these results and should improve design decisions.

Bug: 18771697
Bug: 23685592
Change-Id: Id4d64c449140e4f39078c62b0097e403df91fe0c
2015-12-16 13:12:56 -08:00
Mark Salyzyn
7bc8023857 liblog: logprint security ANDROID_LOG_WARN
Bug: 26029733
Change-Id: I4f0cffc0a45819fb48807bf06ce336316276369d
2015-12-11 12:37:22 -08:00
Mark Salyzyn
86052a5d4f Merge "logd: liblog: logcat: Add LOG_ID_SECURITY" 2015-12-11 17:33:33 +00:00
Mark Salyzyn
42ae82742b liblog: test for maximum payload can not survive change
If we adjusted the maximum log payload, Resolve compile
issues resulting from the changes (gTest).

Bug: 25996918
Change-Id: I672b0f4d9d4a1394a5b2e27bf81a5e906bf92a10
2015-12-09 08:12:07 -08:00
Mark Salyzyn
2aa510e8b4 liblog: logprint use uid name if length less then 5
Bug: 25996918
Change-Id: Id882978b7b0b439e39bedeafc39edf80892f0317
2015-12-09 08:12:07 -08:00
Mark Salyzyn
90e7af30a5 liblog: logprint add uid format modifier
Bug: 25996918
Change-Id: Idff5e080fc5c7b69e0c45d3f596eb9d632451cbd
2015-12-09 08:12:07 -08:00
Mark Salyzyn
8646a54ece liblog: readlog apps get logger_entry_v4 for pstore
Adds the uid field to outgoing content for readlog applications.
AID_LOG, AID_ROOT and AID_SYSTEM gain access to the information.

Bug: 25996918
Change-Id: Ib124eca12c004cdd6e57b98e0aae6ddced385cf6
2015-12-09 08:12:07 -08:00
Mark Salyzyn
083b037c07 logd: liblog: logcat: Add LOG_ID_SECURITY
- Largish commit, buffer and access controls done together
- Add LOG_ID_SECURITY binary content log
- Add "default" meta buffer
- allow LOG_ID_SECURITY only from AID_SYSTEM and AID_ROOT UID & GID
- Use __android_log_security() to gate logging
- Add __android_log_security_bwrite() native access to security
  logging.
- Add liblog.__security_buffer end-to-end gTest

Bug: 26029733
Change-Id: Ibcf5b4660c17c1aa6902c0d93f8ffd29c93d9a93
2015-12-08 16:46:29 -08:00
Mark Salyzyn
b004a7fe6f liblog: Build Problem, BOOLEAN
Checks with BOOLEAN_FALSE and BOOLEAN_TRUE should be made
against an unsigned char.

Bug: 26029733
Change-Id: I405f45a4d6ddae1b060b0e8da9c1585298abe8bd
2015-12-08 15:24:44 -08:00
Mark Salyzyn
ffbd86ff25 liblog: Add __android_log_security()
Return non-zero if ro.device_owner is set and not false
and persist.logd.security is true.

Bug: 26029733
Change-Id: Ie82ae11ae35e9c79017b6e873fefb39d79a1d4fe
2015-12-08 11:28:27 -08:00
Mark Salyzyn
d7bcf40ee6 liblog: print message payload of zero length
logcat will crash if the log message payload is of zero length. Side
effect of possible log messages from LogKlog in eng and userdebug
builds, or lower level logging calls.

NB: The referenced bug cited an example of this native crash, this
    does not fix the problem cited in the bug about the
    com.android.music shutdown.

Bug: 25774695
Change-Id: I5c7a6ad8db640ba9bc8d34fab04ba7cc2a9a426a
2015-12-07 16:14:40 -08:00
Mark Salyzyn
f8e546e609 liblog: Support for ANDROID_LOG_WRAP mode flag on reader
If ANDROID_LOG_WRAP is specified, add timeout=3600 to the reader
request. logd will comply by going to sleep with the socket open.
If the start time is about to wrap or get pruned in the specified log
buffers, then wakeup and dump the logs; or wakeup on timeout,
whichever comes first.

Bug: 25929746
Change-Id: I531b4317a20abcf3ba87d78c68fa2f268a4488ab
2015-12-07 14:24:02 -08:00
Mark Salyzyn
8ca9a775f7 Merge "liblog: test: liblog.android_logger_get_ failure" 2015-12-07 19:30:40 +00:00
Mark Salyzyn
7d8939ec1d liblog: test: liblog.android_logger_get_ failure
Change-Id: I8f74eca7857fe4cd6fa979d7bdeeda2b6a3e596b
2015-12-07 11:08:59 -08:00
Mark Salyzyn
ba7a9a016b logd: liblog: logcat: switch to android_log_clockid() (2)
android_log_timestamp returns the property leading letter,
it is better to return a clockid_t with android_log_clockid()

Bug: 23668800
Change-Id: I38dee773bf3844177826b03a26b03215c79a5359
2015-12-07 18:45:31 +00:00
Mark Salyzyn
9e18cdcebd Revert "logd: liblog: logcat: switch to android_log_clockid()"
This reverts commit 77b5696b1d.

Change-Id: I7711bf1a7e3f72ed29a2498d7287b725a0e624bd
2015-12-07 18:30:58 +00:00
Mark Salyzyn
77b5696b1d logd: liblog: logcat: switch to android_log_clockid()
android_log_timestamp returns the property leading letter,
it is better to return a clockid_t with android_log_clockid()

Bug: 23668800
Change-Id: I3c4e3e6b87f6676950797f1f0e203b44c542ed43
2015-12-04 14:49:19 -08:00
Dan Willemsen
a3f41bf774 liblog: enable windows builds in soong
Change-Id: I426cdebeddf653bf2daacb3e0724516ac78756cb
2015-11-30 15:57:41 -08:00
Mark Salyzyn
2d2e0a5c5e liblog: resolve deadlocks
Although ever present, an increased regression introduced with
commit b6bee33182 (liblog: logd:
support logd.timestamp = monotonic).

A signal handler can interrupt in locked context, if log is written
in the signal handler, we are in deadlock. To reduce the contention
and chances for this problem separate out timestamp lock from is
loggable lock to reduce contention situations. Provide a best-guess
response if lock would fail in timestamp path.

Use a common lock() inline within each module, with a comment speaking
to the issues surrounding calling a function that has a mutex within
a signal handler.

ToDo: Hold off signals temporarily in mainline, restart when unblock.
      Can not use pthread_sigmask(SIG_BLOCK,,) as it breaks AtCmd.

Signed-off-by: Mark Salyzyn <salyzyn@google.com>
Bug: 25563384
Change-Id: I47e2c87c988c3e359eb9eef129c6a3a08e9eedef
2015-11-19 13:14:16 -08:00
Mark Salyzyn
65d5ca2001 liblog: printable do not escape tabs
Signed-off-by: Mark Salyzyn <salyzyn@google.com>
Bug: 25755153
Change-Id: I99324e751db0e1ed1eb00820e82b176b6d789249
2015-11-18 09:59:12 -08:00
Mark Salyzyn
c2e7d4965f Revert "liblog: resolve deadlocks"
This reverts commit 7a2a307192.

Bug: 25693940
Change-Id: I9a7c926289e972f80c03c92e33535e1dedaa7381
2015-11-16 19:00:41 +00:00
Mark Salyzyn
7a2a307192 liblog: resolve deadlocks
Although ever present, an increased regression introduced with
commit b6bee33182 (liblog: logd:
support logd.timestamp = monotonic).

A signal handler can interrupt in locked context, if log is written
in the signal handler, we are in deadlock. Block signals while we
are locked. Separate out timestamp lock from is loggable lock to
reduce contention situations. Provide a best-guess response if
lock would fail in timestamp path.

Bug: 25563384
Change-Id: I6dccd6b99ebace1c473c03a785a35c63ed5c6a8a
2015-11-12 15:39:04 -08:00
Mark Salyzyn
b6bee33182 liblog: logd: support logd.timestamp = monotonic
if ro.logd.timestamp or persist.logd.timestamp are set to the value
monotonic then liblog writer, liblog printing and logd all switch to
recording/printing monotonic time rather than realtime. If reinit
detects a change for presist.logd.timestamp, correct the older entry
timestamps in place.

ToDo: A corner case condition where new log entries in monotonic time
      occur before logd reinit detects persist.logd.timestamp, there
      will be a few out-of-order entries, but with accurate
      timestamps. This problem does not happen for ro.logd.timestamp
      as it is set before logd starts.

NB: This offers a nano second time accuracy on all log entries
    that may be more suitable for merging with other system
    activities, such as systrace, that also use monotonic time. This
    feature is for debugging.

Bug: 23668800
Change-Id: Iee6dab7140061b1a6627254921411f61b01aa5c2
2015-11-03 15:15:51 -08:00
Mark Salyzyn
500afc7532 liblog: add android_log_timestamp() private function
Change-Id: Iefbea3b1be2f97cfdeb35e5330e5495e0337215b
2015-10-29 14:23:42 -07:00
Mark Salyzyn
4cbed02e44 liblog: logcat: add epoch and monotonic format modifiers
- '-v epoch' prints seconds since Jan 1 1970
- '-v monotonic' print cpu seconds since start of device
- '-T sssss.mmm...' as alternate tail time format

NB: monotonic is a best estimate and may be out by a few ms
    given the synchronization source clue accuracy.

Bug: 23668800
Change-Id: Ieb924b6d3817669c7e53beb9c970fb626eaad460
2015-10-29 14:23:42 -07:00
Mark Salyzyn
16e1c9dfdc liblog: optimize code hotspot
strcmp was 1/10 #2 behind find_property in __android_log_level(),
now virtually eliminated from performance profile.

Bug: 23685592
Change-Id: I3978886193af77e489c6d1728d6a26b7f53f8f2f
2015-10-02 13:55:44 -07:00
Mark Salyzyn
447356ddb4 Merge "liblog: logcat: Add year and zone to date on each line" 2015-09-30 18:56:48 +00:00
Mark Salyzyn
faa92e9915 liblog: logprint: printable nul
Change-Id: I57d1f86ce040ad196c558bb72ac0464af793c214
2015-09-29 15:43:34 -07:00
Dmitriy Ivanov
58558a59c9 Fix bug number for linker related workarounds
Bug: http:/b/24425865
Change-Id: I87e1af3cf39b5234647ecbbd5844c9d88eeb9200
2015-09-28 10:40:35 -07:00
Mark Salyzyn
f28f6a9ba2 liblog: logcat: Add year and zone to date on each line
- '-v year' modifier adds the four digit year prefix
- '-v <timezone>' modifier sets and prints the timezone suffix
- Only promise in logcat to support UTC as a timezone since
  all others are based on the configured environment
- '-v zone' modifier toggles the timezone suffix on or off
- '-T YYYY-MM-DD HH:MM:SS.mmm...' format is added

Bug: 23668700
Change-Id: I7521c1efb7455dc9a25434fce72a69a65dcf72ea
2015-09-24 14:49:55 -07:00
Dan Willemsen
63aa47afd7 Add Android.bp for liblog
Change-Id: Ibbb476a5e6b247cba96929e683727c25f66d90f0
2015-09-16 15:59:22 -07:00
Stephen Hines
b0e4f08226 Ensure that libbase and liblog can be built for Windows.
Change-Id: If4adf1e2bd7ec36a7f02ae2e263d2db5187c6e7b
2015-09-11 11:39:16 -07:00
Dan Willemsen
87a419c8b1 Remove USE_MINGW/CYGWIN; Whitelist windows modules
CYGWIN is not supported, USE_MINGW and HOST_OS==windows are being
replaced with LOCAL_..._windows variables.

Bug: 23566667
Change-Id: I3e4a1e4097dc994cf5abdce6939e83a91758fd75
2015-09-02 17:10:35 -07:00
William Luh
964428c0a6 Add macro to call event logger for errors.
Bug:23180694
Change-Id: I566a290334345f48013029534efef3e08e726e40
2015-08-26 15:59:06 -07:00
Elliott Hughes
adbf442a51 Use _WIN32 rather than HAVE_WINSOCK.
Change-Id: I9855b6fe72e2f2f3a8360c0993a67cb988024ee4
2015-07-29 17:45:24 -07:00
Mark Salyzyn
514243d5bd liblog: deprecate TARGET_USES_LOGD
This is not the kernel logger you are loiking for

Bug: 22787659
Change-Id: Id65ed2e8e7ffe4b2be1bdeed65fa8db23bd66b51
2015-07-28 09:37:07 -07:00
Mark Salyzyn
87e16036ec Merge "liblog: __android_log_is_loggable support global properties" 2015-06-15 14:32:20 +00:00
Evgenii Stepanov
c744ef5547 Fix SANITIZE_TARGET build of liblog.
* liblog does not use STL, don't link it.
* ASan runtime library depends on liblog, hence liblog can never be
  sanitized.

Bug: 21785137
Change-Id: I1e97378c61d4d18d740287f5f0881427aa7cc227
2015-06-12 14:18:33 -07:00
Mark Salyzyn
c158456f50 liblog: __android_log_is_loggable support global properties
- Add support for "log.tag" and "persist.log.tag" global
  logging properties, effectively a runtime default minimum
  logging level.
- Add a thread-safe single level cache plus selective logic for the
  four properties being checked to help speed up logging decision
  on subsequent identical calls.
- Using new __system_property_area_serial() to make for
  efficient (<100ns) handling of cache misses. Despite adding
  two new properties, we are 8 times faster on subsequent calls
  even if the properties do not exist.
- A NULL or blank tag is no longer directed to return default,
  it will check the pair of global logging properties first.
- Add liblog.is_loggable gTest
- Fixup liblog.android_logger_get_, allow no content in crash buffer
- Fixup liblog.max_payload, lowered logd priority increases latency

Bug: 19544788
Bug: 21696721
Change-Id: Ideb887755aa3f1fd14a2603bda1fe23cba49642c
2015-06-12 10:35:09 -07:00
Mark Salyzyn
b932b2f8ba liblog: logcat: Add printable format modifier
- added printable format modifier:
  logcat -v printable
- opencoded borrowed individual utf8 validity checking algorithm
  from utf8_length() in libutils/Unicode.cpp
- if considered basic one-character ASCII, use popular \x escape
  sequences for non-printable
- logprint convert to C comments to drop mixed-mode

Bug: 19000361
Change-Id: I122a5b8fb41216fc0bc816178c0b768f3df56586
2015-06-04 08:27:29 -07:00
Mark Salyzyn
f3555d9427 logcat: -f flag to continue
On startup, check the current logging content, then grab logs from
that time forward rather than restarting from the beginning. Add
support for reading tail time down to the nano-second.

Bonus, permits us to create a logcatd logpersist daemon

Bug: 19608716
Change-Id: Iaab58de4c02b7f97c69de12cf954fedc2163059e
2015-06-02 14:56:44 -07:00
Mark Salyzyn
10c18d64c6 Merge "liblog: gtest open("/dev/pmsg0", "a")" 2015-05-13 16:30:59 +00:00
Mark Salyzyn
e1f2004ecc logcat: liblog: Add "usec" format argument
- Add additional 3 digits of time precision for time output
  adding in the reporting of usec
- Remove trailing space in header file

Change-Id: Ifb560850b8e01080e126fbaeab640db71cce3eea
2015-05-12 15:51:46 -07:00
Mark Salyzyn
b51546f43f Merge "liblog: Add kernel log id" 2015-05-11 16:09:04 +00:00
Dmitriy Ivanov
fd8afe6f31 Switch liblog.so to hash-style=both
Bug: http://b/19059885
Change-Id: I7cde911f11b09c3a13553154aca6e291bb91befb
2015-05-08 14:09:24 -07:00
Mark Salyzyn
440e109d64 liblog: Add kernel log id
Change-Id: I53002f05a8bdf8d67e1d761c56c8761d3b534a76
2015-05-06 08:54:59 -07:00
Jeff Brown
44193d9eae Add float support to binary event log.
Bug: 20664753
Change-Id: Ib4752bd785496dab5bb4d4979d5d80f662adbdfa
2015-04-28 18:20:48 -07:00
Mark Salyzyn
1ac79cbd89 liblog: Add BM_is_loggable benchmark
- On a N9 64-bit benchmark, the __android_log_is_loggable overhead
  is roughly 500ns (1/2 of a syscall?)

Bug: 19544788
Bug: 17760225
Bug: 20416721
Change-Id: Ib9e4d06d96e1b19ca5d459e569ead451ef47a9c0
2015-04-24 07:59:44 -07:00
Mark Salyzyn
1f028b2fdf liblog: __android_log_is_loggable support Developer Options
- If logd.tag.<tag> is not found, check if persist.logd.tag.<tag> is available
- Do not turn off the isLoggable functionality on "user" builds

Bug: 19544788
Bug: 17760225
Change-Id: I3fec67b547aa431438965519507033798398e1e1
2015-04-22 10:39:39 -07:00
Dan Albert
eb56013348 Merge "Share log writing code." 2015-04-03 17:51:13 +00:00
Dan Albert
c7aadc49d3 Share log writing code.
__android_log_write() was just a special form of
__android_log_buf_write that used a default log ID and set the abort
message for fatal messages. Presumably the latter was intended to be
set for __android_log_buf_write as well.

Change-Id: I51cff7561a2754676b2088d95fa4f4505ac3c3c2
2015-04-03 10:41:59 -07:00
Elliott Hughes
bcc2b5f44a Remove LOCAL_ADDITIONAL_DEPENDENCIES in cases where it's not needed.
Change-Id: I720b8ef1050da45a7833adef8219b6acb2cf3a38
2015-04-02 14:31:07 -07:00
Mark Salyzyn
0d00a44a8b liblog: remove internal __write_to_log_null
__write_to_log_null never retries initialization and only
made sense for the kernel logger. The user space logger
can come and go.

Bug: 19732485
Change-Id: Iac34ea1c52ec82db4ee0c2c73ba0950ace4d4dec
2015-03-23 22:07:29 +00:00
Mark Salyzyn
31f7df5fd1 liblog: reject empty logging messages
A regression after "liblog: Instrument logging of logd write drops"
where an empty payload would result in an insufficient iovec to
report the write drop.

Change-Id: Iffabcfbb0680898d7a42004700e638e9d940ff5f
2015-03-18 23:43:42 +00:00
Mark Salyzyn
df0257d344 liblog: gtest open("/dev/pmsg0", "a")
Change-Id: I918025a8ac28204076ce4831ce277b04091619f6
2015-03-18 16:34:49 -07:00
Dmitriy Ivanov
28a3b7cae0 Switch liblog to sysv-only hash style
Bug: 19059885
Change-Id: I5519a4e19716303692d4117bc24988f21d5a829e
2015-03-13 12:51:02 -07:00
Goran Jakovljevic
3947d5da3f Generate gnu hash for arm only
Fixes mips build failure caused by:
https://android-review.googlesource.com/#/c/139580/

As previously discussed [1], MIPS does not support GNU-style ELF hashes.

[1] https://android-review.googlesource.com/#/c/49282/2/tests/Android.mk

Change-Id: I757fef1d47663da3e414f5771dfc580ea7aa3732
2015-03-10 09:47:23 -07:00
Dmitriy Ivanov
692c0e41e1 Generate sysv hash for liblog
Bug: 19059885
Change-Id: I6fff4372504e3ca0d870c5cafe6f19d412787923
2015-03-09 18:30:54 -07:00
Elliott Hughes
02ff4b8feb Fix __android_log_assert to abort.
If you rely on __builtin_trap, it's likely to use an illegal instruction,
which is a misleading way to abort. If we just call abort, it's more
immediately obvious that we've aborted.

Bug: 19644330
Change-Id: I63a962e4748aec7b019ea94b007593e478a3b61a
2015-03-07 11:21:37 -08:00
Mark Salyzyn
8470dad24f Revert "liblog: logprint use <endian.h>"
This reverts commit 66bfc5ccbd.

Bug: 19634248
Change-Id: I7c4851a247042193674f226fd0d5c5663e8074c7
2015-03-06 20:46:31 +00:00
Mark Salyzyn
1b79369877 liblog: build cleanup
- Drop CYGWIN build checking
- Hard code the "liblog" event tag
- Drop use of internal WITH_MINGW

Change-Id: I7b63bd7fa4471f340f356b477a0e5e25fe83a851
2015-03-05 11:10:00 -08:00
Mark Salyzyn
31dd00fcf5 liblog: logprint use <endian.h> part three
Fix host/sdk builds:
- Drop logprint from list of host products
- Drop <endian.h> for FAKE_LOG_DEVICE

Change-Id: I8aa854413ff6d809f0b04987cf913eb228e4213c
2015-03-04 17:40:04 -08:00
Mark Salyzyn
051222c243 Merge changes I12d6aa4e,I9e802113,I2b30e0fc,Iaf387b9e
* changes:
  logcat: remove dead label code
  logcat: do not stop on unexpected log ID
  Revert "logd: Add minimum time bucket statistics"
  liblog: Instrument logging of logd write drops
2015-03-05 01:12:06 +00:00
Mark Salyzyn
f8d62a0107 liblog: logprint use <endian.h> part deux
Change-Id: I042194d0f5ec444dd192ee9da50d6b48d556f8ac
2015-03-04 16:20:50 -08:00
Mark Salyzyn
43e92819fe liblog: Remove paranoia regarding logd
We are changing the log read API to allow event notification
regarding logging system data loss. We would like these out
of band events to be reported.

Change-Id: I2bcd0ec7499b8139956613d72d7f62aff44b92ec
2015-03-04 13:21:42 -08:00
Mark Salyzyn
d45d36e011 liblog: Instrument logging of logd write drops
- If logger system is prostrated, send an event message with the
  liblog tag from the associated UID and PID with a count of
  dropped messages once logging is resumed.
- Added to the README a description of the error return values.
- Describe in the README the appropriate mitigations for dropped
  messages.
- If the caller sees this message, then
  /proc/sys/net/unix/max_dgram_qlen is likely too small

Change-Id: Iaf387b9e5e1b6aa93bebc7481f9e8353732e3229
2015-03-04 13:21:41 -08:00
Mark Salyzyn
66bfc5ccbd liblog: logprint use <endian.h>
Change-Id: I0ec0fe3e954f6f04964d58e57c817d28057b630b
2015-03-04 12:48:04 -08:00
Mark Salyzyn
6eef417119 liblog: add pstore read
Used to pull the Android log messages after a reboot. Adding
an ANDROID_LOG_PSTORE flag to the mode parameter in calls to
android_logger_list_alloc() and android_logger_list_alloc_time().
The side effects are that android_logger_clear() and
android_logger_list_read() will react with the user space
pstore driver. Forms a companion to the pstore console logs.

Change-Id: I7bb07b87b3bf73f059a21af3f810af37c7715b6d
2015-02-26 06:37:35 -08:00
Mark Salyzyn
2d3f38a6b8 liblog: introduce ANDROID_LOG_* flags
Move away from using POSIX open(2) flags and introduce ANDROID_LOG_* flags to
replace them. Add security by preventing random mode flags from getting into
underlying POSIX calls. ANDROID_LOG_* flags overlap POSIX O_* flag definitions.

Change-Id: Ib32bb64c287e8bf150be62242e1ba46bb37839fc
2015-02-25 17:44:18 +00:00
Mark Salyzyn
53016d8949 liblog: test: ARM64: Enable 32 and 64-bit liblog_benchmark
- Enable build for 32 and 64 bit benchmark executables
- Fix some cosmetics issues in logd_write.c

Change-Id: I544446e5116607d7fec89171135f6e1eff6aebd8
2015-02-10 18:15:51 +00:00
Mark Salyzyn
956870518e liblog: add __android_log_is_loggable()
- Add new liblog API __android_log_is_loggable(prio, tag, def)
- future plan to integrate this into the runtime checks and into
  the logd daemon for filtration. Inert for now.

Bug: 17760225
Change-Id: I16395b4d42acc08f0209f55a1cbf87b0b2112898
2015-02-09 22:12:59 +00:00
Yabin Cui
4a6e5a3b64 Kill HAVE_PTHREADS.
Bug: 19083585
Change-Id: Ic09eb3dd250bc5c5b63cac7998f99f5fa007f407
2015-01-27 14:23:22 -08:00
Mark Salyzyn
d91ab5815d liblog: add pstore write
Used to push the Android log messages into pstore
(when available, and no propagation of error).

Change-Id: I9def8cf796d35d347f502d9745d5f42ec1200253
2015-01-23 23:33:31 +00:00
Mark Salyzyn
7a80940121 liblog: use private/android_logger.h
- fix a latent issue with retransmitting on failure.

Change-Id: I2d0e5c3531c279f2dc1fbd74807210ff8d804de1
2015-01-23 23:32:50 +00:00
Mark Salyzyn
e2428429e0 liblog: logcat color output corrupted on 32-bit
sizeof(suffixBuf), not sizeof(suffixLen)!

Change-Id: I6e085089237585bb8b406372639b644556747699
2015-01-22 10:00:04 -08:00
Mark Salyzyn
decd92945f liblog: Add log_time += operator
Change-Id: I1d2987b6cb333fc344d4fee1b7bb25f32a4143c6
2015-01-05 16:27:54 +00:00
Elliott Hughes
111e3d3d9c Only Windows doesn't have <sys/uio.h>.
This should probably be in libcutils instead, so code that needs to
care about Windows can use readv/writev.

Change-Id: I7c2ceec3f742cee0e44f69fd4c88459376bd0e08
2014-11-25 13:27:43 -08:00
Elliott Hughes
2a5fecb3cd Only Win32 doesn't have writev.
Change-Id: I9b5328cea3c88a75135dcb0711cbb5471e8fa388
2014-11-25 10:25:42 -08:00
Andreas Gampe
1f742864fa Liblog: Remove unused function
For build-system CFLAGS clean-up, remove unused function.

Change-Id: I8c28c4bbbadaea6a5b32483e9e220794967bdd4e
2014-11-24 10:36:55 -08:00