From 2b63d54af81b2d061b98799b97f01d771bfa6782 Mon Sep 17 00:00:00 2001 From: Steven Moreland Date: Fri, 10 Mar 2017 14:04:37 -0800 Subject: [PATCH] init: add class_restart Bug: 34093663 Test: hwservicemanager `onrestart class_restart hal` works Change-Id: Ie1e4daab2b7b4c6c714d4e3d05afa2d86d6233df --- init/README.md | 6 +++++- init/builtins.cpp | 7 +++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/init/README.md b/init/README.md index 709c6675f..9d352f821 100644 --- a/init/README.md +++ b/init/README.md @@ -279,6 +279,9 @@ Commands currently running, without disabling them. They can be restarted later using `class_start`. +`class_restart ` +> Restarts all services of the specified class. + `copy ` > Copies a file. Similar to write, but useful for binary/large amounts of data. @@ -358,7 +361,8 @@ Commands "sys.powerctl" system property, used to implement rebooting. `restart ` -> Like stop, but doesn't disable the service. +> Stops and restarts a running service, does nothing if the service is currently + restarting, otherwise, it just starts the service. `restorecon [ \* ]` > Restore the file named by _path_ to the security context specified diff --git a/init/builtins.cpp b/init/builtins.cpp index 32e9ef642..95f1aa0f8 100644 --- a/init/builtins.cpp +++ b/init/builtins.cpp @@ -148,6 +148,12 @@ static int do_class_reset(const std::vector& args) { return 0; } +static int do_class_restart(const std::vector& args) { + ServiceManager::GetInstance(). + ForEachServiceInClass(args[1], [] (Service* s) { s->Restart(); }); + return 0; +} + static int do_domainname(const std::vector& args) { return write_file("/proc/sys/kernel/domainname", args[1].c_str()) ? 0 : 1; } @@ -897,6 +903,7 @@ BuiltinFunctionMap::Map& BuiltinFunctionMap::map() const { {"chmod", {2, 2, do_chmod}}, {"chown", {2, 3, do_chown}}, {"class_reset", {1, 1, do_class_reset}}, + {"class_restart", {1, 1, do_class_restart}}, {"class_start", {1, 1, do_class_start}}, {"class_stop", {1, 1, do_class_stop}}, {"copy", {2, 2, do_copy}},