summaryrefslogtreecommitdiffstats
path: root/init/builtins.cpp
diff options
context:
space:
mode:
authorTom Cherry <tomcherry@google.com>2017-08-01 20:25:57 +0000
committerandroid-build-merger <android-build-merger@google.com>2017-08-01 20:25:57 +0000
commitb1c18af2475100c2926356917c5acf5ffcea0257 (patch)
tree56a20ab8450e706e16f987adfbdb312d017f77ce /init/builtins.cpp
parent25422816d4acad3c4e4d7cae5eb44c1525ed896d (diff)
parent2a2a8d9ec04676974a2c1edfc0715e8b1a66f903 (diff)
downloadsystem_core-b1c18af2475100c2926356917c5acf5ffcea0257.tar.gz
system_core-b1c18af2475100c2926356917c5acf5ffcea0257.tar.bz2
system_core-b1c18af2475100c2926356917c5acf5ffcea0257.zip
Merge changes Ibd57c103,I81f1e8ac,Ia6e546fe
am: 2a2a8d9ec0 Change-Id: Id39de0d3d62c1e0f3585ae7817940dbbebfa6ae3
Diffstat (limited to 'init/builtins.cpp')
-rw-r--r--init/builtins.cpp60
1 files changed, 40 insertions, 20 deletions
diff --git a/init/builtins.cpp b/init/builtins.cpp
index dec6f40e6..035158201 100644
--- a/init/builtins.cpp
+++ b/init/builtins.cpp
@@ -124,31 +124,32 @@ static int reboot_into_recovery(const std::vector<std::string>& options) {
return 0;
}
+template <typename F>
+static void ForEachServiceInClass(const std::string& classname, F function) {
+ for (const auto& service : ServiceList::GetInstance()) {
+ if (service->classnames().count(classname)) std::invoke(function, service);
+ }
+}
+
static int do_class_start(const std::vector<std::string>& args) {
- /* Starting a class does not start services
- * which are explicitly disabled. They must
- * be started individually.
- */
- ServiceManager::GetInstance().
- ForEachServiceInClass(args[1], [] (Service* s) { s->StartIfNotDisabled(); });
+ // Starting a class does not start services which are explicitly disabled.
+ // They must be started individually.
+ ForEachServiceInClass(args[1], &Service::StartIfNotDisabled);
return 0;
}
static int do_class_stop(const std::vector<std::string>& args) {
- ServiceManager::GetInstance().
- ForEachServiceInClass(args[1], [] (Service* s) { s->Stop(); });
+ ForEachServiceInClass(args[1], &Service::Stop);
return 0;
}
static int do_class_reset(const std::vector<std::string>& args) {
- ServiceManager::GetInstance().
- ForEachServiceInClass(args[1], [] (Service* s) { s->Reset(); });
+ ForEachServiceInClass(args[1], &Service::Reset);
return 0;
}
static int do_class_restart(const std::vector<std::string>& args) {
- ServiceManager::GetInstance().
- ForEachServiceInClass(args[1], [] (Service* s) { s->Restart(); });
+ ForEachServiceInClass(args[1], &Service::Restart);
return 0;
}
@@ -162,7 +163,7 @@ static int do_domainname(const std::vector<std::string>& args) {
}
static int do_enable(const std::vector<std::string>& args) {
- Service* svc = ServiceManager::GetInstance().FindServiceByName(args[1]);
+ Service* svc = ServiceList::GetInstance().FindService(args[1]);
if (!svc) {
return -1;
}
@@ -170,11 +171,30 @@ static int do_enable(const std::vector<std::string>& args) {
}
static int do_exec(const std::vector<std::string>& args) {
- return ServiceManager::GetInstance().Exec(args) ? 0 : -1;
+ auto service = Service::MakeTemporaryOneshotService(args);
+ if (!service) {
+ LOG(ERROR) << "Failed to create exec service: " << android::base::Join(args, " ");
+ return -1;
+ }
+ if (!service->ExecStart()) {
+ LOG(ERROR) << "Failed to Start exec service";
+ return -1;
+ }
+ ServiceList::GetInstance().AddService(std::move(service));
+ return 0;
}
static int do_exec_start(const std::vector<std::string>& args) {
- return ServiceManager::GetInstance().ExecStart(args[1]) ? 0 : -1;
+ Service* service = ServiceList::GetInstance().FindService(args[1]);
+ if (!service) {
+ LOG(ERROR) << "ExecStart(" << args[1] << "): Service not found";
+ return -1;
+ }
+ if (!service->ExecStart()) {
+ LOG(ERROR) << "ExecStart(" << args[1] << "): Could not start Service";
+ return -1;
+ }
+ return 0;
}
static int do_export(const std::vector<std::string>& args) {
@@ -389,8 +409,8 @@ exit_success:
*/
static void import_late(const std::vector<std::string>& args, size_t start_index, size_t end_index) {
auto& action_manager = ActionManager::GetInstance();
- auto& service_manager = ServiceManager::GetInstance();
- Parser parser = CreateParser(action_manager, service_manager);
+ auto& service_list = ServiceList::GetInstance();
+ Parser parser = CreateParser(action_manager, service_list);
if (end_index <= start_index) {
// Fallbacks for partitions on which early mount isn't enabled.
for (const auto& path : late_import_paths) {
@@ -580,7 +600,7 @@ static int do_setrlimit(const std::vector<std::string>& args) {
}
static int do_start(const std::vector<std::string>& args) {
- Service* svc = ServiceManager::GetInstance().FindServiceByName(args[1]);
+ Service* svc = ServiceList::GetInstance().FindService(args[1]);
if (!svc) {
LOG(ERROR) << "do_start: Service " << args[1] << " not found";
return -1;
@@ -591,7 +611,7 @@ static int do_start(const std::vector<std::string>& args) {
}
static int do_stop(const std::vector<std::string>& args) {
- Service* svc = ServiceManager::GetInstance().FindServiceByName(args[1]);
+ Service* svc = ServiceList::GetInstance().FindService(args[1]);
if (!svc) {
LOG(ERROR) << "do_stop: Service " << args[1] << " not found";
return -1;
@@ -601,7 +621,7 @@ static int do_stop(const std::vector<std::string>& args) {
}
static int do_restart(const std::vector<std::string>& args) {
- Service* svc = ServiceManager::GetInstance().FindServiceByName(args[1]);
+ Service* svc = ServiceList::GetInstance().FindService(args[1]);
if (!svc) {
LOG(ERROR) << "do_restart: Service " << args[1] << " not found";
return -1;