Index: util/file/file_io_posix.cc |
diff --git a/util/file/file_io_posix.cc b/util/file/file_io_posix.cc |
index 60bc9a8daaac1473a1f49c01f76433c77cc7b7e7..fc8358822723bb28273a8f526b7b26a20ca02c3d 100644 |
--- a/util/file/file_io_posix.cc |
+++ b/util/file/file_io_posix.cc |
@@ -15,6 +15,7 @@ |
#include "util/file/file_io.h" |
#include <fcntl.h> |
+#include <sys/file.h> |
#include <unistd.h> |
#include "base/files/file_path.h" |
@@ -100,6 +101,36 @@ FileHandle LoggingOpenFileForWrite(const base::FilePath& path, |
return fd; |
} |
+bool LoggingLockFile(FileHandle file, FileLocking locking) { |
+#if 0 |
+ struct flock fl = {0}; |
+ fl.l_type = (locking == FileLocking::kShared) ? F_RDLCK : F_WRLCK; |
+ fl.l_whence = SEEK_SET; |
+ int rv = HANDLE_EINTR(fcntl(file, F_SETLKW, &fl)); |
+ PLOG_IF(ERROR, rv < 0) << "fcntl F_SETLKW " << fl.l_type; |
+#else |
+ int operation = locking == FileLocking::kShared ? LOCK_SH : LOCK_EX; |
+ int rv = HANDLE_EINTR(flock(file, operation)); |
+ PLOG_IF(ERROR, rv < 0) << "flock"; |
+#endif |
+ return rv == 0; |
+ |
+} |
+ |
+bool LoggingUnlockFile(FileHandle file) { |
+#if 0 |
+ struct flock fl = {0}; |
+ fl.l_type = F_UNLCK; |
+ fl.l_whence = SEEK_SET; |
+ int rv = fcntl(file, F_SETLK, &fl); |
+ PLOG_IF(ERROR, rv < 0) << "fcntl F_UNLCK"; |
+#else |
+ int rv = HANDLE_EINTR(flock(file, LOCK_UN)); |
Mark Mentovai
2015/03/20 15:03:55
Shouldn’t need to HANDLE_EINTR for an unlock (alth
scottmg
2015/03/20 21:07:34
Done.
|
+ PLOG_IF(ERROR, rv < 0) << "flock"; |
+#endif |
+ return rv == 0; |
+} |
+ |
FileOffset LoggingSeekFile(FileHandle file, FileOffset offset, int whence) { |
off_t rv = lseek(file, offset, whence); |
PLOG_IF(ERROR, rv < 0) << "lseek"; |