summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorphajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-04-12 06:07:25 +0000
committerphajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-04-12 06:07:25 +0000
commitb266ffea340315ef1cee2c69afe314b545c08d91 (patch)
treebfaf304ed986ac5490474772ad85a06eb658edf6
parentb5d41bf892f31b76ca39da16174d00378996b389 (diff)
downloadchromium_src-b266ffea340315ef1cee2c69afe314b545c08d91.zip
chromium_src-b266ffea340315ef1cee2c69afe314b545c08d91.tar.gz
chromium_src-b266ffea340315ef1cee2c69afe314b545c08d91.tar.bz2
Fix problems in src/base:
- de-facto ignored return value of PathService::Get in base_paths_mac.mm - missing EINTR handling in other files I was just reading the code looking for some issues. BUG=none Review URL: http://codereview.chromium.org/6820030 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@81220 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--base/base_paths_mac.mm27
-rw-r--r--base/file_util_posix.cc24
-rw-r--r--base/platform_file_posix.cc10
-rw-r--r--base/shared_memory_posix.cc2
4 files changed, 35 insertions, 28 deletions
diff --git a/base/base_paths_mac.mm b/base/base_paths_mac.mm
index 1210834..ec1398b 100644
--- a/base/base_paths_mac.mm
+++ b/base/base_paths_mac.mm
@@ -53,19 +53,20 @@ bool PathProviderMac(int key, FilePath* result) {
return base::mac::GetUserDirectory(NSApplicationSupportDirectory, result);
case base::DIR_SOURCE_ROOT: {
// Go through PathService to catch overrides.
- if (PathService::Get(base::FILE_EXE, result)) {
- // Start with the executable's directory.
- *result = result->DirName();
- if (base::mac::AmIBundled()) {
- // The bundled app executables (Chromium, TestShell, etc) live five
- // levels down, eg:
- // src/xcodebuild/{Debug|Release}/Chromium.app/Contents/MacOS/Chromium
- *result = result->DirName().DirName().DirName().DirName().DirName();
- } else {
- // Unit tests execute two levels deep from the source root, eg:
- // src/xcodebuild/{Debug|Release}/base_unittests
- *result = result->DirName().DirName();
- }
+ if (!PathService::Get(base::FILE_EXE, result))
+ return false;
+
+ // Start with the executable's directory.
+ *result = result->DirName();
+ if (base::mac::AmIBundled()) {
+ // The bundled app executables (Chromium, TestShell, etc) live five
+ // levels down, eg:
+ // src/xcodebuild/{Debug|Release}/Chromium.app/Contents/MacOS/Chromium
+ *result = result->DirName().DirName().DirName().DirName().DirName();
+ } else {
+ // Unit tests execute two levels deep from the source root, eg:
+ // src/xcodebuild/{Debug|Release}/base_unittests
+ *result = result->DirName().DirName();
}
return true;
}
diff --git a/base/file_util_posix.cc b/base/file_util_posix.cc
index 5e1214b..3d4f5b5 100644
--- a/base/file_util_posix.cc
+++ b/base/file_util_posix.cc
@@ -407,7 +407,7 @@ int CreateAndOpenFdForTemporaryFile(FilePath directory, FilePath* path) {
// this should be OK since mkstemp just replaces characters in place
char* buffer = const_cast<char*>(tmpdir_string.c_str());
- return mkstemp(buffer);
+ return HANDLE_EINTR(mkstemp(buffer));
}
bool CreateTemporaryFile(FilePath* path) {
@@ -418,7 +418,7 @@ bool CreateTemporaryFile(FilePath* path) {
int fd = CreateAndOpenFdForTemporaryFile(directory, path);
if (fd < 0)
return false;
- close(fd);
+ HANDLE_EINTR(close(fd));
return true;
}
@@ -441,7 +441,7 @@ FILE* CreateAndOpenTemporaryFileInDir(const FilePath& dir, FilePath* path) {
bool CreateTemporaryFileInDir(const FilePath& dir, FilePath* temp_file) {
base::ThreadRestrictions::AssertIOAllowed(); // For call to close().
int fd = CreateAndOpenFdForTemporaryFile(dir, temp_file);
- return ((fd >= 0) && !close(fd));
+ return ((fd >= 0) && !HANDLE_EINTR(close(fd)));
}
static bool CreateTemporaryDirInDirImpl(const FilePath& base_dir,
@@ -541,12 +541,16 @@ FILE* OpenFile(const std::string& filename, const char* mode) {
FILE* OpenFile(const FilePath& filename, const char* mode) {
base::ThreadRestrictions::AssertIOAllowed();
- return fopen(filename.value().c_str(), mode);
+ FILE* result = NULL;
+ do {
+ result = fopen(filename.value().c_str(), mode);
+ } while (!result && errno == EINTR);
+ return result;
}
int ReadFile(const FilePath& filename, char* data, int size) {
base::ThreadRestrictions::AssertIOAllowed();
- int fd = open(filename.value().c_str(), O_RDONLY);
+ int fd = HANDLE_EINTR(open(filename.value().c_str(), O_RDONLY));
if (fd < 0)
return -1;
@@ -558,7 +562,7 @@ int ReadFile(const FilePath& filename, char* data, int size) {
int WriteFile(const FilePath& filename, const char* data, int size) {
base::ThreadRestrictions::AssertIOAllowed();
- int fd = creat(filename.value().c_str(), 0666);
+ int fd = HANDLE_EINTR(creat(filename.value().c_str(), 0666));
if (fd < 0)
return -1;
@@ -776,7 +780,7 @@ void MemoryMappedFile::CloseHandles() {
if (data_ != NULL)
munmap(data_, length_);
if (file_ != base::kInvalidPlatformFileValue)
- close(file_);
+ HANDLE_EINTR(close(file_));
data_ = NULL;
length_ = 0;
@@ -841,13 +845,13 @@ FilePath GetHomeDir() {
bool CopyFile(const FilePath& from_path, const FilePath& to_path) {
base::ThreadRestrictions::AssertIOAllowed();
- int infile = open(from_path.value().c_str(), O_RDONLY);
+ int infile = HANDLE_EINTR(open(from_path.value().c_str(), O_RDONLY));
if (infile < 0)
return false;
- int outfile = creat(to_path.value().c_str(), 0666);
+ int outfile = HANDLE_EINTR(creat(to_path.value().c_str(), 0666));
if (outfile < 0) {
- close(infile);
+ HANDLE_EINTR(close(infile));
return false;
}
diff --git a/base/platform_file_posix.cc b/base/platform_file_posix.cc
index 2a8d2ca..6e2cff6 100644
--- a/base/platform_file_posix.cc
+++ b/base/platform_file_posix.cc
@@ -66,7 +66,8 @@ PlatformFile CreatePlatformFile(const FilePath& name, int flags,
COMPILE_ASSERT(O_RDONLY == 0, O_RDONLY_must_equal_zero);
- int descriptor = open(name.value().c_str(), open_flags, S_IRUSR | S_IWUSR);
+ int descriptor =
+ HANDLE_EINTR(open(name.value().c_str(), open_flags, S_IRUSR | S_IWUSR));
if (flags & PLATFORM_FILE_OPEN_ALWAYS) {
if (descriptor > 0) {
@@ -78,7 +79,8 @@ PlatformFile CreatePlatformFile(const FilePath& name, int flags,
flags & PLATFORM_FILE_EXCLUSIVE_WRITE) {
open_flags |= O_EXCL; // together with O_CREAT implies O_NOFOLLOW
}
- descriptor = open(name.value().c_str(), open_flags, S_IRUSR | S_IWUSR);
+ descriptor = HANDLE_EINTR(
+ open(name.value().c_str(), open_flags, S_IRUSR | S_IWUSR));
if (created && descriptor > 0)
*created = true;
}
@@ -134,7 +136,7 @@ PlatformFile CreatePlatformFile(const FilePath& name, int flags,
}
bool ClosePlatformFile(PlatformFile file) {
- return !close(file);
+ return !HANDLE_EINTR(close(file));
}
int ReadPlatformFile(PlatformFile file, int64 offset, char* data, int size) {
@@ -157,7 +159,7 @@ bool TruncatePlatformFile(PlatformFile file, int64 length) {
}
bool FlushPlatformFile(PlatformFile file) {
- return !fsync(file);
+ return !HANDLE_EINTR(fsync(file));
}
bool TouchPlatformFile(PlatformFile file, const base::Time& last_access_time,
diff --git a/base/shared_memory_posix.cc b/base/shared_memory_posix.cc
index 538aed4..873432a 100644
--- a/base/shared_memory_posix.cc
+++ b/base/shared_memory_posix.cc
@@ -142,7 +142,7 @@ bool SharedMemory::CreateNamed(const std::string& name,
return false;
const uint32 current_size = stat.st_size;
if (current_size != size) {
- if (ftruncate(fileno(fp), size) != 0)
+ if (HANDLE_EINTR(ftruncate(fileno(fp), size)) != 0)
return false;
if (fseeko(fp, size, SEEK_SET) != 0)
return false;