Commit graph

415 commits

Author SHA1 Message Date
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
Elliott Hughes
9768d24fa0 Kill LOCAL_SOCKET_NAMESPACE.
Change-Id: I18928f89f66c37be310c45ff4c05a6d47ab84f66
2014-11-21 22:50:20 -08:00
Yabin Cui
8a98535bcb kill HAVE_LOCALTIME_R
Bug: 18361583
Change-Id: Icdc745a5204bba26c6438d16ed38ec791e136163
2014-11-13 10:11:23 -08:00
Dan Albert
f2dedb7a5f Move liblog tests and benchmarks to libc++.
Bug: 15193147
Change-Id: Ib063eb9490e40f9d10c0b0f29b7808c729e4fff9
2014-11-12 03:44:16 +00:00
Adam Lesinski
b2042f7263 am a1ac84cd: MingW doesn\'t handle __attribute__((weak)) for Windows PE
* commit 'a1ac84cd8d7357f38a9fc60ab9d42e81d1790fd2':
  MingW doesn't handle __attribute__((weak)) for Windows PE
2014-10-20 21:15:53 +00:00
Adam Lesinski
a1ac84cd8d MingW doesn't handle __attribute__((weak)) for Windows PE
Windows PE format doesn't have the same support for weak symbols
as ELF does.

The symbol android_log_id_to_name was strangely omitted from the
resulting Windows executable and the callsite where it was supposed
to be called was relaced with a different symbol, which caused a crash
in AAPT on Windows.

This change works due to a careful set of #ifdefs that ensure only one
definition of android_log_id_to_name is defined, but there are other
uses of __attribute__((weak)) which should be inspected.

Change-Id: I3b58076e31d9b28c5143773a170e9ffda9fa3815
2014-10-20 12:33:59 -07:00
Dan Albert
e18ed89eae Merge "Remove makefile cruft." 2014-09-12 18:07:26 +00:00
Dmitriy Ivanov
5f68087efe Add -std=gnu++11 to test cflags
Change-Id: Ife92cea10021658eba6e22a7ebc9e31f3d194a25
2014-09-12 10:39:12 -07:00
Dan Albert
fbb8db2e2a Remove makefile cruft.
Don't manually include stlport, and don't use private bionic headers.

Change-Id: I0fc4e8b34ab449e9ef07c26f71e472fca5640590
2014-09-12 10:36:26 -07:00
Pierre Zurek
ead88fca6e liblog: logcat: colored output.
This patch adds a new '-v color' option to logcat so that the output is
colored similar to the ones in DDMS. Simply type "adb logcat -v color"
to use it. Works well with bash in gnome-terminal. NO GUARANTEE IT WILL
WORK ON A NON xterm STYLE TERMINAL.

Signed-off-by: Michael Zimmermann <sigmaepsilon92@gmail.com>
Signed-off-by: Mark Salyzyn <salyzyn@google.com>
Change-Id: I9189c5f27fed991579edbcbc6834536eb8112152
2014-09-11 19:04:17 -07:00
Dmitriy Ivanov
85af05ae37 Fix typo: ifndef -> ifneq
Change-Id: Id71c70b6fcd2659078a19cc652fd02807372f3a0
2014-08-25 16:26:29 -07:00
Dan Albert
c68fedce06 Update for public android_set_abort_message().
Since android_set_abort_message() is quite helpful to the platform, it's
becoming promoted to a real header with a non-private name.

Bug: 17059126
Change-Id: I3ed12b66eb07f3a6a08366d5eee147809d9a3ce9
(cherry picked from commit 4047075da6)
2014-08-19 10:39:46 -07:00
Dan Albert
4047075da6 Update for public android_set_abort_message().
Since android_set_abort_message() is quite helpful to the platform, it's
becoming promoted to a real header with a non-private name.

Bug: 17059126
Change-Id: I3ed12b66eb07f3a6a08366d5eee147809d9a3ce9
2014-08-18 17:29:34 -07:00
Stephen Hines
eb49dd791e Remove invalid 64-bit host objects.
Bug: 16408818

These targets are no longer in use, since we have a proper way to create both
32-bit and 64-bit host libraries in a single build now.

Cherry-pick from AOSP: 03cc1f747c

Change-Id: Icd09f795acd220de5b5e956a8d8e1b4ab4864fa9
2014-07-25 10:39:38 -07:00
Stephen Hines
03cc1f747c Remove invalid 64-bit host objects.
Bug: 16408818

These targets are no longer in use, since we have a proper way to create both
32-bit and 64-bit host libraries in a single build now.

Change-Id: Icd09f795acd220de5b5e956a8d8e1b4ab4864fa9
2014-07-22 13:36:16 -07:00
Nick Kralevich
118d1b3930 logd_write: set SOCK_CLOEXEC on socket
Socket file descriptors remain open across exec unless
SOCK_CLOEXEC is set. Enable this option, to avoid leaking
file descriptors.

See https://android-review.googlesource.com/53736 for a similar
problem with the old logging code.

Change-Id: I9e045d2291ae6680044ab86604f3ff2c55b5eaed
2014-07-02 22:30:39 -07:00
Nick Kralevich
2a4d05a4e3 implement LOG_EVENT_STRING
Implement LOG_EVENT_STRING, so that native code can create new
event log entries. This is needed to support logging SELinux denials
to the event log.

Change-Id: I6a269a832bc2f5e5da6c9dbd169ed2f901b49166
2014-07-01 12:22:04 -07:00
Ian Rogers
59ec765382 Host multilib build of both 32-bit and 64-bit libraries.
Change-Id: I54f91f385b109fc664a1a1f9320affb2a846fef1
2014-06-05 15:26:22 -07:00
Mark Salyzyn
90aa3d59a5 liblog: test: Send bionc's fatal logging to the crash log
Bug: 14159417
Change-Id: Ia2e29ce03d4e2b02919c62be091da37ce4082647
2014-06-03 09:29:11 -07:00
Mark Salyzyn
076ba81ce9 liblog: cache getuid() syscall
BUG: 15315766
Change-Id: I8f889a1c6ede74f2621f1b8ea5fda666c4b9cba2
2014-06-02 12:33:57 -07:00
Ben Cheng
43232920f3 Address additional warnings found by GCC 4.9.
Change-Id: I8aae6c3e1ccc2294f4db455e1b4f3b4c34a00aaf
2014-05-20 10:51:02 -07:00
Mark Salyzyn
a04464adaf liblog: set -Werror
- Deal with some -Wunused issues
- Cleanup UNUSED to __unused transition

Change-Id: Icd33808d4c974625f4fd0a126a90a2b4c90c8314
2014-05-07 16:56:21 -07:00
Ying Wang
9f437d7181 Remove unused LOCAL_LDLIBS.
Change-Id: I42aeb7668183e7a06207ee063f6eee4d37d66c6e
2014-05-07 15:36:05 -07:00
Elliott Hughes
26864bf9cb Switch to the new bionic fatal logging interface.
This is more general and will work for anyone's custom logging
code, as long as they use ANDROID_LOG_FATAL priority.

Change-Id: Iaf7fc0858fce04f3af407882a58ee5a827d50ddd
2014-05-06 20:40:15 -07:00
Mark Salyzyn
5045f57525 liblog: logcat: Move library print test into gTest
Change-Id: Icd33808d4c974625f4fd0a126a90a2b4c90c8315
2014-05-02 14:16:00 -07:00
Mark Salyzyn
d2e3747e70 liblog: test bionic libc_logging.cpp
Change-Id: Ia778c43513a28c85ae54e96926ee9ed56717d527
2014-04-25 10:59:29 -07:00
Mark Salyzyn
8444eb81b3 logd: liblog: ALOG silently drops excessively long messages
Bug: 14280914
Change-Id: Idddd29784625094e54144953c29f64692a88eee9
2014-04-24 15:49:57 -07:00
Elliott Hughes
6798914b6f Merge "Improve liblog's fatal logging." 2014-04-24 20:33:59 +00:00
Elliott Hughes
da6b2e2fd7 Improve liblog's fatal logging.
This makes LOG_ALWAYS_FATAL and LOG_ALWAYS_FATAL_IF as good as regular
assert(3).

Change-Id: I0666684d30cae7baf23c64b33d35c1e43f81acf0
2014-04-24 13:28:24 -07:00
Mark Salyzyn
696817d352 liblog: Statistics truncated to 16384 bytes
- if network read/write broken up, reassemble the pieces.
- Use a 20ms poll to check if a new fragment has been
  sent by the other side.
- fixup logd-unit-tests to take a (simplified) fragment
  from the liblog changes.

Bug: 14164765
Change-Id: I98ff87888c119e1e8349717646d0f733e8971bc8
2014-04-21 17:07:25 -07:00
Mark Salyzyn
99f47a9e7c logd: liblog: logcat: debuggerd: Add LOG_ID_CRASH
Change-Id: Iea453764a1a4fc1661f461f10c641c30150e4d20
2014-04-16 15:38:50 -07:00
Ben Cheng
1bafa52172 Fix signed vs unsigned comparison.
Change-Id: I4011607858f3a82acc04509c9f795f960496ed69
2014-04-11 16:27:30 -07:00
Mark Salyzyn
1c95047939 logd: liblog: logcat: enable prune features for user
- Enable whitelist, blacklist and logsize tuneables for user

Change-Id: Id0c283844c71c5263a8cfbebf2e550f7ac415858
2014-04-02 13:12:04 -07:00
Mark Salyzyn
e644664f1c Merge "liblog: deal with restart of logd" 2014-03-26 23:24:22 +00:00
Mark Salyzyn
8196be3032 liblog: test for LOGGER_ENTRY_MAX_PAYLOAD compliance
- Add max_payload test
- Add dual_reader test
- Switch to EXPECT from ASSERT to increase test coverage

Bug: 13514601
Change-Id: I0e1c273e0ec430c0461e424731dbf166f2a3ce1b
2014-03-26 10:49:46 -07:00
Mark Salyzyn
8245af1ffd liblog: deal with restart of logd
- API change, return -errno on failure for log writing
- ENOTCONN results in a reconnection and a retry of the write

Change-Id: Ib0a90b730edeaa7e3a3c9797e4e1b0c81b6adb0a
2014-03-26 09:20:22 -07:00
Mark Salyzyn
b992d0d7d3 logd: liblog: Thread IDs missing from logcat -v thread
- stuff caller's thread id into the packet.

Bug: 13568206
Change-Id: I02d0cdf9b1d9e839ff8969f591db42dfe6e4cc95
2014-03-21 10:37:44 -07:00
Greg Hackmann
8084a53897 liblog: improve errno handling on read failure
1. socket() failures should skip close(), since sock is not an open fd
2. on other I/O related failures, preserve errno around the close() call
3. set errno to a meaningful value on check_log_success() failure

Change-Id: I0fb9e726ae5fee2f7b84344aa925e5159d57c360
Signed-off-by: Greg Hackmann <ghackmann@google.com>
2014-03-17 13:16:27 -07:00