summaryrefslogtreecommitdiff
path: root/init/builtins.cpp
Commit message (Collapse)AuthorAgeFilesLines
* Adds an init host lib for use in host_apex_verifier.Daniel Norman2022-03-211-49/+2
| | | | | | | | | | Includes extracting the APEX-specific SDK version naming scheme filter logic so it can be reused when host_apex_verifier looks at rc files inside the APEX. Bug: 222121216 Test: Use in host_apex_verifier Change-Id: I0396a455f30d2de71525ccd3fa69c75576054048
* OR_RETURN supports status_tJiyong Park2022-01-121-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This change provide a specialization of android::base::OkOrFail for status_t. As a result, a statement whose type is status_t can be used with OR_RETURN. The specialization also provides conversion operators to Result<T, StatusT> where StatusT is a wrapper type for status_t. This allows OR_RETURN macro to be used in newer functions that returns Result<T, StatusT>. Example usage: \#include <utils/ErrorsMacros.h> status_t legacy_inner(); status_t legacy_outer() { OR_RETURN(legacy_inner()); return OK; } Result<T, StatusT> new_outer() { OR_RETURN(legacy_inner()); // the same macro return T{...}; } Bug: 209929099 Test: atest libutils_test Change-Id: I0def0e84ce3f0c4ff6d508c202bd51902dfc9618
* android::base::ResultError/Error are template classesJiyong Park2021-12-141-2/+3
| | | | | | | | | | | They are changed to template classes. s/Error/Error<>/g to reflect that. In addition, the direct uses of ResultError for error reporting is replaced with Error and Errorf. Bug: 209929099 Test: m Change-Id: I815526a8e6fa30e63fa3efcf5700b146bf70a507
* init: Add --only-if-running argument to restart command.David Anderson2021-12-031-3/+16
| | | | | | | | | | If surfaceflinger crashes before zygote starts, it will restart zygote too early. Add this argument will allow it to only restart zygote if it's already running. Bug: 197224273 Test: manual test Change-Id: I0ac8dbeaf0a002f8cfcfcc0f63d4b90d08393c5c
* init: Add a way to class_restart only enabled services.David Anderson2021-11-121-2/+26
| | | | | | | | | | | | | | class_restart accidentally restarts disabled services. Changing this behavior is risky as it could break compatibility. Instead, add an "--only-enabled" argument to class_restart to opt-in to the new functionality. This syntax is backward compatible, as previously only a 1-argument form was accepted. Bug: 190065372 Bug: 198105685 Test: add a class_restart action and a disabled service, make sure service is not restarted. Change-Id: Idb08779de7ac7a21e23f8b8a3276bd5a66a43299
* init: remove the class_{start,reset}_post_data commandsEric Biggers2021-11-111-38/+0
| | | | | | | | | | | | | | Remove the class_start_post_data and class_reset_post_data commands, since they aren't used anymore. They were only used on devices that used FDE (Full Disk Encryption), via actions in rootdir/init.rc. These actions have been removed, since support for FDE has been removed. There is no use case for these commands in vendor init scripts either. Keep the mark_post_data command, since DoUserspaceReboot() uses the post-data service flag even on non-FDE devices. Bug: 191796797 Change-Id: Ibcd97543daa724feb610546b5fc2a0dd7f1e62e7
* init: remove FDE workaround from load_persist_propsEric Biggers2021-11-091-11/+0
| | | | | | | FDE is no longer supported, so this workaround is no longer needed. Bug: 191796797 Change-Id: I059b07035b2158fe84e19544f03aab48de787e62
* init: stop handling FDE-specific fs_mgr return codesEric Biggers2021-11-091-26/+1
| | | | | | | These codes can't be returned anymore, so stop handling them. Bug: 191796797 Change-Id: I9bffd43db7c2f43e5f749e04e84154165dec279e
* Versioning for apex init.rc filesRay Essick2021-10-111-5/+56
| | | | | | | | | | | Support an "init.#rc" versioning scheme for apex init files. chooses highest # <= current system sdk. ".rc" (aka the old init.rc) is treated as sdk 0 Document these semantics in README.md Bug: 198186200 Test: booting, lots of logcat output Change-Id: I2d0405be73dae9bafa6f22535b29ed6b053ddbc4
* Dump the root digest of hashtree for dm-verity partitionsTianjie2021-08-301-3/+5
| | | | | | | | | It's requested by the partner engineering team to uniquely identify a partition. Bug: 197973981 Test: boot the device and check props Change-Id: I0f7aa34dd0087f0698fe90b9df6c0eae06fc4f5d
* Move flattened APEX activation logic to apexd.Shikha Malhotra2021-08-051-13/+1
| | | | | | | | | | | | Also the check that linker configuration should not be updated if APEX is in updatable state, is removed as now with refactoring of code and its movement to apex project, that is also needed. Resolves: https://b.corp.google.com/issues/192838499 Test: Run the AVD Device and check that it boots and run atest ApexTestCases Change-Id: I80a94fa0a4145d30546bb34a6d478a20a2881368
* Check if service is executed before APEX is readyKiyoung Kim2021-03-051-0/+8
| | | | | | | | | | | | | Any service which is executed when Runtime apex is mounted, but linkerconfig is not updated can fail to be executed due to missing information in ld.config.txt. This change updates init to have a status variable which contains if current mount namespace is default and APEX is not ready from ld.config.txt, and use bootstrap namespace if it is not ready. Bug: 181348374 Test: cuttlefish boot succeeded Change-Id: Ia574b1fad2110d4e68586680dacbe6137186546e
* Introduce load_exports action.Artur Satayev2021-02-191-0/+33
| | | | | | | | | | | The action reads a file with individual `export` actions declared on each line, and calls `setenv` for each. See go/updatable-classpath for details on how this is going to be used. Bug: 180105615 Test: manual Change-Id: I5390e52cf8ffd9c3babf31ed854eeecc727351eb
* Set hashtree algorithm for verity partitionsTianjie2021-01-201-0/+5
| | | | | | | | | | | This is used in cts tests to verify that algorithms in blocklist aren't used to build the hashtree. The system properties are required to perform the check on unrooted devices. Bug: 175236047 Test: flash, getprop; atest CtsNativeVerifiedBootTestCases Change-Id: I2dcfdb06f85dbe92cde45e836dd68e7bd835020f
* Use bootstrap linkerconfig from early initKiyoung Kim2020-12-021-1/+1
| | | | | | | | | | Linkerconfig will be moved into Runtime APEX, so /system/bin/linkerconfig would not be available before APEX is mounted. Use bootstrap linkerconfig instead during early init. Bug: 165769179 Test: Cuttlefish boot succeeded Change-Id: Iae41f325bbd5f5194aaf4613141860f913dfbff1
* init: add a copy_per_line built-in commandWei Wang2020-11-201-0/+19
| | | | | | | | | | There are sysfs nodes that don't take multiple inputs, adding a new copy_per_line built-in command to copy from source file to destination line by line. Bug: 171740453 Test: boot and check file and log Change-Id: I41b7a565829299d56b81d4509525dfa6a0a52444
* Only store result of mount_all that mounted userdataNikita Ioffe2020-09-081-3/+11
| | | | | | | | | | | | | During boot sequence there can be multiple calls to mount_all. For the userspace reboot to correctly remount userdata, we need to store the return code of the one that was responsible in mounting userdata. Test: adb root Test: adb shell setprop init.userspace_reboot.is_supported 1 Test: adb reboot userspace Test: checked dmsg Bug: 166353152 Change-Id: Id0ae15f3bcf65fa54e4e72b76f64716c053af7fb
* Merge "Store userspace reboot info in /metadata"Gavin Corkery2020-08-261-0/+4
|\
| * Store userspace reboot info in /metadataGavin Corkery2020-08-211-0/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Store pertinent information about userspace reboot events in the case of failure. This information is any services which failed to stop cleanly, the output of the default fstab and /proc/mounts, and a list of mounts which failed to unmount. This information is only stored as necessary (i.e. mount information will not be stored if everything unmounted, even if some services failed to stop). Added new /metadata/userspacereboot directory to persist this information. Information older than 3 days will be deleted. Test: adb reboot userspace with sigterm/sigkill timeouts set to very low values Test: Manual test of storing all other information Bug: 151820675 Change-Id: I6cfbfae92a7fc6f6c984475cad2c50c559924866
* | Set ro.crypto.type even on failurePaul Crowley2020-08-141-4/+0
| | | | | | | | | | | | | | | | | | | | Move responsibility for setting ro.crypto.type into fs_mgr_mount_all, so that even if setting up the filesystem fails, the type is set correctly and so errors are appropriately handled. Bug: 162289984 Test: simulate a failure and check that it's set. Change-Id: Ib061a454e7e21d7206c3c1fa8e88e16618099581
* | init: start ueventd in the default mount namespaceJooyung Han2020-06-111-4/+21
|/ | | | | | | | | | | Init starts ueventd in the default mount namespace to support loading firmware from APEXes. Bug: 155023652 Test: devices boots adb$ nsenter -t (pid of ueventd) -m ls /apex => shows all APEXes Change-Id: Ibb8b33a07eb014752275e3bca4541b8b694dc64b
* Respect ro.boot.fstab_suffix in swapon_allAlistair Delva2020-06-081-3/+13
| | | | | | | | | While mount_all and umount_all were updated to use ro.boot.fstab_suffix, I neglected to update swapon_all. Trivially copied from umount_all. Bug: 142424832 Change-Id: Icd706fe7a1fe16c687cd2811b0a3158d7d2e224e Merged-In: Icd706fe7a1fe16c687cd2811b0a3158d7d2e224e
* Add ro.boot.fstab_suffix and modify mount_all to use itAlistair Delva2020-05-211-36/+41
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Currently the ReadDefaultFstab function, which calls GetFstabPath, makes some assumptions about what the fstab will be called and where it is located. This is being used by vold to set up userdata encryption and for gsid, and is even used in the default boot control HAL, so it has become quite baked. The original way for a board to specify things to mount was to use the "mount_all /path/to/fstab" command in init.rc. However, due to the above functionality, the path after mount_all is no longer very useful, as it cannot differ from the inferred path, or userdata encryption and other features will be broken. On Cuttlefish, we have an interest in being able to test alternative userdata configurations (ext4 vs f2fs, encryption on/off, etc.) and currently the only way to achieve this is to either a) modify the ro.hardware or ro.hardware.platform properties, which breaks a bunch of things like default HAL filenames, or regenerate our odm.img or vendor.img filesystems. We can't simply install another fstab and point to it with "mount_all". This change allows the fstab path to be omitted from "mount_all", and adds another property which overrides the existing checks for fstab.${ro.hardware} and fstab.${ro.hardware.platform}. Specifying ${ro.boot.fstab_suffix} will cause fstab.${ro.boot.fstab_suffix} to be checked first. Bug: 142424832 Test: booted cuttlefish with 'mount_all ${ro.hardware} --late' Test: booted cuttlefish with 'mount_all --late' Test: booted cuttlefish with 'mount_all --late' and fstab_suffix=f2fs Test: partially booted cuttlefish with 'mount_all ${ro.hardware}' Test: partially booted cuttlefish with 'mount_all' Change-Id: I3e10f66aecfcd48bdb9ebf1d304b7aae745cbd3c
* init: support wait timeout with more precisionMark Salyzyn2020-05-151-3/+5
| | | | | | | | | | | A one second timeout is so coarse and can affect boot time when the possibility that the file does not exist. Switch to accepting a floating point number for seconds for the wait for file command. Signed-off-by: Mark Salyzyn <salyzyn@google.com> Bug: 151950334 Test: wait_for_file sleep 0.05 reports an appropriate delay Change-Id: I8d8ed386519ab54270b05ce91663d0add30f12e7
* Revert "init: handle property service callbacks asynchronously"Tom Cherry2020-03-101-15/+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/+15
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* Merge "Don't log userspace_reboot.started/finished properties from init"Nikita Ioffe2020-02-101-12/+0
|\
| * Don't log userspace_reboot.started/finished properties from initNikita Ioffe2020-02-071-12/+0
| | | | | | | | | | | | | | | | | | Instead they will be logged from system_server. This CL just prepares grounds for logging CL to land. Test: adb reboot userspace Bug: 148767783 Change-Id: Ie9482ef735344ecfb0de8a37785d314a3c0417ff
* | Convert system/core to Result::ok()Bernie Innocenti2020-02-061-30/+30
|/ | | | | | | | No functionality changes, this is a mechanical cleanup. Test: m Test: cd system/core && atest Change-Id: Ifdaa3ce1947ed578f656d5a446978726eb416c36
* Whitelist reboot reasons related to userspace reboot failureNikita Ioffe2020-01-231-1/+2
| | | | | | Test: system/core/bootstat/boot_reason_test.sh Bug: 135984674 Change-Id: I31422329f1109273909293a83913ae801eb1fe52
* Give x permission on apex data directories.Oli Lan2020-01-171-1/+1
| | | | | | | | | | | This gives search (x) permission on the parent apex data directory /data/misc/apexdata so that directories below it may be opened. It also gives that permission on the apex data directories themselves. Bug: 147848983 Test: Build & flash, check perms are correct Change-Id: I27c4ea01602002c89d0771a144265e3879d9041a
* Don't reboot into recovery during userspace rebootNikita Ioffe2020-01-151-8/+17
| | | | | | | | | | In case one of the cryptfs calls to vdc fails, first try a normal reboot. Test: manual Bug: 135984674 Bug: 143970043 Change-Id: I5706d9cd6c3a08fa06329ffb7d141de632620e3d
* Change ownership of apex data directories to root.Oli Lan2020-01-031-3/+2
| | | | | | | | | | | | The apex data directories must be accessed by apexd in order for it to perform snapshot and restore as part of the rollback process. As apexd runs as root, this CL changes the apex data directories under /data/misc to be owned by root. Bug: 141148175 Test: Build and flash; check permissions are set correctly. Change-Id: Ib534e705802c06900884a15f39fee257d4987f4c
* Update linkerconfig to target out directoryKiyoung Kim2019-12-301-6/+1
| | | | | | | | | | | Current linkerconfig targets for specific output file. However, linkerconfig will generate more than 1 file based on APEX modules, so it should take argument for target directory rather than target file. This change updates linkerconfig's argument to point output directory. Bug: 146993126 Test: m -j passed & Cuttlefish succeeded to boot Change-Id: I3a720a047077688582436aabd307adafeafc5398
* Generate linkerconfig per mount namespacesKiyoung Kim2019-12-201-0/+44
| | | | | | | | | | | | | | There are two namespaces from init - bootstrap and default - and those will have different set of APEX modules. To support difference between two namespaces, linker config should be generated per namespace and each namespace should use its own linker configuration. As a first step of the work, this change will create different mount point for each namespace, and re-generate linker config after APEX mount from each namespaces. Bug: 144664390 Test: m -j passed & tested from cuttlefish Change-Id: Iac2e222376ec4b0ced6c29eed18b21d39ff0b1ba
* Create DE_sys APEX data directories.Oli Lan2019-12-091-25/+68
| | | | | | | | | | | | | | | | | This creates the directory /data/misc/apexdata, at the same time as other directories under /data/misc. Then, when apexd has finished activating APEXes, a directory is created under /data/misc/apexdata for every APEX, with the same name as the APEX module name. See go/apex-data-directories. APEXes are discovered by scanning the /apex directory. It may be better to delegate this process to a library, but it is proposed to defer that change to a future CL. Bug: 141148175 Test: Built and flashed, checked directories were created. Change-Id: I639d6f490ae0b97f116ce38ff3ac348bd73aa20e
* Merge "Remove service defined in an APEX during userspace reboot"Nikita Ioffe2019-12-061-1/+1
|\
| * 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: Replace property_set() with android::base::SetProperty()Tom Cherry2019-12-041-15/+16
|/ | | | | | | | | | | | | | Init is no longer a special case and talks to property service just like every other client, therefore move it away from property_set() and to android::base::SetProperty(). In doing so, this change moves the initial property set up from the kernel command line and property files directly into PropertyInit(). This makes the responsibilities between init and property services more clear. Test: boot, unit test cases Change-Id: I36b8c83e845d887f1b203355c2391ec123c3d05f
* FscryptInstallKeyring: don't re-create keyring if it's already createdNikita Ioffe2019-12-041-3/+3
| | | | | | | | | | | | During userspace reboot FscryptInstallKeyring will be called again, this CL will make it second call a no-op, which IMHO is better than having a special logic in init to conditionally call FscryptInstallKeyring depending on whenever it's normal boot, or userspace reboot. Test: adb reboot userspace Test: checked in kernel logs that new keyring is not created Bug: 135984674 Change-Id: I4ad5aee6887b7318fb1cd02bf1c7be8da6ece599
* Make userspace_reboot.in_progress sysprop-as-apiNikita Ioffe2019-11-151-1/+4
| | | | | | | | | | | | | | sys.init.userspace_reboot.in_progress will be used to notify all the processes (including vendor ones) that userspace reboot is happening, hence it should be treated as stable public api. All other sys.init.userspace_reboot.* props will be internal to /system partition and don't require any stability guarantees. Test: builds Test: adb reboot userspace Bug: 135984674 Change-Id: Ifb64a6bfae2de76bac67edea68df44e33c9cfe2d
* Add sysprops for start & end of userspace rebootNikita Ioffe2019-11-141-0/+11
| | | | | | | | | | | | | | | There will be useful in debugging/logging events to statsd. Also as part of this CL, sys.init.userspace_reboot.in_progress property is now used as a mean of synchronization. It is set directly in DoUserspaceReboot, to make sure that all the setprop actions triggered by userspace-reboot-requested were processed. Test: adb reboot userspace Test: adb shell getprop sys.init.userspace_reboot.last_started Test: adb shell getprop sys.init.userspace_reboot.last_finished Bug: 135984674 Change-Id: I9debcd4f058e790855200d5295344dafb30e496a
* init: make triggering shutdown from vendor_init betterTom Cherry2019-11-131-11/+4
| | | | | | | | | | | | Previously, we assumed that TriggerShutdown() should never be called from vendor_init and used property service as a back up in case it ever did. We have since then found out that vendor_init may indeed call TriggerShutdown() and we want to make it just as strict as it is in init, wherein it will immediately start the shutdown sequence without executing any further commands. Test: init unit tests, trigger shuttdown from init and vendor_init Change-Id: I1f44dae801a28269eb8127879a8b7d6adff6f353
* userspace reboot: don't re-install keyring when remounting userdataNikita Ioffe2019-11-081-6/+20
| | | | | | | | | | | | | | | | | From the implementation of FscryptInstallKeyring it looks like it will install a new keyring on each call. Another approach would be change FscryptInstallKeyring to first call request_key[0] (http://man7.org/linux/man-pages/man2/request_key.2.html), and don't add keyring in case request_key succeeded, but it looks like that libkeyutils doesn't provide such functionality. Since I was there, I've also added checks that we are not trying to remount userdata on FDE devices. Test: adb reboot userspace Bug: 135984674 Change-Id: I2e063d7d87a3c2c26810e913a33e3a5c0364332b
* Make encryption action an argument to mkdirPaul Crowley2019-11-051-49/+34
| | | | | | | | | | | FscryptSetDirectoryPolicy no longer tries to infer the action from the filename. Well mostly; it still assumes top-level directories in /data should be encrypted unless the mkdir arguments say otherwise, but it warns. Bug: 26641735 Test: boot, check log messages Change-Id: Id6d2cea7fb856f17323897d85cf6190c981b443c
* Userspace reboot: Support remounting userdata for f2fsNikita Ioffe2019-10-251-0/+26
| | | | | | | | Test: adb reboot userspace Test: adb shell /system/bin/vdc startCheckpoint 1; adb reboot userspace Bug: 135984674 Change-Id: I227f2c1cc18495d893decb2df5173fc7a7919df6
* init: trigger shutdown directly from builtinsTom Cherry2019-10-111-1/+8
| | | | | | | | | | | | | | | | Especially now that property_service is a thread, there may be some delay between when init sets sys.powerctl and when the main thread of init receives this and triggers shutdown. It's possible that outstanding init commands are run during this gap and that is not desirable. Instead, have builtins call TriggerShutdown() directly, so we can be sure that the next action that init runs will be to shutdown the device. Test: reboot works Test: reboot into recovery due to bad /data works Change-Id: I26fb9f4f57f46c7451b8b58187138cfedd6fd9eb
* init: add reboot_on_failure service optionTom Cherry2019-09-131-15/+0
| | | | | | | | | | | | | 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
* Reland^2: "init: run property service in a thread"Tom Cherry2019-09-051-1/+24
| | | | | | | | | | | | | | | | | | | | | | | | | It's been a long standing issue that init cannot respond to property set messages when it is running a builtin command. This is particularly problematic when the commands involve IPC to vold or other daemons, as it prevents them from being able to set properties. This change has init run property service in a thread, which eliminates the above issue. This change may also serve as a starting block to running property service in an entirely different process to better isolate init from handling property requests. Reland: during reboot, init stops processing property_changed messages from property service, since it will not act on these anyway. This had an unexpected effect of causing future property_set calls to block indefinitely, since the buffer between init and property_service was filling up and the send() call from property_service would then block. This change has init tell property_service to stop sending it property_changed messages once reboot begins. Test: CF boots, walleye boots, properties are set appropriately Change-Id: I26902708e8be788caa6dbcf4b6d2968d90962785
* init: add exec_reboot_on_failure builtinTom Cherry2019-09-041-23/+46
| | | | | | | | | | | Add exec_reboot_on_failure builtin and refactor the VDC commands that had similar functionality. These will now also reboot in the case that the program cannot be found or run for any reason. Test: boots normally, reboots if command is not found or if command returns status '1' Change-Id: I1c99498c2b741512a50188e1a325c25e9ec8fba0