summaryrefslogtreecommitdiffstats
path: root/base
diff options
context:
space:
mode:
authorevan@chromium.org <evan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-02-02 02:28:16 +0000
committerevan@chromium.org <evan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-02-02 02:28:16 +0000
commitcabe39c43a98b6b635951d5cb3649e061e36ea21 (patch)
treec76282b5ed8452f490edbda9ed0a32bf364b5d6a /base
parentce716d859764f7a6e8ea0c79bbcd445d856f4da0 (diff)
downloadchromium_src-cabe39c43a98b6b635951d5cb3649e061e36ea21.zip
chromium_src-cabe39c43a98b6b635951d5cb3649e061e36ea21.tar.gz
chromium_src-cabe39c43a98b6b635951d5cb3649e061e36ea21.tar.bz2
linux: check the return value passed through HANDLE_EINTR
A smarter compiler (clang) can notice that we were not using the return values being passed through HANDLE_EINTR, which meant most frequently that we were missing checking the return value of close(). Review URL: http://codereview.chromium.org/569003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@37786 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base')
-rw-r--r--base/debug_util_posix.cc3
-rw-r--r--base/directory_watcher_inotify.cc4
-rw-r--r--base/file_descriptor_shuffle.cc3
-rw-r--r--base/file_util_posix.cc14
-rw-r--r--base/process_util_posix.cc17
-rw-r--r--base/process_util_unittest.cc19
6 files changed, 40 insertions, 20 deletions
diff --git a/base/debug_util_posix.cc b/base/debug_util_posix.cc
index a57f102..0cccd9e 100644
--- a/base/debug_util_posix.cc
+++ b/base/debug_util_posix.cc
@@ -203,7 +203,8 @@ bool DebugUtil::BeingDebugged() {
char buf[1024];
ssize_t num_read = HANDLE_EINTR(read(status_fd, buf, sizeof(buf)));
- HANDLE_EINTR(close(status_fd));
+ if (HANDLE_EINTR(close(status_fd)) < 0)
+ return false;
if (num_read <= 0)
return false;
diff --git a/base/directory_watcher_inotify.cc b/base/directory_watcher_inotify.cc
index d171a7a..c593ff5 100644
--- a/base/directory_watcher_inotify.cc
+++ b/base/directory_watcher_inotify.cc
@@ -272,7 +272,9 @@ InotifyReader::~InotifyReader() {
if (valid_) {
// Write to the self-pipe so that the select call in InotifyReaderTask
// returns.
- HANDLE_EINTR(write(shutdown_pipe_[1], "", 1));
+ ssize_t ret = HANDLE_EINTR(write(shutdown_pipe_[1], "", 1));
+ DPCHECK(ret > 0);
+ DCHECK_EQ(ret, 1);
thread_.Stop();
}
if (inotify_fd_ >= 0)
diff --git a/base/file_descriptor_shuffle.cc b/base/file_descriptor_shuffle.cc
index b26ea7f..e722a29 100644
--- a/base/file_descriptor_shuffle.cc
+++ b/base/file_descriptor_shuffle.cc
@@ -76,7 +76,8 @@ bool FileDescriptorTableInjection::Move(int src, int dest) {
}
void FileDescriptorTableInjection::Close(int fd) {
- HANDLE_EINTR(close(fd));
+ int ret = HANDLE_EINTR(close(fd));
+ DPCHECK(ret == 0);
}
} // namespace base
diff --git a/base/file_util_posix.cc b/base/file_util_posix.cc
index d7df8a0..3bd5376 100644
--- a/base/file_util_posix.cc
+++ b/base/file_util_posix.cc
@@ -481,9 +481,10 @@ int ReadFile(const FilePath& filename, char* data, int size) {
if (fd < 0)
return -1;
- int ret_value = HANDLE_EINTR(read(fd, data, size));
- HANDLE_EINTR(close(fd));
- return ret_value;
+ ssize_t bytes_read = HANDLE_EINTR(read(fd, data, size));
+ if (int ret = HANDLE_EINTR(close(fd)) < 0)
+ return ret;
+ return bytes_read;
}
int WriteFile(const FilePath& filename, const char* data, int size) {
@@ -491,9 +492,10 @@ int WriteFile(const FilePath& filename, const char* data, int size) {
if (fd < 0)
return -1;
- int rv = WriteFileDescriptor(fd, data, size);
- HANDLE_EINTR(close(fd));
- return rv;
+ int bytes_written = WriteFileDescriptor(fd, data, size);
+ if (int ret = HANDLE_EINTR(close(fd)) < 0)
+ return ret;
+ return bytes_written;
}
int WriteFileDescriptor(const int fd, const char* data, int size) {
diff --git a/base/process_util_posix.cc b/base/process_util_posix.cc
index f49ba7e..a29304d 100644
--- a/base/process_util_posix.cc
+++ b/base/process_util_posix.cc
@@ -16,6 +16,7 @@
#include <limits>
#include <set>
+#include "base/compiler_specific.h"
#include "base/debug_util.h"
#include "base/eintr_wrapper.h"
#include "base/logging.h"
@@ -223,7 +224,9 @@ void CloseSuperfluousFds(const base::InjectiveMultimap& saved_mapping) {
if (saved_fds.find(fd) != saved_fds.end())
continue;
- HANDLE_EINTR(close(fd));
+ // Since we're just trying to close anything we can find,
+ // ignore any error return values of close().
+ int unused ALLOW_UNUSED = HANDLE_EINTR(close(fd));
}
return;
}
@@ -249,8 +252,10 @@ void CloseSuperfluousFds(const base::InjectiveMultimap& saved_mapping) {
// own use and will complain if we try to close them. All of
// these FDs are >= |max_fds|, so we can check against that here
// before closing. See https://bugs.kde.org/show_bug.cgi?id=191758
- if (fd < static_cast<int>(max_fds))
- HANDLE_EINTR(close(fd));
+ if (fd < static_cast<int>(max_fds)) {
+ int ret = HANDLE_EINTR(close(fd));
+ DPCHECK(ret == 0);
+ }
}
}
@@ -436,8 +441,10 @@ bool LaunchApp(
_exit(127);
} else {
// Parent process
- if (wait)
- HANDLE_EINTR(waitpid(pid, 0, 0));
+ if (wait) {
+ pid_t ret = HANDLE_EINTR(waitpid(pid, 0, 0));
+ DPCHECK(ret > 0);
+ }
if (process_handle)
*process_handle = pid;
diff --git a/base/process_util_unittest.cc b/base/process_util_unittest.cc
index 2ccca54..6ab081e 100644
--- a/base/process_util_unittest.cc
+++ b/base/process_util_unittest.cc
@@ -238,7 +238,8 @@ MULTIPROCESS_TEST_MAIN(ProcessUtilsLeakFDChildProcess) {
int written = HANDLE_EINTR(write(write_pipe, &num_open_files,
sizeof(num_open_files)));
DCHECK_EQ(static_cast<size_t>(written), sizeof(num_open_files));
- HANDLE_EINTR(close(write_pipe));
+ int ret = HANDLE_EINTR(close(write_pipe));
+ DPCHECK(ret == 0);
return 0;
}
@@ -254,7 +255,8 @@ int ProcessUtilTest::CountOpenFDsInChild() {
fd_mapping_vec,
false);
CHECK(handle);
- HANDLE_EINTR(close(fds[1]));
+ int ret = HANDLE_EINTR(close(fds[1]));
+ DPCHECK(ret == 0);
// Read number of open files in client process from pipe;
int num_open_files = -1;
@@ -264,7 +266,8 @@ int ProcessUtilTest::CountOpenFDsInChild() {
CHECK(WaitForSingleProcess(handle, 1000));
base::CloseProcessHandle(handle);
- HANDLE_EINTR(close(fds[0]));
+ ret = HANDLE_EINTR(close(fds[0]));
+ DPCHECK(ret == 0);
return num_open_files;
}
@@ -282,9 +285,13 @@ TEST_F(ProcessUtilTest, FDRemapping) {
ASSERT_EQ(fds_after, fds_before);
- HANDLE_EINTR(close(sockets[0]));
- HANDLE_EINTR(close(sockets[1]));
- HANDLE_EINTR(close(dev_null));
+ int ret;
+ ret = HANDLE_EINTR(close(sockets[0]));
+ DPCHECK(ret == 0);
+ ret = HANDLE_EINTR(close(sockets[1]));
+ DPCHECK(ret == 0);
+ ret = HANDLE_EINTR(close(dev_null));
+ DPCHECK(ret == 0);
}
TEST_F(ProcessUtilTest, GetAppOutput) {