Merge "init: add [[nodiscard]] to Result"
diff --git a/init/builtins.cpp b/init/builtins.cpp
index 17d34e1..7da2526 100644
--- a/init/builtins.cpp
+++ b/init/builtins.cpp
@@ -1018,7 +1018,11 @@
if (siginfo.si_code != CLD_EXITED || siginfo.si_status != 0) {
if (e4crypt_is_native()) {
LOG(ERROR) << "Rebooting into recovery, reason: " << reboot_reason;
- reboot_into_recovery({"--prompt_and_wipe_data", "--reason="s + reboot_reason});
+ if (auto result = reboot_into_recovery(
+ {"--prompt_and_wipe_data", "--reason="s + reboot_reason});
+ !result) {
+ LOG(FATAL) << "Could not reboot into recovery: " << result.error();
+ }
} else {
LOG(ERROR) << "Failure (reboot suppressed): " << reboot_reason;
}
diff --git a/init/keychords.cpp b/init/keychords.cpp
index b8c1cfd..f5ac44f 100644
--- a/init/keychords.cpp
+++ b/init/keychords.cpp
@@ -41,7 +41,7 @@
Keychords::~Keychords() noexcept {
if (inotify_fd_ >= 0) {
- epoll_->UnregisterHandler(inotify_fd_);
+ epoll_->UnregisterHandler(inotify_fd_).IgnoreError();
::close(inotify_fd_);
}
while (!registration_.empty()) GeteventCloseDevice(registration_.begin()->first);
@@ -186,7 +186,11 @@
current_ |= mask & available & set;
LambdaCheck();
}
- epoll_->RegisterHandler(fd, [this, fd]() { this->LambdaHandler(fd); });
+ if (auto result = epoll_->RegisterHandler(fd, [this, fd]() { this->LambdaHandler(fd); });
+ !result) {
+ LOG(WARNING) << "Could not register keychord epoll handler: " << result.error();
+ return false;
+ }
return true;
}
@@ -208,7 +212,7 @@
auto it = registration_.find(device);
if (it == registration_.end()) return;
auto fd = (*it).second;
- epoll_->UnregisterHandler(fd);
+ epoll_->UnregisterHandler(fd).IgnoreError();
registration_.erase(it);
::close(fd);
}
@@ -266,7 +270,11 @@
}
if (inotify_fd_ >= 0) {
- epoll_->RegisterHandler(inotify_fd_, [this]() { this->InotifyHandler(); });
+ if (auto result =
+ epoll_->RegisterHandler(inotify_fd_, [this]() { this->InotifyHandler(); });
+ !result) {
+ LOG(WARNING) << "Could not register keychord epoll handler: " << result.error();
+ }
}
}
diff --git a/init/keychords_test.cpp b/init/keychords_test.cpp
index a3baeb1..e5a6fd3 100644
--- a/init/keychords_test.cpp
+++ b/init/keychords_test.cpp
@@ -213,7 +213,7 @@
}
void TestFrame::RelaxForMs(std::chrono::milliseconds wait) {
- epoll_.Wait(wait);
+ epoll_.Wait(wait).IgnoreError();
}
void TestFrame::SetChord(int key, bool value) {
diff --git a/init/reboot.cpp b/init/reboot.cpp
index d476336..a145797 100644
--- a/init/reboot.cpp
+++ b/init/reboot.cpp
@@ -142,7 +142,9 @@
LOG(WARNING) << "cannot find blank_screen in TurnOffBacklight";
return;
}
- service->Start();
+ if (auto result = service->Start(); !result) {
+ LOG(WARNING) << "Could not start blank_screen service: " << result.error();
+ }
}
static void ShutdownVold() {
diff --git a/init/result.h b/init/result.h
index fc03962..0e3fd3d 100644
--- a/init/result.h
+++ b/init/result.h
@@ -151,7 +151,7 @@
}
template <typename T>
-class Result {
+class [[nodiscard]] Result {
public:
Result() {}
@@ -170,6 +170,8 @@
: contents_(std::in_place_index_t<1>(), std::move(result_error.error_string),
result_error.error_errno) {}
+ void IgnoreError() const {}
+
bool has_value() const { return contents_.index() == 0; }
T& value() & { return std::get<0>(contents_); }
diff --git a/init/subcontext_benchmark.cpp b/init/subcontext_benchmark.cpp
index 6307993..eae03e3 100644
--- a/init/subcontext_benchmark.cpp
+++ b/init/subcontext_benchmark.cpp
@@ -39,7 +39,7 @@
free(context);
while (state.KeepRunning()) {
- subcontext.Execute(std::vector<std::string>{"return_success"});
+ subcontext.Execute(std::vector<std::string>{"return_success"}).IgnoreError();
}
if (subcontext.pid() > 0) {