Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "ipc/ipc_channel_posix.h" | 5 #include "ipc/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/socket.h> | 10 #include <sys/socket.h> |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 169 #if defined(OS_ANDROID) | 169 #if defined(OS_ANDROID) |
| 170 // When we fork for simple tests on Android, we can't 'exec', so we need to | 170 // When we fork for simple tests on Android, we can't 'exec', so we need to |
| 171 // reset these entries manually to get the expected testing behavior. | 171 // reset these entries manually to get the expected testing behavior. |
| 172 void Channel::NotifyProcessForkedForTesting() { | 172 void Channel::NotifyProcessForkedForTesting() { |
| 173 PipeMap::GetInstance()->map_.clear(); | 173 PipeMap::GetInstance()->map_.clear(); |
| 174 } | 174 } |
| 175 #endif | 175 #endif |
| 176 | 176 |
| 177 //------------------------------------------------------------------------------ | 177 //------------------------------------------------------------------------------ |
| 178 | 178 |
| 179 #if defined(OS_LINUX) | 179 #if defined(OS_LINUX) || defined(OS_NACL_NONSFI) |
| 180 int ChannelPosix::global_pid_ = 0; | 180 int ChannelPosix::global_pid_ = 0; |
| 181 #endif // OS_LINUX | 181 #endif // defined(OS_LINUX) || defined(OS_NACL_NONSFI) |
| 182 | 182 |
| 183 ChannelPosix::ChannelPosix(const IPC::ChannelHandle& channel_handle, | 183 ChannelPosix::ChannelPosix(const IPC::ChannelHandle& channel_handle, |
| 184 Mode mode, Listener* listener) | 184 Mode mode, Listener* listener) |
| 185 : ChannelReader(listener), | 185 : ChannelReader(listener), |
| 186 mode_(mode), | 186 mode_(mode), |
| 187 peer_pid_(base::kNullProcessId), | 187 peer_pid_(base::kNullProcessId), |
| 188 is_blocked_on_write_(false), | 188 is_blocked_on_write_(false), |
| 189 waiting_connect_(true), | 189 waiting_connect_(true), |
| 190 message_send_bytes_written_(0), | 190 message_send_bytes_written_(0), |
| 191 pipe_name_(channel_handle.name), | 191 pipe_name_(channel_handle.name), |
| (...skipping 446 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 638 fds_to_close_.clear(); | 638 fds_to_close_.clear(); |
| 639 #endif | 639 #endif |
| 640 } | 640 } |
| 641 | 641 |
| 642 // static | 642 // static |
| 643 bool ChannelPosix::IsNamedServerInitialized( | 643 bool ChannelPosix::IsNamedServerInitialized( |
| 644 const std::string& channel_id) { | 644 const std::string& channel_id) { |
| 645 return base::PathExists(base::FilePath(channel_id)); | 645 return base::PathExists(base::FilePath(channel_id)); |
| 646 } | 646 } |
| 647 | 647 |
| 648 #if defined(OS_LINUX) | 648 #if defined(OS_LINUX) || defined(OS_NACL_NONSFI) |
| 649 // static | 649 // static |
| 650 void ChannelPosix::SetGlobalPid(int pid) { | 650 void ChannelPosix::SetGlobalPid(int pid) { |
| 651 global_pid_ = pid; | 651 global_pid_ = pid; |
| 652 } | 652 } |
| 653 #endif // OS_LINUX | 653 #endif // defined(OS_LINUX) || defined(OS_NACL_NONSFI) |
| 654 | 654 |
| 655 // Called by libevent when we can read from the pipe without blocking. | 655 // Called by libevent when we can read from the pipe without blocking. |
| 656 void ChannelPosix::OnFileCanReadWithoutBlocking(int fd) { | 656 void ChannelPosix::OnFileCanReadWithoutBlocking(int fd) { |
| 657 if (fd == server_listen_pipe_.get()) { | 657 if (fd == server_listen_pipe_.get()) { |
| 658 #if defined(__native_client_nonsfi__) | 658 #if defined(__native_client_nonsfi__) |
| 659 LOG(FATAL) | 659 LOG(FATAL) |
| 660 << "IPC channels in nacl_helper_nonsfi should not be SERVER mode."; | 660 << "IPC channels in nacl_helper_nonsfi should not be SERVER mode."; |
| 661 #else | 661 #else |
| 662 int new_pipe = 0; | 662 int new_pipe = 0; |
| 663 if (!ServerAcceptConnection(server_listen_pipe_.get(), &new_pipe) || | 663 if (!ServerAcceptConnection(server_listen_pipe_.get(), &new_pipe) || |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 764 Close(); | 764 Close(); |
| 765 if (AcceptsConnections()) { | 765 if (AcceptsConnections()) { |
| 766 listener()->OnChannelListenError(); | 766 listener()->OnChannelListenError(); |
| 767 } else { | 767 } else { |
| 768 listener()->OnChannelError(); | 768 listener()->OnChannelError(); |
| 769 } | 769 } |
| 770 } | 770 } |
| 771 } | 771 } |
| 772 | 772 |
| 773 int ChannelPosix::GetHelloMessageProcId() const { | 773 int ChannelPosix::GetHelloMessageProcId() const { |
| 774 int pid = base::GetCurrentProcId(); | 774 #if defined(OS_LINUX) || defined(OS_NACL_NONSFI) |
| 775 #if defined(OS_LINUX) | 775 // Our process may be in a sandbox with a separate PID namespace in Linux. |
| 776 // Our process may be in a sandbox with a separate PID namespace. | 776 // In nacl_helper_nonsfi, getpid() invoked by GetCurrentProcId() is not |
| 777 if (global_pid_) { | 777 // allowed and would cause a SIGSYS crashing because of seccomp sandbox. |
|
dmichael (off chromium)
2014/11/05 23:48:41
nit: of +the+ seccomp sandbox
hidehiko
2014/11/06 14:19:30
Done.
| |
| 778 pid = global_pid_; | 778 // |global_pid_| should be initialized in advance in the process. |
| 779 } | 779 if (global_pid_) |
| 780 return global_pid_; | |
| 780 #endif | 781 #endif |
| 781 return pid; | 782 return base::GetCurrentProcId(); |
| 782 } | 783 } |
| 783 | 784 |
| 784 void ChannelPosix::QueueHelloMessage() { | 785 void ChannelPosix::QueueHelloMessage() { |
| 785 // Create the Hello message | 786 // Create the Hello message |
| 786 scoped_ptr<Message> msg(new Message(MSG_ROUTING_NONE, | 787 scoped_ptr<Message> msg(new Message(MSG_ROUTING_NONE, |
| 787 HELLO_MESSAGE_TYPE, | 788 HELLO_MESSAGE_TYPE, |
| 788 IPC::Message::PRIORITY_NORMAL)); | 789 IPC::Message::PRIORITY_NORMAL)); |
| 789 if (!msg->WriteInt(GetHelloMessageProcId())) { | 790 if (!msg->WriteInt(GetHelloMessageProcId())) { |
| 790 NOTREACHED() << "Unable to pickle hello message proc id"; | 791 NOTREACHED() << "Unable to pickle hello message proc id"; |
| 791 } | 792 } |
| (...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1104 | 1105 |
| 1105 return id.append(GenerateUniqueRandomChannelID()); | 1106 return id.append(GenerateUniqueRandomChannelID()); |
| 1106 } | 1107 } |
| 1107 | 1108 |
| 1108 | 1109 |
| 1109 bool Channel::IsNamedServerInitialized( | 1110 bool Channel::IsNamedServerInitialized( |
| 1110 const std::string& channel_id) { | 1111 const std::string& channel_id) { |
| 1111 return ChannelPosix::IsNamedServerInitialized(channel_id); | 1112 return ChannelPosix::IsNamedServerInitialized(channel_id); |
| 1112 } | 1113 } |
| 1113 | 1114 |
| 1114 #if defined(OS_LINUX) | 1115 #if defined(OS_LINUX) || defined(OS_NACL_NONSFI) |
| 1115 // static | 1116 // static |
| 1116 void Channel::SetGlobalPid(int pid) { | 1117 void Channel::SetGlobalPid(int pid) { |
| 1117 ChannelPosix::SetGlobalPid(pid); | 1118 ChannelPosix::SetGlobalPid(pid); |
| 1118 } | 1119 } |
| 1119 #endif // OS_LINUX | 1120 #endif // defined(OS_LINUX) || defined(OS_NACL_NONSFI) |
| 1120 | 1121 |
| 1121 } // namespace IPC | 1122 } // namespace IPC |
| OLD | NEW |