Merge "libdm: Fix WaitForFile early-returning on failed accesses." am: 66147bad94
Change-Id: I96c24c1b8d0941d291505e7668fdeda37542bdba
This commit is contained in:
commit
8ae833f2e2
2 changed files with 14 additions and 4 deletions
|
@ -120,7 +120,7 @@ bool DeviceMapper::DeleteDevice(const std::string& name,
|
|||
return false;
|
||||
}
|
||||
if (!WaitForFileDeleted(unique_path, timeout_ms)) {
|
||||
LOG(ERROR) << "Timeout out waiting for " << unique_path << " to be deleted";
|
||||
LOG(ERROR) << "Failed waiting for " << unique_path << " to be deleted";
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
@ -161,7 +161,7 @@ bool DeviceMapper::CreateDevice(const std::string& name, const DmTable& table, s
|
|||
return true;
|
||||
}
|
||||
if (!WaitForFile(unique_path, timeout_ms)) {
|
||||
LOG(ERROR) << "Timed out waiting for device path: " << unique_path;
|
||||
LOG(ERROR) << "Failed waiting for device path: " << unique_path;
|
||||
DeleteDevice(name);
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -19,6 +19,8 @@
|
|||
|
||||
#include <thread>
|
||||
|
||||
#include <android-base/logging.h>
|
||||
|
||||
using namespace std::literals;
|
||||
|
||||
namespace android {
|
||||
|
@ -45,7 +47,11 @@ bool WaitForFile(const std::string& path, const std::chrono::milliseconds& timeo
|
|||
// If the file exists but returns EPERM or something, we consider the
|
||||
// condition met.
|
||||
if (access(path.c_str(), F_OK) != 0) {
|
||||
if (errno == ENOENT) return WaitResult::Wait;
|
||||
if (errno == ENOENT) {
|
||||
return WaitResult::Wait;
|
||||
}
|
||||
PLOG(ERROR) << "access failed: " << path;
|
||||
return WaitResult::Fail;
|
||||
}
|
||||
return WaitResult::Done;
|
||||
};
|
||||
|
@ -54,9 +60,13 @@ bool WaitForFile(const std::string& path, const std::chrono::milliseconds& timeo
|
|||
|
||||
bool WaitForFileDeleted(const std::string& path, const std::chrono::milliseconds& timeout_ms) {
|
||||
auto condition = [&]() -> WaitResult {
|
||||
if (access(path.c_str(), F_OK) == 0 || errno != ENOENT) {
|
||||
if (access(path.c_str(), F_OK) == 0) {
|
||||
return WaitResult::Wait;
|
||||
}
|
||||
if (errno != ENOENT) {
|
||||
PLOG(ERROR) << "access failed: " << path;
|
||||
return WaitResult::Fail;
|
||||
}
|
||||
return WaitResult::Done;
|
||||
};
|
||||
return WaitForCondition(condition, timeout_ms);
|
||||
|
|
Loading…
Reference in a new issue