Loading init/action_parser.cpp +2 −7 Original line number Original line Diff line number Diff line Loading @@ -121,13 +121,8 @@ Result<void> ActionParser::ParseSection(std::vector<std::string>&& args, } } Subcontext* action_subcontext = nullptr; Subcontext* action_subcontext = nullptr; if (subcontexts_) { if (subcontext_ && subcontext_->PathMatchesSubcontext(filename)) { for (auto& subcontext : *subcontexts_) { action_subcontext = subcontext_; if (StartsWith(filename, subcontext.path_prefix())) { action_subcontext = &subcontext; break; } } } } std::string event_trigger; std::string event_trigger; Loading init/action_parser.h +3 −3 Original line number Original line Diff line number Diff line Loading @@ -30,8 +30,8 @@ namespace init { class ActionParser : public SectionParser { class ActionParser : public SectionParser { public: public: ActionParser(ActionManager* action_manager, std::vector<Subcontext>* subcontexts) ActionParser(ActionManager* action_manager, Subcontext* subcontext) : action_manager_(action_manager), subcontexts_(subcontexts), action_(nullptr) {} : action_manager_(action_manager), subcontext_(subcontext), action_(nullptr) {} Result<void> ParseSection(std::vector<std::string>&& args, const std::string& filename, Result<void> ParseSection(std::vector<std::string>&& args, const std::string& filename, int line) override; int line) override; Result<void> ParseLineSection(std::vector<std::string>&& args, int line) override; Result<void> ParseLineSection(std::vector<std::string>&& args, int line) override; Loading @@ -39,7 +39,7 @@ class ActionParser : public SectionParser { private: private: ActionManager* action_manager_; ActionManager* action_manager_; std::vector<Subcontext>* subcontexts_; Subcontext* subcontext_; std::unique_ptr<Action> action_; std::unique_ptr<Action> action_; }; }; Loading init/init.cpp +8 −7 Original line number Original line Diff line number Diff line Loading @@ -103,7 +103,7 @@ static std::string shutdown_command; static bool do_shutdown = false; static bool do_shutdown = false; static bool load_debug_prop = false; static bool load_debug_prop = false; static std::vector<Subcontext>* subcontexts; static std::unique_ptr<Subcontext> subcontext; void DumpState() { void DumpState() { ServiceList::GetInstance().DumpState(); ServiceList::GetInstance().DumpState(); Loading @@ -113,9 +113,10 @@ void DumpState() { Parser CreateParser(ActionManager& action_manager, ServiceList& service_list) { Parser CreateParser(ActionManager& action_manager, ServiceList& service_list) { Parser parser; Parser parser; parser.AddSectionParser( parser.AddSectionParser("service", std::make_unique<ServiceParser>( "service", std::make_unique<ServiceParser>(&service_list, subcontexts, std::nullopt)); &service_list, subcontext.get(), std::nullopt)); parser.AddSectionParser("on", std::make_unique<ActionParser>(&action_manager, subcontexts)); parser.AddSectionParser("on", std::make_unique<ActionParser>(&action_manager, subcontext.get())); parser.AddSectionParser("import", std::make_unique<ImportParser>(&parser)); parser.AddSectionParser("import", std::make_unique<ImportParser>(&parser)); return parser; return parser; Loading @@ -125,8 +126,8 @@ Parser CreateParser(ActionManager& action_manager, ServiceList& service_list) { Parser CreateServiceOnlyParser(ServiceList& service_list) { Parser CreateServiceOnlyParser(ServiceList& service_list) { Parser parser; Parser parser; parser.AddSectionParser( parser.AddSectionParser("service", std::make_unique<ServiceParser>( "service", std::make_unique<ServiceParser>(&service_list, subcontexts, std::nullopt)); &service_list, subcontext.get(), std::nullopt)); return parser; return parser; } } Loading Loading @@ -749,7 +750,7 @@ int SecondStageMain(int argc, char** argv) { PLOG(FATAL) << "SetupMountNamespaces failed"; PLOG(FATAL) << "SetupMountNamespaces failed"; } } subcontexts = InitializeSubcontexts(); subcontext = InitializeSubcontext(); ActionManager& am = ActionManager::GetInstance(); ActionManager& am = ActionManager::GetInstance(); ServiceList& sm = ServiceList::GetInstance(); ServiceList& sm = ServiceList::GetInstance(); Loading init/property_service.cpp +10 −5 Original line number Original line Diff line number Diff line Loading @@ -530,7 +530,7 @@ uint32_t InitPropertySet(const std::string& name, const std::string& value) { uint32_t result = 0; uint32_t result = 0; ucred cr = {.pid = 1, .uid = 0, .gid = 0}; ucred cr = {.pid = 1, .uid = 0, .gid = 0}; std::string error; std::string error; result = HandlePropertySet(name, value, kInitContext.c_str(), cr, nullptr, &error); result = HandlePropertySet(name, value, kInitContext, cr, nullptr, &error); if (result != PROP_SUCCESS) { if (result != PROP_SUCCESS) { LOG(ERROR) << "Init cannot set '" << name << "' to '" << value << "': " << error; LOG(ERROR) << "Init cannot set '" << name << "' to '" << value << "': " << error; } } Loading Loading @@ -645,11 +645,16 @@ static void LoadProperties(char* data, const char* filter, const char* filename, char *key, *value, *eol, *sol, *tmp, *fn; char *key, *value, *eol, *sol, *tmp, *fn; size_t flen = 0; size_t flen = 0; const char* context = kInitContext.c_str(); static constexpr const char* const kVendorPathPrefixes[2] = { "/vendor", "/odm", }; const char* context = kInitContext; if (SelinuxGetVendorAndroidVersion() >= __ANDROID_API_P__) { if (SelinuxGetVendorAndroidVersion() >= __ANDROID_API_P__) { for (const auto& [path_prefix, secontext] : paths_and_secontexts) { for (const auto& vendor_path_prefix : kVendorPathPrefixes) { if (StartsWith(filename, path_prefix)) { if (StartsWith(filename, vendor_path_prefix)) { context = secontext; context = kVendorContext; } } } } } } Loading init/service_parser.cpp +2 −7 Original line number Original line Diff line number Diff line Loading @@ -537,13 +537,8 @@ Result<void> ServiceParser::ParseSection(std::vector<std::string>&& args, filename_ = filename; filename_ = filename; Subcontext* restart_action_subcontext = nullptr; Subcontext* restart_action_subcontext = nullptr; if (subcontexts_) { if (subcontext_ && subcontext_->PathMatchesSubcontext(filename)) { for (auto& subcontext : *subcontexts_) { restart_action_subcontext = subcontext_; if (StartsWith(filename, subcontext.path_prefix())) { restart_action_subcontext = &subcontext; break; } } } } std::vector<std::string> str_args(args.begin() + 2, args.end()); std::vector<std::string> str_args(args.begin() + 2, args.end()); Loading Loading
init/action_parser.cpp +2 −7 Original line number Original line Diff line number Diff line Loading @@ -121,13 +121,8 @@ Result<void> ActionParser::ParseSection(std::vector<std::string>&& args, } } Subcontext* action_subcontext = nullptr; Subcontext* action_subcontext = nullptr; if (subcontexts_) { if (subcontext_ && subcontext_->PathMatchesSubcontext(filename)) { for (auto& subcontext : *subcontexts_) { action_subcontext = subcontext_; if (StartsWith(filename, subcontext.path_prefix())) { action_subcontext = &subcontext; break; } } } } std::string event_trigger; std::string event_trigger; Loading
init/action_parser.h +3 −3 Original line number Original line Diff line number Diff line Loading @@ -30,8 +30,8 @@ namespace init { class ActionParser : public SectionParser { class ActionParser : public SectionParser { public: public: ActionParser(ActionManager* action_manager, std::vector<Subcontext>* subcontexts) ActionParser(ActionManager* action_manager, Subcontext* subcontext) : action_manager_(action_manager), subcontexts_(subcontexts), action_(nullptr) {} : action_manager_(action_manager), subcontext_(subcontext), action_(nullptr) {} Result<void> ParseSection(std::vector<std::string>&& args, const std::string& filename, Result<void> ParseSection(std::vector<std::string>&& args, const std::string& filename, int line) override; int line) override; Result<void> ParseLineSection(std::vector<std::string>&& args, int line) override; Result<void> ParseLineSection(std::vector<std::string>&& args, int line) override; Loading @@ -39,7 +39,7 @@ class ActionParser : public SectionParser { private: private: ActionManager* action_manager_; ActionManager* action_manager_; std::vector<Subcontext>* subcontexts_; Subcontext* subcontext_; std::unique_ptr<Action> action_; std::unique_ptr<Action> action_; }; }; Loading
init/init.cpp +8 −7 Original line number Original line Diff line number Diff line Loading @@ -103,7 +103,7 @@ static std::string shutdown_command; static bool do_shutdown = false; static bool do_shutdown = false; static bool load_debug_prop = false; static bool load_debug_prop = false; static std::vector<Subcontext>* subcontexts; static std::unique_ptr<Subcontext> subcontext; void DumpState() { void DumpState() { ServiceList::GetInstance().DumpState(); ServiceList::GetInstance().DumpState(); Loading @@ -113,9 +113,10 @@ void DumpState() { Parser CreateParser(ActionManager& action_manager, ServiceList& service_list) { Parser CreateParser(ActionManager& action_manager, ServiceList& service_list) { Parser parser; Parser parser; parser.AddSectionParser( parser.AddSectionParser("service", std::make_unique<ServiceParser>( "service", std::make_unique<ServiceParser>(&service_list, subcontexts, std::nullopt)); &service_list, subcontext.get(), std::nullopt)); parser.AddSectionParser("on", std::make_unique<ActionParser>(&action_manager, subcontexts)); parser.AddSectionParser("on", std::make_unique<ActionParser>(&action_manager, subcontext.get())); parser.AddSectionParser("import", std::make_unique<ImportParser>(&parser)); parser.AddSectionParser("import", std::make_unique<ImportParser>(&parser)); return parser; return parser; Loading @@ -125,8 +126,8 @@ Parser CreateParser(ActionManager& action_manager, ServiceList& service_list) { Parser CreateServiceOnlyParser(ServiceList& service_list) { Parser CreateServiceOnlyParser(ServiceList& service_list) { Parser parser; Parser parser; parser.AddSectionParser( parser.AddSectionParser("service", std::make_unique<ServiceParser>( "service", std::make_unique<ServiceParser>(&service_list, subcontexts, std::nullopt)); &service_list, subcontext.get(), std::nullopt)); return parser; return parser; } } Loading Loading @@ -749,7 +750,7 @@ int SecondStageMain(int argc, char** argv) { PLOG(FATAL) << "SetupMountNamespaces failed"; PLOG(FATAL) << "SetupMountNamespaces failed"; } } subcontexts = InitializeSubcontexts(); subcontext = InitializeSubcontext(); ActionManager& am = ActionManager::GetInstance(); ActionManager& am = ActionManager::GetInstance(); ServiceList& sm = ServiceList::GetInstance(); ServiceList& sm = ServiceList::GetInstance(); Loading
init/property_service.cpp +10 −5 Original line number Original line Diff line number Diff line Loading @@ -530,7 +530,7 @@ uint32_t InitPropertySet(const std::string& name, const std::string& value) { uint32_t result = 0; uint32_t result = 0; ucred cr = {.pid = 1, .uid = 0, .gid = 0}; ucred cr = {.pid = 1, .uid = 0, .gid = 0}; std::string error; std::string error; result = HandlePropertySet(name, value, kInitContext.c_str(), cr, nullptr, &error); result = HandlePropertySet(name, value, kInitContext, cr, nullptr, &error); if (result != PROP_SUCCESS) { if (result != PROP_SUCCESS) { LOG(ERROR) << "Init cannot set '" << name << "' to '" << value << "': " << error; LOG(ERROR) << "Init cannot set '" << name << "' to '" << value << "': " << error; } } Loading Loading @@ -645,11 +645,16 @@ static void LoadProperties(char* data, const char* filter, const char* filename, char *key, *value, *eol, *sol, *tmp, *fn; char *key, *value, *eol, *sol, *tmp, *fn; size_t flen = 0; size_t flen = 0; const char* context = kInitContext.c_str(); static constexpr const char* const kVendorPathPrefixes[2] = { "/vendor", "/odm", }; const char* context = kInitContext; if (SelinuxGetVendorAndroidVersion() >= __ANDROID_API_P__) { if (SelinuxGetVendorAndroidVersion() >= __ANDROID_API_P__) { for (const auto& [path_prefix, secontext] : paths_and_secontexts) { for (const auto& vendor_path_prefix : kVendorPathPrefixes) { if (StartsWith(filename, path_prefix)) { if (StartsWith(filename, vendor_path_prefix)) { context = secontext; context = kVendorContext; } } } } } } Loading
init/service_parser.cpp +2 −7 Original line number Original line Diff line number Diff line Loading @@ -537,13 +537,8 @@ Result<void> ServiceParser::ParseSection(std::vector<std::string>&& args, filename_ = filename; filename_ = filename; Subcontext* restart_action_subcontext = nullptr; Subcontext* restart_action_subcontext = nullptr; if (subcontexts_) { if (subcontext_ && subcontext_->PathMatchesSubcontext(filename)) { for (auto& subcontext : *subcontexts_) { restart_action_subcontext = subcontext_; if (StartsWith(filename, subcontext.path_prefix())) { restart_action_subcontext = &subcontext; break; } } } } std::vector<std::string> str_args(args.begin() + 2, args.end()); std::vector<std::string> str_args(args.begin() + 2, args.end()); Loading