summaryrefslogtreecommitdiff
path: root/init/builtins.cpp
AgeCommit message (Collapse)Author
2017-05-09init: remove restorecon() from util.cppTom Cherry
restorecon() has become nothing more than a small wrapper around selinux_android_restore(). This itself isn't super problematic, but it is an obstacle for compiling util.cpp on the host as that function is not available on the host. Bug: 36970783 Test: Boot bullhead Merged-In: I7e209ece6898f9a0d5eb9e5d5d8155c2f1ba9faf Change-Id: I7e209ece6898f9a0d5eb9e5d5d8155c2f1ba9faf
2017-05-09Merge "init: remove restorecon() from util.cpp" into oc-dev-plus-aospTom Cherry
am: 2813d87484 Change-Id: Ib6619f696fb08b99410b3a33221fe8eacebf89d6
2017-05-08init: remove restorecon() from util.cppTom Cherry
restorecon() has become nothing more than a small wrapper around selinux_android_restore(). This itself isn't super problematic, but it is an obstacle for compiling util.cpp on the host as that function is not available on the host. Bug: 36970783 Test: Boot bullhead Change-Id: I7e209ece6898f9a0d5eb9e5d5d8155c2f1ba9faf
2017-05-08Merge changes I46690d1c,I84c11aa5 am: 0dda322d4a am: 18b23afa4b am: 3f9ba91d8fTom Cherry
am: 756ee8ded9 Change-Id: Ib005ef875bfc8116c320007acc10e7cf9accdc10
2017-05-05init: do not log directly from read_file() and write_file()Tom Cherry
Their callers may be able to add more context, so use an error string to record the error. Bug: 38038887 Test: boot bullhead Test: Init unit tests Change-Id: I46690d1c66e00a4b15cadc6fd0d6b50e990388c3
2017-05-05init: Check DecodeUid() result and use error stringTom Cherry
Check the result of DecodeUid() and return failure when uids/gids are unable to be decoded. Also, use an error string instead of logging directly such that more context can be added when decoding fails. Bug: 38038887 Test: Boot bullhead Test: Init unit tests Change-Id: I84c11aa5a8041bf5d2f754ee9af748344b789b37
2017-05-03Merge "init: use do_exec() for init_user0" am: 5ad06cbb1c am: 577c75e78c am: ↵Tom Cherry
bc8a4ad7aa am: 10cdd5bbf1 Change-Id: I3fa46dc57426738550beffb71932e06a0407c68c
2017-05-03init: use do_exec() for init_user0Tom Cherry
Similar to what installkey used to do, init_user0 forks and synchronously waits for vdc to return. This is dangerous to do in init however as init also processes properties from a single thread. I'm not aware of any specific issues that this is currently causing, but it's a good preventative measure to match what installkey does and use do_exec(). Test: Boot bullhead, see that init_user0 still happens Change-Id: I853c61594fe3d97e91bbb2319ebddf2bbe80d457
2017-05-03Merge "ueventd: do not reference init's sehandle" am: 672dd970f4 am: ↵Tom Cherry
e4988c9a34 am: 4c664d8c5c am: 214e45a5a7 Change-Id: I9e73d1849df48dffd886f47c2b358f36309918c0
2017-05-01ueventd: do not reference init's sehandleTom Cherry
Init exposes a global 'sehandle' that ueventd references as part of devices.cpp and util.cpp. This is particularly dangerous in device_init() in which both uevent and init write to this global. This change creates a separate local copy for devices.cpp and puts restrictions on where init.h can be included to make sure the global used by init is not reference by non-init code. Future changes to init should remove this global. Test: Boot bullhead Change-Id: Ifefa9e1932e9d647d06cca2618f5c8e5a7a85460
2017-04-24Merge changes Ic446c026,I86568a5b am: 51b7cb006f am: 41dbec9791 am: fea35fc7e4Tom Cherry
am: d0ea8a98cd Change-Id: I4f8fe713f768748e521ad4d6c18edf0e4b382591
2017-04-21init: create init_tests.cppTom Cherry
Start a init_tests.cpp file for end-to-end tests that parse small init script segments and verify that they act as expected. The first tests ensure that the execution order of event triggers happens appropriately. Test: Boot bullhead, run unit tests Change-Id: Ic446c02605ab796fd41e0596ce1fd381aee80ce0
2017-04-21init: clean up the SectionParser interface and Parser classTom Cherry
Remove the dependency on Action and Service from what should be a generic Parser class. Make ActionParser, ImportParser, and ServiceParser take a pointer to their associated classes instead of accessing them through a singleton. Misc fixes to SectionParser Interface: 1) Make SectionParser::ParseLineSection() non-const as it always should have been. 2) Use Rvalue references where appropriate 3) Remove extra std::string& filename in SectionParser::EndFile() 4) Only have SectionParser::ParseSection() as pure virtual Document SectionParser. Make ImportParser report the filename and line number of failed imports. Make ServiceParser report the filename and line number of duplicated services. Test: Boot bullhead Change-Id: I86568a5b375fb4f27f4cb235ed1e37635f01d630
2017-04-21Support metadata encryptionPaul Lawrence
Bug: 29189559 Test: Angler, Marlin build and boot Change-Id: Ia7b070781f5f16ff8bfd934569a2209c80c28385
2017-04-17init: handle sys.powerctl immediatelyTom Cherry
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-14fs_mgr: support AVB in fs_mgr_update_verity_state()Bowgo Tsai
fs_mgr_update_verity_state() is invoked by 'verity_update_state' in init.rc. It will then set property "partition.system.verified" and "partition.vendor.verified" to verify_mode. We should support this for AVB as well. Also change the order of static libs in init to fix the build error after this change: system/extras/ext4_utils/ext4_crypt.cpp:69: error: undefined reference to 'property_get' Bug: 35416769 Test: Mount /system and /vendor with vboot 2.0 (AVB), check the following properties exist. - [partition.system.verified]: [2] - [partition.vendor.verified]: [2] Test: Mount /system and /vendor with vboot 1.0, check the following properties exist. - [partition.system.verified]: [0] - [partition.vendor.verified]: [0] Change-Id: I4328d66a8cb93f26e7960e620a0b2292d5f15900
2017-04-12Passing additional parameter to powerctlDmitri Plotnikov
Test: adb reboot recovery,foo and verify that the parameter reaches bootloader Change-Id: I9690cf96cf9730e5324b9f5310c3d0341fe25fe2
2017-04-07init: clean up more headersTom Cherry
We don't need everyone including <sys/system_properties.h> Test: boot bullhead Change-Id: I73d507e4f273678eaf15947725741e1e3b966cc6
2017-04-06init: more header cleanupTom Cherry
Remove includes of "log.h" that really want <android-base/logging.h> Fix header include order Remove headers included in .cpp files that their associated .h already includes Remove some unused headers Test: boot bullhead Change-Id: I2b415adfe86a5c8bbe4fb1ebc53c7b0ee2253824
2017-04-04init: use read_file and write_file to implement do_copy builtinYongqin Liu
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-03init: Use std::string for write_file()Tom Cherry
The content parameter of write_file() previously took a char* that was then converted to a std::string in WriteStringToFd(). One unfortunate effect of this, is that it is impossible to write data that contains '\0' within it, as the new string will only contain characters up until the '\0'. This changes write_file() to take an std::string, such that std::string::size() is used to determine the length of the string, allowing it to contain null characters. Also change the path parameter of read_file() and write_file() for consistency. Lastly, add a test for handling strings with '\0' in them. Bug: 36726045 Test: Boot bullhead, run unit tests Change-Id: Idad60e4228ee2de741ab3ab6a4917065b5e63cd8
2017-03-31Merge "Make init builtin command installkey respect property updates"Tom Cherry
2017-03-31Merge "Revert "init: use read_file and write_file to implement do_copy builtin""Wonsik Kim
2017-03-31Revert "init: use read_file and write_file to implement do_copy builtin"Wonsik Kim
This reverts commit 82bac0de6d95bcdf45729516f6a4f29eb2681118. Change-Id: Ibfdf453bd85ba4fcd1948b78bd22e639a883653e
2017-03-30Make init builtin command installkey respect property updatesJanis Danisevskis
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-29Merge changes from topic 'exec-start-update-verifier'Treehugger Robot
* changes: init.rc: launch update_verifier with exec_start init: add exec_start command
2017-03-29init: replace property_get with its android::base equivalentTom Cherry
Slowly try to decouple property_service.cpp from the rest of init. Test: Boot bullhead Change-Id: I267ae0b057bca0bf657b97cb8bfbb18199282729
2017-03-29Merge "init: remove unused cutils includes"Treehugger Robot
2017-03-28init: remove unused cutils includesTom Cherry
Test: Boot bullhead Change-Id: I629f9c3863f00fa38f87a68442c2380d28764718
2017-03-27init: add exec_start commandTom Cherry
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-27init: add class_restartSteven Moreland
Bug: 34093663 Test: hwservicemanager `onrestart class_restart hal` works Change-Id: Ie1e4daab2b7b4c6c714d4e3d05afa2d86d6233df
2017-03-24Merge "init: use read_file and write_file to implement do_copy builtin"Treehugger Robot
2017-03-24init: use read_file and write_file to implement do_copy builtinYongqin Liu
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-22remove emergency shutdown and improve init's reboot logicKeun-young Park
- 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-17powerctl: add thermal-shutdown commandTodd Poynor
Add sys.powerctl property interface for initiating thermal shutdown. Bug: 30994946 Test: Manual: setprop sys.powerctl thermal-shutdown Change-Id: Iffce60bd3cb4b40a5859623d10b91bee5101f168
2017-03-13init: fix DumpState() loggingTom Cherry
Fix two formatting issues in Action::DumpState(), Old: on ro.crypto.state=encrypted ro.crypto.type=file zygote-start New: on ro.crypto.state=encrypted && ro.crypto.type=file && zygote-start Old: on boot %sifup lo %shostname localhost %sdomainname localdomain %swrite /proc/sys/vm/overcommit_memory 1 New: on boot ifup lo hostname localhost domainname localdomain write /proc/sys/vm/overcommit_memory 1 Also, now that we're importing many small rc files, it no longer makes sense to call Parser::DumpState() after each import. Therefore, move the conditional to call Parser::DumpState() to after /init.rc and its imports are parsed and after the late imports are parsed. Test: Boot bullhead with DumpState() enabled and check the output Change-Id: I0b81305b8938aa1a7133d7dd2055f34f47609cf9
2017-03-03add ro.boottime.init.mount_all.* for measuring mount timeKeun-young Park
- three properties: .early, .default, .late - for tracking critical early boot times bug: 35949600 Test: manual, getprop after boot Change-Id: I851891518428e6e21cb43a2a6f982ab7db281d4c
2017-02-25Treblize init.rc locationJaekyun Seok
Treblization requires to locate partner-specific modules in its own partition. So their own init.rc file could be located in /odm or /vendor. This CL is to support those locations for the init.rc. Additionally thic CL modified import parser to support importing a relative path. Test: building succeeded and tested on sailfish with enabling early mount. Bug: 35269867 Change-Id: I1bce924a32c8a2b53fb5d981d35d758cf9ddd9a6
2017-02-03init: clean up exec commandWei Wang
Add wait time log for exec service execution time Fix memory leak when exec service failed to start Test: on marlin Bug: 34518530 Change-Id: I01736bd9b1429414f3dc91dd5d02d88a681f0985
2017-02-01init: add wait_for_prop builtin commandWei Wang
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
2016-12-28init: Make 'write_file' return bool to match 'read_file'.Jorge Lucangeli Obes
The mismatch of return values makes reasoning about the correctness of CLs like https://android-review.googlesource.com/317923 quite hard. Bug: 33941660 Test: Init builds, HiKey boots. Change-Id: Ia4b8a9af420682997b154a594892740181980921
2016-12-21Ask the user before wiping if crypto policy fails.Paul Crowley
If crypto policy fails, instruct recovery to prompt the user before wiping all data. Test: adb shell rmdir /data/ota && adb shell mkdir -p /data/ota/forcefail && adb reboot Bug: 28693324 Change-Id: I4d09b35a20c513a76c9ba56fe826114449a9ad68
2016-12-16Merge "Improve init bootcharting."Elliott Hughes
2016-12-14init: Specify the data wipe reason.Tao Bao
We should say that if the data wipe is triggered by fs_mgr_mount_all. Test: mmma system/core/init Change-Id: I3998d9493611ecc286de0913a95cf22fc41100b5
2016-12-08Improve init bootcharting.Elliott Hughes
Most notably, there's no longer any need to guess an end time. Bug: http://b/23478578 Bug: http://b/33450491 Test: rebooted with bootcharting on/off Change-Id: Icb7d6859581da5526d77dfc5aa4d57c9bfbfd7e2
2016-12-05Merge "Replace the "coldboot" timeout with a property."Elliott Hughes
am: e218fc673f Change-Id: Ibaf1f7ad3a90e5216db04506288df51258e19f4b
2016-12-03Replace the "coldboot" timeout with a property.Elliott Hughes
Also rename init's existing boot-time related properties so they're all "ro.*" properties. Example result: # Three properties showing when init started... [ro.boottime.init]: [5294587604] # ...how long it waited for ueventd... [ro.boottime.init.cold_boot_wait]: [646956470] # ...and how long SELinux initialization took... [ro.boottime.init.selinux]: [45742921] # Plus one property for each service, showing when it first started. [ro.boottime.InputEventFind]: [10278767840] [ro.boottime.adbd]: [8359267180] [ro.boottime.atfwd]: [10338554773] [ro.boottime.audioserver]: [10298157478] [ro.boottime.bootanim]: [9323670089] [ro.boottime.cameraserver]: [10299402321] [ro.boottime.cnd]: [10335931856] [ro.boottime.debuggerd]: [7001352774] [ro.boottime.debuggerd64]: [7002261785] [ro.boottime.drm]: [10301082113] [ro.boottime.fingerprintd]: [10331443314] [ro.boottime.flash-nanohub-fw]: [6995265534] [ro.boottime.gatekeeperd]: [10340355242] [ro.boottime.healthd]: [7856893380] [ro.boottime.hwservicemanager]: [7856051088] [ro.boottime.imscmservice]: [10290530758] [ro.boottime.imsdatadaemon]: [10358136702] [ro.boottime.imsqmidaemon]: [10289084872] [ro.boottime.installd]: [10303296020] [ro.boottime.irsc_util]: [10279807632] [ro.boottime.keystore]: [10305034093] [ro.boottime.lmkd]: [7863506714] [ro.boottime.loc_launcher]: [10324525241] [ro.boottime.logd]: [6526221633] [ro.boottime.logd-reinit]: [7850662702] [ro.boottime.mcfg-sh]: [10337268315] [ro.boottime.media]: [10312152687] [ro.boottime.mediacodec]: [10306852530] [ro.boottime.mediadrm]: [10308707999] [ro.boottime.mediaextractor]: [10310681177] [ro.boottime.msm_irqbalance]: [7862451974] [ro.boottime.netd]: [10313523104] [ro.boottime.netmgrd]: [10285009351] [ro.boottime.oem_qmi_server]: [10293329092] [ro.boottime.per_mgr]: [7857915776] [ro.boottime.per_proxy]: [8335121605] [ro.boottime.perfd]: [10283443101] [ro.boottime.qcamerasvr]: [10329644772] [ro.boottime.qmuxd]: [10282346643] [ro.boottime.qseecomd]: [6855708593] [ro.boottime.qti]: [10286196851] [ro.boottime.ril-daemon]: [10314933677] [ro.boottime.rmt_storage]: [7859105047] [ro.boottime.servicemanager]: [7864555881] [ro.boottime.ss_ramdump]: [8337634938] [ro.boottime.ssr_setup]: [8336268324] [ro.boottime.surfaceflinger]: [7866921402] [ro.boottime.thermal-engine]: [10281249924] [ro.boottime.time_daemon]: [10322006542] [ro.boottime.ueventd]: [5618663938] [ro.boottime.vold]: [7003493920] [ro.boottime.wificond]: [10316641073] [ro.boottime.wpa_supplicant]: [18959816881] [ro.boottime.zygote]: [10295295029] [ro.boottime.zygote_secondary]: [10296637269] Bug: http://b/31800756 Test: boots Change-Id: I094cce0c1bab9406d950ca94212689dc2e15dba5
2016-11-17Merge "Add flags to restorecon_recursive to traverse filesystems"Paul Lawrence
am: 5fbd1cfd34 Change-Id: I539d7e9d441c7bb3f5602b892408a85436b857e8
2016-11-17Merge "Add flags to restorecon_recursive to traverse filesystems"Treehugger Robot
2016-11-17init: fix undefined behavior in ExecuteCommandWei Wang
am: d67a4abc64 Change-Id: I1ecbb1d083af62dd5e69b4cff19ec411016054f3