Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 8189339d authored by David Anderson's avatar David Anderson Committed by Gerrit Code Review
Browse files

Merge "init: Add --only-if-running argument to restart command."

parents fc569285 6d7c7a21
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -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
+16 −3
Original line number Diff line number Diff line
@@ -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}}},