| Tom Cherry | de6bd50 | 2018-02-13 16:50:08 -0800 | [diff] [blame] | 1 | // |
| 2 | // Copyright (C) 2018 The Android Open Source Project |
| 3 | // |
| 4 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | // you may not use this file except in compliance with the License. |
| 6 | // You may obtain a copy of the License at |
| 7 | // |
| 8 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | // |
| 10 | // Unless required by applicable law or agreed to in writing, software |
| 11 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | // See the License for the specific language governing permissions and |
| 14 | // limitations under the License. |
| 15 | // |
| 16 | |
| Tom Cherry | 31525f5 | 2018-05-09 18:33:31 -0700 | [diff] [blame] | 17 | #include <errno.h> |
| Tom Cherry | 3f1bce8 | 2019-06-05 09:13:11 -0700 | [diff] [blame] | 18 | #include <getopt.h> |
| Tom Cherry | de6bd50 | 2018-02-13 16:50:08 -0800 | [diff] [blame] | 19 | #include <pwd.h> |
| Tom Cherry | 31525f5 | 2018-05-09 18:33:31 -0700 | [diff] [blame] | 20 | #include <stdio.h> |
| Tom Cherry | 863d808 | 2018-06-12 14:40:38 -0700 | [diff] [blame] | 21 | #include <stdlib.h> |
| Tom Cherry | de6bd50 | 2018-02-13 16:50:08 -0800 | [diff] [blame] | 22 | |
| Daniel Norman | 3f42a76 | 2019-07-09 11:00:53 -0700 | [diff] [blame] | 23 | #include <fstream> |
| Tom Cherry | 194b5d1 | 2018-05-09 17:38:30 -0700 | [diff] [blame] | 24 | #include <iostream> |
| Tom Cherry | 3f1bce8 | 2019-06-05 09:13:11 -0700 | [diff] [blame] | 25 | #include <iterator> |
| Daniel Norman | f597fa5 | 2020-11-09 17:28:24 -0800 | [diff] [blame] | 26 | #include <map> |
| 27 | #include <set> |
| Tom Cherry | 194b5d1 | 2018-05-09 17:38:30 -0700 | [diff] [blame] | 28 | #include <string> |
| Tom Cherry | 31525f5 | 2018-05-09 18:33:31 -0700 | [diff] [blame] | 29 | #include <vector> |
| Tom Cherry | 194b5d1 | 2018-05-09 17:38:30 -0700 | [diff] [blame] | 30 | |
| Tom Cherry | 31525f5 | 2018-05-09 18:33:31 -0700 | [diff] [blame] | 31 | #include <android-base/file.h> |
| Tom Cherry | de6bd50 | 2018-02-13 16:50:08 -0800 | [diff] [blame] | 32 | #include <android-base/logging.h> |
| Tom Cherry | 31525f5 | 2018-05-09 18:33:31 -0700 | [diff] [blame] | 33 | #include <android-base/parseint.h> |
| Tom Cherry | 194b5d1 | 2018-05-09 17:38:30 -0700 | [diff] [blame] | 34 | #include <android-base/strings.h> |
| Tom Cherry | 6ad4d0a | 2020-03-04 13:35:28 -0800 | [diff] [blame] | 35 | #include <generated_android_ids.h> |
| Steven Moreland | 422a758 | 2019-10-15 14:53:19 -0700 | [diff] [blame] | 36 | #include <hidl/metadata.h> |
| Jooyung Han | 39e8be4 | 2024-02-16 17:23:34 +0900 | [diff] [blame] | 37 | #include <property_info_parser/property_info_parser.h> |
| Tom Cherry | b5f2ec0 | 2019-11-08 17:54:27 -0800 | [diff] [blame] | 38 | #include <property_info_serializer/property_info_serializer.h> |
| Tom Cherry | de6bd50 | 2018-02-13 16:50:08 -0800 | [diff] [blame] | 39 | |
| 40 | #include "action.h" |
| 41 | #include "action_manager.h" |
| 42 | #include "action_parser.h" |
| Tom Cherry | 4772f1d | 2019-07-30 09:34:41 -0700 | [diff] [blame] | 43 | #include "check_builtins.h" |
| Tom Cherry | 194b5d1 | 2018-05-09 17:38:30 -0700 | [diff] [blame] | 44 | #include "host_import_parser.h" |
| 45 | #include "host_init_stubs.h" |
| Daniel Norman | d2533c3 | 2019-08-02 15:13:50 -0700 | [diff] [blame] | 46 | #include "interface_utils.h" |
| Tom Cherry | de6bd50 | 2018-02-13 16:50:08 -0800 | [diff] [blame] | 47 | #include "parser.h" |
| 48 | #include "result.h" |
| 49 | #include "service.h" |
| Tom Cherry | 2aeb1ad | 2019-06-26 10:46:20 -0700 | [diff] [blame] | 50 | #include "service_list.h" |
| 51 | #include "service_parser.h" |
| Tom Cherry | de6bd50 | 2018-02-13 16:50:08 -0800 | [diff] [blame] | 52 | |
| Tom Cherry | 194b5d1 | 2018-05-09 17:38:30 -0700 | [diff] [blame] | 53 | using namespace std::literals; |
| 54 | |
| Daniel Norman | f597fa5 | 2020-11-09 17:28:24 -0800 | [diff] [blame] | 55 | using android::base::EndsWith; |
| Tom Cherry | 31525f5 | 2018-05-09 18:33:31 -0700 | [diff] [blame] | 56 | using android::base::ParseInt; |
| 57 | using android::base::ReadFileToString; |
| Tom Cherry | 194b5d1 | 2018-05-09 17:38:30 -0700 | [diff] [blame] | 58 | using android::base::Split; |
| Tom Cherry | b5f2ec0 | 2019-11-08 17:54:27 -0800 | [diff] [blame] | 59 | using android::properties::ParsePropertyInfoFile; |
| Tom Cherry | b5f2ec0 | 2019-11-08 17:54:27 -0800 | [diff] [blame] | 60 | using android::properties::PropertyInfoEntry; |
| Tom Cherry | 194b5d1 | 2018-05-09 17:38:30 -0700 | [diff] [blame] | 61 | |
| Tom Cherry | 3f1bce8 | 2019-06-05 09:13:11 -0700 | [diff] [blame] | 62 | static std::vector<std::string> passwd_files; |
| Tom Cherry | 31525f5 | 2018-05-09 18:33:31 -0700 | [diff] [blame] | 63 | |
| Daniel Norman | f597fa5 | 2020-11-09 17:28:24 -0800 | [diff] [blame] | 64 | // NOTE: Keep this in sync with the order used by init.cpp LoadBootScripts() |
| 65 | static const std::vector<std::string> partition_search_order = |
| 66 | std::vector<std::string>({"system", "system_ext", "odm", "vendor", "product"}); |
| 67 | |
| Tom Cherry | 3f1bce8 | 2019-06-05 09:13:11 -0700 | [diff] [blame] | 68 | static std::vector<std::pair<std::string, int>> GetVendorPasswd(const std::string& passwd_file) { |
| Tom Cherry | 31525f5 | 2018-05-09 18:33:31 -0700 | [diff] [blame] | 69 | std::string passwd; |
| Tom Cherry | 863d808 | 2018-06-12 14:40:38 -0700 | [diff] [blame] | 70 | if (!ReadFileToString(passwd_file, &passwd)) { |
| Tom Cherry | 31525f5 | 2018-05-09 18:33:31 -0700 | [diff] [blame] | 71 | return {}; |
| 72 | } |
| 73 | |
| 74 | std::vector<std::pair<std::string, int>> result; |
| 75 | auto passwd_lines = Split(passwd, "\n"); |
| 76 | for (const auto& line : passwd_lines) { |
| 77 | auto split_line = Split(line, ":"); |
| 78 | if (split_line.size() < 3) { |
| 79 | continue; |
| 80 | } |
| 81 | int uid = 0; |
| 82 | if (!ParseInt(split_line[2], &uid)) { |
| 83 | continue; |
| 84 | } |
| 85 | result.emplace_back(split_line[0], uid); |
| 86 | } |
| 87 | return result; |
| 88 | } |
| 89 | |
| Tom Cherry | 3f1bce8 | 2019-06-05 09:13:11 -0700 | [diff] [blame] | 90 | static std::vector<std::pair<std::string, int>> GetVendorPasswd() { |
| 91 | std::vector<std::pair<std::string, int>> result; |
| 92 | for (const auto& passwd_file : passwd_files) { |
| 93 | auto individual_result = GetVendorPasswd(passwd_file); |
| 94 | std::move(individual_result.begin(), individual_result.end(), |
| 95 | std::back_insert_iterator(result)); |
| 96 | } |
| 97 | return result; |
| 98 | } |
| 99 | |
| Tom Cherry | de6bd50 | 2018-02-13 16:50:08 -0800 | [diff] [blame] | 100 | passwd* getpwnam(const char* login) { // NOLINT: implementing bad function. |
| Tom Cherry | 31525f5 | 2018-05-09 18:33:31 -0700 | [diff] [blame] | 101 | // This isn't thread safe, but that's okay for our purposes. |
| 102 | static char static_name[32] = ""; |
| 103 | static char static_dir[32] = "/"; |
| 104 | static char static_shell[32] = "/system/bin/sh"; |
| 105 | static passwd static_passwd = { |
| 106 | .pw_name = static_name, |
| 107 | .pw_dir = static_dir, |
| Tom Cherry | 31525f5 | 2018-05-09 18:33:31 -0700 | [diff] [blame] | 108 | .pw_uid = 0, |
| 109 | .pw_gid = 0, |
| Bart Van Assche | 4844092 | 2023-11-02 13:02:57 -0700 | [diff] [blame] | 110 | .pw_shell = static_shell, |
| Tom Cherry | de6bd50 | 2018-02-13 16:50:08 -0800 | [diff] [blame] | 111 | }; |
| Tom Cherry | 31525f5 | 2018-05-09 18:33:31 -0700 | [diff] [blame] | 112 | |
| 113 | for (size_t n = 0; n < android_id_count; ++n) { |
| 114 | if (!strcmp(android_ids[n].name, login)) { |
| 115 | snprintf(static_name, sizeof(static_name), "%s", android_ids[n].name); |
| 116 | static_passwd.pw_uid = android_ids[n].aid; |
| 117 | static_passwd.pw_gid = android_ids[n].aid; |
| 118 | return &static_passwd; |
| 119 | } |
| 120 | } |
| 121 | |
| 122 | static const auto vendor_passwd = GetVendorPasswd(); |
| 123 | |
| 124 | for (const auto& [name, uid] : vendor_passwd) { |
| 125 | if (name == login) { |
| 126 | snprintf(static_name, sizeof(static_name), "%s", name.c_str()); |
| 127 | static_passwd.pw_uid = uid; |
| 128 | static_passwd.pw_gid = uid; |
| 129 | return &static_passwd; |
| 130 | } |
| 131 | } |
| 132 | |
| Tom Cherry | 290427b | 2018-06-14 13:40:20 -0700 | [diff] [blame] | 133 | unsigned int oem_uid; |
| 134 | if (sscanf(login, "oem_%u", &oem_uid) == 1) { |
| 135 | snprintf(static_name, sizeof(static_name), "%s", login); |
| 136 | static_passwd.pw_uid = oem_uid; |
| 137 | static_passwd.pw_gid = oem_uid; |
| 138 | return &static_passwd; |
| 139 | } |
| 140 | |
| Tom Cherry | 31525f5 | 2018-05-09 18:33:31 -0700 | [diff] [blame] | 141 | errno = ENOENT; |
| 142 | return nullptr; |
| Tom Cherry | de6bd50 | 2018-02-13 16:50:08 -0800 | [diff] [blame] | 143 | } |
| 144 | |
| 145 | namespace android { |
| 146 | namespace init { |
| 147 | |
| Tom Cherry | 3f1bce8 | 2019-06-05 09:13:11 -0700 | [diff] [blame] | 148 | void PrintUsage() { |
| Daniel Norman | f597fa5 | 2020-11-09 17:28:24 -0800 | [diff] [blame] | 149 | fprintf(stdout, R"(usage: host_init_verifier [options] |
| 150 | |
| 151 | Tests init script(s) for correctness. |
| 152 | |
| 153 | Generic options: |
| 154 | -p FILE Search this passwd file for users and groups. |
| 155 | --property_contexts=FILE Use this file for property_contexts. |
| 156 | |
| 157 | Single script mode options: |
| 158 | [init rc file] Positional argument; test this init script. |
| 159 | |
| 160 | Multiple script mode options: |
| 161 | --out_system=DIR Path to the output product directory for the system partition. |
| 162 | --out_system_ext=DIR Path to the output product directory for the system_ext partition. |
| 163 | --out_odm=DIR Path to the output product directory for the odm partition. |
| 164 | --out_vendor=DIR Path to the output product directory for the vendor partition. |
| 165 | --out_product=DIR Path to the output product directory for the product partition. |
| 166 | )"); |
| Tom Cherry | 3f1bce8 | 2019-06-05 09:13:11 -0700 | [diff] [blame] | 167 | } |
| 168 | |
| Steven Moreland | 422a758 | 2019-10-15 14:53:19 -0700 | [diff] [blame] | 169 | Result<InterfaceInheritanceHierarchyMap> ReadInterfaceInheritanceHierarchy() { |
| 170 | InterfaceInheritanceHierarchyMap result; |
| 171 | for (const HidlInterfaceMetadata& iface : HidlInterfaceMetadata::all()) { |
| 172 | std::set<FQName> inherited_interfaces; |
| 173 | for (const std::string& intf : iface.inherited) { |
| 174 | FQName fqname; |
| 175 | if (!fqname.setTo(intf)) { |
| 176 | return Error() << "Unable to parse interface '" << intf << "'"; |
| 177 | } |
| 178 | inherited_interfaces.insert(fqname); |
| 179 | } |
| 180 | FQName fqname; |
| 181 | if (!fqname.setTo(iface.name)) { |
| 182 | return Error() << "Unable to parse interface '" << iface.name << "'"; |
| 183 | } |
| 184 | result[fqname] = inherited_interfaces; |
| 185 | } |
| 186 | |
| 187 | return result; |
| 188 | } |
| 189 | |
| Tom Cherry | b5f2ec0 | 2019-11-08 17:54:27 -0800 | [diff] [blame] | 190 | void HandlePropertyContexts(const std::string& filename, |
| 191 | std::vector<PropertyInfoEntry>* property_infos) { |
| 192 | auto file_contents = std::string(); |
| 193 | if (!ReadFileToString(filename, &file_contents)) { |
| 194 | PLOG(ERROR) << "Could not read properties from '" << filename << "'"; |
| 195 | exit(EXIT_FAILURE); |
| 196 | } |
| 197 | |
| 198 | auto errors = std::vector<std::string>{}; |
| Tom Cherry | 4b077c5 | 2019-12-11 07:56:51 -0800 | [diff] [blame] | 199 | ParsePropertyInfoFile(file_contents, true, property_infos, &errors); |
| Tom Cherry | b5f2ec0 | 2019-11-08 17:54:27 -0800 | [diff] [blame] | 200 | for (const auto& error : errors) { |
| 201 | LOG(ERROR) << "Could not read line from '" << filename << "': " << error; |
| 202 | } |
| 203 | if (!errors.empty()) { |
| 204 | exit(EXIT_FAILURE); |
| 205 | } |
| 206 | } |
| 207 | |
| Tom Cherry | de6bd50 | 2018-02-13 16:50:08 -0800 | [diff] [blame] | 208 | int main(int argc, char** argv) { |
| Elliott Hughes | 1be0d14 | 2018-05-23 09:16:46 -0700 | [diff] [blame] | 209 | android::base::InitLogging(argv, &android::base::StdioLogger); |
| Tom Cherry | 194b5d1 | 2018-05-09 17:38:30 -0700 | [diff] [blame] | 210 | android::base::SetMinimumLogSeverity(android::base::ERROR); |
| Tom Cherry | 863d808 | 2018-06-12 14:40:38 -0700 | [diff] [blame] | 211 | |
| Tom Cherry | b5f2ec0 | 2019-11-08 17:54:27 -0800 | [diff] [blame] | 212 | auto property_infos = std::vector<PropertyInfoEntry>(); |
| Daniel Norman | f597fa5 | 2020-11-09 17:28:24 -0800 | [diff] [blame] | 213 | std::map<std::string, std::string> partition_map; |
| Tom Cherry | b5f2ec0 | 2019-11-08 17:54:27 -0800 | [diff] [blame] | 214 | |
| Tom Cherry | 3f1bce8 | 2019-06-05 09:13:11 -0700 | [diff] [blame] | 215 | while (true) { |
| Tom Cherry | b5f2ec0 | 2019-11-08 17:54:27 -0800 | [diff] [blame] | 216 | static const char kPropertyContexts[] = "property-contexts="; |
| Tom Cherry | 3f1bce8 | 2019-06-05 09:13:11 -0700 | [diff] [blame] | 217 | static const struct option long_options[] = { |
| 218 | {"help", no_argument, nullptr, 'h'}, |
| Tom Cherry | b5f2ec0 | 2019-11-08 17:54:27 -0800 | [diff] [blame] | 219 | {kPropertyContexts, required_argument, nullptr, 0}, |
| Daniel Norman | f597fa5 | 2020-11-09 17:28:24 -0800 | [diff] [blame] | 220 | {"out_system", required_argument, nullptr, 0}, |
| 221 | {"out_system_ext", required_argument, nullptr, 0}, |
| 222 | {"out_odm", required_argument, nullptr, 0}, |
| 223 | {"out_vendor", required_argument, nullptr, 0}, |
| 224 | {"out_product", required_argument, nullptr, 0}, |
| Tom Cherry | 3f1bce8 | 2019-06-05 09:13:11 -0700 | [diff] [blame] | 225 | {nullptr, 0, nullptr, 0}, |
| 226 | }; |
| 227 | |
| Tom Cherry | b5f2ec0 | 2019-11-08 17:54:27 -0800 | [diff] [blame] | 228 | int option_index; |
| 229 | int arg = getopt_long(argc, argv, "p:", long_options, &option_index); |
| Tom Cherry | 3f1bce8 | 2019-06-05 09:13:11 -0700 | [diff] [blame] | 230 | |
| 231 | if (arg == -1) { |
| 232 | break; |
| 233 | } |
| 234 | |
| 235 | switch (arg) { |
| Tom Cherry | b5f2ec0 | 2019-11-08 17:54:27 -0800 | [diff] [blame] | 236 | case 0: |
| 237 | if (long_options[option_index].name == kPropertyContexts) { |
| 238 | HandlePropertyContexts(optarg, &property_infos); |
| 239 | } |
| Daniel Norman | f597fa5 | 2020-11-09 17:28:24 -0800 | [diff] [blame] | 240 | for (const auto& p : partition_search_order) { |
| 241 | if (long_options[option_index].name == "out_" + p) { |
| 242 | if (partition_map.find(p) != partition_map.end()) { |
| 243 | PrintUsage(); |
| 244 | return EXIT_FAILURE; |
| 245 | } |
| 246 | partition_map[p] = |
| 247 | EndsWith(optarg, "/") ? optarg : std::string(optarg) + "/"; |
| 248 | } |
| 249 | } |
| Tom Cherry | b5f2ec0 | 2019-11-08 17:54:27 -0800 | [diff] [blame] | 250 | break; |
| Tom Cherry | 3f1bce8 | 2019-06-05 09:13:11 -0700 | [diff] [blame] | 251 | case 'h': |
| 252 | PrintUsage(); |
| 253 | return EXIT_FAILURE; |
| 254 | case 'p': |
| 255 | passwd_files.emplace_back(optarg); |
| 256 | break; |
| 257 | default: |
| 258 | std::cerr << "getprop: getopt returned invalid result: " << arg << std::endl; |
| 259 | return EXIT_FAILURE; |
| 260 | } |
| Tom Cherry | de6bd50 | 2018-02-13 16:50:08 -0800 | [diff] [blame] | 261 | } |
| Tom Cherry | 194b5d1 | 2018-05-09 17:38:30 -0700 | [diff] [blame] | 262 | |
| Tom Cherry | 3f1bce8 | 2019-06-05 09:13:11 -0700 | [diff] [blame] | 263 | argc -= optind; |
| 264 | argv += optind; |
| 265 | |
| Daniel Norman | f597fa5 | 2020-11-09 17:28:24 -0800 | [diff] [blame] | 266 | // If provided, use the partition map to check multiple init rc files. |
| 267 | // Otherwise, check a single init rc file. |
| 268 | if ((!partition_map.empty() && argc != 0) || (partition_map.empty() && argc != 1)) { |
| Tom Cherry | 3f1bce8 | 2019-06-05 09:13:11 -0700 | [diff] [blame] | 269 | PrintUsage(); |
| 270 | return EXIT_FAILURE; |
| Tom Cherry | 194b5d1 | 2018-05-09 17:38:30 -0700 | [diff] [blame] | 271 | } |
| 272 | |
| Steven Moreland | 422a758 | 2019-10-15 14:53:19 -0700 | [diff] [blame] | 273 | auto interface_inheritance_hierarchy_map = ReadInterfaceInheritanceHierarchy(); |
| Bernie Innocenti | cecebbb | 2020-02-06 03:49:33 +0900 | [diff] [blame] | 274 | if (!interface_inheritance_hierarchy_map.ok()) { |
| Daniel Norman | d2533c3 | 2019-08-02 15:13:50 -0700 | [diff] [blame] | 275 | LOG(ERROR) << interface_inheritance_hierarchy_map.error(); |
| 276 | return EXIT_FAILURE; |
| 277 | } |
| 278 | SetKnownInterfaces(*interface_inheritance_hierarchy_map); |
| 279 | |
| Jooyung Han | 39e8be4 | 2024-02-16 17:23:34 +0900 | [diff] [blame] | 280 | if (auto result = InitializeHostPropertyInfoArea(property_infos); !result.ok()) { |
| 281 | LOG(ERROR) << result.error(); |
| Tom Cherry | b5f2ec0 | 2019-11-08 17:54:27 -0800 | [diff] [blame] | 282 | return EXIT_FAILURE; |
| 283 | } |
| 284 | |
| Daniel Norman | f597fa5 | 2020-11-09 17:28:24 -0800 | [diff] [blame] | 285 | if (!partition_map.empty()) { |
| 286 | std::vector<std::string> vendor_prefixes; |
| 287 | for (const auto& partition : {"vendor", "odm"}) { |
| 288 | if (partition_map.find(partition) != partition_map.end()) { |
| 289 | vendor_prefixes.push_back(partition_map.at(partition)); |
| 290 | } |
| 291 | } |
| 292 | InitializeHostSubcontext(vendor_prefixes); |
| 293 | } |
| 294 | |
| Tom Cherry | d52a5b3 | 2019-07-22 16:05:36 -0700 | [diff] [blame] | 295 | const BuiltinFunctionMap& function_map = GetBuiltinFunctionMap(); |
| Tom Cherry | de6bd50 | 2018-02-13 16:50:08 -0800 | [diff] [blame] | 296 | Action::set_function_map(&function_map); |
| 297 | ActionManager& am = ActionManager::GetInstance(); |
| 298 | ServiceList& sl = ServiceList::GetInstance(); |
| 299 | Parser parser; |
| Jooyung Han | d51fb54 | 2024-08-21 16:25:10 +0900 | [diff] [blame] | 300 | parser.AddSectionParser("service", std::make_unique<ServiceParser>(&sl, GetSubcontext())); |
| Daniel Norman | f597fa5 | 2020-11-09 17:28:24 -0800 | [diff] [blame] | 301 | parser.AddSectionParser("on", std::make_unique<ActionParser>(&am, GetSubcontext())); |
| Tom Cherry | 863d808 | 2018-06-12 14:40:38 -0700 | [diff] [blame] | 302 | parser.AddSectionParser("import", std::make_unique<HostImportParser>()); |
| Tom Cherry | de6bd50 | 2018-02-13 16:50:08 -0800 | [diff] [blame] | 303 | |
| Daniel Norman | f597fa5 | 2020-11-09 17:28:24 -0800 | [diff] [blame] | 304 | if (!partition_map.empty()) { |
| 305 | for (const auto& p : partition_search_order) { |
| 306 | if (partition_map.find(p) != partition_map.end()) { |
| 307 | parser.ParseConfig(partition_map.at(p) + "etc/init"); |
| 308 | } |
| 309 | } |
| 310 | } else { |
| Jingwen Chen | f643b35 | 2023-03-16 16:22:25 +0000 | [diff] [blame] | 311 | if (!parser.ParseConfigFileInsecure(*argv, true /* follow_symlinks */)) { |
| 312 | // Follow symlinks as inputs during build execution in Bazel's |
| 313 | // execution root are symlinks, unlike Soong or Make. |
| Daniel Norman | f597fa5 | 2020-11-09 17:28:24 -0800 | [diff] [blame] | 314 | LOG(ERROR) << "Failed to open init rc script '" << *argv << "'"; |
| 315 | return EXIT_FAILURE; |
| 316 | } |
| Tom Cherry | de6bd50 | 2018-02-13 16:50:08 -0800 | [diff] [blame] | 317 | } |
| Jooyung Han | 95c4242 | 2024-08-21 13:57:44 +0900 | [diff] [blame] | 318 | |
| Tom Cherry | 6737a6b | 2019-08-05 15:03:58 -0700 | [diff] [blame] | 319 | size_t failures = parser.parse_error_count() + am.CheckAllCommands() + sl.CheckAllCommands(); |
| Tom Cherry | 4772f1d | 2019-07-30 09:34:41 -0700 | [diff] [blame] | 320 | if (failures > 0) { |
| Daniel Norman | f597fa5 | 2020-11-09 17:28:24 -0800 | [diff] [blame] | 321 | LOG(ERROR) << "Failed to parse init scripts with " << failures << " error(s)."; |
| Tom Cherry | 863d808 | 2018-06-12 14:40:38 -0700 | [diff] [blame] | 322 | return EXIT_FAILURE; |
| Tom Cherry | de6bd50 | 2018-02-13 16:50:08 -0800 | [diff] [blame] | 323 | } |
| Jooyung Han | 95c4242 | 2024-08-21 13:57:44 +0900 | [diff] [blame] | 324 | |
| 325 | for (const auto& service : sl) { |
| 326 | if (const auto& result = CheckInterfaceInheritanceHierarchy( |
| 327 | service->interfaces(), *interface_inheritance_hierarchy_map); |
| 328 | !result.ok()) { |
| 329 | LOG(ERROR) << service->filename() << ": invalid interface in service '" |
| 330 | << service->name() << "': " << result.error(); |
| 331 | return EXIT_FAILURE; |
| 332 | } |
| 333 | } |
| 334 | |
| Tom Cherry | 863d808 | 2018-06-12 14:40:38 -0700 | [diff] [blame] | 335 | return EXIT_SUCCESS; |
| Tom Cherry | de6bd50 | 2018-02-13 16:50:08 -0800 | [diff] [blame] | 336 | } |
| 337 | |
| 338 | } // namespace init |
| 339 | } // namespace android |
| 340 | |
| 341 | int main(int argc, char** argv) { |
| Tom Cherry | 863d808 | 2018-06-12 14:40:38 -0700 | [diff] [blame] | 342 | return android::init::main(argc, argv); |
| Tom Cherry | de6bd50 | 2018-02-13 16:50:08 -0800 | [diff] [blame] | 343 | } |