Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(400)

Side by Side Diff: ipc/ipc_channel_posix.h

Issue 9968111: Make IPC channels track their peer process ID (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ipc/ipc_channel.h ('k') | ipc/ipc_channel_posix.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #ifndef IPC_IPC_CHANNEL_POSIX_H_ 5 #ifndef IPC_IPC_CHANNEL_POSIX_H_
6 #define IPC_IPC_CHANNEL_POSIX_H_ 6 #define IPC_IPC_CHANNEL_POSIX_H_
7 #pragma once 7 #pragma once
8 8
9 #include "ipc/ipc_channel.h" 9 #include "ipc/ipc_channel.h"
10 10
11 #include <sys/socket.h> // for CMSG macros 11 #include <sys/socket.h> // for CMSG macros
12 12
13 #include <queue> 13 #include <queue>
14 #include <string> 14 #include <string>
15 #include <vector> 15 #include <vector>
16 16
17 #include "base/message_loop.h" 17 #include "base/message_loop.h"
18 #include "base/process.h"
18 #include "ipc/file_descriptor_set_posix.h" 19 #include "ipc/file_descriptor_set_posix.h"
19 #include "ipc/ipc_channel_reader.h" 20 #include "ipc/ipc_channel_reader.h"
20 21
21 #if !defined(OS_MACOSX) 22 #if !defined(OS_MACOSX)
22 // On Linux, the seccomp sandbox makes it very expensive to call 23 // On Linux, the seccomp sandbox makes it very expensive to call
23 // recvmsg() and sendmsg(). The restriction on calling read() and write(), which 24 // recvmsg() and sendmsg(). The restriction on calling read() and write(), which
24 // are cheap, is that we can't pass file descriptors over them. 25 // are cheap, is that we can't pass file descriptors over them.
25 // 26 //
26 // As we cannot anticipate when the sender will provide us with file 27 // As we cannot anticipate when the sender will provide us with file
27 // descriptors, we have to make the decision about whether we call read() or 28 // descriptors, we have to make the decision about whether we call read() or
(...skipping 30 matching lines...) Expand all
58 bool Connect(); 59 bool Connect();
59 void Close(); 60 void Close();
60 bool Send(Message* message); 61 bool Send(Message* message);
61 int GetClientFileDescriptor(); 62 int GetClientFileDescriptor();
62 int TakeClientFileDescriptor(); 63 int TakeClientFileDescriptor();
63 void CloseClientFileDescriptor(); 64 void CloseClientFileDescriptor();
64 bool AcceptsConnections() const; 65 bool AcceptsConnections() const;
65 bool HasAcceptedConnection() const; 66 bool HasAcceptedConnection() const;
66 bool GetClientEuid(uid_t* client_euid) const; 67 bool GetClientEuid(uid_t* client_euid) const;
67 void ResetToAcceptingConnectionState(); 68 void ResetToAcceptingConnectionState();
69 base::ProcessId peer_pid() const { return peer_pid_; }
68 static bool IsNamedServerInitialized(const std::string& channel_id); 70 static bool IsNamedServerInitialized(const std::string& channel_id);
69 #if defined(OS_LINUX) 71 #if defined(OS_LINUX)
70 static void SetGlobalPid(int pid); 72 static void SetGlobalPid(int pid);
71 #endif // OS_LINUX 73 #endif // OS_LINUX
72 74
73 private: 75 private:
74 bool CreatePipe(const IPC::ChannelHandle& channel_handle); 76 bool CreatePipe(const IPC::ChannelHandle& channel_handle);
75 77
76 bool ProcessOutgoingMessages(); 78 bool ProcessOutgoingMessages();
77 79
(...skipping 28 matching lines...) Expand all
106 // Closes all handles in the input_fds_ list and clears the list. This is 108 // Closes all handles in the input_fds_ list and clears the list. This is
107 // used to clean up handles in error conditions to avoid leaking the handles. 109 // used to clean up handles in error conditions to avoid leaking the handles.
108 void ClearInputFDs(); 110 void ClearInputFDs();
109 111
110 // MessageLoopForIO::Watcher implementation. 112 // MessageLoopForIO::Watcher implementation.
111 virtual void OnFileCanReadWithoutBlocking(int fd) OVERRIDE; 113 virtual void OnFileCanReadWithoutBlocking(int fd) OVERRIDE;
112 virtual void OnFileCanWriteWithoutBlocking(int fd) OVERRIDE; 114 virtual void OnFileCanWriteWithoutBlocking(int fd) OVERRIDE;
113 115
114 Mode mode_; 116 Mode mode_;
115 117
118 base::ProcessId peer_pid_;
119
116 // After accepting one client connection on our server socket we want to 120 // After accepting one client connection on our server socket we want to
117 // stop listening. 121 // stop listening.
118 MessageLoopForIO::FileDescriptorWatcher server_listen_connection_watcher_; 122 MessageLoopForIO::FileDescriptorWatcher server_listen_connection_watcher_;
119 MessageLoopForIO::FileDescriptorWatcher read_watcher_; 123 MessageLoopForIO::FileDescriptorWatcher read_watcher_;
120 MessageLoopForIO::FileDescriptorWatcher write_watcher_; 124 MessageLoopForIO::FileDescriptorWatcher write_watcher_;
121 125
122 // Indicates whether we're currently blocked waiting for a write to complete. 126 // Indicates whether we're currently blocked waiting for a write to complete.
123 bool is_blocked_on_write_; 127 bool is_blocked_on_write_;
124 bool waiting_connect_; 128 bool waiting_connect_;
125 129
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 194
191 // The maximum length of the name of a pipe for MODE_NAMED_SERVER or 195 // The maximum length of the name of a pipe for MODE_NAMED_SERVER or
192 // MODE_NAMED_CLIENT if you want to pass in your own socket. 196 // MODE_NAMED_CLIENT if you want to pass in your own socket.
193 // The standard size on linux is 108, mac is 104. To maintain consistency 197 // The standard size on linux is 108, mac is 104. To maintain consistency
194 // across platforms we standardize on the smaller value. 198 // across platforms we standardize on the smaller value.
195 static const size_t kMaxPipeNameLength = 104; 199 static const size_t kMaxPipeNameLength = 104;
196 200
197 } // namespace IPC 201 } // namespace IPC
198 202
199 #endif // IPC_IPC_CHANNEL_POSIX_H_ 203 #endif // IPC_IPC_CHANNEL_POSIX_H_
OLDNEW
« no previous file with comments | « ipc/ipc_channel.h ('k') | ipc/ipc_channel_posix.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698