summaryrefslogtreecommitdiff
path: root/init/builtins.cpp
AgeCommit message (Collapse)Author
2018-02-05init: add TODO for mount operations.Tom Cherry
mount operations should be done in vendor init context, but their complexity currently limits this. Add a TODO to make this reason clear to those viewing the code. Bug: 72488820 Test: N/A Change-Id: I8b6dd92aa79f31dc24603559ed6de0815facfcba
2018-02-01Use vold's mount with metadata encryption service.Paul Crowley
Don't use the FDE flow to support metadata encryption; just use the vold service which directly mounts the volume. Bug: 63927601 Test: Boot Taimen to SUW with and without metadata encryption. Change-Id: Idf9c27a69872cd7a9e2fb76df09a91d8e5ef4896
2018-01-22Make vendor_init check SELinux before setting propertiesTom Cherry
Finishing a TODO from vendor_init, check SELinux permissions before setting properties in vendor_init. Bug: 62875318 Test: N/A Change-Id: I3cb6abadd2613ae083705cc6b9c970587b6c6b19
2017-11-29Run restorecon after init creates a symlink or writes to a file.Joel Galenson
Init currently sets the SELinux context on a mkdir but not on other operations. This patch modifies it to do so when creating symlinks, writing to a file, or copying a file. Test: Built, flashed, and booted. Added fake init entries and verified that they received the proper SELinux context. Change-Id: I836b570fef81d74f3b6c8e7ce0274e94ca7b12d3
2017-10-19Merge "init: wait_for_prop shouldn't run in a subcontext"Tom Cherry
am: 6e52973623 Change-Id: I160bedcb91668ccf2b663c36835871d21be2db8b
2017-10-18init: wait_for_prop shouldn't run in a subcontextTom Cherry
wait_for_prop sets a flag that prevents the action queue from continuing while otherwise allowing init's main loop to continue executing. This cannot be done from a subcontext, so it's moved to normal init. All property functions need work in any case, particularly once property_service is moved out of init. Bug: 62875318 Test: boot sailfish and see that the previous failure related to this is fixed Change-Id: Ib9e0d0bdbd0ff22ab0e5c3fe6db620700af266c6
2017-10-03Merge "init: log failures if a service cannot start during class_start"Tom Cherry
am: 533fbd62ab Change-Id: I7a05ae9f806a23d04d649fb230e2875633b2caee
2017-10-03init: log failures if a service cannot start during class_startTom Cherry
Test: boot system with this logging and see appropriate failures Change-Id: I312dca89f6215afe05b10b2539258a212a0c1ae2
2017-10-02Merge "init: run vendor commands in a separate SELinux context"Tom Cherry
am: 8e09b0b953 Change-Id: I7e0272f29bd8bab029a9f9c07aa413c9172f6f5a
2017-09-29init: run vendor commands in a separate SELinux contextTom Cherry
One of the major aspects of treble is the compartmentalization of system and vendor components, however init leaves a huge gap here, as vendor init scripts run in the same context as system init scripts and thus can access and modify the same properties, files, etc as the system can. This change is meant to close that gap. It forks a separate 'subcontext' init that runs in a different SELinux context with permissions that match what vendors should have access to. Commands get sent over a socket to this 'subcontext' init that then runs them in this SELinux context and returns the result. Note that not all commands run in the subcontext; some commands such as those dealing with services only make sense in the context of the main init process. Bug: 62875318 Test: init unit tests, boot bullhead, boot sailfish Change-Id: Idf4a4ebf98842d27b8627f901f961ab9eb412aee
2017-09-18Merge "init: add exec_background command"Tom Cherry
am: 424ed42fb4 Change-Id: I9529146ea9b29b2fb2e2c92f3533efc4e3106943
2017-09-18Merge "init: add exec_background command"Tom Cherry
2017-09-18init: add exec_background commandTom Cherry
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-15Merge "init: fix crash when reboot is triggered by a builtin"Tom Cherry
am: b92415cee2 Change-Id: I4137679d88e58c706f14adeeaf84b41426079de4
2017-09-15init: fix crash when reboot is triggered by a builtinTom Cherry
Builtin commands may set the sys.powerctl property, which causes reboot to be immediately processed. Unfortunately, part of the reboot processing involves clearing the action queue, so when this scenario happens, ActionManager::ExecuteOneCommand() can abort due to its state being unexpectedly changed. Longer term, the real fix here is to split init and property service. In this case, the property sets will be sent to property service and the reboot will only be processed once property service responds back to init that the property has been set. Since that will not happen within the action queue, there will be no risk of failure. Short term, this change sets a flag in init to shutdown the device before the next action is run, which defers the shutdown enough to fix the crash, but continues to prevent any further commands from running. Bug: 65374456 Test: force bullhead into the repro case and observe that it no longer repros Change-Id: I89c73dad8d7912a845d694b095cab061b8dcc05e
2017-09-07Merge "init: Allow clean system shutdown upon SIGTERM"Luis Hector Chavez
am: 61cb88add2 Change-Id: If0a495fa067440f0b59969ac0dbc010b4687b52f
2017-09-07init: Allow clean system shutdown upon SIGTERMLuis Hector Chavez
This allows Android to cleanly shutdown when running in a PID namespace in a way that does not rely on adbd running. This is useful to allow Android to be running in a container and its lifetime managed by an OCI-compliant tool. Bug: 65415372 Test: `kill -TERM 1` as root is correctly dropped. Test: `kill -TERM 1` from the init PID namespace causes init to cleanly shutdown. Change-Id: Ia66ebdb436221919081bc4723337c0c7f1e53b09
2017-09-02Merge "init: add option to read file fully on readahead"Wei Wang
am: d97a1710b8 Change-Id: I2a49bd384b1fe621314916c1f325c03b7fa43162
2017-09-01init: add option to read file fully on readaheadWei Wang
Bug: 62413151 Test: boottime, dumpcache Change-Id: I1a7b69f0619428e4db31c5a7639c5d895c89ecdb
2017-08-28Merge "init: support setting rlimits per service"Tom Cherry
am: 459aa1cac6 Change-Id: I4ef5abc3371ce52783bfb14669bcffe33febb73e
2017-08-28init: support setting rlimits per serviceTom Cherry
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-23Merge changes I316c13e3,I4d99744d,Id9614b72,I7c98a0b7Tom Cherry
am: a78b5b300b Change-Id: I0e4221611fb34489b2ecdd713933a2e4ba4e5055
2017-08-23init: enable error reporting of builtin functionsTom Cherry
Enable error reporting when builtin functions fail. These errors are now reported with full context including the source file and line number, e.g. init: Command 'write /sys/module/subsystem_restart/parameters/enable_debug ${persist.sys.ssr.enable_debug}' action=early-boot (/init.bullhead.rc:84) took 0ms and failed: cannot expand '${persist.sys.ssr.enable_debug}' There are two small caveats: 1) There are nearly 200 reports of builtins failure due to "No such file or directory". Many of these are due to legacy paths included in rootdir/init.rc. Until they are cleaned up, reporting of these failures is disabled. 2) Similarly, symlink is often used to create backwards compatible symlinks. By their very nature, these calls are expected to fail on newer systems that do already use the new path. Due to this, failures of symlink due to EEXIST are not reported. Bug: 38038887 Test: boot bullhead, only see true errors reported from builtins. Change-Id: I316c13e3adc992cacc6d79ffee987adc8738fca0
2017-08-23init: log Service failures via Result<T>Tom Cherry
Log Service failures via Result<T> such that their context can be captured when interacting with services through builtin functions. Test: boot bullhead Change-Id: I4d99744d64008d4a06a404e3c9817182c6e177bc
2017-08-23init: cleanup environment handlingTom Cherry
Init keep its own copy of the environment that it uses for execve when starting services. This is unnecessary however as libc already has functions that mutate the environment and the environment that init uses is clean for starting services. This change removes init's copy of the environment and uses the libc functions instead. This also makes small clean-up to the way the Service class stores service specific environment variables. Test: boot bullhead Change-Id: I7c98a0b7aac9fa8f195ae33bd6a7515bb56faf78
2017-08-14init: use Result<T> for builtin functionsTom Cherry
We currently throw out the return values from builtin functions and occasionally log errors with no supporting context. This change uses the newly introduced Result<T> class to communicate a successful result or an error back to callers in order to print an error with clear context when a builtin fails. Example: init: Command 'write /sys/class/leds/vibrator/trigger transient' action=init (/init.rc:245) took 0ms and failed: Unable to write to file '/sys/class/leds/vibrator/trigger': open() failed: No such file or directory Test: boot bullhead Merged-In: Idc18f331d2d646629c6093c1e0f2996cf9b42aec Change-Id: Idc18f331d2d646629c6093c1e0f2996cf9b42aec
2017-08-14init: introduce Result<T> for return values and error handlingTom Cherry
init tries to propagate error information up to build context before logging errors. This is a good thing, however too often init has the overly verbose paradigm for error handling, below: bool CalculateResult(const T& input, U* output, std::string* err) bool CalculateAndUseResult(const T& input, std::string* err) { U output; std::string calculate_result_err; if (!CalculateResult(input, &output, &calculate_result_err)) { *err = "CalculateResult " + input + " failed: " + calculate_result_err; return false; } UseResult(output); return true; } Even more common are functions that return only true/false but also require passing a std::string* err in order to see the error message. This change introduces a Result<T> that is use to either hold a successful return value of type T or to hold an error message as a std::string. If the functional only returns success or a failure with an error message, Result<Success> may be used. The classes Error and ErrnoError are used to indicate a failed Result<T>. A successful Result<T> is constructed implicitly from any type that can be implicitly converted to T or from the constructor arguments for T. This allows you to return a type T directly from a function that returns Result<T>. Error and ErrnoError are used to construct a Result<T> has failed. Each of these classes take an ostream as an input and are implicitly cast to a Result<T> containing that failure. ErrnoError() additionally appends ": " + strerror(errno) to the end of the failure string to aid in interacting with C APIs. The end result is that the above code snippet is turned into the much clearer example below: Result<U> CalculateResult(const T& input); Result<Success> CalculateAndUseResult(const T& input) { auto output = CalculateResult(input); if (!output) { return Error() << "CalculateResult " << input << " failed: " << output.error(); } UseResult(*output); return Success(); } This change also makes this conversion for some of the util.cpp functions that used the old paradigm. Test: boot bullhead, init unit tests Merged-In: I1e7d3a8820a79362245041251057fbeed2f7979b Change-Id: I1e7d3a8820a79362245041251057fbeed2f7979b
2017-08-14init: use Result<T> for builtin functionsTom Cherry
We currently throw out the return values from builtin functions and occasionally log errors with no supporting context. This change uses the newly introduced Result<T> class to communicate a successful result or an error back to callers in order to print an error with clear context when a builtin fails. Example: init: Command 'write /sys/class/leds/vibrator/trigger transient' action=init (/init.rc:245) took 0ms and failed: Unable to write to file '/sys/class/leds/vibrator/trigger': open() failed: No such file or directory Test: boot bullhead Change-Id: Idc18f331d2d646629c6093c1e0f2996cf9b42aec
2017-08-14init: introduce Result<T> for return values and error handlingTom Cherry
init tries to propagate error information up to build context before logging errors. This is a good thing, however too often init has the overly verbose paradigm for error handling, below: bool CalculateResult(const T& input, U* output, std::string* err) bool CalculateAndUseResult(const T& input, std::string* err) { U output; std::string calculate_result_err; if (!CalculateResult(input, &output, &calculate_result_err)) { *err = "CalculateResult " + input + " failed: " + calculate_result_err; return false; } UseResult(output); return true; } Even more common are functions that return only true/false but also require passing a std::string* err in order to see the error message. This change introduces a Result<T> that is use to either hold a successful return value of type T or to hold an error message as a std::string. If the functional only returns success or a failure with an error message, Result<Success> may be used. The classes Error and ErrnoError are used to indicate a failed Result<T>. A successful Result<T> is constructed implicitly from any type that can be implicitly converted to T or from the constructor arguments for T. This allows you to return a type T directly from a function that returns Result<T>. Error and ErrnoError are used to construct a Result<T> has failed. Each of these classes take an ostream as an input and are implicitly cast to a Result<T> containing that failure. ErrnoError() additionally appends ": " + strerror(errno) to the end of the failure string to aid in interacting with C APIs. The end result is that the above code snippet is turned into the much clearer example below: Result<U> CalculateResult(const T& input); Result<Success> CalculateAndUseResult(const T& input) { auto output = CalculateResult(input); if (!output) { return Error() << "CalculateResult " << input << " failed: " << output.error(); } UseResult(*output); return Success(); } This change also makes this conversion for some of the util.cpp functions that used the old paradigm. Test: boot bullhead, init unit tests Change-Id: I1e7d3a8820a79362245041251057fbeed2f7979b
2017-08-14Merge "init: split security functions out of init.cpp" into oc-dev-plus-aospTom Cherry
am: 08228116a8 Change-Id: I3fc6288cf03cd1e262852ceb3fc9dbcedb32c7c3
2017-08-14Merge "init: split security functions out of init.cpp" into oc-dev-plus-aospTom Cherry
2017-08-14init: split security functions out of init.cppTom Cherry
This change splits out the selinux initialization and supporting functionality into selinux.cpp and splits the security related initialization of the rng, etc to security.cpp. It also provides additional documentation for SEPolicy loading as this has been requested by some teams. It additionally cleans up sehandle and sehandle_prop. The former is static within selinux.cpp and new wrapper functions are created around selabel_lookup*() to better serve the users. The latter is moved to property_service.cpp as it is isolated to that file for its usage. Test: boot bullhead Merged-In: Idc95d493cebc681fbe686b5160502f36af149f60 Change-Id: Idc95d493cebc681fbe686b5160502f36af149f60
2017-08-11Merge "init: Add readahead built-in command" am: 12bd22badf am: 826bc7b507Wei Wang
am: 67eac4fa36 Change-Id: I852ee7278ec94e3b483a8ef61fe34477f73517fb
2017-08-11init: split security functions out of init.cppTom Cherry
This change splits out the selinux initialization and supporting functionality into selinux.cpp and splits the security related initialization of the rng, etc to security.cpp. It also provides additional documentation for SEPolicy loading as this has been requested by some teams. It additionally cleans up sehandle and sehandle_prop. The former is static within selinux.cpp and new wrapper functions are created around selabel_lookup*() to better serve the users. The latter is moved to property_service.cpp as it is isolated to that file for its usage. Test: boot bullhead Merged-In: Idc95d493cebc681fbe686b5160502f36af149f60 Change-Id: Idc95d493cebc681fbe686b5160502f36af149f60 (cherry picked from commit 9afb86b25d8675927cb37c86119a7ecf19f74819)
2017-08-11init: Add readahead built-in commandWei Wang
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-02Merge "init: use unique_fd in builtins.cpp" am: c34afb1cd5 am: 76756aa1ddTom Cherry
am: 54032d387a Change-Id: I20865544dd1692979c8fbd21c05272a98c00eca4
2017-08-01init: use unique_fd in builtins.cppTom Cherry
Test: boot Change-Id: I09295856dbd0de9436a95a2fe99ab6be156b995f
2017-08-01Merge changes Ibd57c103,I81f1e8ac,Ia6e546fe am: 2a2a8d9ec0 am: b1c18af247Tom Cherry
am: 3d6b46a789 Change-Id: I704cb309efb106cff34c28b9c7fde3e86bb34cc0
2017-08-01init: rename ServiceManager to ServiceList and clean it upTom Cherry
ServiceManager is essentially just a list now that the rest of its functionality has been moved elsewhere, so the class is renamed appropriately. The ServiceList::Find* functions have been cleaned up into a single smaller interface. The ServiceList::ForEach functions have been removed in favor of ServiceList itself being directly iterable. Test: boot bullhead Change-Id: Ibd57c103338f03b83d81e8b48ea0e46cd48fd8f0
2017-08-01init: move exec operations out of ServiceManagerTom Cherry
These can be implemented without ServiceManager, so we remove them and make ServiceManager slightly less of a God class. Test: boot bullhead Test: init unit tests Change-Id: Ia6e546fe5292255412245256f7d230af4ece135f
2017-07-28Merge "init: remove Parser singleton and related cleanup" am: 379123f9ab am: ↵Tom Cherry
bf4afbb288 am: 1b74d14b7e Change-Id: Ifaaeae8fb3f43235846207fa02a83edbc1e427d9
2017-07-27init: remove Parser singleton and related cleanupTom Cherry
* Remove the Parser singleton (Hooray!) * Rename parser.* to tokenizer.* as this is actually a tokenizer * Rename init_parser.* to parser.* as this is a generic parser * Move contents of init_parser_test.cpp to service_test.cpp as this actually is a test of the parsing in MakeExecOneshotService() and nothing related to (init_)parser.cpp Test: boot bullhead Test: bool sailfish Test: init unit tests Change-Id: I4fe39e6483f58ebd3ce5ee715a45dbba0acf5d91
2017-07-10Merge "Move Timer from init to libbase" am: 896297b2ef am: 7ff0b008f7Tom Cherry
am: 4e5c4f18d8 Change-Id: Iffad0dcde94fce7dac627ebf0530420f9cfd38d1
2017-07-10Move Timer from init to libbaseTom Cherry
Test: boot bullhead Test: new libbase unit tests Change-Id: Ic398a1daa1fe92c10ea7bc1e6ac3f781cee9a5b5
2017-07-05Merge "init: Support custom shutdown actions" am: c1bc4241f8 am: 5b89535442Wei Wang
am: b39890048c Change-Id: I57a0422f47094cc061163510138e9562648fdd98
2017-07-05init: Support custom shutdown actionsWei Wang
We have been seeing panics and errors during shutdown sequence in some vendor's platform, and it is required to disable error handling during shutdown. This CL separates the shutdown request to execute another "shutdown" trigger at the beginning of shutdown stage. And vendor can use this trigger to add custom commands needed for shutting down gracefully. Bug: 38203024 Bug: 62084631 Test: device reboot/shutdown Change-Id: I3fac4ed59f06667d86e477ee55ed391cf113717f
2017-06-23Merge "init: create android::init:: namespace" am: 040212706b am: d3d79b2196Tom Cherry
am: b57e1180e3 Change-Id: Ic6d35273820d70136a6085bf49dcf3afcbb24f24
2017-06-23init: create android::init:: namespaceTom Cherry
With some small fixups along the way Test: Boot bullhead Test: init unit tests Change-Id: I7beaa473cfa9397f845f810557d1631b4a462d6a
2017-06-23Merge "init: cleanup some string usage" am: 84c2eebbdd am: 77382acf42Tom Cherry
am: 288fb7c2cc Change-Id: I61e6ee578e55ebe343112c8114816ac4e18b9c7e
2017-06-22init: cleanup some string usageTom Cherry
1) property_set() takes const std::string& for both of its arguments, so stop using .c_str() with its parameters 2) Simplify a few places where StringPrintf() is used to concatenate strings 3) Use std::to_string() instead of StringPrintf() where it's better suited Test: Boot bullhead Test: init unit tests Change-Id: I68ebda0e469f6230c8f9ad3c8d5f9444e0c4fdfd