| 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 <stdint.h> | 10 #include <stdint.h> |
| (...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 357 // Watch the pipe for connections, and turn any connections into | 357 // Watch the pipe for connections, and turn any connections into |
| 358 // active sockets. | 358 // active sockets. |
| 359 base::MessageLoopForIO::current()->WatchFileDescriptor( | 359 base::MessageLoopForIO::current()->WatchFileDescriptor( |
| 360 server_listen_pipe_.get(), | 360 server_listen_pipe_.get(), |
| 361 true, | 361 true, |
| 362 base::MessageLoopForIO::WATCH_READ, | 362 base::MessageLoopForIO::WATCH_READ, |
| 363 &server_listen_connection_watcher_, | 363 &server_listen_connection_watcher_, |
| 364 this); | 364 this); |
| 365 #endif | 365 #endif |
| 366 } else { | 366 } else { |
| 367 did_connect = AcceptConnection(); | 367 did_connect = OnConnect(); |
| 368 } | 368 } |
| 369 return did_connect; | 369 return did_connect; |
| 370 } | 370 } |
| 371 | 371 |
| 372 void ChannelPosix::CloseFileDescriptors(Message* msg) { | 372 void ChannelPosix::CloseFileDescriptors(Message* msg) { |
| 373 #if defined(OS_MACOSX) | 373 #if defined(OS_MACOSX) |
| 374 // There is a bug on OSX which makes it dangerous to close | 374 // There is a bug on OSX which makes it dangerous to close |
| 375 // a file descriptor while it is in transit. So instead we | 375 // a file descriptor while it is in transit. So instead we |
| 376 // store the file descriptor in a set and send a message to | 376 // store the file descriptor in a set and send a message to |
| 377 // the recipient, which is queued AFTER the message that | 377 // the recipient, which is queued AFTER the message that |
| (...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 625 #endif // OS_LINUX | 625 #endif // OS_LINUX |
| 626 | 626 |
| 627 // Called by libevent when we can read from the pipe without blocking. | 627 // Called by libevent when we can read from the pipe without blocking. |
| 628 void ChannelPosix::OnFileCanReadWithoutBlocking(int fd) { | 628 void ChannelPosix::OnFileCanReadWithoutBlocking(int fd) { |
| 629 if (fd == server_listen_pipe_.get()) { | 629 if (fd == server_listen_pipe_.get()) { |
| 630 #if defined(OS_NACL_NONSFI) | 630 #if defined(OS_NACL_NONSFI) |
| 631 LOG(FATAL) | 631 LOG(FATAL) |
| 632 << "IPC channels in nacl_helper_nonsfi should not be SERVER mode."; | 632 << "IPC channels in nacl_helper_nonsfi should not be SERVER mode."; |
| 633 #else | 633 #else |
| 634 int new_pipe = 0; | 634 int new_pipe = 0; |
| 635 if (!ServerAcceptConnection(server_listen_pipe_.get(), &new_pipe) || | 635 if (!ServerOnConnect(server_listen_pipe_.get(), &new_pipe) || |
| 636 new_pipe < 0) { | 636 new_pipe < 0) { |
| 637 Close(); | 637 Close(); |
| 638 listener()->OnChannelListenError(); | 638 listener()->OnChannelListenError(); |
| 639 } | 639 } |
| 640 | 640 |
| 641 if (pipe_.is_valid()) { | 641 if (pipe_.is_valid()) { |
| 642 // We already have a connection. We only handle one at a time. | 642 // We already have a connection. We only handle one at a time. |
| 643 // close our new descriptor. | 643 // close our new descriptor. |
| 644 if (HANDLE_EINTR(shutdown(new_pipe, SHUT_RDWR)) < 0) | 644 if (HANDLE_EINTR(shutdown(new_pipe, SHUT_RDWR)) < 0) |
| 645 DPLOG(ERROR) << "shutdown " << pipe_name_; | 645 DPLOG(ERROR) << "shutdown " << pipe_name_; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 658 ResetToAcceptingConnectionState(); | 658 ResetToAcceptingConnectionState(); |
| 659 return; | 659 return; |
| 660 } | 660 } |
| 661 if (client_euid != geteuid()) { | 661 if (client_euid != geteuid()) { |
| 662 DLOG(WARNING) << "Client euid is not authorised"; | 662 DLOG(WARNING) << "Client euid is not authorised"; |
| 663 ResetToAcceptingConnectionState(); | 663 ResetToAcceptingConnectionState(); |
| 664 return; | 664 return; |
| 665 } | 665 } |
| 666 } | 666 } |
| 667 | 667 |
| 668 if (!AcceptConnection()) { | 668 if (!OnConnect()) { |
| 669 NOTREACHED() << "AcceptConnection should not fail on server"; | 669 NOTREACHED() << "AcceptConnection should not fail on server"; |
| 670 } | 670 } |
| 671 waiting_connect_ = false; | 671 waiting_connect_ = false; |
| 672 #endif | 672 #endif |
| 673 } else if (fd == pipe_) { | 673 } else if (fd == pipe_) { |
| 674 if (waiting_connect_ && (mode_ & MODE_SERVER_FLAG)) { | 674 if (waiting_connect_ && (mode_ & MODE_SERVER_FLAG)) { |
| 675 waiting_connect_ = false; | 675 waiting_connect_ = false; |
| 676 } | 676 } |
| 677 if (ProcessIncomingMessages() == DISPATCH_ERROR) { | 677 if (ProcessIncomingMessages() == DISPATCH_ERROR) { |
| 678 // ClosePipeOnError may delete this object, so we mustn't call | 678 // ClosePipeOnError may delete this object, so we mustn't call |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 761 // Delete any unprocessed messages. | 761 // Delete any unprocessed messages. |
| 762 while (!prelim_queue.empty()) { | 762 while (!prelim_queue.empty()) { |
| 763 Message* m = prelim_queue.front(); | 763 Message* m = prelim_queue.front(); |
| 764 delete m; | 764 delete m; |
| 765 prelim_queue.pop(); | 765 prelim_queue.pop(); |
| 766 } | 766 } |
| 767 | 767 |
| 768 return !processing_error; | 768 return !processing_error; |
| 769 } | 769 } |
| 770 | 770 |
| 771 bool ChannelPosix::AcceptConnection() { | 771 bool ChannelPosix::OnConnect() { |
| 772 base::MessageLoopForIO::current()->WatchFileDescriptor( | 772 base::MessageLoopForIO::current()->WatchFileDescriptor( |
| 773 pipe_.get(), | 773 pipe_.get(), |
| 774 true, | 774 true, |
| 775 base::MessageLoopForIO::WATCH_READ, | 775 base::MessageLoopForIO::WATCH_READ, |
| 776 &read_watcher_, | 776 &read_watcher_, |
| 777 this); | 777 this); |
| 778 QueueHelloMessage(); | 778 QueueHelloMessage(); |
| 779 | 779 |
| 780 if (mode_ & MODE_CLIENT_FLAG) { | 780 if (mode_ & MODE_CLIENT_FLAG) { |
| 781 // If we are a client we want to send a hello message out immediately. | 781 // If we are a client we want to send a hello message out immediately. |
| (...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1139 // static | 1139 // static |
| 1140 void Channel::SetGlobalPid(int pid) { | 1140 void Channel::SetGlobalPid(int pid) { |
| 1141 ChannelPosix::SetGlobalPid(pid); | 1141 ChannelPosix::SetGlobalPid(pid); |
| 1142 } | 1142 } |
| 1143 int Channel::GetGlobalPid() { | 1143 int Channel::GetGlobalPid() { |
| 1144 return ChannelPosix::GetGlobalPid(); | 1144 return ChannelPosix::GetGlobalPid(); |
| 1145 } | 1145 } |
| 1146 #endif // OS_LINUX | 1146 #endif // OS_LINUX |
| 1147 | 1147 |
| 1148 } // namespace IPC | 1148 } // namespace IPC |
| OLD | NEW |