summaryrefslogtreecommitdiffstats
path: root/init/parser.cpp
Commit message (Collapse)AuthorAgeFilesLines
* init: add host side parser for initTom Cherry2018-02-281-7/+17
| | | | | | | | | | Create a host side parser for init such that init rc files can be verified for syntax correctness before being used on the device. Bug: 36970783 Test: run the parser on init files on host Change-Id: I7e8772e278ebaff727057308596ebacf28b6fdda
* Add std::string StartsWith*/EndsWith* overloads.Elliott Hughes2017-12-201-1/+1
| | | | | | | | | We should have done this from the beginning. Thanks to Windows, we're not going to be able to switch libbase over to std::string_view any time soon. Bug: N/A Test: ran tests Change-Id: Iff2f56986e39de53f3ac484415378af17dacf26b
* EndSection returns Result<Success>Steven Moreland2017-11-151-4/+16
| | | | | | | | | Allow it to fail. When there is an error for a section ending, print the error pointing to the line where the section starts. Bug: 69050941 Test: boot, init_tests Change-Id: I1d8ed25f4b74cc9ac24d38b8075751c7d606aea8
* init: use Result<T> for the parsing functionsTom Cherry2017-08-141-10/+9
| | | | | Test: boot bullhead Change-Id: I7f00c5f0f54dd4fe05df73e1d6a89b56d788e113
* init: introduce Result<T> for return values and error handlingTom Cherry2017-08-141-6/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* init: remove Parser singleton and related cleanupTom Cherry2017-07-271-106/+139
| | | | | | | | | | | | | | * 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: remove unused parts of parser.cppTom Cherry2017-04-251-23/+0
| | | | | | | | Now that ueventd is using init's parser, we no longer need anything other than the tokenizer from parser.cpp. Test: Boot bullhead Change-Id: I1f70f2c4479af576174bd74dd919d81817500216
* init: more header cleanupTom Cherry2017-04-061-1/+1
| | | | | | | | | | 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
* Move init to libbase logging.Elliott Hughes2016-06-271-1/+1
| | | | Change-Id: Ibfbefeff587a69e948978a037c555fd12a5ade6a
* Cleanup uses of sprintf so we can deprecate it.George Burgess IV2016-03-071-1/+1
| | | | | | | | Also cleans up two instances of open() with useless mode params, and changes a few uses of snprintf to use sizeof(buffer) instead of hardcoded buffer sizes. Change-Id: If11591003d910c995e72ad8f75afd072c255a3c5
* Stop using #if for conditional compilation.Elliott Hughes2015-02-041-51/+4
| | | | | | | | Use regular 'if' to prevent bitrot. Also remove remaining typedefs. Change-Id: I2e6ca928e2db29b88b643cf990ff05cfb0be94a6
* Build init as C++.Elliott Hughes2015-02-041-0/+188
This is just the minimal change to keep it building. Change-Id: I245c5b8413a1db114576c81462eb5737f5ffcef2