summaryrefslogtreecommitdiffstats
path: root/init/init_test.cpp
Commit message (Collapse)AuthorAgeFilesLines
* Move ActionManager to its own fileTom Cherry2018-02-141-0/+1
| | | | | | Bug: 36970783 Test: build Change-Id: I08fa39052236b462249f79de1d02bf02bdbf4c84
* Move ActionParser to its own fileTom Cherry2018-02-131-0/+1
| | | | | | Bug: 36970783 Test: build Change-Id: Idd5b923e4789760bb9ef67c10982b2642bc6a31a
* Allow a service to override another.Steven Moreland2017-11-151-6/+34
| | | | | | | | | | | | | | | | For instance, on vendor.img: service foo /vendor/bin/nfc ... And then on odm.img: service foo /odm/bin/super-nfc override Allows a service on ODM to override a HAL on vendor. Bug: 69050941 Test: boot, init_tests Change-Id: I4e908fb66e89fc6e021799fe1fa6603d3072d62a
* init: run vendor commands in a separate SELinux contextTom Cherry2017-09-291-25/+4
| | | | | | | | | | | | | | | | | | | | | | 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
* init: use Result<T> for builtin functionsTom Cherry2017-08-141-2/+2
| | | | | | | | | | | | | | | | 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
* init: introduce Result<T> for return values and error handlingTom Cherry2017-08-141-3/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* init: remove Parser singleton and related cleanupTom Cherry2017-07-271-1/+1
| | | | | | | | | | | | | | * 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
* init: create android::init:: namespaceTom Cherry2017-06-231-0/+6
| | | | | | | | With some small fixups along the way Test: Boot bullhead Test: init unit tests Change-Id: I7beaa473cfa9397f845f810557d1631b4a462d6a
* init: do not log directly from read_file() and write_file()Tom Cherry2017-05-051-3/+4
| | | | | | | | | | 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
* init: create init_tests.cppTom Cherry2017-04-211-0/+186
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