Wrap flock with TEMP_FAILURE_RETRY.

flock may return EINTR. There are code using LockShared() to test
existance of the directory. Don't fail spuriously.

Test: pass
Bug: 160457903
Change-Id: I51628abe05599422eb3f344781d8f3acd653c822
This commit is contained in:
Yifan Hong 2020-07-07 14:28:41 -07:00
parent 44033e75cc
commit bd6d2cded8

View file

@ -1846,7 +1846,7 @@ auto SnapshotManager::OpenFile(const std::string& file, int lock_flags)
PLOG(ERROR) << "Open failed: " << file; PLOG(ERROR) << "Open failed: " << file;
return nullptr; return nullptr;
} }
if (lock_flags != 0 && flock(fd, lock_flags) < 0) { if (lock_flags != 0 && TEMP_FAILURE_RETRY(flock(fd, lock_flags)) < 0) {
PLOG(ERROR) << "Acquire flock failed: " << file; PLOG(ERROR) << "Acquire flock failed: " << file;
return nullptr; return nullptr;
} }
@ -1857,7 +1857,7 @@ auto SnapshotManager::OpenFile(const std::string& file, int lock_flags)
} }
SnapshotManager::LockedFile::~LockedFile() { SnapshotManager::LockedFile::~LockedFile() {
if (flock(fd_, LOCK_UN) < 0) { if (TEMP_FAILURE_RETRY(flock(fd_, LOCK_UN)) < 0) {
PLOG(ERROR) << "Failed to unlock file: " << path_; PLOG(ERROR) << "Failed to unlock file: " << path_;
} }
} }