Adds check_interface_{restart,start,stop} check_builtins.
Includes refactoring out interface inheritance hierarchy logic to a new
interface_utils file.
Bug: 137397100
Test: 'm' with an init_rc that misspells an interface in an
interface_start, interface_restart, or interface_stop line.
Change-Id: I9f650289d64ae2b13435a81e1693c7ab5e6e9ecf
diff --git a/init/service_parser.cpp b/init/service_parser.cpp
index e45e804..dd552fb 100644
--- a/init/service_parser.cpp
+++ b/init/service_parser.cpp
@@ -568,33 +568,10 @@
}
if (interface_inheritance_hierarchy_) {
- std::set<std::string> interface_names;
- for (const std::string& intf : service_->interfaces()) {
- interface_names.insert(Split(intf, "/")[0]);
- }
- std::ostringstream error_stream;
- for (const std::string& intf : interface_names) {
- if (interface_inheritance_hierarchy_->count(intf) == 0) {
- error_stream << "\nInterface is not in the known set of hidl_interfaces: '" << intf
- << "'. Please ensure the interface is spelled correctly and built "
- << "by a hidl_interface target.";
- continue;
- }
- const std::set<std::string>& required_interfaces =
- (*interface_inheritance_hierarchy_)[intf];
- std::set<std::string> diff;
- std::set_difference(required_interfaces.begin(), required_interfaces.end(),
- interface_names.begin(), interface_names.end(),
- std::inserter(diff, diff.begin()));
- if (!diff.empty()) {
- error_stream << "\nInterface '" << intf << "' requires its full inheritance "
- << "hierarchy to be listed in this init_rc file. Missing "
- << "interfaces: [" << base::Join(diff, " ") << "]";
- }
- }
- const std::string& errors = error_stream.str();
- if (!errors.empty()) {
- return Error() << errors;
+ if (const auto& check_hierarchy_result = CheckInterfaceInheritanceHierarchy(
+ service_->interfaces(), *interface_inheritance_hierarchy_);
+ !check_hierarchy_result) {
+ return Error() << check_hierarchy_result.error();
}
}