Commit graph

24318 commits

Author SHA1 Message Date
Josh Gao
911d729c8a libprocinfo: introduce.
Add a new library for parsing /proc files. Start with helpers for
parsing /proc/<pid>/status and /proc/<pid>/task.

Bug: http://b/30705528
Test: libprocinfo_test32/64 on host/bullhead
Change-Id: I5757514c0aede8a9d75834b55aae42a5cf762b95
2016-11-14 13:42:18 -08:00
Elliott Hughes
f77d8b0452 Merge "Switch ueventd to sendfile(2)." 2016-11-14 21:39:25 +00:00
Elliott Hughes
601bf9e7c9 Merge "init start time tracking." 2016-11-14 21:21:00 +00:00
Christopher Ferris
f96e7446fd Merge "Revert "Use process_vm_readv to read memory."" 2016-11-14 20:14:18 +00:00
Elliott Hughes
632e99a0d4 Switch ueventd to sendfile(2).
Bug: http://b/32826495
Test: booted and checked dmesg
Change-Id: Idfd813dfe6f512fdbc05b1411c7960e950e2f59b
2016-11-14 11:40:06 -08:00
Treehugger Robot
557359863c Merge "fix swapped min / max in priority parsing" 2016-11-13 04:44:43 +00:00
Elliott Hughes
9605a945f7 init start time tracking.
With this change, init sets a property "init.start" to show the
CLOCK_BOOTTIME time at which init itself started, and for each service
an "init.svc.<name>.start" property to show the CLOCK_BOOTTIME time at
which that service was most recently started.

These times can be used by tools like bootstat to track boot time.

As part of this change, move init over to std::chrono. Also, rather than
make the command-line argument handling more complex, I've switched to
using an environment variable for communication between first- and
second-stage init, and added another environment variable to pass the
start time of the first stage through to the second stage.

Bug: http://b/32780225
Test: manual
Change-Id: Ia65a623e1866ea688b9a5433d6507926ce301dfe
2016-11-12 11:17:40 -08:00
Keun-young Park
dd34ca45ea fix swapped min / max in priority parsing
- This error led into not handling highest priority,
  which made zygote's priority boost no-op

bug: 32718256
Test: check init log during bootup

Change-Id: I959eb94912a9c1d95bfdb98ee675fdd12cf85699
2016-11-11 18:32:13 -08:00
Treehugger Robot
84db3f19bc Merge "crasher: add option to wait for input before crashing." 2016-11-12 01:04:41 +00:00
Josh Gao
100ce3910d crasher: add option to wait for input before crashing.
This will be useful for tests that want to do things with crasher's pid
before it crashes.

Bug: http://b/30705528
Test: crasher wait-abort; crasher wait-thread-abort
Change-Id: I8ba826094dc304d6cd0e6ab088e5cfdb35d2007b
2016-11-11 14:29:13 -08:00
Christopher Ferris
fdb02f8b9c Revert "Use process_vm_readv to read memory."
This reverts commit 279843e139.

Bug: 32806783

Change-Id: I61df26d979a8139a571ff5a6442fb5499ca20547
Test: Verified that the stack and read data works with the revert.
2016-11-10 23:19:30 +00:00
Treehugger Robot
e759c83bde Merge "Implement Reboot bootloader via bootloader_message" 2016-11-10 02:43:08 +00:00
Treehugger Robot
5782f72711 Merge "init: warn slow action" 2016-11-10 00:53:04 +00:00
Tianjie Xu
8cbc89527c Merge "Start update_verifier in cache group" 2016-11-09 23:52:52 +00:00
Wei Wang
b1a309ac1f init: warn slow action
Slow action that takes longer than 50ms will be warned to user

Test: grep init log
Bug: 32712851
Change-Id: I3a6a881a8dee1807270343b511a47c76dd230392
2016-11-09 15:19:11 -08:00
Tianjie Xu
c488087aa0 Start update_verifier in cache group
Start update_verifier in cache group to avoid dac_override

Bug: 30020920
Change-Id: I227b4a0e1c07e7b9bf209b432e9db02275ffe660
Test: mma
(cherry picked from commit 1e4635f0a8)
2016-11-09 11:57:26 -08:00
Treehugger Robot
2422d55d2b Merge "liblog: android_closeEventTagMap pointer check" 2016-11-09 19:47:50 +00: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
Treehugger Robot
bccb521c6b Merge "init: errno handling in create_file" 2016-11-09 16:01:48 +00:00
Mark Salyzyn
db69107de6 init: errno handling in create_file
Save errno before resetting global context. Use unique_fd.

Test: gTest init_tests
Bug: 32450474
Change-Id: If45eeaebc3ae379f84bf3ffa3c40194043191854
2016-11-09 08:00:17 -08:00
Vineela Tummalapalli
039734c7de Implement Reboot bootloader via bootloader_message
- Write reboot bootloader message to misc
 - Clarify naming for reboot to recovery

BUG: https://issuetracker.google.com/issues/32474515

Change-Id: I4e42509bfcf572e37c8fc070d6571afe406a48b6
Signed-off-by: Vineela Tummalapalli <vineela.tummalapalli@intel.com>
Signed-off-by: Bruce Beare <bruce.j.beare@intel.com>
Reviewed-on: https://android.intel.com/548494
2016-11-08 16:45:03 -08:00
Treehugger Robot
847670437b Merge "fs_mgr: fix clang static analyzer warning" 2016-11-08 21:36:53 +00:00
Jin Qian
905948ed74 fs_mgr: fix clang static analyzer warning
Pointer from strdup is lost hence triggers mem leak warning from
clang, since ptr returned from basename may not point to start of
duplicated string any more.

Switch to use gnu version of basename which doesn't modify input
string so that strdup is no longer necessary.

Bug: 27126348

Change-Id: Iadb5cf343437a1e27e588ee067b084897633ea07
Merged-In: I937a68c01c223230932c932bffdd35da6503c3c4
2016-11-08 20:07:31 +00:00
Mark Salyzyn
e133feb6b4 Merge changes I93a1c003,I283fec89
* changes:
  liblog: logcat: logprint support -v descriptive
  liblog: add android_lookupEventFormat_len
2016-11-07 22:42:08 +00:00
Dimitry Ivanov
a61c48d5fd Merge "Allow different namespace types for different classloaders" 2016-11-07 18:00:40 +00:00
Paul Lawrence
0ad600bdc6 Merge "Fix selinux warning on tracefs systems" 2016-11-07 15:02:08 +00: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
Dimitry Ivanov
d836ab005a Allow different namespace types for different classloaders
An app should be able to make cross-arch calls to different apps
via other app's Context.getClassLoader()

Bug: 32542970
Test: Boot fugu. Check that there are no linker-namespace
      related errors in the log.

Change-Id: I1593f4688bcde0121a5e24a707441a4935fa7dc4
2016-11-04 15:21:13 -07:00
Treehugger Robot
b5f062bde4 Merge changes Icd2e9bc0,Ibe241c0b
* changes:
  logd: report last prune memory overhead
  logd: report statistics memory overhead
2016-11-04 20:52:49 +00:00
Mark Salyzyn
8d339e940f Merge "libcutils: sockets_test breaks MAC build" 2016-11-04 19:43:48 +00:00
Mark Salyzyn
44ba139bba libcutils: sockets_test breaks MAC build
- Neuter SOCK_NONBLOCK and SOCK_CLOEXEC if they are not defined.
- F_SETFL O_NONBLOCK after socket() call.
- Correct environment reference (we recently changed handler to
  replace non-ascii and non-numericals with '_' for env tag).

Test: libcutils_test32 --gtest_filter=SocketsTest.android_get_control_socket
Bug: 32450474
Change-Id: I409a8c2c78e5f057af5fd6251cbd8657018be22b
2016-11-04 12:27:43 -07:00
Paul Lawrence
d2abcbd0ab Fix selinux warning on tracefs systems
restorecon_recursive doesn't traverse filesystem boundaries. On
tracefs systems, tracing is a separate filesystem, so restorecon
this as well

Bug: 30963384
Test: Boot hikey, and check that there are no debugfs_tracing denials in dmesg
Change-Id: I24abd3ad80d2cfdab4f64fecee799fc0c24ed238
2016-11-04 10:56:06 -07:00
Mark Salyzyn
b0672290e3 logd: report last prune memory overhead
An estimate based on chatty impact for all known pids, uids and tags
and per log id if applicable, calculate the maximum last pruned
watermark iterator map usage and add to the Total Overhead.

Test: Confirm that the Total Overhead change is negligable.
Bug: 31942525
Change-Id: Icd2e9bc0747c3376ca0e9c90aa110c103529d98f
2016-11-04 07:43:16 -07:00
Mark Salyzyn
6d981af120 logd: report statistics memory overhead
Add in to the Total Overhead the amount of storage we are
using to hold on to the statistics.

Test: see that the Total Overhead accounts for about 100K
Bug: 31942525
Change-Id: Ibe241c0bccc5a9df52395802338c8a7fc3b64104
2016-11-04 07:43:16 -07:00
Treehugger Robot
fc3e90689e Merge changes I432016e2,Id208b11b,Ia6a38729,Icdaf9e35,I842a7a64, ...
* changes:
  logd: if eng build, be a bit more permissive about failures
  libcutils: klog inherit android_get_control_file("/dev/kmsg")
  logd: start logd service in logd uid
  logd: auditd + klogd control CAPS
  logd: drop capabilities in logd --reinit and logd.daemon
  logd: drop libminijail dependency
  logd: start logd services in logd gid
  logd: set executable's capabilities in file system
  logd: inherit android_get_control_file()
  init: service file keyword
  libcutils: add android_get_control_file()
  libcutils: add android_get_control_socket() test
2016-11-04 14:38:23 +00:00
Treehugger Robot
fc08963f85 Merge "logd: switch to using arraysize() from libbase macros" 2016-11-03 22:07:42 +00:00
Mark Salyzyn
11f8b20068 Merge changes Ifb1b550c,Ic7377efc
* changes:
  liblog: test report pmsg not configured if ENOMEM return
  logd: clear DUMPABLE
2016-11-03 20:53:09 +00:00
Mark Salyzyn
107e29ac1b logd: if eng build, be a bit more permissive about failures
Allows us some leaway to investigate logd issues on eng builds

Test: gTests logd-unit-tests, liblog-unit-tests and logcat-unit-tests
      Manual on eng builds, bad logd.rc to fake permission issues
Bug: 32450474
Change-Id: I432016e29e5601d67c502076ead941cecdcbebe7
2016-11-03 13:34:27 -07:00
Mark Salyzyn
c377843258 libcutils: klog inherit android_get_control_file("/dev/kmsg")
If the file descriptor is in the environment, use it.

Test: compile
Bug: 32450474
Change-Id: Id208b11b727a44dc861a141130a644d7d8009c5f
2016-11-03 13:34:27 -07:00
Mark Salyzyn
77fdb22cf6 logd: start logd service in logd uid
Test: gTest logd-unit-tests, liblog-unit-tests and logcat-unit-tests
      Manual inspect grep '^Cap' /proc/<tid>/status for correct capabilities
Bug: 32450474
Change-Id: Ia6a3872901969a789d4309d410dbfd5f5d17b3ce
2016-11-03 13:34:27 -07:00
Mark Salyzyn
d2b3291ffa logd: auditd + klogd control CAPS
Test: gTest logd-unit-tests, liblog-unit-tests and logcat-unit-testsa
Bug: 32450474
Change-Id: Icdaf9e352e86c9e140928509201da743004aeedb
2016-11-03 13:34:27 -07:00
Mark Salyzyn
d8f01807b8 logd: drop capabilities in logd --reinit and logd.daemon
Test: gTest logd-unit-tests, liblog-unit-tests and logcat-unit-tests
Bug: 32450474
Change-Id: I842a7a64f0ba695acef66caf54270f9475c9f9ac
2016-11-03 13:34:27 -07:00
Mark Salyzyn
f0b8e1bce6 logd: drop libminijail dependency
Use libcap instead of libminijail.  Set CAP_SETGID before setgroups,
then clear it afterwards.

Test: gTest logd-unit-tests, liblog-unit-tests and logcat-unit-tests
Bug: 32450474
Change-Id: I2ed027fd5efd95f76b1dd4c5791bae5f2ea94c28
2016-11-03 13:34:27 -07:00
Mark Salyzyn
5b44340acb logd: start logd services in logd gid
logd - start as root:logd+system+readproc
logd-reinit - start as logd:logd

ToDo: start as logd:logd+system+readproc (libminijail)
Test: gTest logd-unit-tests, liblog-unit-tests and logcat-unit-tests
Bug: 32450474
Change-Id: I42c806ca1730a7f9eb9e34f064ae31a2ef9fc678
2016-11-03 13:34:27 -07:00
Mark Salyzyn
0d2a1dcb49 logd: set executable's capabilities in file system
Add CAP_SYSLOG, CAP_AUDIT_CONTROL and CAP_SETGID, set
uid and gid to AID_LOGD, and permissions user and group
read and execute only.

Fix up indents for in table for clarity.

Test: gTest logd-unit-tests, liblog-unit-tests and logcat-unit-tests
      Manually inspect owner and group for /system/bin/logd
Bug: 32450474
Change-Id: I5183ab200dbcd13efb0727cb91db5b12018ae804
2016-11-03 13:34:27 -07:00
Mark Salyzyn
e0b8ccd1a3 logd: inherit android_get_control_file()
Setup and then collect from the environment /proc/kmsg and /dev/kmsg
file descriptors. Do not do so for logcat --reinit.

Test: gTest logd-unit-tests, liblog-unit-tests and logcat-unit-tests
Bug: 32450474
Change-Id: Ied537ca561fcd4e71a9ad9c57398a23ba23f6ced
2016-11-03 13:34:27 -07:00
Mark Salyzyn
62767fe29f init: service file keyword
Solve one more issue where privilege is required to open a file and
we do not want to grant such to the service. This is the service side
of the picture, android_get_control_file() in libcutils is the client.
The file's descriptor is placed into the environment as
"ANDROID_FILE_<path>".  For socket and files where non-alpha and
non-numeric characters in the <name/path> are replaced with _.  There
was an accompanying change in android_get_control_socket() to match
in commit 'libcutils: add android_get_control_socket() test'

Add a gTest unit test for this that tests create_file and
android_get_control_file().

Test: gTest init_tests --gtest_filter=util.create_file
Bug: 32450474
Change-Id: I96eb970c707db6d51a9885873329ba1cb1f23140
2016-11-03 13:34:26 -07:00
Mark Salyzyn
0b034d9d7b libcutils: add android_get_control_file()
Solve one more issue where privilege is required to open a file and
we do not want to grant such to the service. This is the client side
of the picture, init is the server. The file's descriptor was placed
into the environment as "ANDROID_FILE_<path>" where non-alpha and
non-numeric characters in the <path> are replaced with _ and this
function picks the file descriptor up.

Added definition ANDROID_FILE_ENV_PREFIX ("ANDROID_FILE_") and
android_get_control_file() prototype in a new include <cutils/files.h>

android_get_control_file() checks if the resulting file descriptor is
valid, open and matches the name reference, which on purpose will fail
if a symbolic link is in the path rather than using a fully qualified
path.  Add gTest unit test for both.

Test: gTest libcutils_test --gtest_filter=FileTest.android_get_control_file
Bug: 32450474
Change-Id: I2d0310a1727f1e393a00d9fc7e6cf5d028f27905
2016-11-03 13:34:20 -07:00
Mark Salyzyn
547e0dc45a libcutils: add android_get_control_socket() test
android_get_control_socket() checks if the resulting file descriptor
is valid, open and matches the socket bound name reference, which on
purpose will fail if a symbolic link is in the path rather than using
a fully qualified path.  If there are any non-alpha and non-numeric
characters in the name, they are replaced with _.  Add unit test.

Test: gTest libcutils_test --gtest_filter=SocketTest.android_get_control_socket
Bug: 32450474
Change-Id: I27a6419012033ef8bd6ca04f3e479d01264d8c49
2016-11-03 13:34:13 -07:00