summaryrefslogtreecommitdiff
path: root/init/service_parser.cpp
Commit message (Collapse)AuthorAgeFilesLines
* init: Add option to listen on sockets before starting service.Adam Langley2022-11-151-3/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Review note: Original change was a p-o-c by agl in https://r.android.com/2094350 which I think is actually production quality. I'm just taking it over so that he doesn't get spammed by any review comments as that's not a good use of his time. Needed for the hardware entropy daemon (see bug). Original commit message: If one needs to create a service that synchronously starts listening on a socket then there are currently no good options. The traditional UNIX solution is to have the service create the socket and then daemonise. In this situation, init could start the service with `exec_start` and yet not block forever because the service forks and exits. However, when the initial child process exits, init kills the daemon process: > init: Killed 1 additional processes from a oneshot process group for > service 'foo'. This is new behavior, previously child processes > would not be killed in this case. Next, there is a `socket` option for services and (although the documentation didn't nail this down), the socket is created synchronously by `start`. However, init doesn't call `listen` on the socket so, until the service starts listening on the socket itself, clients will get ECONNREFUSED. This this change adds a `+listen` option, similar to `+passcred` which allows a socket service to reliably handle connections. Bug: 243933553 Test: Started prng_seeder from init using the new listen flag Change-Id: I91b3b2b1fd38cc3d96e19e92b76c8e95788191d5 Merged-In: I91b3b2b1fd38cc3d96e19e92b76c8e95788191d5 (cherry picked from commit ecc14a595809846cd09760d2c59b1fdfa9660ce8) (cherry picked from commit 56a658874be2e8f5bdda288cb4fc37353c07ca37) Merged-In: I91b3b2b1fd38cc3d96e19e92b76c8e95788191d5
* init: try converting writepid used with cgroups into task_profiles commandSuren Baghdasaryan2022-04-051-1/+39
| | | | | | | | | | | | | | | | writepid usage to add a task to a cgroup was deprecated in favor of the task_profile command. The reason is that writepid hardcodes cgroup path and makes it hard to change it in the future, whereas task profiles configure cgroup paths in one centralized place and are easy to change. Log a warning when writepid is used with cgroups and try converting it into a task_profiles command for well-known cgroups. If conversion is not possible the writepid operation will still be attempted to avoid breaking existing use cases and an error will be logged. Bug: 191283136 Test: build and boot Signed-off-by: Suren Baghdasaryan <surenb@google.com> Change-Id: Ie58393468ef7d92ab0ffb41e6f339e36d21f7478
* init: Skip interface duplicates if service is an overrideAlexander Koskovich2022-03-071-1/+1
| | | | | | | | | | | These aren't actually duplicate interfaces because we are overriding the service so interfaces in the original definition will never be used. Test: Verify 'm dist' works without complaining about duplicate interfaces. Change-Id: Iab5e1d8bb4cb7d5b2608028c3cee73af94c47424
* Returns a service parse error on overrides across the treble boundary.Daniel Norman2020-11-191-0/+8
| | | | | | | | | | | | Also includes new --out_<partition> flags for system,system_ext,product,vendor,odm to allow host_init_verifier to work with a collection of init rc files. Test: host_init_verifier --out_system=... --out_vendor=... where vendor contains an init rc file that overrides a service present in system. Observe parse failure and non-zero exit. Bug: 163089173 Change-Id: I520fef613e0036df8a7d47a98d47405eaa969110
* init/service_parser: Add arguments `window' and `target' for `critical'Woody Lin2020-10-261-1/+34
| | | | | | | | | | | | | | | The critical services can now using the interface `critical [window=<fatal crash window mins>] [target=<fatal reboot target>]` to setup the timing window that when there are more than 4 crashes in it, the init will regard it as a fatal system error and reboot the system. Config `window=${zygote.critical_window.minute:-off}' and `target=zygote-fatal' for all system-server services, so platform that configures ro.boot.zygote_critical_window can escape the system-server crash-loop via init fatal handler. Bug: 146818493 Change-Id: Ib2dc253616be6935ab9ab52184a1b6394665e813
* Reject services that are both critical and oneshotNikita Ioffe2020-05-011-0/+7
| | | | | | | | | | Test: atest CtsInitTestCases Test: builds Test: device boots Bug: 155275196 Merged-In: I1bb9099371bd1a3f339396ef343c49b054fcef66 Change-Id: I1bb9099371bd1a3f339396ef343c49b054fcef66 (cherry picked from commit 6a3c94b3aa9545b6a955caf558e5120ef4c12ee5)
* init: Add task_profiles init commandSuren Baghdasaryan2020-04-301-0/+7
| | | | | | | | | | | | | | Introduce new command to allow setting task profiles from inside .rc script. This is to replace usage of writepid when a service is trying to join a cgroup. Usage example from a .rc file: service surfaceflinger /system/bin/surfaceflinger task_profiles HighPerformance Bug: 155419956 Test: change .rc file and confirm task profile is applied Signed-off-by: Suren Baghdasaryan <surenb@google.com> Change-Id: I0add9c3b363a7cb1ea89778780896cae1c8a303c
* Revert "init: handle property service callbacks asynchronously"Tom Cherry2020-03-101-2/+0
| | | | | | | | | | This is apparently causing problems with reboot. This reverts commit 7205c6293341c82701e849fa29cfab66916d1052. Bug: 150863651 Test: build Change-Id: Ib8a4835cdc8358a54c7acdebc5c95038963a0419
* init: handle property service callbacks asynchronouslyTom Cherry2020-02-201-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | A previous change moved property_service into its own thread, since there was otherwise a deadlock whenever a process called by init would try to set a property. This new thread, however, would send a message via a blocking socket to init for each property that it received, since init may need to take action depending on which property it is. Unfortunately, this means that the deadlock is still possible, the only difference is the socket's buffer must be filled before init deadlocks. There are possible partial solutions here: the socket's buffer may be increased or property_service may only send messages for the properties that init will take action on, however all of these solutions still lead to eventual deadlock. The only complete solution is to handle these messages asynchronously. This change, therefore, adds the following: 1) A lock for instructing init to reboot 2) A lock for waiting on properties 3) A lock for queueing new properties 4) A lock for any actions with ServiceList or any Services, enforced through thread annotations, particularly since this code was not designed with the intention of being multi-threaded. Bug: 146877356 Bug: 148236233 Test: boot Test: kill hwservicemanager without deadlock Change-Id: I84108e54217866205a48c45e8b59355012c32ea8
* Refactor libinit_test_utils to not use libinit and expose its librariesTom Cherry2020-02-201-1/+1
| | | | | | | | | | | | Users of libinit_test_utils must include all libraries that it uses. If it uses libinit, then there is a large number of libraries that must be included. To avoid this, make libinit_test_utils only use init_common_sources and the small number of required libraries that go along with those sources. Additionally, expose these sources as a default for users of libinit_test_utils. Test: build Change-Id: I224fa7e0590d073e4cd40412b5dcb6f72a64b6bf
* Convert system/core to Result::ok()Bernie Innocenti2020-02-061-11/+11
| | | | | | | | No functionality changes, this is a mechanical cleanup. Test: m Test: cd system/core && atest Change-Id: Ifdaa3ce1947ed578f656d5a446978726eb416c36
* Delete dangerous comparison operators from base::expectedBernie Innocenti2020-02-041-1/+1
| | | | | | | | | These operators were included because they're present in the draft standard proposal of std::expected, but they were deemed to lead to bugs, particularly when T is implicitly convertible to bool. Change-Id: Ib149decf1f230198f358dc1ae0eaed71961363f6 Test: m
* Remove service defined in an APEX during userspace rebootNikita Ioffe2019-12-051-1/+1
| | | | | | | | | | | Such services will be re-parsed and added back to the service list during post-fs-data stage. Test: adb reboot userspace Test: atest CtsInitTestCases Bug: 145669993 Bug: 135984674 Change-Id: Ibb393dfe0f101c4ebe37bc763733fd5d981d3691
* init: Add support for native service registration with lmkdSuren Baghdasaryan2019-11-071-2/+5
| | | | | | | | | | | | | | | | | init should be able to register native services with lmkd so that they can be killed when needed. Only processes with oom_score_adjust not equal to the default -1000 will be registered with lmkd because with the score that low the process is unkillable anyway. Inform lmkd when a registered process is killed so that the record can be removed. Change init.rc to start lmkd during init phase so that it is there to register other services. Replace hardcoded oom_score_adj values with appropriate definitions. Bug: 129011369 Test: boot and verify native service registration Change-Id: Ie5ed62203395120d86dc1c8250fae01aa0b3c511 Signed-off-by: Suren Baghdasaryan <surenb@google.com>
* init: hack for /charger symlinkYifan Hong2019-10-311-0/+5
| | | | | | | | | | | | Legacy symlink from /charger to /system/bin/charger is removed. Instead, all Android R devices are required to use /system/bin/charger instead. See hardware/interfaces/health/2.1/README.md for details. Bug: 142286265 Test: charger mode Change-Id: Ib478a864ef68647bc9fc14650ca3d382952b80c8
* init: add stdio_to_kmsg optionTom Cherry2019-09-241-0/+12
| | | | | | | | | Some services are not native android services and therefore don't log via the normal mechanisms. This gives developers an option to have their stdout/stderr logs sent directly to kmsg. Test: see test prints to kernel log Change-Id: I7973ea74d5cab3a90c2cd9a3d5de2266439d0c01
* init: degeneralize subcontext init into only vendor_initTom Cherry2019-09-181-7/+2
| | | | | | | | | | | | | | This code is more generic than it needs to be and one of the side effects is that an extra init process is forked for odm_init, despite it having the same context as vendor_init. I don't think anything is going to change regarding that soon, so this change stops forking that extra process to save its memory and simplifies the code overall. Bug: 141164879 Test: init still uses vendor_init for vendor_scripts Test: init unit tests Test: init only has one subcontext process Change-Id: I0d224455604a681711e32f89fb20132378f69060
* init: add reboot_on_failure service optionTom Cherry2019-09-131-42/+46
| | | | | | | | | | | | | This replaces the recently added `exec_reboot_on_failure` builtin, since it'll be cleaner to extend service definitions than extending `exec`. This is in line with what we decided when adding `exec_start` instead of extending `exec` to add parameters for priority. Test: `exec_start` a service with a reboot_on_failure option and watch the system reboot appropriately when the service is not found and when the service terminates with a non-zero exit code. Change-Id: I332bf9839fa94840d159a810c4a6ba2522189d0b
* Allow AIDL interfaces in service parsingJon Spivack2019-09-091-9/+13
| | | | | | Bug: 138756857 Test: Manual (using mediaextractor as a test service) Change-Id: Ice2c695fca7062d6a115df13a6ac1d6fe82a3a98
* Adds check_interface_{restart,start,stop} check_builtins.Daniel Norman2019-08-061-27/+4
| | | | | | | | | | Includes refactoring out interface inheritance hierarchy logic to a new interface_utils file. Bug: 137397100 Test: 'm' with an init_rc that misspells an interface in an interface_start, interface_restart, or interface_stop line. Change-Id: I9f650289d64ae2b13435a81e1693c7ab5e6e9ecf
* init: don't log in expand_props directlyTom Cherry2019-08-011-6/+8
| | | | | | | | It's better to pass the error message to the caller to determine how best to print the error. Test: build Change-Id: Id8857c459df2f26c031650166609608d20e4d051
* init: simplify keyword_mapTom Cherry2019-07-231-13/+4
| | | | | | | | | | | I've heard that keyword_map is too complex, in particular the tuple and the pair in BuiltinFunctionMap, so this change removes a lot of that complexity and, more importantly, better documents how all of this works. Test: boot, init unit tests Change-Id: I74e5f9de7f2ec524cb6127bb9da2956b5f307f56
* init: clean up file / socket descriptor creationTom Cherry2019-07-151-30/+67
| | | | | | | | | | | | | | | | clang-tidy hinted that some of this code wasn't right. Looking deeper, there is really not much related to file and socket descriptors, except that they're published in similar ways to the environment. All of the abstraction into a 'Descriptor' class takes us further away from specifying what we really mean. This removes that abstraction, adds stricter checks and better errors for parsing init scripts, reports sockets and files that are unable to be acquired before exec, and updates the README.md for the passcred option. Test: build, logd (uses files and sockets) works Change-Id: I59e611e95c85bdbefa779ef69b32b9dd4ee203e2
* Checks the interface inheritance hierarchy in init_rc files.Daniel Norman2019-07-111-6/+34
| | | | | | | Bug: 118016875 Test: Added 'interface' lines to an init_rc file and observed errors when misspelled or missing entire inheritance hierarchy. Change-Id: I681420f15539742d8415808b2a0dcbf0bf6faaf1
* Checks each interface in an init_rc file is a known hidl_interface.Daniel Norman2019-06-281-0/+6
| | | | | | | Test: Adding a misspelling to an init_rc's interface line and observing build failure. Bug: 77646540 Change-Id: I58f66d73f0bd9b4203e8259161843b56ad428d73
* Move actual parsing from Service to ServiceParserTom Cherry2019-06-261-15/+474
| | | | | | | This is how this should have been done since the beginning. Test: build, boot Change-Id: Ifd795776c71a2e666da7fab90cbb3f356af93d4f
* Split out ServiceList and ServiceParser from service.cpp/.hTom Cherry2019-06-261-0/+108
These always should have been in their own files. Test: build Change-Id: I201109b5ee63016e78901bbfd404846d45e1d4e6