From: Philip Pronin Date: Sat, 17 Aug 2013 09:06:35 +0000 (-0700) Subject: retry flock() if interrupted (EINTR) X-Git-Tag: v0.22.0~899 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=257ff9ff793e7f8f69731c91630540088c43c349;p=folly.git retry flock() if interrupted (EINTR) Test Plan: fbconfig folly/test:file_test && fbmake runtests_opt Reviewed By: soren@fb.com FB internal diff: D932782 --- diff --git a/folly/File.cpp b/folly/File.cpp index aaf109f0..3c961aaa 100644 --- a/folly/File.cpp +++ b/folly/File.cpp @@ -16,12 +16,12 @@ #include "folly/File.h" -#include #include #include -#include "folly/Format.h" #include "folly/Exception.h" +#include "folly/FileUtil.h" +#include "folly/Format.h" #include "folly/ScopeGuard.h" #include @@ -112,11 +112,11 @@ void File::lock_shared() { doLock(LOCK_SH); } bool File::try_lock_shared() { return doTryLock(LOCK_SH); } void File::doLock(int op) { - checkUnixError(flock(fd_, op), "flock() failed (lock)"); + checkUnixError(flockNoInt(fd_, op), "flock() failed (lock)"); } bool File::doTryLock(int op) { - int r = flock(fd_, op | LOCK_NB); + int r = flockNoInt(fd_, op | LOCK_NB); // flock returns EWOULDBLOCK if already locked if (r == -1 && errno == EWOULDBLOCK) return false; checkUnixError(r, "flock() failed (try_lock)"); @@ -124,7 +124,7 @@ bool File::doTryLock(int op) { } void File::unlock() { - checkUnixError(flock(fd_, LOCK_UN), "flock() failed (unlock)"); + checkUnixError(flockNoInt(fd_, LOCK_UN), "flock() failed (unlock)"); } void File::unlock_shared() { unlock(); } diff --git a/folly/FileUtil.cpp b/folly/FileUtil.cpp index 4a4ca6b6..45c313ff 100644 --- a/folly/FileUtil.cpp +++ b/folly/FileUtil.cpp @@ -20,6 +20,7 @@ #ifdef __APPLE__ #include #endif +#include #include "folly/detail/FileUtilDetail.h" @@ -70,6 +71,10 @@ int truncateNoInt(const char* path, off_t len) { return wrapNoInt(truncate, path, len); } +int flockNoInt(int fd, int operation) { + return wrapNoInt(flock, fd, operation); +} + ssize_t readNoInt(int fd, void* buf, size_t count) { return wrapNoInt(read, fd, buf, count); } diff --git a/folly/FileUtil.h b/folly/FileUtil.h index 81974871..a542e1c9 100644 --- a/folly/FileUtil.h +++ b/folly/FileUtil.h @@ -39,6 +39,7 @@ int fsyncNoInt(int fd); int fdatasyncNoInt(int fd); int ftruncateNoInt(int fd, off_t len); int truncateNoInt(const char* path, off_t len); +int flockNoInt(int fd, int operation); ssize_t readNoInt(int fd, void* buf, size_t n); ssize_t preadNoInt(int fd, void* buf, size_t n, off_t offset);