Commit graph

1389 commits

Author SHA1 Message Date
Treehugger Robot
fd72bbe91f Merge "Make ueventd error messages indicate where the error is in ueventd script" 2017-04-03 23:50:31 +00:00
Christopher Desjardins
7d3e2c4d4e Make ueventd error messages indicate where the error is in ueventd script
Test: Boot bullhead
Test: Observe errors with file and line number with faulty ueventd.rc

Change-Id: Ieae6151e253f1e6437dfdebd14da4e1e04a45fae
2017-04-03 22:20:55 +00:00
Keun-young Park
7830d59500 add shutdown animation
- Run shutdown animation during shutdown if surfaceflinger is
  available / running.
- services necessary for animation should be added to animation
  class.
- Keep debugging tools while non-critical services are terminated:
  logd, adbd, tombstoned

bug: 36526187
Test: many reboots

Change-Id: I758f700a622c6005f3df9f29de2b55270055ad4d
2017-03-31 16:48:20 -07:00
James Hawkins
bc9cb3885b Merge "bootstat: Refactor init/utils/boot_clock into base/chrono_utils." 2017-03-31 20:47:09 +00:00
Tom Cherry
cf29755e28 Merge "Make init builtin command installkey respect property updates" 2017-03-31 16:41:02 +00:00
Wonsik Kim
3428d0c2c0 Merge "Revert "init: use read_file and write_file to implement do_copy builtin"" 2017-03-31 00:22:00 +00:00
Wonsik Kim
395e29472f Revert "init: use read_file and write_file to implement do_copy builtin"
This reverts commit 82bac0de6d.

Change-Id: Ibfdf453bd85ba4fcd1948b78bd22e639a883653e
2017-03-31 00:18:13 +00:00
James Hawkins
e78ea77f69 bootstat: Refactor init/utils/boot_clock into base/chrono_utils.
Use this for bootstat and init. This replaces the custom uptime parser in
bootstat.

This is a reland of aosp/338325 with a stubbed implementation for Darwin.

This change also has clang_format fixes (automatic).

Bug: 34352037
Test: chrono_utils_test
Change-Id: I72a62a3ca1ccfc0a4ccc6294ff1776c263144686
2017-03-30 14:24:12 -07:00
Treehugger Robot
9ead7c4a74 Merge "send SIGTERM only once" 2017-03-30 04:10:41 +00:00
Janis Danisevskis
9cc51728af Make init builtin command installkey respect property updates
init used to block on installkey such that it was unable to
process property events. This lead to a deadlock by which
the Keymaster HAL would wait indefinitely for the
hwservicemanager.ready=true. 

This fixes the issue by implementing the builtin in terms of 
do_exec, which allows init to stay responsive to properties 
while waiting for the child to terminate.

Bug: 36278706
Test: Add a 3s delay into hwservicemanager before it sets the property
      hwservicemanager.ready and the device still boots.

Change-Id: Iaefd31156ca01f3a44b4f85a8bf78beee8dfe224
2017-03-30 00:11:48 +00:00
Keun-young Park
acd55b39fe send SIGTERM only once
- Processes capturing SIGTERM signal will not terminate and
  killProcessGroup will timeout after retry. This gives 200ms
  of waiting per such process. Change it to retry only once as
  SIGTERM will keep failing for such process.

bug: 36696408
Test: check time spent in SIGTERM for reboot
Change-Id: I9b0843614598dd3f97a50b21352046297ed70b6b
2017-03-29 16:33:25 -07:00
Sandeep Patil
7ef60b4ed4 init: consolidate restorecon after selinux initialization in single function
Test: Boot sailfish
Change-Id: I423028f12a84c4e0c12c9bdde52b6d795d45b620
(cherry picked from commit 74df5bab16)
Signed-off-by: Sandeep Patil <sspatil@google.com>
2017-03-29 16:01:31 -07:00
Keun-young Park
c4ffa5c47d set zero shutdown timeout for eng build
- still it will take time to kill services, < 3 secs in tested device.

bug: 36678028
Test: reboot
Change-Id: I3f3eb83aede8cd950da12e3fcc259eeaf8517c3b
2017-03-29 12:25:33 -07:00
Treehugger Robot
8772b3686e Merge changes from topic 'exec-start-update-verifier'
* changes:
  init.rc: launch update_verifier with exec_start
  init: add exec_start command
2017-03-29 18:39:32 +00:00
Tom Cherry
ccf23537ee init: replace property_get with its android::base equivalent
Slowly try to decouple property_service.cpp from the rest of init.

Test: Boot bullhead
Change-Id: I267ae0b057bca0bf657b97cb8bfbb18199282729
2017-03-29 10:07:54 -07:00
Treehugger Robot
20e43a2f2c Merge "init: remove unused cutils includes" 2017-03-29 01:27:19 +00:00
Tom Cherry
1ec1bd918c init: remove unused cutils includes
Test: Boot bullhead
Change-Id: I629f9c3863f00fa38f87a68442c2380d28764718
2017-03-28 16:22:33 -07:00
Treehugger Robot
8678872a00 Merge "init: add class_restart" 2017-03-28 04:22:47 +00:00
Treehugger Robot
deb23ba2c1 Merge "init: remove superfluous forward definitions" 2017-03-28 02:22:51 +00:00
Treehugger Robot
88d6b4af16 Merge "init: Fix README.md for writepid" 2017-03-28 01:07:50 +00:00
Tom Cherry
46b6c43b7c init: remove superfluous forward definitions
Test: Boot bullhead
Change-Id: I4a005616a825529bc2ad1b413e51b501f6407cbd
2017-03-27 17:55:37 -07:00
Tom Cherry
b27004aa05 init: add exec_start command
Exec services may also want to set other service flags such as
priority.  Instead of expanding the exec syntax to handle this, create
a new command, exec_start, that will treat an existing service
definition as an exec service.  The new exec_start command will start
the service then halt init from executing further commands until the
service has exited.

This change additionally encapsulates the waiting_for_exec logic into
ServiceManager and removes the ambiguous 'bool' return value from
Reap() which previously indicated if a Reaped service was an exec
service or not.

Bug: 36511808
Bug: 36102163
Test: Bullhead boots, services run with exec_start as they do exec.

Change-Id: I44f775cf1c1dd81d5c715f44fdc150c651a2c80a
2017-03-27 17:41:27 -07:00
Treehugger Robot
3c1568aa13 Merge "init: add support of multiple class names" 2017-03-28 00:39:09 +00:00
Keun-young Park
59cebb6e6f Merge "update shutdown sequence and use shutdown_timeout to cover all wait" 2017-03-27 22:27:30 +00:00
Wei Wang
641ff0a4d8 init: add support of multiple class names
Add support of multiple class names in service, so that related services
can be grouped together. By doing this, we can start/stop some services
for special purpose. For example, early zygote, early boot animation
and etc.

Bug: 36535312
Test: marlin boots with defined classes
Change-Id: Ifeaaf034fd836816e24f3775bece53ea83faada6
2017-03-27 20:59:05 +00:00
Steven Moreland
2b63d54af8 init: add class_restart
Bug: 34093663
Test: hwservicemanager `onrestart class_restart hal` works
Change-Id: Ie1e4daab2b7b4c6c714d4e3d05afa2d86d6233df
2017-03-27 13:52:47 -07:00
Keun-young Park
3ee0df9bdf update shutdown sequence and use shutdown_timeout to cover all wait
- Use ro.build.shutdown_timeout to cover the total time for shutdown.
  Limit wait time for termination only to half of shutdown_timeout
  with max of 3 secs as process not terminating by that time
  will not terminate anyway. It is better to move to the next
  stage quickly. fsck time for user shutdown is excluded from timeout.
- Change last detach to kill, sync, and umount. Last detach did not
  work in many tests.
- add sync after emulated partitions umount as it can trigger
  change in /data.

bug: 36551393
Test: many reboots
Change-Id: Ib75dc19af79b8326b02ccef6b16a8817ae7f8b0e
2017-03-27 13:44:50 -07:00
Treehugger Robot
784c851785 Merge "Move selinux policy build decisions to sepolicy Makefile" 2017-03-27 20:03:04 +00:00
Tom Cherry
e564dac2b3 init: Fix README.md for writepid
writepid takes a list of space delimited files.  Make this clear in
the documentation, following the format for repeated fields used in
the rest of the file.

Test: N/A
Change-Id: I5bbe453fcb54f060d3cc5a82e9b38d3091a1ece3
2017-03-27 12:55:33 -07:00
Jeff Vander Stoep
7ef28f4e4f Move selinux policy build decisions to sepolicy Makefile
Test: Test build/boot Marlin with split policy
Test: Test build/boot Bullhead with combined policy
Bug: 36138508
Change-Id: I84654d19c4d8e9fe9086fde742ee80cd043dfbe1
2017-03-26 07:56:29 -07:00
Treehugger Robot
dd26e1a28c Merge "add kill all for shutdown_timeout of 0" 2017-03-24 05:15:20 +00:00
Treehugger Robot
7f0d15a6f2 Merge "init: use read_file and write_file to implement do_copy builtin" 2017-03-24 02:26:14 +00:00
Treehugger Robot
c1ca1a8328 Merge "init: Prevent spin loop while waiting for exec or property" 2017-03-24 01:52:37 +00:00
Treehugger Robot
186edb1aef Merge "init: Remove superfluous error check" 2017-03-24 01:51:31 +00:00
Keun-young Park
aa08ea458a add kill all for shutdown_timeout of 0
- If it is explicitly set to 0, active processes can block
  umount completely. Safe to kill all processes and umount.
- also add additional sync after emulated partition umount
  as that can change /data partition files

bug: 36004738
Test: many reboots

Change-Id: I6c9b07b6fdece44b9caec4e45ecf26a20d0eb96e
2017-03-23 18:01:24 -07:00
Yongqin Liu
82bac0de6d init: use read_file and write_file to implement do_copy builtin
this will make the implementation more cleaner,
and has error message output when failed on some operations

also add the O_TRUNC flag explicitly for the open function
called in write_file.

And add more test on read_file and write_file functions

Test: manual with hikey

Change-Id: Ifc1086a20e85db6980b497b1150a8a7952e672d6
Signed-off-by: Yongqin Liu <yongqin.liu@linaro.org>
2017-03-24 08:34:25 +08:00
Tom Cherry
77ddcd5a3f init: Prevent spin loop while waiting for exec or property
Currently, when we are waiting for an exec service or a property, if
there are either any services to be restarted or any more commands to
be run, we set the epoll_timeout to handle these events.  However, we
don't actually restart and processes or execute any commands while
waiting, so this essentially turns this waiting into a spin loop,
particularly in the common case of having more commands to execute,
where epoll_timeout is set to 0.

The change only sets epoll_timeout if we're not waiting.

Note that the only way to stop waiting for an exec service or a
property is for a signal or property to be delivered to init, which
happens through the epoll fds, so it's safe to indefinitely wait for
epoll to return.

Test: Boot bullhead
Change-Id: Iae3b217eb28182038b464fd39df8e7d27b5e23ff
2017-03-23 17:17:54 -07:00
Keun-young Park
3cd8c6f912 add clear log for reboot start / end
- hard to tell if reboot itself is problem or not.

bug: 36004738
Test: reboot and check last kmsg
Change-Id: I0de0e10eac9ac336cc352ddee22a4a1d9e46cb79
2017-03-23 16:55:24 -07:00
Tom Cherry
9bdddd713a init: Remove superfluous error check
new doesn't return nullptr in C++, so there is no need to check for
it.

Test: Boot bullhead
Change-Id: I666afb1ba7082dd8d5b9911605b7e20a5561b49e
2017-03-23 16:44:42 -07:00
Keun-young Park
8d01f63f50 remove emergency shutdown and improve init's reboot logic
- Emergency shutdown just marks the fs as clean while leaving fs
  in the middle of any state. Do not use it anymore.

- Changed android_reboot to set sys.powerctl property so that
  all shutdown can be done by init.

- Normal reboot sequence changed to
    1. Terminate processes (give time to clean up). And wait for
      completion based on ro.build.shutdown_timeout.
        Default value (when not set) is changed to 3 secs. If it is 0, do not
        terminate processes.
    2. Kill all remaining services except critical services for shutdown.
    3. Shutdown vold using "vdc volume shutdown"
    4. umount all emulated partitions. If it fails, just detach.
       Wait in step 5 can handle it.
    5. Try umounting R/W block devices for up to max timeout.
      If it fails, try DETACH.
      If umount fails to complete before reboot, it can be detected when
      system reboots.
    6. Reboot

- Log shutdown time and umount stat to log so that it can be collected after reboot

- To umount emulated partitions, all pending writes inside kernel should
  be completed.
- To umount /data partition, all emulated partitions on top of /data should
  be umounted and all pending writes should be completed.
- umount retry will only wait up to timeout. If there are too many pending
  writes, reboot will discard them and e2fsck after reboot will fix any file system
  issues.

bug: 36004738
bug: 32246772

Test: many reboots combining reboot from UI and adb reboot. Check last_kmsg and
      fs_stat after reboot.

Change-Id: I6e74d6c68a21e76e08cc0438573d1586fd9aaee2
2017-03-22 11:23:31 -07:00
Treehugger Robot
2fdcf37af1 Merge "Add 'ro.cpuset.default' system property for default cpusets." 2017-03-21 23:46:56 +00:00
Treehugger Robot
ac8a3bd283 Merge "init: reboot to bootloader on crash for development builds" 2017-03-21 22:50:38 +00:00
Tom Cherry
663fdfc1b2 init: reboot to bootloader on crash for development builds
Currently, if init crashes, the kernel panics.  During development, we
would like to catch this crash before the kernel panics and reboot
into bootloader. This will prevent boot looping bad configurations,
particularly desired in test labs where manual intervention would
otherwise be required to reset the devices.

Keep the existing behavior for user builds, as init crashes should be
rare for production builds and rebooting the device is the correct
behavior for end users.

Bug: 34147472
Test: Boot bullhead userdebug, force init to crash, check that the
      device is in bootloader
Test: Boot bullhead user, force init to crash, check that the kernel
      panics and the device reboots as it did previously
Change-Id: Iab3d45ed0d1f82ffaad2a0835d9ca537c0516421
2017-03-21 13:42:17 -07:00
Alex Vakulenko
0828676dff Add 'ro.cpuset.default' system property for default cpusets.
Normally 'writepid' is used to add a process to a particular cpuset. However
certain systems with big/small cores might need to specify a default cpuset for
system processes which do not explicitly specify one. Add an option to use
'ro.cpuset.default' system property to specify default cpuset for system processes
which do not explicitly write to /dev/cpuset/... with 'writepid' option.

The cpuset name specified in ro.cpuset.default is just the cpuset name, e.g.
'/system-background', '/foreground', or simply '/' for the "root" cpuset.

Bug: 28550814
Test: `m -j32` succeeds for aosp_sailfish-eng. Phone boots successfully.
      Also tested manually with debug trace messages on emulator with different
      combinations of values for 'ro.cpuset.default'.
Change-Id: I501727fa5ee3f4bb7a938fa104b81a404b616633
2017-03-21 12:00:31 -07:00
Tom Cherry
40578ab91f init: Fix leaking fd and error print
read_file() does not close its fd if either stat() fails or the file
has group/world writable permissions.

Use unique_fd to ensure that all return paths close the fd and make
the same change to write_file() for consistency.

Replace PLOG() with LOG() after a simple if conditional, that does not
set errno.

Old:
init: skipping insecure file '/data/bootchart/header': No such device or address
New:
init: skipping insecure file '/data/bootchart/header'

Test: Cause an invalid file read and check the error log
Test: Ensure non-error read_file() and write_file() work
Change-Id: Ib15d94e38362e335d671d30b36aa5605254ec7ab
2017-03-20 14:40:02 -07:00
Todd Poynor
16663a2aa4 powerctl: add thermal-shutdown command
Add sys.powerctl property interface for initiating thermal shutdown.

Bug: 30994946
Test: Manual: setprop sys.powerctl thermal-shutdown
Change-Id: Iffce60bd3cb4b40a5859623d10b91bee5101f168
2017-03-17 17:16:40 -07:00
Tom Cherry
34e70410ee init: cleanup is_first_stage conditionals
A recent change to the is_first_stage conditionals created a unneeded
else { } block as both the code in the else { } block and any code
that runs after it are both in the second stage of init.  A first step
to clean this up is to remove this else block.

Secondly, given the above confusion, it makes sense to simplify the two
if (is_first_stage) conditions into one, which only now requires
duplicating one line to initialize logging and the actual "init
first/second stage started!" logs.

Lastly, there are a few commands ran at the beginning of both init
stages that do not need to be,

* boot_clock::time_point start_time = boot_clock::now();
This is only used in the first stage so keep it there

* umask(0);
umasks are preserved across execve() so it only needs to be set in the
first stage

* chmod("/proc/cmdline", 0440);
This needs to be moved until after /proc is mounted in the first
stage, but otherwise only needs to be done once

Test: Boot bullhead, check umask, check cmdline permissions, check
boot time property

Change-Id: Idb7df1d4330960ce282d9609f5c62281ee2638b9
2017-03-17 10:58:17 -07:00
Tom Cherry
f31abeb973 Merge "init: fix DumpState() logging" 2017-03-14 20:12:48 +00:00
Treehugger Robot
0b4d34e31c Merge "ueventd: support by-name symlinks for virtual block devices" 2017-03-14 19:29:35 +00:00
Tom Cherry
e3aef3dd99 Merge "init: enable C++17" 2017-03-14 17:17:40 +00:00