diff options
author | mark@chromium.org <mark@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-12-03 14:10:59 +0000 |
---|---|---|
committer | mark@chromium.org <mark@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-12-03 14:10:59 +0000 |
commit | d89eec809e2d25aee8d386186653699f5017b15b (patch) | |
tree | b8b0433f5766958907ea4cebb7b954e82fc1148a /ipc | |
parent | 34b5946e889071a9c838a4b87d32437415148fed (diff) | |
download | chromium_src-d89eec809e2d25aee8d386186653699f5017b15b.zip chromium_src-d89eec809e2d25aee8d386186653699f5017b15b.tar.gz chromium_src-d89eec809e2d25aee8d386186653699f5017b15b.tar.bz2 |
Don't HANDLE_EINTR(close). Either IGNORE_EINTR(close) or just close.
It is incorrect to wrap close in HANDLE_EINTR on Linux. Correctness is
generally undefined on Mac, but as of r223369, it is incorrect in Chrome on
Mac.
To avoid new offenders, a PRESUBMIT check ensures that HANDLE_EINTR is not
used with close, and that IGNORE_EINTR is only used with close. Unnecessary
#includes of eintr_wrapper.h are also removed.
base/posix/einter_wrapper.h, PRESUBMIT.py, and ppapi/tests/test_broker.cc
contain non-mechanical changes. Variable naming within the latter is updated
per r178174. Missing #includes for <errno.h> in
content/zygote/zygote_main_linux.cc and tools/android/common/daemon.cc were
manually added. Mechanical changes were generated by running:
sed -E -i '' \
-e 's/((=|if|return|CHECK|EXPECT|ASSERT).*)HANDLE(_EINTR\(.*close)/\1IGNORE\3/' \
-e 's/(ignore_result|void ?)\(HANDLE_EINTR\((.*close\(.*)\)\)/\2/' \
-e 's/(\(void\) ?)?HANDLE_EINTR\((.*close\(.*)\)/\2/' \
$(git grep -El 'HANDLE_EINTR.*close')
sed -E -i '' -e '/#include.*eintr_wrapper\.h"/d' \
$(grep -EL '(HANDLE|IGNORE)_EINTR' \
$(git grep -El '#include.*eintr_wrapper\.h"'))
BUG=269623
R=agl@chromium.org, jln@chromium.org
TBR=OWNERS
Review URL: https://codereview.chromium.org/100253002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@238390 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ipc')
-rw-r--r-- | ipc/file_descriptor_set_posix.cc | 4 | ||||
-rw-r--r-- | ipc/file_descriptor_set_posix_unittest.cc | 4 | ||||
-rw-r--r-- | ipc/ipc_channel_factory.cc | 2 | ||||
-rw-r--r-- | ipc/ipc_channel_posix.cc | 22 | ||||
-rw-r--r-- | ipc/ipc_channel_posix_unittest.cc | 2 | ||||
-rw-r--r-- | ipc/ipc_send_fds_test.cc | 8 |
6 files changed, 21 insertions, 21 deletions
diff --git a/ipc/file_descriptor_set_posix.cc b/ipc/file_descriptor_set_posix.cc index fc15c2d..1aa86a7 100644 --- a/ipc/file_descriptor_set_posix.cc +++ b/ipc/file_descriptor_set_posix.cc @@ -31,7 +31,7 @@ FileDescriptorSet::~FileDescriptorSet() { for (unsigned i = consumed_descriptor_highwater_; i < descriptors_.size(); ++i) { if (descriptors_[i].auto_close) - if (HANDLE_EINTR(close(descriptors_[i].fd)) < 0) + if (IGNORE_EINTR(close(descriptors_[i].fd)) < 0) PLOG(ERROR) << "close"; } } @@ -119,7 +119,7 @@ void FileDescriptorSet::CommitAll() { for (std::vector<base::FileDescriptor>::iterator i = descriptors_.begin(); i != descriptors_.end(); ++i) { if (i->auto_close) - if (HANDLE_EINTR(close(i->fd)) < 0) + if (IGNORE_EINTR(close(i->fd)) < 0) PLOG(ERROR) << "close"; } descriptors_.clear(); diff --git a/ipc/file_descriptor_set_posix_unittest.cc b/ipc/file_descriptor_set_posix_unittest.cc index b4a0141..d9107f9 100644 --- a/ipc/file_descriptor_set_posix_unittest.cc +++ b/ipc/file_descriptor_set_posix_unittest.cc @@ -24,8 +24,8 @@ int GetSafeFd() { bool VerifyClosed(int fd) { const int duped = dup(fd); if (duped != -1) { - EXPECT_NE(HANDLE_EINTR(close(duped)), -1); - EXPECT_NE(HANDLE_EINTR(close(fd)), -1); + EXPECT_NE(IGNORE_EINTR(close(duped)), -1); + EXPECT_NE(IGNORE_EINTR(close(fd)), -1); return false; } return true; diff --git a/ipc/ipc_channel_factory.cc b/ipc/ipc_channel_factory.cc index f3ad11a..5c24284 100644 --- a/ipc/ipc_channel_factory.cc +++ b/ipc/ipc_channel_factory.cc @@ -76,7 +76,7 @@ void ChannelFactory::OnFileCanWriteWithoutBlocking(int fd) { void ChannelFactory::Close() { if (listen_fd_ < 0) return; - if (HANDLE_EINTR(close(listen_fd_)) < 0) + if (IGNORE_EINTR(close(listen_fd_)) < 0) PLOG(ERROR) << "close"; listen_fd_ = -1; if (unlink(path_.value().c_str()) < 0) diff --git a/ipc/ipc_channel_posix.cc b/ipc/ipc_channel_posix.cc index a74178a..8788532 100644 --- a/ipc/ipc_channel_posix.cc +++ b/ipc/ipc_channel_posix.cc @@ -206,9 +206,9 @@ bool SocketPair(int* fd1, int* fd2) { if (fcntl(pipe_fds[0], F_SETFL, O_NONBLOCK) == -1 || fcntl(pipe_fds[1], F_SETFL, O_NONBLOCK) == -1) { PLOG(ERROR) << "fcntl(O_NONBLOCK)"; - if (HANDLE_EINTR(close(pipe_fds[0])) < 0) + if (IGNORE_EINTR(close(pipe_fds[0])) < 0) PLOG(ERROR) << "close"; - if (HANDLE_EINTR(close(pipe_fds[1])) < 0) + if (IGNORE_EINTR(close(pipe_fds[1])) < 0) PLOG(ERROR) << "close"; return false; } @@ -547,7 +547,7 @@ void Channel::ChannelImpl::CloseClientFileDescriptor() { base::AutoLock lock(client_pipe_lock_); if (client_pipe_ != -1) { PipeMap::GetInstance()->Remove(pipe_name_); - if (HANDLE_EINTR(close(client_pipe_)) < 0) + if (IGNORE_EINTR(close(client_pipe_)) < 0) PLOG(ERROR) << "close " << pipe_name_; client_pipe_ = -1; } @@ -571,18 +571,18 @@ void Channel::ChannelImpl::ResetToAcceptingConnectionState() { read_watcher_.StopWatchingFileDescriptor(); write_watcher_.StopWatchingFileDescriptor(); if (pipe_ != -1) { - if (HANDLE_EINTR(close(pipe_)) < 0) + if (IGNORE_EINTR(close(pipe_)) < 0) PLOG(ERROR) << "close pipe_ " << pipe_name_; pipe_ = -1; } #if defined(IPC_USES_READWRITE) if (fd_pipe_ != -1) { - if (HANDLE_EINTR(close(fd_pipe_)) < 0) + if (IGNORE_EINTR(close(fd_pipe_)) < 0) PLOG(ERROR) << "close fd_pipe_ " << pipe_name_; fd_pipe_ = -1; } if (remote_fd_pipe_ != -1) { - if (HANDLE_EINTR(close(remote_fd_pipe_)) < 0) + if (IGNORE_EINTR(close(remote_fd_pipe_)) < 0) PLOG(ERROR) << "close remote_fd_pipe_ " << pipe_name_; remote_fd_pipe_ = -1; } @@ -602,7 +602,7 @@ void Channel::ChannelImpl::ResetToAcceptingConnectionState() { for (std::set<int>::iterator i = fds_to_close_.begin(); i != fds_to_close_.end(); ++i) { - if (HANDLE_EINTR(close(*i)) < 0) + if (IGNORE_EINTR(close(*i)) < 0) PLOG(ERROR) << "close"; } fds_to_close_.clear(); @@ -637,7 +637,7 @@ void Channel::ChannelImpl::OnFileCanReadWithoutBlocking(int fd) { // close our new descriptor. if (HANDLE_EINTR(shutdown(new_pipe, SHUT_RDWR)) < 0) DPLOG(ERROR) << "shutdown " << pipe_name_; - if (HANDLE_EINTR(close(new_pipe)) < 0) + if (IGNORE_EINTR(close(new_pipe)) < 0) DPLOG(ERROR) << "close " << pipe_name_; listener()->OnChannelDenied(); return; @@ -927,7 +927,7 @@ bool Channel::ChannelImpl::ExtractFileDescriptorsFromMsghdr(msghdr* msg) { void Channel::ChannelImpl::ClearInputFDs() { for (size_t i = 0; i < input_fds_.size(); ++i) { - if (HANDLE_EINTR(close(input_fds_[i])) < 0) + if (IGNORE_EINTR(close(input_fds_[i])) < 0) PLOG(ERROR) << "close "; } input_fds_.clear(); @@ -996,7 +996,7 @@ void Channel::ChannelImpl::HandleInternalMessage(const Message& msg) { NOTREACHED(); if (hops == 0) { if (fds_to_close_.erase(fd) > 0) { - if (HANDLE_EINTR(close(fd)) < 0) + if (IGNORE_EINTR(close(fd)) < 0) PLOG(ERROR) << "close"; } else { NOTREACHED(); @@ -1020,7 +1020,7 @@ void Channel::ChannelImpl::Close() { must_unlink_ = false; } if (server_listen_pipe_ != -1) { - if (HANDLE_EINTR(close(server_listen_pipe_)) < 0) + if (IGNORE_EINTR(close(server_listen_pipe_)) < 0) DPLOG(ERROR) << "close " << server_listen_pipe_; server_listen_pipe_ = -1; // Unregister libevent for the listening socket and close it. diff --git a/ipc/ipc_channel_posix_unittest.cc b/ipc/ipc_channel_posix_unittest.cc index 66ddeb2..eca78f1 100644 --- a/ipc/ipc_channel_posix_unittest.cc +++ b/ipc/ipc_channel_posix_unittest.cc @@ -219,7 +219,7 @@ TEST_F(IPCChannelPosixTest, BasicConnected) { ASSERT_TRUE(channel.Connect()); ASSERT_FALSE(channel.AcceptsConnections()); channel.Close(); - ASSERT_TRUE(HANDLE_EINTR(close(pipe_fds[1])) == 0); + ASSERT_TRUE(IGNORE_EINTR(close(pipe_fds[1])) == 0); // Make sure that we can use the socket that is created for us by // a standard channel. diff --git a/ipc/ipc_send_fds_test.cc b/ipc/ipc_send_fds_test.cc index 20c3ed5..aeec890 100644 --- a/ipc/ipc_send_fds_test.cc +++ b/ipc/ipc_send_fds_test.cc @@ -153,7 +153,7 @@ MULTIPROCESS_IPC_TEST_CLIENT_MAIN(SendFdsClient) { struct stat st; int fd = open(kDevZeroPath, O_RDONLY); fstat(fd, &st); - EXPECT_GE(HANDLE_EINTR(close(fd)), 0); + EXPECT_GE(IGNORE_EINTR(close(fd)), 0); return SendFdsClientCommon("SendFdsClient", st.st_ino); } @@ -169,7 +169,7 @@ MULTIPROCESS_IPC_TEST_CLIENT_MAIN(SendFdsSandboxedClient) { struct stat st; const int fd = open(kDevZeroPath, O_RDONLY); fstat(fd, &st); - if (HANDLE_EINTR(close(fd)) < 0) + if (IGNORE_EINTR(close(fd)) < 0) return -1; // Enable the sandbox. @@ -321,7 +321,7 @@ class IPCMultiSendingFdsTest : public testing::Test { pipe_fds.second)); char tmp = 'x'; CHECK_EQ(1, HANDLE_EINTR(write(pipe_fds.first, &tmp, 1))); - CHECK_EQ(0, HANDLE_EINTR(close(pipe_fds.first))); + CHECK_EQ(0, IGNORE_EINTR(close(pipe_fds.first))); received_.Wait(); } } @@ -330,7 +330,7 @@ class IPCMultiSendingFdsTest : public testing::Test { char tmp = 'y'; CHECK_EQ(1, HANDLE_EINTR(read(fd, &tmp, 1))); CHECK_EQ(tmp, 'x'); - CHECK_EQ(0, HANDLE_EINTR(close(fd))); + CHECK_EQ(0, IGNORE_EINTR(close(fd))); received_.Signal(); } |