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

Side by Side Diff: services/native_support/process_impl.cc

Issue 1682113003: Mojo C++ bindings: Generate InterfaceHandle<> instead of InterfacePtr<>. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: rebase ontop of master, address trung's comments Created 4 years, 10 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
« no previous file with comments | « services/native_support/process_impl.h ('k') | services/native_viewport/native_viewport_impl.h » ('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 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 "services/native_support/process_impl.h" 5 #include "services/native_support/process_impl.h"
6 6
7 #include <fcntl.h> 7 #include <fcntl.h>
8 #include <stdio.h> 8 #include <stdio.h>
9 #include <unistd.h> 9 #include <unistd.h>
10 10
11 #include <algorithm> 11 #include <algorithm>
12 #include <limits> 12 #include <limits>
13 #include <utility> 13 #include <utility>
14 #include <vector> 14 #include <vector>
15 15
16 #include "base/command_line.h" 16 #include "base/command_line.h"
17 #include "base/environment.h" 17 #include "base/environment.h"
18 #include "base/files/scoped_file.h" 18 #include "base/files/scoped_file.h"
19 #include "base/logging.h" 19 #include "base/logging.h"
20 #include "base/posix/eintr_wrapper.h" 20 #include "base/posix/eintr_wrapper.h"
21 #include "base/process/launch.h" 21 #include "base/process/launch.h"
22 #include "base/process/process.h" 22 #include "base/process/process.h"
23 #include "build/build_config.h" 23 #include "build/build_config.h"
24 #include "mojo/services/files/interfaces/types.mojom.h" 24 #include "mojo/services/files/interfaces/types.mojom.h"
25 #include "services/native_support/make_pty_pair.h" 25 #include "services/native_support/make_pty_pair.h"
26 #include "services/native_support/process_controller_impl.h" 26 #include "services/native_support/process_controller_impl.h"
27 #include "services/native_support/process_io_redirection.h" 27 #include "services/native_support/process_io_redirection.h"
28 28
29 using mojo::files::FilePtr;
30
29 namespace native_support { 31 namespace native_support {
30 32
31 namespace { 33 namespace {
32 34
33 class SetsidPreExecDelegate : public base::LaunchOptions::PreExecDelegate { 35 class SetsidPreExecDelegate : public base::LaunchOptions::PreExecDelegate {
34 public: 36 public:
35 SetsidPreExecDelegate() {} 37 SetsidPreExecDelegate() {}
36 ~SetsidPreExecDelegate() override {} 38 ~SetsidPreExecDelegate() override {}
37 39
38 void RunAsyncSafe() override { 40 void RunAsyncSafe() override {
(...skipping 14 matching lines...) Expand all
53 mojo::ApplicationConnection* connection, 55 mojo::ApplicationConnection* connection,
54 mojo::InterfaceRequest<Process> request) 56 mojo::InterfaceRequest<Process> request)
55 : worker_runner_(worker_runner.Pass()), binding_(this, request.Pass()) {} 57 : worker_runner_(worker_runner.Pass()), binding_(this, request.Pass()) {}
56 58
57 ProcessImpl::~ProcessImpl() {} 59 ProcessImpl::~ProcessImpl() {}
58 60
59 void ProcessImpl::Spawn( 61 void ProcessImpl::Spawn(
60 mojo::Array<uint8_t> path, 62 mojo::Array<uint8_t> path,
61 mojo::Array<mojo::Array<uint8_t>> argv, 63 mojo::Array<mojo::Array<uint8_t>> argv,
62 mojo::Array<mojo::Array<uint8_t>> envp, 64 mojo::Array<mojo::Array<uint8_t>> envp,
63 mojo::files::FilePtr stdin_file, 65 mojo::InterfaceHandle<mojo::files::File> stdin_file,
64 mojo::files::FilePtr stdout_file, 66 mojo::InterfaceHandle<mojo::files::File> stdout_file,
65 mojo::files::FilePtr stderr_file, 67 mojo::InterfaceHandle<mojo::files::File> stderr_file,
66 mojo::InterfaceRequest<ProcessController> process_controller, 68 mojo::InterfaceRequest<ProcessController> process_controller,
67 const SpawnCallback& callback) { 69 const SpawnCallback& callback) {
68 std::vector<int> fds_to_inherit(3, -1); 70 std::vector<int> fds_to_inherit(3, -1);
69 71
70 // stdin: 72 // stdin:
71 base::ScopedFD stdin_fd; 73 base::ScopedFD stdin_fd;
72 base::ScopedFD stdin_parent_fd; 74 base::ScopedFD stdin_parent_fd;
73 if (stdin_file) { 75 if (stdin_file) {
74 int stdin_pipe_fds[2] = {-1, -1}; 76 int stdin_pipe_fds[2] = {-1, -1};
75 CHECK_EQ(pipe(stdin_pipe_fds), 0); 77 CHECK_EQ(pipe(stdin_pipe_fds), 0);
(...skipping 25 matching lines...) Expand all
101 CHECK_EQ(pipe(stderr_pipe_fds), 0); 103 CHECK_EQ(pipe(stderr_pipe_fds), 0);
102 stderr_fd.reset(stderr_pipe_fds[1]); 104 stderr_fd.reset(stderr_pipe_fds[1]);
103 stderr_parent_fd.reset(stderr_pipe_fds[0]); 105 stderr_parent_fd.reset(stderr_pipe_fds[0]);
104 } else { 106 } else {
105 stderr_fd.reset(HANDLE_EINTR(open("/dev/null", O_WRONLY))); 107 stderr_fd.reset(HANDLE_EINTR(open("/dev/null", O_WRONLY)));
106 } 108 }
107 fds_to_inherit[STDERR_FILENO] = stderr_fd.get(); 109 fds_to_inherit[STDERR_FILENO] = stderr_fd.get();
108 110
109 std::unique_ptr<ProcessIORedirection> process_io_redirection( 111 std::unique_ptr<ProcessIORedirection> process_io_redirection(
110 new ProcessIORedirectionForStdIO( 112 new ProcessIORedirectionForStdIO(
111 stdin_file.Pass(), stdout_file.Pass(), stderr_file.Pass(), 113 FilePtr::Create(std::move(stdin_file)),
112 stdin_parent_fd.Pass(), stdout_parent_fd.Pass(), 114 FilePtr::Create(std::move(stdout_file)),
113 stderr_parent_fd.Pass())); 115 FilePtr::Create(std::move(stderr_file)), stdin_parent_fd.Pass(),
116 stdout_parent_fd.Pass(), stderr_parent_fd.Pass()));
114 117
115 SpawnImpl(path.Pass(), argv.Pass(), envp.Pass(), 118 SpawnImpl(path.Pass(), argv.Pass(), envp.Pass(),
116 std::move(process_io_redirection), fds_to_inherit, 119 std::move(process_io_redirection), fds_to_inherit,
117 process_controller.Pass(), callback); 120 process_controller.Pass(), callback);
118 } 121 }
119 122
120 void ProcessImpl::SpawnWithTerminal( 123 void ProcessImpl::SpawnWithTerminal(
121 mojo::Array<uint8_t> path, 124 mojo::Array<uint8_t> path,
122 mojo::Array<mojo::Array<uint8_t>> argv, 125 mojo::Array<mojo::Array<uint8_t>> argv,
123 mojo::Array<mojo::Array<uint8_t>> envp, 126 mojo::Array<mojo::Array<uint8_t>> envp,
124 mojo::files::FilePtr terminal_file, 127 mojo::InterfaceHandle<mojo::files::File> terminal_file,
125 mojo::InterfaceRequest<ProcessController> process_controller, 128 mojo::InterfaceRequest<ProcessController> process_controller,
126 const SpawnWithTerminalCallback& callback) { 129 const SpawnWithTerminalCallback& callback) {
127 DCHECK(terminal_file); 130 DCHECK(terminal_file);
128 131
129 std::vector<int> fds_to_inherit(3, -1); 132 std::vector<int> fds_to_inherit(3, -1);
130 133
131 base::ScopedFD master_fd; 134 base::ScopedFD master_fd;
132 base::ScopedFD slave_fd; 135 base::ScopedFD slave_fd;
133 int errno_value = 0; 136 int errno_value = 0;
134 if (!MakePtyPair(&master_fd, &slave_fd, &errno_value)) { 137 if (!MakePtyPair(&master_fd, &slave_fd, &errno_value)) {
135 // TODO(vtl): Well, this is dumb (we should use errno_value). 138 // TODO(vtl): Well, this is dumb (we should use errno_value).
136 callback.Run(mojo::files::Error::UNKNOWN); 139 callback.Run(mojo::files::Error::UNKNOWN);
137 return; 140 return;
138 } 141 }
139 142
140 // stdin: 143 // stdin:
141 base::ScopedFD stdin_fd(slave_fd.Pass()); 144 base::ScopedFD stdin_fd(slave_fd.Pass());
142 fds_to_inherit[STDIN_FILENO] = stdin_fd.get(); 145 fds_to_inherit[STDIN_FILENO] = stdin_fd.get();
143 146
144 // stdout: 147 // stdout:
145 base::ScopedFD stdout_fd(HANDLE_EINTR(dup(stdin_fd.get()))); 148 base::ScopedFD stdout_fd(HANDLE_EINTR(dup(stdin_fd.get())));
146 fds_to_inherit[STDOUT_FILENO] = stdout_fd.get(); 149 fds_to_inherit[STDOUT_FILENO] = stdout_fd.get();
147 150
148 // stderr: 151 // stderr:
149 base::ScopedFD stderr_fd(HANDLE_EINTR(dup(stdin_fd.get()))); 152 base::ScopedFD stderr_fd(HANDLE_EINTR(dup(stdin_fd.get())));
150 fds_to_inherit[STDERR_FILENO] = stderr_fd.get(); 153 fds_to_inherit[STDERR_FILENO] = stderr_fd.get();
151 154
152 std::unique_ptr<ProcessIORedirection> process_io_redirection( 155 std::unique_ptr<ProcessIORedirection> process_io_redirection(
153 new ProcessIORedirectionForTerminal(terminal_file.Pass(), 156 new ProcessIORedirectionForTerminal(
154 master_fd.Pass())); 157 FilePtr::Create(std::move(terminal_file)), master_fd.Pass()));
155 158
156 SpawnImpl(path.Pass(), argv.Pass(), envp.Pass(), 159 SpawnImpl(path.Pass(), argv.Pass(), envp.Pass(),
157 std::move(process_io_redirection), fds_to_inherit, 160 std::move(process_io_redirection), fds_to_inherit,
158 process_controller.Pass(), callback); 161 process_controller.Pass(), callback);
159 } 162 }
160 163
161 void ProcessImpl::SpawnImpl( 164 void ProcessImpl::SpawnImpl(
162 mojo::Array<uint8_t> path, 165 mojo::Array<uint8_t> path,
163 mojo::Array<mojo::Array<uint8_t>> argv, 166 mojo::Array<mojo::Array<uint8_t>> argv,
164 mojo::Array<mojo::Array<uint8_t>> envp, 167 mojo::Array<mojo::Array<uint8_t>> envp,
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 callback.Run(mojo::files::Error::UNKNOWN); 249 callback.Run(mojo::files::Error::UNKNOWN);
247 return; 250 return;
248 } 251 }
249 252
250 new ProcessControllerImpl(worker_runner_, process_controller.Pass(), 253 new ProcessControllerImpl(worker_runner_, process_controller.Pass(),
251 process.Pass(), std::move(process_io_redirection)); 254 process.Pass(), std::move(process_io_redirection));
252 callback.Run(mojo::files::Error::OK); 255 callback.Run(mojo::files::Error::OK);
253 } 256 }
254 257
255 } // namespace native_support 258 } // namespace native_support
OLDNEW
« no previous file with comments | « services/native_support/process_impl.h ('k') | services/native_viewport/native_viewport_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698