Commit graph

42 commits

Author SHA1 Message Date
Jiyong Park
80aa44704c Add support for updatable services
A service with 'updatable' option can be overriden by the same service
definition in APEXes.

/system/etc/init/foo.rc:

service foo /system/bin/foo
    updatable

/apex/myapex/etc/init.rc:

service foo /apex/myapex/bin/foo
    override

Overriding a non-updatable (i.e. without updatable option) service
from APEXes is prohibited.

When an updatable service is started before APEXes are all activated,
the execution is delayed until when the APEXes are all activated.

Bug: 117403679
Test: m apex.test; adb push <built_apex> /data/apex; adb reboot
adb shell, then lsof -p $(pidof surfaceflinger) shows that
the process is executing
/apex/com.android.example.apex@1/bin/surfaceflinger instead of
/system/bin/surfaceflinger

Change-Id: I8a57b8e7f6da81b4d2843e261a9a935dd279067c
2018-11-13 08:59:14 +09:00
Jiyong Park
c240440eec init parses *.rc files from APEXes
Init now parses *.rc files from the APEXs when the apexd notifies the
mount event via apexd.status sysprop.

Bug: 117403679
Test: m apex.test; adb root; adb push <builtfile> /data/apex; adb reboot
adb root; adb shell setprop ctl.start apex.test; dmesg shows that init
tries to start the service which doesn't exist.

[   47.979657] init: Could not ctl.start for 'apex.test': Cannot find '/apex/com.android.example.apex/bin/test': No such file or directory

Change-Id: I3f12355346eeb212eca4de85b6b73257283fa054
2018-11-10 04:18:09 +09:00
Peter Collingbourne
d7157c22af Introduce additional service options for controlling memory cgroups.
The memcg.limit_percent option can be used to limit the cgroup's
max RSS to the given value as a percentage of the device's physical
memory. The memcg.limit_property option specifies the name of a
property that can be used to control the cgroup's max RSS. These
new options correspond to the arguments to the limitProcessMemory
function in frameworks/av/media/libmedia/MediaUtils.cpp; this will
allow us to add these options to the rc files for the programs that
call this function and then remove the callers in a later change.

There is also a change in semantics: the memcg.* options now have
an effect on all devices which support memory cgroups, not just
those with ro.config.low_ram or ro.config.per_app_memcg set to true.
This change also brings the semantics in line with the documentation,
so it looks like the previous semantics were unintentional.

Change-Id: I9495826de6e477b952e23866743b5fa600adcacb
Bug: 118642754
2018-10-31 17:09:59 -07:00
Tom Cherry
791668462a init: allow properties to be used for the keycodes option
Bug: 117828597
Test: bugreport launches with a test property set to appropriate keys
Test: bugreport doesn't launch with the test property unset
Test: no errors seen in build or boot in either of the above cases
Change-Id: Iea27032080a0a7863932b1c1b573857ac66b56b5
2018-10-17 11:30:53 -07:00
Tom Cherry
ad9e7eaf2d init: clarify some text/README about 'critical' services
'Critical' services have rebooted into bootloader, like all other
catastrophic init crashes, for years now.  Update the text to match.

Test: n/a
Change-Id: Icfc41bf3e383958f14ecfaab9ca187e2c3dc7fd9
2018-10-15 17:21:48 -07:00
Steven Moreland
48aed8f02d init: clarify multiple 'interface' keyword use
This keyword can (and should) be used multiple times when multiple
services are served together. I've documented this here.

Bug: N/A
Test: N/A
Change-Id: Ie986c9cac486db346555f359e9ccbed93d8d1d22
2018-10-15 18:00:36 +00:00
Tom Cherry
73f535e33b init: allow customizable restart and timeout periods for services
Allow services to specify a custom restart period via the
restart_period service option.  This will allow services to be run
periodically, such as a service that needs to run every hour.

Allow services to specify a timeout period via the timeout_period
service option.  This will allow services to be killed after the
timeout expires if they are still running.  This can be combined with
restart_period for creating period services.

Test: test app restarts every minute
Change-Id: Iad017820f9a602f9826104fb8cafc91bfb4b28d6
2018-10-04 19:52:37 -07:00
Tom Cherry
ab434c70ce init: accept -1 or 'unlimited' for an infinite rlimit
Due to a bug with ParseUint(), init would defacto accept -1 for an
infinite rlimit, but only on 64bit devices.  That bug is now fixed,
such that -1 would be rejected by ParseUint() for all devices.

This change explicitly checks for -1 for all devices or 'unlimited' to
match ulimit's reporting and accepts either as an infinite rlimit.

Bug: 112668205
Test: new (and old) unit tests
Change-Id: Ie28ff622cdf375a65ceb5f32ffb14fb3d5d9f2ba
2018-08-22 15:07:53 -07:00
Tom Cherry
47111aee40 init: document what host init verifier checks
Bug: 36970783
Test: n/a
Change-Id: Ic42a55d7b5bb4fec364ac3b5d9a67bcd38cbcc8d
2018-06-20 10:21:37 -07:00
Tom Cherry
aead51b418 init: allow entering of network namespaces
Add the ability to enter a network namespace when launching a service.
Typical usage of this would be something similar to the below:

on fs
  exec ip netns add namespace_name

service vendor_something /vendor/...
  capabilities <lower than root>
  user not_root
  enter_namespace net /mnt/.../namespace_name

Note changes to the `ip` tool are needed to create the namespace in
the correct directory.

Bug: 73334854
Test: not yet
Change-Id: Ifa91c873d36d69db399bb9c04ff2362518a0b07d
2018-05-18 17:19:36 -07:00
Steven Moreland
8cb36868a4 init: clarify documentation for disabled
Services can be started by name or interface name now.

Bug: N/A
Test: N/A
Change-Id: I9fef619e7c27d458193311f7cd7fca4dcf8c8e72
2018-04-24 16:24:58 -07:00
Tom Cherry
8f38048f7d init: add sigstop option for debugging services from their start
Test: the examples in README.md
Change-Id: Idb528ea4017f8f4ce62911928c040f4bc558d196
2018-04-17 14:52:49 -07:00
Tom Cherry
cb336eef48 init: document previously undocumentary service options
These all should have been documented previously but haven't been.

Test: n/a
Change-Id: I443e733f06584bb09b68b404608c8a611bb2baa0
2018-03-08 14:41:20 -08:00
Tom Cherry
bbbfed6083 init: alphabetize service options in README.md
Test: n/a
Change-Id: If1e89a67a41279cab6acf3e38ff8eb5b77a274c1
2018-03-08 14:40:18 -08:00
Elliott Hughes
7e469ce60c Document property expansion.
Bug: N/A
Test: N/A
Change-Id: I54b9d2d08d98d83060b54981b1c5dc9660b93e8f
2018-02-23 10:40:53 -08:00
Tom Cherry
3631c545b8 init: add exec_background command
This command functions similarly to `exec` except that it does not
cause init to halt executing commands until the process has
terminated.  It is useful for launching simple one time background
tasks.

Bug: 65736247
Test: create an exec_background service and see it function properly
Change-Id: I719c8b85479b65201770aedc0a13191303007c11
2017-09-18 12:19:47 -07:00
Wei Wang
02628f3b23 init: add option to read file fully on readahead
Bug: 62413151
Test: boottime, dumpcache
Change-Id: I1a7b69f0619428e4db31c5a7639c5d895c89ecdb
2017-09-01 15:15:51 -07:00
Tom Cherry
7ac013de7e init: support setting rlimits per service
Add a new service option, `rlimit` that allows a given rlimit to be
set for a specific service instead of globally.

Use the same parsing, now allowing text such as 'cpu' or 'rtprio'
instead of relying on the enum value for the `setrlimit` builtin
command as well.

Bug: 63882119
Bug: 64894637

Test: boot bullhead, run a test app that attempts to set its rtprio to
      95, see that the priority set fails normally but passes when
      `rlimit rtprio 99 99` is used as its service option.
      See that this fails when `rlimit rtprio 50 50` is used as well.
Test: new unit tests

Change-Id: I4a13ca20e8529937d8b4bc11718ffaaf77523a52
2017-08-28 10:19:50 -07:00
Wei Wang
542aae443f init: Add readahead built-in command
Inspired by ag/2659809/, this CL add readahead built-in command in init
to let files be prefetched into pagecache for faster reading.
Readahead happens in background but due to filesystem limitation it
might take small amount of time in it reading the filesystem metadata
needed to locate the requested blocks. So the command is executed in a
forked process to not block init execution.

Bug: 62413151
Test: boottime, dumpcache
Change-Id: I56c86e2ebc20efda4aa509e6efb736bd1d92baa5
2017-08-11 11:24:08 -07:00
Robert Benea
d485226951 Add memcg related configs to init.
Allow configuring memory.swappiness, memory.soft_limit_in_bytes
and memory.limit_in_bytes by init; by doing so there is better
control of memory consumption per native app.

Test: tested on gobo branch.
bug: 63765067
Change-Id: I8906f3ff5ef77f75a0f4cdfbf9d424a579ed52bb
2017-07-18 15:58:40 -07:00
Keun-young Park
cccb34fce8 add "shutdown critical" to service
- "shutdown critical" prevents killing the service during
  shutdown. And the service will be started if not running.
- Without it, services will be killed by SIGTERM / SIGKILL during shutdown.
- Even services with "shutdown critical" will be killed if shutdown
  times out.
- Removes ueventd and vold from hard coded list. Each service's rc will
  be updated to add "shutdown critical". watchdogd is still kept in the list.

bug: 37626581
Test: reboot and check last kmsg

Change-Id: Ie8cc699d1efbc59b9a2561bdd40fec64aed5a4bb
2017-07-05 14:55:22 -07:00
William Roberts
323d5791b4 init: cleanup exec_service documentation
The exec_service documentation was difficult to read, clarify it.

Tests:
Run grip.py to verify that the markdown still works correctly.
Run aspell to verify spelling.

Change-Id: I29bdd456f3d3ea2a91c9d4772bd09a5a195f97a9
Signed-off-by: William Roberts <william.c.roberts@intel.com>
2017-05-04 11:14:23 -07:00
Bowgo Tsai
d262017fef init: moving early mount logic into init_first_stage.cpp
Also renames "early mount" to "first stage mount" to prevent confusion
with "mount_all --early", which is run in the init second stage.

Also creates a base class: FirstStageMount and two derived classes:
FirstStageMountVBootV1 and FirstStageMountVBootV2 to replace/refactor
existing functions:

   - early_mount() -> DoFirstStageMount() and FirstStageMount::DoFirstStageMount()

   - vboot_1_0_early_partitions -> FirstStageMountVBootV1::GetRequiredDevices()
   - vboot_2_0_early_partitions -> FirstStageMountVBootV2::GetRequiredDevices()

   - vboot_1_0_mount_partitions ->
       FirstStageMount::MountPartitions() and
       FirstStageMountVBootV1::SetUpDmVerity()

   - vboot_2_0_mount_partitions ->
       FirstStageMount::MountPartitions() and
       FirstStageMountVBootV2::SetUpDmVerity()

Bug: 37413399
Test: first stage mount /vendor with vboot 2.0 (avb) on bullhead
Test: first stage mount /system with without verity on bullhead
Test: first stage mount /vendor with with vboot 1.0 on sailfish
Change-Id: I6584bdf7d832c9fbc8740f97c9b8b94e68a90783
2017-04-24 23:10:10 +08:00
Tom Cherry
012c573e26 init: Stop combining actions
In the past, I had thought it didn't make sense to have multiple
Action classes with identical triggers within ActionManager::actions_,
and opted to instead combine these into a single action.  In theory,
it should reduce memory overhead as only one copy of the triggers
needs to be stored.

In practice, this ends up not being a good idea.

Most importantly, given a file with the below three sections in this
same order:

on boot
  setprop a b

on boot && property:true=true
  setprop c d

on boot
  setprop e f

Assuming that property 'true' == 'true', when the `boot` event
happens, the order of the setprop commands will actually be:

setprop a b
setprop e f
setprop c d

instead of the more intuitive order of:

setprop a b
setprop c d
setprop e f

This is a mistake and this CL fixes it.  It also documents this order.

Secondly, with a given 'Action' now spanning multiple files, in order
to keep track of which file a command is run from, the 'Command'
itself needs to store this.  Ironically to the original intention,
this increases total ram usage.  This change now only stores the file
name in each 'Action' instead of each 'Command'.  All in all this is a
negligible trade off of ram usage.

Thirdly, this requires a bunch of extra code and assumptions that
don't help anything else.  In particular it forces to keep property triggers
sorted for easy comparison, which I'm using an std::map for currently,
but that is not the best data structure to contain them.

Lastly, I added the filename and line number to the 'processing
action' LOG(INFO) message.

Test: Boot bullhead, observe above changes
Test: Boot sailfish, observe no change in boot time
Change-Id: I3fbcac4ee677351314e33012c758145be82346e9
2017-04-19 11:26:29 -07:00
Tom Cherry
19866bf19f init: add warning that start is not synchronous
Bug: 36571736
Bug: 37481363
Change-Id: I5d360cbb3635f00453a492ee4e3650fb80f390f5
2017-04-19 00:46:44 +00:00
Tom Cherry
98ad32a967 init: handle sys.powerctl immediately
Currently if a process sets the sys.powerctl property, init adds this
property change into the event queue, just like any other property.
The actual logic to shutdown the device is not executed until init
gets to the action associated with the property change.

This is bad for multiple reasons, but explicitly causes deadlock in
the follow scenario:

A service is started with `exec` or `exec_start`
The same service sets sys.powerctl indicating to the system to
shutdown
The same service then waits infinitely

In this case, init doesn't process any further commands until the exec
service completes, including the command to reboot the device.

This change causes init to immediately handle sys.powerctl and reboot
the device regardless of the state of the event queue, wait for exec,
or wait for property conditions.

Bug: 37209359
Bug: 37415192

Test: Init reboots normally
Test: Update verifier can reboot the system
Change-Id: Iff2295aed970840f47e56c4bacc93001b791fa35
2017-04-17 16:40:06 -07:00
Yongqin Liu
dbe88e7953 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

Bug: 36726045
Test: manual with hikey
Test: boot and init tests on bullhead
Test: cast with fugu, per b/36726045
Merged-In: If3c30a2fff58cfece2fcd27e69c30382146e6808

Change-Id: If3c30a2fff58cfece2fcd27e69c30382146e6808
Signed-off-by: Yongqin Liu <yongqin.liu@linaro.org>
2017-04-04 06:21:29 +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
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
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
Treehugger Robot
8678872a00 Merge "init: add class_restart" 2017-03-28 04:22:47 +00:00
Treehugger Robot
88d6b4af16 Merge "init: Fix README.md for writepid" 2017-03-28 01:07:50 +00: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
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
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
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
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
Bin Chen
a08f002c23 init: minor fix to READEME.md
Change-Id: I149c2a8f2053ac4dcc61bea6fa8c57f4c7b73c9e
Signed-off-by: Bin Chen <bin.chen@linaro.org>
2017-02-22 09:38:25 +11:00
Wei Wang
132ac31b47 init: add wait_for_prop builtin command
There are many use cases from vendors to exec service in background and then
use a shell scriprt to wait for the command done.

This CL is to add a wait_for_prop command to suppor those use cases.

Bug: 34746108
Test: on marlin
Change-Id: Ia81290b0928f9d375710d2daa546714f0cd65b72
2017-02-01 16:11:33 -08:00
Elliott Hughes
15f0f504ac Move to .md files for even trivial documentation.
So it's automatically displayed for folks browsing the source.

Bug: N/A
Test: N/A
Change-Id: Ib595ab428054f274a92374728e3e66474ffc5116
2017-01-12 22:40:49 -08:00