init: add [[nodiscard]] to Result

It's better to either check these results or explicitly ignore them.
Only a few callers weren't already doing this, so it's relatively
trivial to enforce.

Test: build
Change-Id: I44cdc342e46128f66cac914aaa0b9b4559cacd8c
This commit is contained in:
Tom Cherry 2018-10-11 10:38:05 -07:00
parent f7d154e10f
commit d987264625
6 changed files with 25 additions and 9 deletions

View file

@ -1018,7 +1018,11 @@ static Result<Success> ExecWithRebootOnFailure(const std::string& reboot_reason,
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;
}

View file

@ -41,7 +41,7 @@ Keychords::Keychords() : epoll_(nullptr), inotify_fd_(-1) {}
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 @@ bool Keychords::GeteventEnable(int fd) {
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 @@ void Keychords::GeteventCloseDevice(const std::string& device) {
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 @@ void Keychords::GeteventOpenDevice() {
}
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();
}
}
}

View file

@ -213,7 +213,7 @@ TestFrame::TestFrame(const std::vector<const std::vector<int>>& chords, EventHan
}
void TestFrame::RelaxForMs(std::chrono::milliseconds wait) {
epoll_.Wait(wait);
epoll_.Wait(wait).IgnoreError();
}
void TestFrame::SetChord(int key, bool value) {

View file

@ -142,7 +142,9 @@ static void TurnOffBacklight() {
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() {

View file

@ -151,7 +151,7 @@ inline Error ErrnoError() {
}
template <typename T>
class Result {
class [[nodiscard]] Result {
public:
Result() {}
@ -170,6 +170,8 @@ class Result {
: 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_); }

View file

@ -39,7 +39,7 @@ static void BenchmarkSuccess(benchmark::State& state) {
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) {