Merge "init: Add --only-if-running argument to restart command." am: 8189339de3
Original change: https://android-review.googlesource.com/c/platform/system/core/+/1910536 Change-Id: I840853a26ff4b76431c78145df81a2617207bd6a
This commit is contained in:
commit
3a9fc6ea0a
|
@ -641,9 +641,10 @@ provides the `aidl_lazy_test_1` interface.
|
|||
configurations. Intended to be used only once when apexd notifies the mount
|
||||
event by setting `apexd.status` to ready.
|
||||
|
||||
`restart <service>`
|
||||
`restart [--only-if-running] <service>`
|
||||
> Stops and restarts a running service, does nothing if the service is currently
|
||||
restarting, otherwise, it just starts the service.
|
||||
restarting, otherwise, it just starts the service. If "--only-if-running" is
|
||||
specified, the service is only restarted if it is already running.
|
||||
|
||||
`restorecon <path> [ <path>\* ]`
|
||||
> Restore the file named by _path_ to the security context specified
|
||||
|
|
|
@ -774,8 +774,21 @@ static Result<void> do_stop(const BuiltinArguments& args) {
|
|||
}
|
||||
|
||||
static Result<void> do_restart(const BuiltinArguments& args) {
|
||||
Service* svc = ServiceList::GetInstance().FindService(args[1]);
|
||||
if (!svc) return Error() << "service " << args[1] << " not found";
|
||||
bool only_if_running = false;
|
||||
if (args.size() == 3) {
|
||||
if (args[1] == "--only-if-running") {
|
||||
only_if_running = true;
|
||||
} else {
|
||||
return Error() << "Unknown argument to restart: " << args[1];
|
||||
}
|
||||
}
|
||||
|
||||
const auto& classname = args[args.size() - 1];
|
||||
Service* svc = ServiceList::GetInstance().FindService(classname);
|
||||
if (!svc) return Error() << "service " << classname << " not found";
|
||||
if (only_if_running && !svc->IsRunning()) {
|
||||
return {};
|
||||
}
|
||||
svc->Restart();
|
||||
return {};
|
||||
}
|
||||
|
@ -1453,7 +1466,7 @@ const BuiltinFunctionMap& GetBuiltinFunctionMap() {
|
|||
{"update_linker_config", {0, 0, {false, do_update_linker_config}}},
|
||||
{"readahead", {1, 2, {true, do_readahead}}},
|
||||
{"remount_userdata", {0, 0, {false, do_remount_userdata}}},
|
||||
{"restart", {1, 1, {false, do_restart}}},
|
||||
{"restart", {1, 2, {false, do_restart}}},
|
||||
{"restorecon", {1, kMax, {true, do_restorecon}}},
|
||||
{"restorecon_recursive", {1, kMax, {true, do_restorecon_recursive}}},
|
||||
{"rm", {1, 1, {true, do_rm}}},
|
||||
|
|
Loading…
Reference in New Issue