Loading init/builtins.cpp +26 −0 Original line number Diff line number Diff line Loading @@ -240,6 +240,29 @@ static Result<Success> do_insmod(const BuiltinArguments& args) { return Success(); } static Result<Success> do_interface_restart(const BuiltinArguments& args) { Service* svc = ServiceList::GetInstance().FindInterface(args[1]); if (!svc) return Error() << "interface " << args[1] << " not found"; svc->Restart(); return Success(); } static Result<Success> do_interface_start(const BuiltinArguments& args) { Service* svc = ServiceList::GetInstance().FindInterface(args[1]); if (!svc) return Error() << "interface " << args[1] << " not found"; if (auto result = svc->Start(); !result) { return Error() << "Could not start interface: " << result.error(); } return Success(); } static Result<Success> do_interface_stop(const BuiltinArguments& args) { Service* svc = ServiceList::GetInstance().FindInterface(args[1]); if (!svc) return Error() << "interface " << args[1] << " not found"; svc->Stop(); return Success(); } // mkdir <path> [mode] [owner] [group] static Result<Success> do_mkdir(const BuiltinArguments& args) { mode_t mode = 0755; Loading Loading @@ -1050,6 +1073,9 @@ const BuiltinFunctionMap::Map& BuiltinFunctionMap::map() const { {"init_user0", {0, 0, {false, do_init_user0}}}, {"insmod", {1, kMax, {true, do_insmod}}}, {"installkey", {1, 1, {false, do_installkey}}}, {"interface_restart", {1, 1, {false, do_interface_restart}}}, {"interface_start", {1, 1, {false, do_interface_start}}}, {"interface_stop", {1, 1, {false, do_interface_stop}}}, {"load_persist_props", {0, 0, {false, do_load_persist_props}}}, {"load_system_props", {0, 0, {false, do_load_system_props}}}, {"loglevel", {1, 1, {false, do_loglevel}}}, Loading init/init.cpp +17 −28 Original line number Diff line number Diff line Loading @@ -297,40 +297,29 @@ void HandleControlMessage(const std::string& msg, const std::string& name, pid_t const ControlMessageFunction& function = it->second; if (function.target == ControlTarget::SERVICE) { Service* svc = ServiceList::GetInstance().FindService(name); if (svc == nullptr) { LOG(ERROR) << "No such service '" << name << "' for ctl." << msg; return; } if (auto result = function.action(svc); !result) { LOG(ERROR) << "Could not ctl." << msg << " for service " << name << ": " << result.error(); } Service* svc = nullptr; switch (function.target) { case ControlTarget::SERVICE: svc = ServiceList::GetInstance().FindService(name); break; case ControlTarget::INTERFACE: svc = ServiceList::GetInstance().FindInterface(name); break; default: LOG(ERROR) << "Invalid function target from static map key '" << msg << "': " << static_cast<std::underlying_type<ControlTarget>::type>(function.target); return; } if (function.target == ControlTarget::INTERFACE) { for (const auto& svc : ServiceList::GetInstance()) { if (svc->interfaces().count(name) == 0) { continue; } if (auto result = function.action(svc.get()); !result) { LOG(ERROR) << "Could not handle ctl." << msg << " for service " << svc->name() << " with interface " << name << ": " << result.error(); } if (svc == nullptr) { LOG(ERROR) << "Could not find '" << name << "' for ctl." << msg; return; } LOG(ERROR) << "Could not find service hosting interface " << name; return; if (auto result = function.action(svc); !result) { LOG(ERROR) << "Could not ctl." << msg << " for '" << name << "': " << result.error(); } LOG(ERROR) << "Invalid function target from static map key '" << msg << "': " << static_cast<std::underlying_type<ControlTarget>::type>(function.target); } static Result<Success> wait_for_coldboot_done_action(const BuiltinArguments& args) { Loading init/service.h +10 −0 Original line number Diff line number Diff line Loading @@ -244,6 +244,16 @@ class ServiceList { return nullptr; } Service* FindInterface(const std::string& interface_name) { for (const auto& svc : services_) { if (svc->interfaces().count(interface_name) > 0) { return svc.get(); } } return nullptr; } void DumpState() const; auto begin() const { return services_.begin(); } Loading Loading
init/builtins.cpp +26 −0 Original line number Diff line number Diff line Loading @@ -240,6 +240,29 @@ static Result<Success> do_insmod(const BuiltinArguments& args) { return Success(); } static Result<Success> do_interface_restart(const BuiltinArguments& args) { Service* svc = ServiceList::GetInstance().FindInterface(args[1]); if (!svc) return Error() << "interface " << args[1] << " not found"; svc->Restart(); return Success(); } static Result<Success> do_interface_start(const BuiltinArguments& args) { Service* svc = ServiceList::GetInstance().FindInterface(args[1]); if (!svc) return Error() << "interface " << args[1] << " not found"; if (auto result = svc->Start(); !result) { return Error() << "Could not start interface: " << result.error(); } return Success(); } static Result<Success> do_interface_stop(const BuiltinArguments& args) { Service* svc = ServiceList::GetInstance().FindInterface(args[1]); if (!svc) return Error() << "interface " << args[1] << " not found"; svc->Stop(); return Success(); } // mkdir <path> [mode] [owner] [group] static Result<Success> do_mkdir(const BuiltinArguments& args) { mode_t mode = 0755; Loading Loading @@ -1050,6 +1073,9 @@ const BuiltinFunctionMap::Map& BuiltinFunctionMap::map() const { {"init_user0", {0, 0, {false, do_init_user0}}}, {"insmod", {1, kMax, {true, do_insmod}}}, {"installkey", {1, 1, {false, do_installkey}}}, {"interface_restart", {1, 1, {false, do_interface_restart}}}, {"interface_start", {1, 1, {false, do_interface_start}}}, {"interface_stop", {1, 1, {false, do_interface_stop}}}, {"load_persist_props", {0, 0, {false, do_load_persist_props}}}, {"load_system_props", {0, 0, {false, do_load_system_props}}}, {"loglevel", {1, 1, {false, do_loglevel}}}, Loading
init/init.cpp +17 −28 Original line number Diff line number Diff line Loading @@ -297,40 +297,29 @@ void HandleControlMessage(const std::string& msg, const std::string& name, pid_t const ControlMessageFunction& function = it->second; if (function.target == ControlTarget::SERVICE) { Service* svc = ServiceList::GetInstance().FindService(name); if (svc == nullptr) { LOG(ERROR) << "No such service '" << name << "' for ctl." << msg; return; } if (auto result = function.action(svc); !result) { LOG(ERROR) << "Could not ctl." << msg << " for service " << name << ": " << result.error(); } Service* svc = nullptr; switch (function.target) { case ControlTarget::SERVICE: svc = ServiceList::GetInstance().FindService(name); break; case ControlTarget::INTERFACE: svc = ServiceList::GetInstance().FindInterface(name); break; default: LOG(ERROR) << "Invalid function target from static map key '" << msg << "': " << static_cast<std::underlying_type<ControlTarget>::type>(function.target); return; } if (function.target == ControlTarget::INTERFACE) { for (const auto& svc : ServiceList::GetInstance()) { if (svc->interfaces().count(name) == 0) { continue; } if (auto result = function.action(svc.get()); !result) { LOG(ERROR) << "Could not handle ctl." << msg << " for service " << svc->name() << " with interface " << name << ": " << result.error(); } if (svc == nullptr) { LOG(ERROR) << "Could not find '" << name << "' for ctl." << msg; return; } LOG(ERROR) << "Could not find service hosting interface " << name; return; if (auto result = function.action(svc); !result) { LOG(ERROR) << "Could not ctl." << msg << " for '" << name << "': " << result.error(); } LOG(ERROR) << "Invalid function target from static map key '" << msg << "': " << static_cast<std::underlying_type<ControlTarget>::type>(function.target); } static Result<Success> wait_for_coldboot_done_action(const BuiltinArguments& args) { Loading
init/service.h +10 −0 Original line number Diff line number Diff line Loading @@ -244,6 +244,16 @@ class ServiceList { return nullptr; } Service* FindInterface(const std::string& interface_name) { for (const auto& svc : services_) { if (svc->interfaces().count(interface_name) > 0) { return svc.get(); } } return nullptr; } void DumpState() const; auto begin() const { return services_.begin(); } Loading