diff --git a/init/host_import_parser.cpp b/init/host_import_parser.cpp index faf6fc1e3..93e363ff3 100644 --- a/init/host_import_parser.cpp +++ b/init/host_import_parser.cpp @@ -23,22 +23,17 @@ using android::base::StartsWith; namespace android { namespace init { -Result HostImportParser::ParseSection(std::vector&& args, - const std::string& filename, int line) { +Result HostImportParser::ParseSection(std::vector&& args, const std::string&, + int) { if (args.size() != 2) { return Error() << "single argument needed for import\n"; } - auto import_path = args[1]; + return Success(); +} - if (StartsWith(import_path, "/system") || StartsWith(import_path, "/product") || - StartsWith(import_path, "/odm") || StartsWith(import_path, "/vendor")) { - import_path = out_dir_ + "/" + import_path; - } else { - import_path = out_dir_ + "/root/" + import_path; - } - - return ImportParser::ParseSection({"import", import_path}, filename, line); +Result HostImportParser::ParseLineSection(std::vector&&, int) { + return Error() << "Unexpected line found after import statement"; } } // namespace init diff --git a/init/host_import_parser.h b/init/host_import_parser.h index e2980b2ae..52b889196 100644 --- a/init/host_import_parser.h +++ b/init/host_import_parser.h @@ -19,21 +19,16 @@ #include #include -#include "import_parser.h" #include "parser.h" namespace android { namespace init { -class HostImportParser : public ImportParser { +class HostImportParser : public SectionParser { public: - HostImportParser(const std::string& out_dir, Parser* parser) - : ImportParser(parser), out_dir_(out_dir) {} - Result ParseSection(std::vector&& args, const std::string& filename, - int line) override; - - private: - std::string out_dir_; + HostImportParser() {} + Result ParseSection(std::vector&& args, const std::string&, int) override; + Result ParseLineSection(std::vector&&, int) override; }; } // namespace init diff --git a/init/host_init_verifier.cpp b/init/host_init_verifier.cpp index d6884af91..3e510e72c 100644 --- a/init/host_init_verifier.cpp +++ b/init/host_init_verifier.cpp @@ -17,6 +17,7 @@ #include #include #include +#include #include #include @@ -45,11 +46,11 @@ using android::base::ParseInt; using android::base::ReadFileToString; using android::base::Split; -static std::string out_dir; +static std::string passwd_file; static std::vector> GetVendorPasswd() { std::string passwd; - if (!ReadFileToString(out_dir + "/vendor/etc/passwd", &passwd)) { + if (!ReadFileToString(passwd_file, &passwd)) { return {}; } @@ -118,20 +119,14 @@ static Result do_stub(const BuiltinArguments& args) { int main(int argc, char** argv) { android::base::InitLogging(argv, &android::base::StdioLogger); android::base::SetMinimumLogSeverity(android::base::ERROR); - if (argc != 3) { - LOG(ERROR) << "Usage: " << argv[0] << " "; - return -1; + + if (argc != 2 && argc != 3) { + LOG(ERROR) << "Usage: " << argv[0] << " [passwd file]"; + return EXIT_FAILURE; } - out_dir = argv[1]; - - auto properties = Split(argv[2], ","); - for (const auto& property : properties) { - auto split_property = Split(property, "="); - if (split_property.size() != 2) { - continue; - } - property_set(split_property[0], split_property[1]); + if (argc == 3) { + passwd_file = argv[2]; } const BuiltinFunctionMap function_map; @@ -141,22 +136,23 @@ int main(int argc, char** argv) { Parser parser; parser.AddSectionParser("service", std::make_unique(&sl, nullptr)); parser.AddSectionParser("on", std::make_unique(&am, nullptr)); - parser.AddSectionParser("import", std::make_unique(out_dir, &parser)); + parser.AddSectionParser("import", std::make_unique()); - if (!parser.ParseConfig(argv[1] + "/root/init.rc"s)) { - LOG(ERROR) << "Failed to find root init.rc script"; - return -1; + if (!parser.ParseConfig(argv[1])) { + LOG(ERROR) << "Failed to open init rc script '" << argv[1] << "'"; + return EXIT_FAILURE; } if (parser.parse_error_count() > 0) { - LOG(ERROR) << "Init script parsing failed with " << parser.parse_error_count() << " errors"; - return -1; + LOG(ERROR) << "Failed to parse init script '" << argv[1] << "' with " + << parser.parse_error_count() << " errors"; + return EXIT_FAILURE; } - return 0; + return EXIT_SUCCESS; } } // namespace init } // namespace android int main(int argc, char** argv) { - android::init::main(argc, argv); + return android::init::main(argc, argv); }