Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "components/arc/arc_bridge_bootstrap.h" | 5 #include "components/arc/arc_bridge_bootstrap.h" |
| 6 | 6 |
| 7 #include <fcntl.h> | 7 #include <fcntl.h> |
| 8 #include <grp.h> | 8 #include <grp.h> |
| 9 #include <unistd.h> | 9 #include <unistd.h> |
| 10 | 10 |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 27 #include "mojo/edk/embedder/platform_channel_pair.h" | 27 #include "mojo/edk/embedder/platform_channel_pair.h" |
| 28 #include "mojo/edk/embedder/platform_channel_utils_posix.h" | 28 #include "mojo/edk/embedder/platform_channel_utils_posix.h" |
| 29 #include "mojo/edk/embedder/platform_handle_vector.h" | 29 #include "mojo/edk/embedder/platform_handle_vector.h" |
| 30 #include "mojo/edk/embedder/scoped_platform_handle.h" | 30 #include "mojo/edk/embedder/scoped_platform_handle.h" |
| 31 #include "mojo/public/cpp/bindings/binding.h" | 31 #include "mojo/public/cpp/bindings/binding.h" |
| 32 | 32 |
| 33 namespace arc { | 33 namespace arc { |
| 34 | 34 |
| 35 namespace { | 35 namespace { |
| 36 | 36 |
| 37 // We do not know the PID of ARC, since Chrome does not create it directly. | |
| 38 // Since Mojo in POSIX does not use the child PID except as an unique | |
| 39 // identifier for the routing table, rather than doing a lot of plumbing in the | |
| 40 // whole system to get the correct PID, just use an arbitrary number that will | |
| 41 // never be used by a legitimate process. Chrome OS assigns unassigned PIDs | |
| 42 // sequentially until it reaches a certain maximum value (Chrome OS uses the | |
| 43 // default value of 32k), at which point it loops around to zero. An arbitrary | |
| 44 // number larger than the maximum should be safe. | |
| 45 const pid_t kArcPid = 0x3DE0EA7C; | |
| 46 | |
| 47 const base::FilePath::CharType kArcBridgeSocketPath[] = | 37 const base::FilePath::CharType kArcBridgeSocketPath[] = |
| 48 FILE_PATH_LITERAL("/var/run/chrome/arc_bridge.sock"); | 38 FILE_PATH_LITERAL("/var/run/chrome/arc_bridge.sock"); |
| 49 | 39 |
| 50 const char kArcBridgeSocketGroup[] = "arc-bridge"; | 40 const char kArcBridgeSocketGroup[] = "arc-bridge"; |
| 51 | 41 |
| 52 class ArcBridgeBootstrapImpl : public ArcBridgeBootstrap { | 42 class ArcBridgeBootstrapImpl : public ArcBridgeBootstrap { |
| 53 public: | 43 public: |
| 54 // The possible states of the bootstrap connection. In the normal flow, | 44 // The possible states of the bootstrap connection. In the normal flow, |
| 55 // the state changes in the following sequence: | 45 // the state changes in the following sequence: |
| 56 // | 46 // |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 253 | 243 |
| 254 // static | 244 // static |
| 255 base::ScopedFD ArcBridgeBootstrapImpl::AcceptInstanceConnection( | 245 base::ScopedFD ArcBridgeBootstrapImpl::AcceptInstanceConnection( |
| 256 base::ScopedFD socket_fd) { | 246 base::ScopedFD socket_fd) { |
| 257 int raw_fd = -1; | 247 int raw_fd = -1; |
| 258 if (!IPC::ServerAcceptConnection(socket_fd.get(), &raw_fd)) { | 248 if (!IPC::ServerAcceptConnection(socket_fd.get(), &raw_fd)) { |
| 259 return base::ScopedFD(); | 249 return base::ScopedFD(); |
| 260 } | 250 } |
| 261 base::ScopedFD scoped_fd(raw_fd); | 251 base::ScopedFD scoped_fd(raw_fd); |
| 262 | 252 |
| 253 // Hardcode pid 0 since it is unused in mojo. | |
| 263 mojo::edk::ScopedPlatformHandle child_handle = | 254 mojo::edk::ScopedPlatformHandle child_handle = |
| 264 mojo::edk::ChildProcessLaunched(kArcPid); | 255 mojo::edk::ChildProcessLaunched(0); |
|
Luis Héctor Chávez
2016/04/06 15:23:13
Same here.
kcwu
2016/04/07 01:02:27
Done.
| |
| 265 | 256 |
| 266 mojo::edk::ScopedPlatformHandleVectorPtr handles( | 257 mojo::edk::ScopedPlatformHandleVectorPtr handles( |
| 267 new mojo::edk::PlatformHandleVector{child_handle.release()}); | 258 new mojo::edk::PlatformHandleVector{child_handle.release()}); |
| 268 | 259 |
| 269 struct iovec iov = {const_cast<char*>(""), 1}; | 260 struct iovec iov = {const_cast<char*>(""), 1}; |
| 270 ssize_t result = mojo::edk::PlatformChannelSendmsgWithHandles( | 261 ssize_t result = mojo::edk::PlatformChannelSendmsgWithHandles( |
| 271 mojo::edk::PlatformHandle(scoped_fd.get()), &iov, 1, handles->data(), | 262 mojo::edk::PlatformHandle(scoped_fd.get()), &iov, 1, handles->data(), |
| 272 handles->size()); | 263 handles->size()); |
| 273 if (result == -1) { | 264 if (result == -1) { |
| 274 PLOG(ERROR) << "sendmsg"; | 265 PLOG(ERROR) << "sendmsg"; |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 342 | 333 |
| 343 ArcBridgeBootstrap::ArcBridgeBootstrap() {} | 334 ArcBridgeBootstrap::ArcBridgeBootstrap() {} |
| 344 ArcBridgeBootstrap::~ArcBridgeBootstrap() {} | 335 ArcBridgeBootstrap::~ArcBridgeBootstrap() {} |
| 345 | 336 |
| 346 // static | 337 // static |
| 347 scoped_ptr<ArcBridgeBootstrap> ArcBridgeBootstrap::Create() { | 338 scoped_ptr<ArcBridgeBootstrap> ArcBridgeBootstrap::Create() { |
| 348 return make_scoped_ptr(new ArcBridgeBootstrapImpl()); | 339 return make_scoped_ptr(new ArcBridgeBootstrapImpl()); |
| 349 } | 340 } |
| 350 | 341 |
| 351 } // namespace arc | 342 } // namespace arc |
| OLD | NEW |