init: log Service failures via Result<T>
Log Service failures via Result<T> such that their context can be
captured when interacting with services through builtin functions.
Test: boot bullhead
Change-Id: I4d99744d64008d4a06a404e3c9817182c6e177bc
diff --git a/init/builtins.cpp b/init/builtins.cpp
index 593f718..3d0ba55 100644
--- a/init/builtins.cpp
+++ b/init/builtins.cpp
@@ -127,7 +127,9 @@
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 @@
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,8 +153,8 @@
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();
@@ -583,7 +585,9 @@
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();
}