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