Treblize init.rc location
Treblization requires to locate partner-specific modules in its own
partition. So their own init.rc file could be located in /odm or
/vendor.
This CL is to support those locations for the init.rc.
Additionally thic CL modified import parser to support importing a
relative path.
Test: building succeeded and tested on sailfish with enabling early
mount.
Bug: 35269867
Change-Id: I1bce924a32c8a2b53fb5d981d35d758cf9ddd9a6
diff --git a/init/builtins.cpp b/init/builtins.cpp
index 2388edc..6dd1cbb 100644
--- a/init/builtins.cpp
+++ b/init/builtins.cpp
@@ -476,15 +476,18 @@
static void import_late(const std::vector<std::string>& args, size_t start_index, size_t end_index) {
Parser& parser = Parser::GetInstance();
if (end_index <= start_index) {
- // Use the default set if no path is given
- static const std::vector<std::string> init_directories = {
- "/system/etc/init",
- "/vendor/etc/init",
- "/odm/etc/init"
- };
-
- for (const auto& dir : init_directories) {
- parser.ParseConfig(dir);
+ // Fallbacks for partitions on which early mount isn't enabled.
+ if (!parser.is_system_etc_init_loaded()) {
+ parser.ParseConfig("/system/etc/init");
+ parser.set_is_system_etc_init_loaded(true);
+ }
+ if (!parser.is_vendor_etc_init_loaded()) {
+ parser.ParseConfig("/vendor/etc/init");
+ parser.set_is_vendor_etc_init_loaded(true);
+ }
+ if (!parser.is_odm_etc_init_loaded()) {
+ parser.ParseConfig("/odm/etc/init");
+ parser.set_is_odm_etc_init_loaded(true);
}
} else {
for (size_t i = start_index; i < end_index; ++i) {
diff --git a/init/init.cpp b/init/init.cpp
index 3cb1276..9b14467 100644
--- a/init/init.cpp
+++ b/init/init.cpp
@@ -992,8 +992,16 @@
std::string bootscript = property_get("ro.boot.init_rc");
if (bootscript.empty()) {
parser.ParseConfig("/init.rc");
+ parser.set_is_system_etc_init_loaded(
+ parser.ParseConfig("/system/etc/init"));
+ parser.set_is_vendor_etc_init_loaded(
+ parser.ParseConfig("/vendor/etc/init"));
+ parser.set_is_odm_etc_init_loaded(parser.ParseConfig("/odm/etc/init"));
} else {
parser.ParseConfig(bootscript);
+ parser.set_is_system_etc_init_loaded(true);
+ parser.set_is_vendor_etc_init_loaded(true);
+ parser.set_is_odm_etc_init_loaded(true);
}
ActionManager& am = ActionManager::GetInstance();
diff --git a/init/init_parser.h b/init/init_parser.h
index 5ed30ad..f66ba52 100644
--- a/init/init_parser.h
+++ b/init/init_parser.h
@@ -41,6 +41,18 @@
bool ParseConfig(const std::string& path);
void AddSectionParser(const std::string& name,
std::unique_ptr<SectionParser> parser);
+ void set_is_system_etc_init_loaded(bool loaded) {
+ is_system_etc_init_loaded_ = loaded;
+ }
+ void set_is_vendor_etc_init_loaded(bool loaded) {
+ is_vendor_etc_init_loaded_ = loaded;
+ }
+ void set_is_odm_etc_init_loaded(bool loaded) {
+ is_odm_etc_init_loaded_ = loaded;
+ }
+ bool is_system_etc_init_loaded() { return is_system_etc_init_loaded_; }
+ bool is_vendor_etc_init_loaded() { return is_vendor_etc_init_loaded_; }
+ bool is_odm_etc_init_loaded() { return is_odm_etc_init_loaded_; }
private:
Parser();
@@ -50,6 +62,9 @@
bool ParseConfigDir(const std::string& path);
std::map<std::string, std::unique_ptr<SectionParser>> section_parsers_;
+ bool is_system_etc_init_loaded_ = false;
+ bool is_vendor_etc_init_loaded_ = false;
+ bool is_odm_etc_init_loaded_ = false;
};
#endif