summaryrefslogtreecommitdiffstats
path: root/init
diff options
context:
space:
mode:
authorTom Cherry2018-06-15 12:03:42 -0500
committerGerrit Code Review2018-06-15 12:03:42 -0500
commit4632f4e86868a6d9418a4a54c26d36a363360563 (patch)
tree0b95c8d3a2b78169570d8786da7b1b2a35e1521d /init
parent9d9c91acdc3fa4e7ebcd5314adf8cbe577694f54 (diff)
parent863d808c2e7badcbcd43eee45ae7bbb49f2a1e2c (diff)
downloadplatform-system-core-4632f4e86868a6d9418a4a54c26d36a363360563.tar.gz
platform-system-core-4632f4e86868a6d9418a4a54c26d36a363360563.tar.xz
platform-system-core-4632f4e86868a6d9418a4a54c26d36a363360563.zip
Merge "Relax host init parser to work with the build system"
Diffstat (limited to 'init')
-rw-r--r--init/host_import_parser.cpp17
-rw-r--r--init/host_import_parser.h13
-rw-r--r--init/host_init_verifier.cpp40
3 files changed, 28 insertions, 42 deletions
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;
23namespace android { 23namespace android {
24namespace init { 24namespace init {
25 25
26Result<Success> HostImportParser::ParseSection(std::vector<std::string>&& args, 26Result<Success> HostImportParser::ParseSection(std::vector<std::string>&& args, const std::string&,
27 const std::string& filename, int line) { 27 int) {
28 if (args.size() != 2) { 28 if (args.size() != 2) {
29 return Error() << "single argument needed for import\n"; 29 return Error() << "single argument needed for import\n";
30 } 30 }
31 31
32 auto import_path = args[1]; 32 return Success();
33 33}
34 if (StartsWith(import_path, "/system") || StartsWith(import_path, "/product") ||
35 StartsWith(import_path, "/odm") || StartsWith(import_path, "/vendor")) {
36 import_path = out_dir_ + "/" + import_path;
37 } else {
38 import_path = out_dir_ + "/root/" + import_path;
39 }
40 34
41 return ImportParser::ParseSection({"import", import_path}, filename, line); 35Result<Success> HostImportParser::ParseLineSection(std::vector<std::string>&&, int) {
36 return Error() << "Unexpected line found after import statement";
42} 37}
43 38
44} // namespace init 39} // 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 @@
19#include <string> 19#include <string>
20#include <vector> 20#include <vector>
21 21
22#include "import_parser.h"
23#include "parser.h" 22#include "parser.h"
24 23
25namespace android { 24namespace android {
26namespace init { 25namespace init {
27 26
28class HostImportParser : public ImportParser { 27class HostImportParser : public SectionParser {
29 public: 28 public:
30 HostImportParser(const std::string& out_dir, Parser* parser) 29 HostImportParser() {}
31 : ImportParser(parser), out_dir_(out_dir) {} 30 Result<Success> ParseSection(std::vector<std::string>&& args, const std::string&, int) override;
32 Result<Success> ParseSection(std::vector<std::string>&& args, const std::string& filename, 31 Result<Success> ParseLineSection(std::vector<std::string>&&, int) override;
33 int line) override;
34
35 private:
36 std::string out_dir_;
37}; 32};
38 33
39} // namespace init 34} // 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 @@
17#include <errno.h> 17#include <errno.h>
18#include <pwd.h> 18#include <pwd.h>
19#include <stdio.h> 19#include <stdio.h>
20#include <stdlib.h>
20 21
21#include <iostream> 22#include <iostream>
22#include <string> 23#include <string>
@@ -45,11 +46,11 @@ using android::base::ParseInt;
45using android::base::ReadFileToString; 46using android::base::ReadFileToString;
46using android::base::Split; 47using android::base::Split;
47 48
48static std::string out_dir; 49static std::string passwd_file;
49 50
50static std::vector<std::pair<std::string, int>> GetVendorPasswd() { 51static std::vector<std::pair<std::string, int>> GetVendorPasswd() {
51 std::string passwd; 52 std::string passwd;
52 if (!ReadFileToString(out_dir + "/vendor/etc/passwd", &passwd)) { 53 if (!ReadFileToString(passwd_file, &passwd)) {
53 return {}; 54 return {};
54 } 55 }
55 56
@@ -118,20 +119,14 @@ static Result<Success> do_stub(const BuiltinArguments& args) {
118int main(int argc, char** argv) { 119int main(int argc, char** argv) {
119 android::base::InitLogging(argv, &android::base::StdioLogger); 120 android::base::InitLogging(argv, &android::base::StdioLogger);
120 android::base::SetMinimumLogSeverity(android::base::ERROR); 121 android::base::SetMinimumLogSeverity(android::base::ERROR);
121 if (argc != 3) {
122 LOG(ERROR) << "Usage: " << argv[0] << " <out directory> <properties>";
123 return -1;
124 }
125 122
126 out_dir = argv[1]; 123 if (argc != 2 && argc != 3) {
124 LOG(ERROR) << "Usage: " << argv[0] << " <init rc file> [passwd file]";
125 return EXIT_FAILURE;
126 }
127 127
128 auto properties = Split(argv[2], ","); 128 if (argc == 3) {
129 for (const auto& property : properties) { 129 passwd_file = argv[2];
130 auto split_property = Split(property, "=");
131 if (split_property.size() != 2) {
132 continue;
133 }
134 property_set(split_property[0], split_property[1]);
135 } 130 }
136 131
137 const BuiltinFunctionMap function_map; 132 const BuiltinFunctionMap function_map;
@@ -141,22 +136,23 @@ int main(int argc, char** argv) {
141 Parser parser; 136 Parser parser;
142 parser.AddSectionParser("service", std::make_unique<ServiceParser>(&sl, nullptr)); 137 parser.AddSectionParser("service", std::make_unique<ServiceParser>(&sl, nullptr));
143 parser.AddSectionParser("on", std::make_unique<ActionParser>(&am, nullptr)); 138 parser.AddSectionParser("on", std::make_unique<ActionParser>(&am, nullptr));
144 parser.AddSectionParser("import", std::make_unique<HostImportParser>(out_dir, &parser)); 139 parser.AddSectionParser("import", std::make_unique<HostImportParser>());
145 140
146 if (!parser.ParseConfig(argv[1] + "/root/init.rc"s)) { 141 if (!parser.ParseConfig(argv[1])) {
147 LOG(ERROR) << "Failed to find root init.rc script"; 142 LOG(ERROR) << "Failed to open init rc script '" << argv[1] << "'";
148 return -1; 143 return EXIT_FAILURE;
149 } 144 }
150 if (parser.parse_error_count() > 0) { 145 if (parser.parse_error_count() > 0) {
151 LOG(ERROR) << "Init script parsing failed with " << parser.parse_error_count() << " errors"; 146 LOG(ERROR) << "Failed to parse init script '" << argv[1] << "' with "
152 return -1; 147 << parser.parse_error_count() << " errors";
148 return EXIT_FAILURE;
153 } 149 }
154 return 0; 150 return EXIT_SUCCESS;
155} 151}
156 152
157} // namespace init 153} // namespace init
158} // namespace android 154} // namespace android
159 155
160int main(int argc, char** argv) { 156int main(int argc, char** argv) {
161 android::init::main(argc, argv); 157 return android::init::main(argc, argv);
162} 158}