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

Side by Side Diff: base/process/launch_fuchsia.cc

Issue 2692273008: Hacky slashy (Closed)
Patch Set: rebase on config CL, and minor fixes Created 3 years, 7 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 | « base/process/launch.h ('k') | base/process/launch_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
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "base/process/launch.h"
6
7 #include <launchpad/launchpad.h>
8 #include <magenta/process.h>
9
10 #include "base/command_line.h"
11
12 namespace base {
13
14 Process LaunchProcess(const CommandLine& cmdline,
15 const LaunchOptions& options) {
16 return LaunchProcess(cmdline.argv(), options);
17 }
18
19 Process LaunchProcess(const std::vector<std::string>& argv,
20 const LaunchOptions& options) {
21 std::unique_ptr<char* []> argv_cstr(new char*[argv.size() + 1]);
22 for (size_t i = 0; i < argv.size(); i++) {
23 argv_cstr[i] = const_cast<char*>(argv[i].c_str());
24 }
25 argv_cstr[argv.size()] = nullptr;
26
27 launchpad_t* lp;
28 mx_handle_t job = options.job_handle != MX_HANDLE_INVALID
29 ? options.job_handle
30 : mx_job_default();
31 launchpad_create(job, argv_cstr[0], &lp);
32 launchpad_load_from_file(lp, argv_cstr[0]);
33 launchpad_set_args(lp, argv.size(), argv_cstr.get());
34
35 uint32_t to_clone =
36 LP_CLONE_MXIO_ROOT | LP_CLONE_MXIO_CWD | LP_CLONE_DEFAULT_JOB;
37
38 std::unique_ptr<char* []> new_environ;
39 char* const empty_environ = nullptr;
40 char* const* old_environ = environ;
41 if (options.clear_environ)
42 old_environ = &empty_environ;
43 if (!options.environ.empty()) {
44 new_environ = AlterEnvironment(old_environ, options.environ);
45 }
46 if (!options.environ.empty() || options.clear_environ)
47 launchpad_set_environ(lp, new_environ.get());
48 else
49 to_clone |= LP_CLONE_ENVIRON;
50
51 if (!options.fds_to_remap)
52 to_clone |= LP_CLONE_MXIO_STDIO;
53 launchpad_clone(lp, to_clone);
54
55 if (options.fds_to_remap) {
56 for (const auto& src_target : *options.fds_to_remap) {
57 mx_status_t status =
58 launchpad_clone_fd(lp, src_target.first, src_target.second);
59 if (status < 0) {
60 LOG(ERROR) << "launchpad_clone() failed " << src_target.first << " -> "
61 << src_target.second;
62 }
63 }
64 }
65
66 mx_handle_t proc;
67 const char* errmsg;
68 mx_status_t status = launchpad_go(lp, &proc, &errmsg);
69 if (status < 0) {
70 LOG(ERROR) << "launchpad_go() failed: " << errmsg << ", status=" << status;
71 return Process(MX_HANDLE_INVALID);
72 }
73
74 return Process(proc);
75 }
76
77 void CloseSuperfluousFds(const InjectiveMultimap& saved_map) {
78 NOTIMPLEMENTED();
79 }
80
81 bool GetAppOutput(const CommandLine& cl, std::string* output) {
82 return GetAppOutput(cl.argv(), output);
83 }
84
85 bool GetAppOutputAndError(const CommandLine& cl, std::string* output) {
86 // TODO(scottmg): Port.
87 NOTIMPLEMENTED();
88 return false;
89 }
90
91 bool GetAppOutput(const std::vector<std::string>& argv, std::string* output) {
92 // TODO(scottmg): Port.
93 NOTIMPLEMENTED();
94 return false;
95 }
96
97 bool GetAppOutputAndError(const std::vector<std::string>& argv,
98 std::string* output) {
99 // TODO(scottmg): Port.
100 NOTIMPLEMENTED();
101 return false;
102 }
103
104 bool GetAppOutputWithExitCode(const CommandLine& cl,
105 std::string* output,
106 int* exit_code) {
107 // TODO(scottmg): Port.
108 NOTIMPLEMENTED();
109 return false;
110 }
111
112 void RaiseProcessToHighPriority() {
113 NOTIMPLEMENTED();
114 }
115
116 } // namespace base
OLDNEW
« no previous file with comments | « base/process/launch.h ('k') | base/process/launch_posix.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698