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

Side by Side Diff: services/service_manager/runner/host/child_process_host.cc

Issue 2566663004: Revert of Build services as standalone executables (Closed)
Patch Set: Created 4 years 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "services/service_manager/runner/host/child_process_host.h" 5 #include "services/service_manager/runner/host/child_process_host.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <utility> 9 #include <utility>
10 10
11 #include "base/base_paths.h"
12 #include "base/bind.h" 11 #include "base/bind.h"
13 #include "base/command_line.h" 12 #include "base/command_line.h"
14 #include "base/location.h" 13 #include "base/location.h"
15 #include "base/logging.h" 14 #include "base/logging.h"
16 #include "base/macros.h" 15 #include "base/macros.h"
17 #include "base/message_loop/message_loop.h" 16 #include "base/message_loop/message_loop.h"
18 #include "base/path_service.h"
19 #include "base/process/kill.h" 17 #include "base/process/kill.h"
20 #include "base/process/launch.h" 18 #include "base/process/launch.h"
21 #include "base/synchronization/lock.h" 19 #include "base/synchronization/lock.h"
22 #include "base/task_runner.h" 20 #include "base/task_runner.h"
23 #include "base/threading/thread_task_runner_handle.h" 21 #include "base/threading/thread_task_runner_handle.h"
24 #include "mojo/edk/embedder/embedder.h" 22 #include "mojo/edk/embedder/embedder.h"
25 #include "mojo/public/cpp/bindings/interface_ptr_info.h" 23 #include "mojo/public/cpp/bindings/interface_ptr_info.h"
26 #include "mojo/public/cpp/system/core.h" 24 #include "mojo/public/cpp/system/core.h"
27 #include "services/service_manager/native_runner_delegate.h" 25 #include "services/service_manager/native_runner_delegate.h"
28 #include "services/service_manager/public/cpp/standalone_service/switches.h"
29 #include "services/service_manager/runner/common/client_util.h" 26 #include "services/service_manager/runner/common/client_util.h"
30 #include "services/service_manager/runner/common/switches.h" 27 #include "services/service_manager/runner/common/switches.h"
31 28
32 #if defined(OS_LINUX) 29 #if defined(OS_LINUX)
33 #include "sandbox/linux/services/namespace_sandbox.h" 30 #include "sandbox/linux/services/namespace_sandbox.h"
34 #endif 31 #endif
35 32
36 #if defined(OS_WIN) 33 #if defined(OS_WIN)
37 #include "base/win/windows_version.h" 34 #include "base/win/windows_version.h"
38 #endif 35 #endif
39 36
40 #if defined(OS_MACOSX) 37 #if defined(OS_MACOSX)
41 #include "services/service_manager/public/cpp/standalone_service/mach_broker.h" 38 #include "services/service_manager/runner/host/mach_broker.h"
42 #endif 39 #endif
43 40
44 namespace service_manager { 41 namespace service_manager {
45 42
46 ChildProcessHost::ChildProcessHost(base::TaskRunner* launch_process_runner, 43 ChildProcessHost::ChildProcessHost(base::TaskRunner* launch_process_runner,
47 NativeRunnerDelegate* delegate, 44 NativeRunnerDelegate* delegate,
48 bool start_sandboxed, 45 bool start_sandboxed,
49 const Identity& target, 46 const Identity& target,
50 const base::FilePath& service_path) 47 const base::FilePath& app_path)
51 : launch_process_runner_(launch_process_runner), 48 : launch_process_runner_(launch_process_runner),
52 delegate_(delegate), 49 delegate_(delegate),
53 start_sandboxed_(start_sandboxed), 50 start_sandboxed_(start_sandboxed),
54 target_(target), 51 target_(target),
55 service_path_(service_path), 52 app_path_(app_path),
56 child_token_(mojo::edk::GenerateRandomToken()), 53 child_token_(mojo::edk::GenerateRandomToken()),
57 start_child_process_event_( 54 start_child_process_event_(
58 base::WaitableEvent::ResetPolicy::AUTOMATIC, 55 base::WaitableEvent::ResetPolicy::AUTOMATIC,
59 base::WaitableEvent::InitialState::NOT_SIGNALED), 56 base::WaitableEvent::InitialState::NOT_SIGNALED),
60 weak_factory_(this) { 57 weak_factory_(this) {}
61 if (service_path_.empty())
62 service_path_ = base::CommandLine::ForCurrentProcess()->GetProgram();
63 }
64 58
65 ChildProcessHost::~ChildProcessHost() { 59 ChildProcessHost::~ChildProcessHost() {
66 DCHECK(!mojo_ipc_channel_) 60 if (!app_path_.empty()) {
67 << "Destroying ChildProcessHost before calling Join"; 61 CHECK(!mojo_ipc_channel_)
62 << "Destroying ChildProcessHost before calling Join";
63 }
68 } 64 }
69 65
70 mojom::ServicePtr ChildProcessHost::Start( 66 mojom::ServicePtr ChildProcessHost::Start(
71 const Identity& target, 67 const Identity& target,
72 const ProcessReadyCallback& callback, 68 const ProcessReadyCallback& callback,
73 const base::Closure& quit_closure) { 69 const base::Closure& quit_closure) {
74 DCHECK(!child_process_.IsValid()); 70 DCHECK(!child_process_.IsValid());
75 71
76 const base::CommandLine& parent_command_line = 72 const base::CommandLine* parent_command_line =
77 *base::CommandLine::ForCurrentProcess(); 73 base::CommandLine::ForCurrentProcess();
74 base::FilePath target_path = parent_command_line->GetProgram();
75 // |app_path_| can be empty in tests.
76 if (!app_path_.MatchesExtension(FILE_PATH_LITERAL(".library")) &&
77 !app_path_.empty()) {
78 target_path = app_path_;
79 }
78 80
79 std::unique_ptr<base::CommandLine> child_command_line( 81 std::unique_ptr<base::CommandLine> child_command_line(
80 new base::CommandLine(service_path_)); 82 new base::CommandLine(target_path));
81 83
82 child_command_line->AppendArguments(parent_command_line, false); 84 child_command_line->AppendArguments(*parent_command_line, false);
83 85
84 #ifndef NDEBUG 86 #ifndef NDEBUG
85 child_command_line->AppendSwitchASCII("n", target.name()); 87 child_command_line->AppendSwitchASCII("n", target.name());
86 child_command_line->AppendSwitchASCII("u", target.user_id()); 88 child_command_line->AppendSwitchASCII("u", target.user_id());
87 #endif 89 #endif
88 90
91 if (target_path != app_path_)
92 child_command_line->AppendSwitchPath(switches::kChildProcess, app_path_);
93
89 if (start_sandboxed_) 94 if (start_sandboxed_)
90 child_command_line->AppendSwitch(::switches::kEnableSandbox); 95 child_command_line->AppendSwitch(switches::kEnableSandbox);
91 96
92 mojo_ipc_channel_.reset(new mojo::edk::PlatformChannelPair); 97 mojo_ipc_channel_.reset(new mojo::edk::PlatformChannelPair);
93 mojo_ipc_channel_->PrepareToPassClientHandleToChildProcess( 98 mojo_ipc_channel_->PrepareToPassClientHandleToChildProcess(
94 child_command_line.get(), &handle_passing_info_); 99 child_command_line.get(), &handle_passing_info_);
95 100
96 mojom::ServicePtr client = 101 mojom::ServicePtr client =
97 PassServiceRequestOnCommandLine(child_command_line.get(), 102 PassServiceRequestOnCommandLine(child_command_line.get(),
98 child_token_); 103 child_token_);
99 launch_process_runner_->PostTaskAndReply( 104 launch_process_runner_->PostTaskAndReply(
100 FROM_HERE, 105 FROM_HERE,
(...skipping 27 matching lines...) Expand all
128 } 133 }
129 134
130 void ChildProcessHost::DoLaunch( 135 void ChildProcessHost::DoLaunch(
131 std::unique_ptr<base::CommandLine> child_command_line) { 136 std::unique_ptr<base::CommandLine> child_command_line) {
132 if (delegate_) { 137 if (delegate_) {
133 delegate_->AdjustCommandLineArgumentsForTarget(target_, 138 delegate_->AdjustCommandLineArgumentsForTarget(target_,
134 child_command_line.get()); 139 child_command_line.get());
135 } 140 }
136 141
137 base::LaunchOptions options; 142 base::LaunchOptions options;
138
139 base::FilePath exe_dir;
140 DCHECK(base::PathService::Get(base::DIR_EXE, &exe_dir));
141 options.current_directory = exe_dir;
142
143 // The service should look for ICU data next to the service runner's
144 // executable rather than its own.
145 child_command_line->AppendSwitchPath(switches::kIcuDataDir, exe_dir);
146
147 #if defined(OS_POSIX)
148 // We need the dynamic loader to be able to locate things like libbase.so
149 // in component builds, as well as some other dynamic runtime dependencies in
150 // other build environments (e.g. libosmesa.so). For this we set
151 // LD_LIBRARY_PATH to the service runner's executable path where such
152 // artifacts are typically expected to reside.
153 options.environ["LD_LIBRARY_PATH"] = exe_dir.value();
154 #endif
155
156 #if defined(OS_WIN) 143 #if defined(OS_WIN)
157 options.handles_to_inherit = &handle_passing_info_; 144 options.handles_to_inherit = &handle_passing_info_;
158 #if defined(OFFICIAL_BUILD) 145 #if defined(OFFICIAL_BUILD)
159 CHECK(false) << "Launching mojo process with inherit_handles is insecure!"; 146 CHECK(false) << "Launching mojo process with inherit_handles is insecure!";
160 #endif 147 #endif
161 options.inherit_handles = true; 148 options.inherit_handles = true;
162 options.stdin_handle = INVALID_HANDLE_VALUE; 149 options.stdin_handle = INVALID_HANDLE_VALUE;
163 options.stdout_handle = GetStdHandle(STD_OUTPUT_HANDLE); 150 options.stdout_handle = GetStdHandle(STD_OUTPUT_HANDLE);
164 options.stderr_handle = GetStdHandle(STD_ERROR_HANDLE); 151 options.stderr_handle = GetStdHandle(STD_ERROR_HANDLE);
165 // Always inherit stdout/stderr as a pair. 152 // Always inherit stdout/stderr as a pair.
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 child_process_.Handle(), 210 child_process_.Handle(),
224 mojo::edk::ScopedPlatformHandle(mojo::edk::PlatformHandle( 211 mojo::edk::ScopedPlatformHandle(mojo::edk::PlatformHandle(
225 mojo_ipc_channel_->PassServerHandle().release().handle)), 212 mojo_ipc_channel_->PassServerHandle().release().handle)),
226 child_token_); 213 child_token_);
227 } 214 }
228 } 215 }
229 start_child_process_event_.Signal(); 216 start_child_process_event_.Signal();
230 } 217 }
231 218
232 } // namespace service_manager 219 } // namespace service_manager
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698