diff options
author | Tom Cherry <tomcherry@google.com> | 2017-08-23 22:07:30 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2017-08-23 22:07:30 +0000 |
commit | a78b5b300b51b9bf9df33578ec6a71c3de68f6e4 (patch) | |
tree | 703d5efb9826db77d317adf6683ad3f2fa6c1602 /init/builtins.cpp | |
parent | 6aab4e2ca5892d2e32b6b29f08ceb2e425e9cc5e (diff) | |
parent | 68f2a4614518468f1320ad3e62a6db554e509fb1 (diff) |
Merge changes I316c13e3,I4d99744d,Id9614b72,I7c98a0b7
* changes:
init: enable error reporting of builtin functions
init: log Service failures via Result<T>
init: pass errors from one Result<T> to another better
init: cleanup environment handling
Diffstat (limited to 'init/builtins.cpp')
-rw-r--r-- | init/builtins.cpp | 25 |
1 files changed, 17 insertions, 8 deletions
diff --git a/init/builtins.cpp b/init/builtins.cpp index f807343ab..54ccf091e 100644 --- a/init/builtins.cpp +++ b/init/builtins.cpp @@ -127,7 +127,9 @@ static Result<Success> do_enable(const std::vector<std::string>& args) { Service* svc = ServiceList::GetInstance().FindService(args[1]); if (!svc) return Error() << "Could not find service"; - if (!svc->Enable()) return Error() << "Could not enable service"; + if (auto result = svc->Enable(); !result) { + return Error() << "Could not enable service: " << result.error(); + } return Success(); } @@ -137,8 +139,8 @@ static Result<Success> do_exec(const std::vector<std::string>& args) { if (!service) { return Error() << "Could not create exec service"; } - if (!service->ExecStart()) { - return Error() << "Could not start exec service"; + if (auto result = service->ExecStart(); !result) { + return Error() << "Could not start exec service: " << result.error(); } ServiceList::GetInstance().AddService(std::move(service)); @@ -151,16 +153,16 @@ static Result<Success> do_exec_start(const std::vector<std::string>& args) { return Error() << "Service not found"; } - if (!service->ExecStart()) { - return Error() << "Could not start Service"; + if (auto result = service->ExecStart(); !result) { + return Error() << "Could not start exec service: " << result.error(); } return Success(); } static Result<Success> do_export(const std::vector<std::string>& args) { - if (!add_environment(args[1].c_str(), args[2].c_str())) { - return Error(); + if (setenv(args[1].c_str(), args[2].c_str(), 1) == -1) { + return ErrnoError() << "setenv() failed"; } return Success(); } @@ -583,7 +585,9 @@ static Result<Success> do_setrlimit(const std::vector<std::string>& args) { static Result<Success> do_start(const std::vector<std::string>& args) { Service* svc = ServiceList::GetInstance().FindService(args[1]); if (!svc) return Error() << "service " << args[1] << " not found"; - if (!svc->Start()) return Error() << "failed to start service"; + if (auto result = svc->Start(); !result) { + return Error() << "Could not start service: " << result.error(); + } return Success(); } @@ -608,6 +612,11 @@ static Result<Success> do_trigger(const std::vector<std::string>& args) { static Result<Success> do_symlink(const std::vector<std::string>& args) { if (symlink(args[1].c_str(), args[2].c_str()) < 0) { + // The symlink builtin is often used to create symlinks for older devices to be backwards + // compatible with new paths, therefore we skip reporting this error. + if (errno == EEXIST && android::base::GetMinimumLogSeverity() > android::base::DEBUG) { + return Success(); + } return ErrnoError() << "symlink() failed"; } return Success(); |