diff options
author | agl@chromium.org <agl@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-02-10 08:14:58 +0000 |
---|---|---|
committer | agl@chromium.org <agl@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-02-10 08:14:58 +0000 |
commit | d8480ab6be1853998fc053919a3194c14a42aebc (patch) | |
tree | 86bd23850ff2efa5a6177c16cc7548d17ab57f18 | |
parent | 65d881defe3e7f4873f7553bc34bf0cd6ae231fe (diff) | |
download | chromium_src-d8480ab6be1853998fc053919a3194c14a42aebc.zip chromium_src-d8480ab6be1853998fc053919a3194c14a42aebc.tar.gz chromium_src-d8480ab6be1853998fc053919a3194c14a42aebc.tar.bz2 |
POSIX: fix file descriptor passing
Although descriptor passing was working fine in tests, it didn't work
at all in real code. When a Message is taken off the wire, it's copied
before processing. Message has an explicit copy constructor which
wasn't copying the list of FileDescriptors.
This changes makes the Message copy constructor steal the
FileDescriptors from the source Message.
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@9470 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/common/file_descriptor_posix.cc | 8 | ||||
-rw-r--r-- | chrome/common/file_descriptor_posix.h | 9 | ||||
-rw-r--r-- | chrome/common/ipc_message.cc | 1 |
3 files changed, 18 insertions, 0 deletions
diff --git a/chrome/common/file_descriptor_posix.cc b/chrome/common/file_descriptor_posix.cc index b3dc4a0..7db9514 100644 --- a/chrome/common/file_descriptor_posix.cc +++ b/chrome/common/file_descriptor_posix.cc @@ -80,3 +80,11 @@ void DescriptorSet::SetDescriptors(const int* buffer, unsigned count) { descriptors_.push_back(sd); } } + +void DescriptorSet::TakeFrom(DescriptorSet* other) { + DCHECK(descriptors_.size() == 0); + + descriptors_.swap(other->descriptors_); + next_descriptor_ = other->next_descriptor_; + other->next_descriptor_ = 0; +} diff --git a/chrome/common/file_descriptor_posix.h b/chrome/common/file_descriptor_posix.h index 533992e..43590b0 100644 --- a/chrome/common/file_descriptor_posix.h +++ b/chrome/common/file_descriptor_posix.h @@ -101,6 +101,15 @@ class DescriptorSet { // --------------------------------------------------------------------------- + // --------------------------------------------------------------------------- + // Interfaces for IPC::Message... + + // Take all the FileDescriptors from another set. Just like a copy + // constructor, except that the source is emptied. + void TakeFrom(DescriptorSet* other); + + // --------------------------------------------------------------------------- + private: // A vector of descriptors and close flags. If this message is sent, then // these descriptors are sent as control data. After sending, any descriptors diff --git a/chrome/common/ipc_message.cc b/chrome/common/ipc_message.cc index 67dfad8..9ec3105 100644 --- a/chrome/common/ipc_message.cc +++ b/chrome/common/ipc_message.cc @@ -40,6 +40,7 @@ Message::Message(const char* data, int data_len) : Pickle(data, data_len) { Message::Message(const Message& other) : Pickle(other) { InitLoggingVariables(); + descriptor_set_.TakeFrom(&other.descriptor_set_); } void Message::InitLoggingVariables() { |