From bd6d2cded8a5f7e3f602ed7574e80954a8b9104d Mon Sep 17 00:00:00 2001 From: Yifan Hong Date: Tue, 7 Jul 2020 14:28:41 -0700 Subject: [PATCH] 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 --- fs_mgr/libsnapshot/snapshot.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fs_mgr/libsnapshot/snapshot.cpp b/fs_mgr/libsnapshot/snapshot.cpp index a287c353c..4178349ed 100644 --- a/fs_mgr/libsnapshot/snapshot.cpp +++ b/fs_mgr/libsnapshot/snapshot.cpp @@ -1846,7 +1846,7 @@ auto SnapshotManager::OpenFile(const std::string& file, int lock_flags) PLOG(ERROR) << "Open failed: " << file; 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; return nullptr; } @@ -1857,7 +1857,7 @@ auto SnapshotManager::OpenFile(const std::string& file, int lock_flags) } 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_; } }