| Index: base/process/launch_fuchsia.cc
|
| diff --git a/base/process/launch_fuchsia.cc b/base/process/launch_fuchsia.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..4edaa9b2535aa1d97fbcda93659c2d0e8d642f8d
|
| --- /dev/null
|
| +++ b/base/process/launch_fuchsia.cc
|
| @@ -0,0 +1,116 @@
|
| +// Copyright 2017 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "base/process/launch.h"
|
| +
|
| +#include <launchpad/launchpad.h>
|
| +#include <magenta/process.h>
|
| +
|
| +#include "base/command_line.h"
|
| +
|
| +namespace base {
|
| +
|
| +Process LaunchProcess(const CommandLine& cmdline,
|
| + const LaunchOptions& options) {
|
| + return LaunchProcess(cmdline.argv(), options);
|
| +}
|
| +
|
| +Process LaunchProcess(const std::vector<std::string>& argv,
|
| + const LaunchOptions& options) {
|
| + std::unique_ptr<char* []> argv_cstr(new char*[argv.size() + 1]);
|
| + for (size_t i = 0; i < argv.size(); i++) {
|
| + argv_cstr[i] = const_cast<char*>(argv[i].c_str());
|
| + }
|
| + argv_cstr[argv.size()] = nullptr;
|
| +
|
| + launchpad_t* lp;
|
| + mx_handle_t job = options.job_handle != MX_HANDLE_INVALID
|
| + ? options.job_handle
|
| + : mx_job_default();
|
| + launchpad_create(job, argv_cstr[0], &lp);
|
| + launchpad_load_from_file(lp, argv_cstr[0]);
|
| + launchpad_set_args(lp, argv.size(), argv_cstr.get());
|
| +
|
| + uint32_t to_clone =
|
| + LP_CLONE_MXIO_ROOT | LP_CLONE_MXIO_CWD | LP_CLONE_DEFAULT_JOB;
|
| +
|
| + std::unique_ptr<char* []> new_environ;
|
| + char* const empty_environ = nullptr;
|
| + char* const* old_environ = environ;
|
| + if (options.clear_environ)
|
| + old_environ = &empty_environ;
|
| + if (!options.environ.empty()) {
|
| + new_environ = AlterEnvironment(old_environ, options.environ);
|
| + }
|
| + if (!options.environ.empty() || options.clear_environ)
|
| + launchpad_set_environ(lp, new_environ.get());
|
| + else
|
| + to_clone |= LP_CLONE_ENVIRON;
|
| +
|
| + if (!options.fds_to_remap)
|
| + to_clone |= LP_CLONE_MXIO_STDIO;
|
| + launchpad_clone(lp, to_clone);
|
| +
|
| + if (options.fds_to_remap) {
|
| + for (const auto& src_target : *options.fds_to_remap) {
|
| + mx_status_t status =
|
| + launchpad_clone_fd(lp, src_target.first, src_target.second);
|
| + if (status < 0) {
|
| + LOG(ERROR) << "launchpad_clone() failed " << src_target.first << " -> "
|
| + << src_target.second;
|
| + }
|
| + }
|
| + }
|
| +
|
| + mx_handle_t proc;
|
| + const char* errmsg;
|
| + mx_status_t status = launchpad_go(lp, &proc, &errmsg);
|
| + if (status < 0) {
|
| + LOG(ERROR) << "launchpad_go() failed: " << errmsg << ", status=" << status;
|
| + return Process(MX_HANDLE_INVALID);
|
| + }
|
| +
|
| + return Process(proc);
|
| +}
|
| +
|
| +void CloseSuperfluousFds(const InjectiveMultimap& saved_map) {
|
| + NOTIMPLEMENTED();
|
| +}
|
| +
|
| +bool GetAppOutput(const CommandLine& cl, std::string* output) {
|
| + return GetAppOutput(cl.argv(), output);
|
| +}
|
| +
|
| +bool GetAppOutputAndError(const CommandLine& cl, std::string* output) {
|
| + // TODO(scottmg): Port.
|
| + NOTIMPLEMENTED();
|
| + return false;
|
| +}
|
| +
|
| +bool GetAppOutput(const std::vector<std::string>& argv, std::string* output) {
|
| + // TODO(scottmg): Port.
|
| + NOTIMPLEMENTED();
|
| + return false;
|
| +}
|
| +
|
| +bool GetAppOutputAndError(const std::vector<std::string>& argv,
|
| + std::string* output) {
|
| + // TODO(scottmg): Port.
|
| + NOTIMPLEMENTED();
|
| + return false;
|
| +}
|
| +
|
| +bool GetAppOutputWithExitCode(const CommandLine& cl,
|
| + std::string* output,
|
| + int* exit_code) {
|
| + // TODO(scottmg): Port.
|
| + NOTIMPLEMENTED();
|
| + return false;
|
| +}
|
| +
|
| +void RaiseProcessToHighPriority() {
|
| + NOTIMPLEMENTED();
|
| +}
|
| +
|
| +} // namespace base
|
|
|