| OLD | NEW |
| 1 // Copyright (c) 2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2008 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/common/ipc_channel_posix.h" | 5 #include "chrome/common/ipc_channel_posix.h" |
| 6 | 6 |
| 7 #include <errno.h> | 7 #include <errno.h> |
| 8 #include <fcntl.h> | 8 #include <fcntl.h> |
| 9 #include <stddef.h> | 9 #include <stddef.h> |
| 10 #include <sys/types.h> | 10 #include <sys/types.h> |
| 11 #include <sys/socket.h> | 11 #include <sys/socket.h> |
| 12 #include <sys/stat.h> | 12 #include <sys/stat.h> |
| 13 #include <sys/un.h> | 13 #include <sys/un.h> |
| 14 | 14 |
| 15 #include <string> | 15 #include <string> |
| 16 #include <map> | 16 #include <map> |
| 17 | 17 |
| 18 #include "base/command_line.h" | 18 #include "base/command_line.h" |
| 19 #include "base/eintr_wrapper.h" | 19 #include "base/eintr_wrapper.h" |
| 20 #include "base/lock.h" | 20 #include "base/lock.h" |
| 21 #include "base/logging.h" | 21 #include "base/logging.h" |
| 22 #include "base/process_util.h" | 22 #include "base/process_util.h" |
| 23 #include "base/reserved_file_descriptors.h" |
| 23 #include "base/scoped_ptr.h" | 24 #include "base/scoped_ptr.h" |
| 24 #include "base/string_util.h" | 25 #include "base/string_util.h" |
| 25 #include "base/singleton.h" | 26 #include "base/singleton.h" |
| 26 #include "base/stats_counters.h" | 27 #include "base/stats_counters.h" |
| 27 #include "chrome/common/chrome_counters.h" | 28 #include "chrome/common/chrome_counters.h" |
| 28 #include "chrome/common/chrome_switches.h" | 29 #include "chrome/common/chrome_switches.h" |
| 29 #include "chrome/common/file_descriptor_set_posix.h" | 30 #include "chrome/common/file_descriptor_set_posix.h" |
| 30 #include "chrome/common/ipc_logging.h" | 31 #include "chrome/common/ipc_logging.h" |
| 31 #include "chrome/common/ipc_message_utils.h" | 32 #include "chrome/common/ipc_message_utils.h" |
| 32 | 33 |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 << "' while first still exists"; | 108 << "' while first still exists"; |
| 108 map_[channel_id] = fd; | 109 map_[channel_id] = fd; |
| 109 } | 110 } |
| 110 | 111 |
| 111 private: | 112 private: |
| 112 Lock lock_; | 113 Lock lock_; |
| 113 typedef std::map<std::string, int> ChannelToFDMap; | 114 typedef std::map<std::string, int> ChannelToFDMap; |
| 114 ChannelToFDMap map_; | 115 ChannelToFDMap map_; |
| 115 }; | 116 }; |
| 116 | 117 |
| 117 // This is the file descriptor number that a client process expects to find its | |
| 118 // IPC socket. | |
| 119 static const int kClientChannelFd = 3; | |
| 120 | |
| 121 // Used to map a channel name to the equivalent FD # in the client process. | 118 // Used to map a channel name to the equivalent FD # in the client process. |
| 122 int ChannelNameToClientFD(const std::string& channel_id) { | 119 int ChannelNameToClientFD(const std::string& channel_id) { |
| 123 // See the large block comment above PipeMap for the reasoning here. | 120 // See the large block comment above PipeMap for the reasoning here. |
| 124 const int fd = Singleton<PipeMap>()->Lookup(channel_id); | 121 const int fd = Singleton<PipeMap>()->Lookup(channel_id); |
| 125 if (fd != -1) | 122 if (fd != -1) |
| 126 return dup(fd); | 123 return dup(fd); |
| 127 | 124 |
| 128 // If we don't find an entry, we assume that the correct value has been | 125 // If we don't find an entry, we assume that the correct value has been |
| 129 // inserted in the magic slot. | 126 // inserted in the magic slot. |
| 127 // kClientChannelFd is the file descriptor number that a client process |
| 128 // expects to find its IPC socket; see reserved_file_descriptors.h. |
| 129 |
| 130 return kClientChannelFd; | 130 return kClientChannelFd; |
| 131 } | 131 } |
| 132 | 132 |
| 133 //------------------------------------------------------------------------------ | 133 //------------------------------------------------------------------------------ |
| 134 sockaddr_un sizecheck; | 134 sockaddr_un sizecheck; |
| 135 const size_t kMaxPipeNameLength = sizeof(sizecheck.sun_path); | 135 const size_t kMaxPipeNameLength = sizeof(sizecheck.sun_path); |
| 136 | 136 |
| 137 // Creates a Fifo with the specified name ready to listen on. | 137 // Creates a Fifo with the specified name ready to listen on. |
| 138 bool CreateServerFifo(const std::string& pipe_name, int* server_listen_fd) { | 138 bool CreateServerFifo(const std::string& pipe_name, int* server_listen_fd) { |
| 139 DCHECK(server_listen_fd); | 139 DCHECK(server_listen_fd); |
| (...skipping 661 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 801 | 801 |
| 802 bool Channel::Send(Message* message) { | 802 bool Channel::Send(Message* message) { |
| 803 return channel_impl_->Send(message); | 803 return channel_impl_->Send(message); |
| 804 } | 804 } |
| 805 | 805 |
| 806 void Channel::GetClientFileDescriptorMapping(int *src_fd, int *dest_fd) const { | 806 void Channel::GetClientFileDescriptorMapping(int *src_fd, int *dest_fd) const { |
| 807 return channel_impl_->GetClientFileDescriptorMapping(src_fd, dest_fd); | 807 return channel_impl_->GetClientFileDescriptorMapping(src_fd, dest_fd); |
| 808 } | 808 } |
| 809 | 809 |
| 810 } // namespace IPC | 810 } // namespace IPC |
| OLD | NEW |