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

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: 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
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/public/cpp/bindings/interface_handle.h"
24 #include "mojo/services/files/interfaces/types.mojom.h" 25 #include "mojo/services/files/interfaces/types.mojom.h"
25 #include "services/native_support/make_pty_pair.h" 26 #include "services/native_support/make_pty_pair.h"
26 #include "services/native_support/process_controller_impl.h" 27 #include "services/native_support/process_controller_impl.h"
27 #include "services/native_support/process_io_redirection.h" 28 #include "services/native_support/process_io_redirection.h"
28 29
30 using mojo::files::FilePtr;
31
29 namespace native_support { 32 namespace native_support {
30 33
31 namespace { 34 namespace {
32 35
33 class SetsidPreExecDelegate : public base::LaunchOptions::PreExecDelegate { 36 class SetsidPreExecDelegate : public base::LaunchOptions::PreExecDelegate {
34 public: 37 public:
35 SetsidPreExecDelegate() {} 38 SetsidPreExecDelegate() {}
36 ~SetsidPreExecDelegate() override {} 39 ~SetsidPreExecDelegate() override {}
37 40
38 void RunAsyncSafe() override { 41 void RunAsyncSafe() override {
(...skipping 14 matching lines...) Expand all
53 mojo::ApplicationConnection* connection, 56 mojo::ApplicationConnection* connection,
54 mojo::InterfaceRequest<Process> request) 57 mojo::InterfaceRequest<Process> request)
55 : worker_runner_(worker_runner.Pass()), binding_(this, request.Pass()) {} 58 : worker_runner_(worker_runner.Pass()), binding_(this, request.Pass()) {}
56 59
57 ProcessImpl::~ProcessImpl() {} 60 ProcessImpl::~ProcessImpl() {}
58 61
59 void ProcessImpl::Spawn( 62 void ProcessImpl::Spawn(
60 mojo::Array<uint8_t> path, 63 mojo::Array<uint8_t> path,
61 mojo::Array<mojo::Array<uint8_t>> argv, 64 mojo::Array<mojo::Array<uint8_t>> argv,
62 mojo::Array<mojo::Array<uint8_t>> envp, 65 mojo::Array<mojo::Array<uint8_t>> envp,
63 mojo::files::FilePtr stdin_file, 66 mojo::InterfaceHandle<mojo::files::File> stdin_file,
64 mojo::files::FilePtr stdout_file, 67 mojo::InterfaceHandle<mojo::files::File> stdout_file,
65 mojo::files::FilePtr stderr_file, 68 mojo::InterfaceHandle<mojo::files::File> stderr_file,
66 mojo::InterfaceRequest<ProcessController> process_controller, 69 mojo::InterfaceRequest<ProcessController> process_controller,
67 const SpawnCallback& callback) { 70 const SpawnCallback& callback) {
68 std::vector<int> fds_to_inherit(3, -1); 71 std::vector<int> fds_to_inherit(3, -1);
69 72
70 // stdin: 73 // stdin:
71 base::ScopedFD stdin_fd; 74 base::ScopedFD stdin_fd;
72 base::ScopedFD stdin_parent_fd; 75 base::ScopedFD stdin_parent_fd;
73 if (stdin_file) { 76 if (stdin_file) {
74 int stdin_pipe_fds[2] = {-1, -1}; 77 int stdin_pipe_fds[2] = {-1, -1};
75 CHECK_EQ(pipe(stdin_pipe_fds), 0); 78 CHECK_EQ(pipe(stdin_pipe_fds), 0);
(...skipping 25 matching lines...) Expand all
101 CHECK_EQ(pipe(stderr_pipe_fds), 0); 104 CHECK_EQ(pipe(stderr_pipe_fds), 0);
102 stderr_fd.reset(stderr_pipe_fds[1]); 105 stderr_fd.reset(stderr_pipe_fds[1]);
103 stderr_parent_fd.reset(stderr_pipe_fds[0]); 106 stderr_parent_fd.reset(stderr_pipe_fds[0]);
104 } else { 107 } else {
105 stderr_fd.reset(HANDLE_EINTR(open("/dev/null", O_WRONLY))); 108 stderr_fd.reset(HANDLE_EINTR(open("/dev/null", O_WRONLY)));
106 } 109 }
107 fds_to_inherit[STDERR_FILENO] = stderr_fd.get(); 110 fds_to_inherit[STDERR_FILENO] = stderr_fd.get();
108 111
109 std::unique_ptr<ProcessIORedirection> process_io_redirection( 112 std::unique_ptr<ProcessIORedirection> process_io_redirection(
110 new ProcessIORedirectionForStdIO( 113 new ProcessIORedirectionForStdIO(
111 stdin_file.Pass(), stdout_file.Pass(), stderr_file.Pass(), 114 FilePtr::Create(std::move(stdin_file)),
112 stdin_parent_fd.Pass(), stdout_parent_fd.Pass(), 115 FilePtr::Create(std::move(stdout_file)),
113 stderr_parent_fd.Pass())); 116 FilePtr::Create(std::move(stderr_file)), stdin_parent_fd.Pass(),
117 stdout_parent_fd.Pass(), stderr_parent_fd.Pass()));
114 118
115 SpawnImpl(path.Pass(), argv.Pass(), envp.Pass(), 119 SpawnImpl(path.Pass(), argv.Pass(), envp.Pass(),
116 std::move(process_io_redirection), fds_to_inherit, 120 std::move(process_io_redirection), fds_to_inherit,
117 process_controller.Pass(), callback); 121 process_controller.Pass(), callback);
118 } 122 }
119 123
120 void ProcessImpl::SpawnWithTerminal( 124 void ProcessImpl::SpawnWithTerminal(
121 mojo::Array<uint8_t> path, 125 mojo::Array<uint8_t> path,
122 mojo::Array<mojo::Array<uint8_t>> argv, 126 mojo::Array<mojo::Array<uint8_t>> argv,
123 mojo::Array<mojo::Array<uint8_t>> envp, 127 mojo::Array<mojo::Array<uint8_t>> envp,
124 mojo::files::FilePtr terminal_file, 128 mojo::InterfaceHandle<mojo::files::File> terminal_file,
125 mojo::InterfaceRequest<ProcessController> process_controller, 129 mojo::InterfaceRequest<ProcessController> process_controller,
126 const SpawnWithTerminalCallback& callback) { 130 const SpawnWithTerminalCallback& callback) {
127 DCHECK(terminal_file); 131 DCHECK(terminal_file);
128 132
129 std::vector<int> fds_to_inherit(3, -1); 133 std::vector<int> fds_to_inherit(3, -1);
130 134
131 base::ScopedFD master_fd; 135 base::ScopedFD master_fd;
132 base::ScopedFD slave_fd; 136 base::ScopedFD slave_fd;
133 int errno_value = 0; 137 int errno_value = 0;
134 if (!MakePtyPair(&master_fd, &slave_fd, &errno_value)) { 138 if (!MakePtyPair(&master_fd, &slave_fd, &errno_value)) {
135 // TODO(vtl): Well, this is dumb (we should use errno_value). 139 // TODO(vtl): Well, this is dumb (we should use errno_value).
136 callback.Run(mojo::files::Error::UNKNOWN); 140 callback.Run(mojo::files::Error::UNKNOWN);
137 return; 141 return;
138 } 142 }
139 143
140 // stdin: 144 // stdin:
141 base::ScopedFD stdin_fd(slave_fd.Pass()); 145 base::ScopedFD stdin_fd(slave_fd.Pass());
142 fds_to_inherit[STDIN_FILENO] = stdin_fd.get(); 146 fds_to_inherit[STDIN_FILENO] = stdin_fd.get();
143 147
144 // stdout: 148 // stdout:
145 base::ScopedFD stdout_fd(HANDLE_EINTR(dup(stdin_fd.get()))); 149 base::ScopedFD stdout_fd(HANDLE_EINTR(dup(stdin_fd.get())));
146 fds_to_inherit[STDOUT_FILENO] = stdout_fd.get(); 150 fds_to_inherit[STDOUT_FILENO] = stdout_fd.get();
147 151
148 // stderr: 152 // stderr:
149 base::ScopedFD stderr_fd(HANDLE_EINTR(dup(stdin_fd.get()))); 153 base::ScopedFD stderr_fd(HANDLE_EINTR(dup(stdin_fd.get())));
150 fds_to_inherit[STDERR_FILENO] = stderr_fd.get(); 154 fds_to_inherit[STDERR_FILENO] = stderr_fd.get();
151 155
152 std::unique_ptr<ProcessIORedirection> process_io_redirection( 156 std::unique_ptr<ProcessIORedirection> process_io_redirection(
153 new ProcessIORedirectionForTerminal(terminal_file.Pass(), 157 new ProcessIORedirectionForTerminal(
154 master_fd.Pass())); 158 FilePtr::Create(std::move(terminal_file)), master_fd.Pass()));
155 159
156 SpawnImpl(path.Pass(), argv.Pass(), envp.Pass(), 160 SpawnImpl(path.Pass(), argv.Pass(), envp.Pass(),
157 std::move(process_io_redirection), fds_to_inherit, 161 std::move(process_io_redirection), fds_to_inherit,
158 process_controller.Pass(), callback); 162 process_controller.Pass(), callback);
159 } 163 }
160 164
161 void ProcessImpl::SpawnImpl( 165 void ProcessImpl::SpawnImpl(
162 mojo::Array<uint8_t> path, 166 mojo::Array<uint8_t> path,
163 mojo::Array<mojo::Array<uint8_t>> argv, 167 mojo::Array<mojo::Array<uint8_t>> argv,
164 mojo::Array<mojo::Array<uint8_t>> envp, 168 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); 250 callback.Run(mojo::files::Error::UNKNOWN);
247 return; 251 return;
248 } 252 }
249 253
250 new ProcessControllerImpl(worker_runner_, process_controller.Pass(), 254 new ProcessControllerImpl(worker_runner_, process_controller.Pass(),
251 process.Pass(), std::move(process_io_redirection)); 255 process.Pass(), std::move(process_io_redirection));
252 callback.Run(mojo::files::Error::OK); 256 callback.Run(mojo::files::Error::OK);
253 } 257 }
254 258
255 } // namespace native_support 259 } // namespace native_support
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698