Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1263)

Unified Diff: util/file/file_io_posix.cc

Issue 1001673002: Add Locking calls to file_io.h plus implementations and test (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@master
Patch Set: . Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..76454b235ad6b93773188ad17bdec9a29b3bf7d3 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,19 @@ FileHandle LoggingOpenFileForWrite(const base::FilePath& path,
return fd;
}
+bool LoggingLockFile(FileHandle file, FileLocking locking) {
+ int operation = locking == FileLocking::kShared ? LOCK_SH : LOCK_EX;
Robert Sesek 2015/03/12 15:28:03 nit: () around the condition
scottmg 2015/03/19 22:06:19 Done.
+ int rv = HANDLE_EINTR(flock(file, operation));
Mark Mentovai 2015/03/12 04:47:42 Since we’re moving away from the BSD-specific O_SH
scottmg 2015/03/19 22:06:19 I tried to do this, but I haven't been able to get
Mark Mentovai 2015/03/20 15:03:54 I think you got it right, but it seems that fcntl(
scottmg 2015/03/20 21:07:34 Ah, yes. It does repeatedly say process in the doc
+ PLOG_IF(ERROR, rv < 0) << "flock";
+ return rv == 0;
+}
+
+bool LoggingUnlockFile(FileHandle file) {
+ int rv = HANDLE_EINTR(flock(file, LOCK_UN));
+ PLOG_IF(ERROR, rv < 0) << "flock";
+ return rv == 0;
+}
+
FileOffset LoggingSeekFile(FileHandle file, FileOffset offset, int whence) {
off_t rv = lseek(file, offset, whence);
PLOG_IF(ERROR, rv < 0) << "lseek";

Powered by Google App Engine
This is Rietveld 408576698