Commit 257ff9ff authored by Philip Pronin's avatar Philip Pronin Committed by Sara Golemon

retry flock() if interrupted (EINTR)

Test Plan: fbconfig folly/test:file_test && fbmake runtests_opt

Reviewed By: soren@fb.com

FB internal diff: D932782
parent 07ed0a72
......@@ -16,12 +16,12 @@
#include "folly/File.h"
#include <sys/file.h>
#include <fcntl.h>
#include <unistd.h>
#include "folly/Format.h"
#include "folly/Exception.h"
#include "folly/FileUtil.h"
#include "folly/Format.h"
#include "folly/ScopeGuard.h"
#include <system_error>
......@@ -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(); }
......
......@@ -20,6 +20,7 @@
#ifdef __APPLE__
#include <fcntl.h>
#endif
#include <sys/file.h>
#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);
}
......
......@@ -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);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment