scottmg | e5a1d49 | 2017-05-24 23:41:43 | [diff] [blame] | 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 | |
Avi Drissman | 933398e | 2022-01-22 00:55:42 | [diff] [blame] | 7 | #include <tuple> |
| 8 | |
Wez | 5c3c6f15 | 2018-06-09 18:24:02 | [diff] [blame] | 9 | #include <lib/fdio/limits.h> |
| 10 | #include <lib/fdio/namespace.h> |
| 11 | #include <lib/fdio/spawn.h> |
Wez | 82017b0e | 2018-07-09 17:21:10 | [diff] [blame] | 12 | #include <lib/zx/job.h> |
Kevin Marshall | 65c2670 | 2017-09-25 18:21:42 | [diff] [blame] | 13 | #include <stdint.h> |
Scott Graham | 3ba02bd | 2017-05-25 23:16:39 | [diff] [blame] | 14 | #include <unistd.h> |
Scott Graham | fe0e9f46 | 2017-09-18 21:25:04 | [diff] [blame] | 15 | #include <zircon/processargs.h> |
scottmg | e5a1d49 | 2017-05-24 23:41:43 | [diff] [blame] | 16 | |
| 17 | #include "base/command_line.h" |
Sergey Ulanov | fea2f07 | 2017-10-21 04:34:26 | [diff] [blame] | 18 | #include "base/files/file_util.h" |
Kevin Marshall | a6c7a411 | 2017-08-25 23:39:12 | [diff] [blame] | 19 | #include "base/fuchsia/default_job.h" |
Kevin Marshall | ad910ae2 | 2018-06-16 05:40:53 | [diff] [blame] | 20 | #include "base/fuchsia/file_utils.h" |
Wez | eebd36b | 2018-03-28 18:24:03 | [diff] [blame] | 21 | #include "base/fuchsia/fuchsia_logging.h" |
Scott Graham | 3ba02bd | 2017-05-25 23:16:39 | [diff] [blame] | 22 | #include "base/logging.h" |
Kevin Marshall | 2bd0455 | 2018-02-01 21:23:45 | [diff] [blame] | 23 | #include "base/memory/ptr_util.h" |
David Benjamin | 76ee79eb | 2019-03-15 17:02:09 | [diff] [blame] | 24 | #include "base/process/environment_internal.h" |
Kevin Marshall | 2bd0455 | 2018-02-01 21:23:45 | [diff] [blame] | 25 | #include "base/scoped_generic.h" |
Gabriel Charette | 6836c0d5 | 2021-01-11 17:40:26 | [diff] [blame] | 26 | #include "base/threading/scoped_blocking_call.h" |
| 27 | #include "base/trace_event/base_tracing.h" |
scottmg | e5a1d49 | 2017-05-24 23:41:43 | [diff] [blame] | 28 | |
| 29 | namespace base { |
| 30 | |
Scott Graham | 3ba02bd | 2017-05-25 23:16:39 | [diff] [blame] | 31 | namespace { |
| 32 | |
Wez | 78d1265 | 2017-08-29 23:22:48 | [diff] [blame] | 33 | bool GetAppOutputInternal(const CommandLine& cmd_line, |
Scott Graham | 3ba02bd | 2017-05-25 23:16:39 | [diff] [blame] | 34 | bool include_stderr, |
| 35 | std::string* output, |
| 36 | int* exit_code) { |
| 37 | DCHECK(exit_code); |
Gabriel Charette | 6836c0d5 | 2021-01-11 17:40:26 | [diff] [blame] | 38 | TRACE_EVENT0("base", "GetAppOutput"); |
Scott Graham | 3ba02bd | 2017-05-25 23:16:39 | [diff] [blame] | 39 | |
Wez | 78d1265 | 2017-08-29 23:22:48 | [diff] [blame] | 40 | LaunchOptions options; |
Scott Graham | 3ba02bd | 2017-05-25 23:16:39 | [diff] [blame] | 41 | |
Wez | 78d1265 | 2017-08-29 23:22:48 | [diff] [blame] | 42 | // LaunchProcess will automatically clone any stdio fd we do not explicitly |
| 43 | // map. |
| 44 | int pipe_fd[2]; |
| 45 | if (pipe(pipe_fd) < 0) |
Scott Graham | 3ba02bd | 2017-05-25 23:16:39 | [diff] [blame] | 46 | return false; |
Wez | 78d1265 | 2017-08-29 23:22:48 | [diff] [blame] | 47 | options.fds_to_remap.emplace_back(pipe_fd[1], STDOUT_FILENO); |
Scott Graham | 3ba02bd | 2017-05-25 23:16:39 | [diff] [blame] | 48 | if (include_stderr) |
Wez | 78d1265 | 2017-08-29 23:22:48 | [diff] [blame] | 49 | options.fds_to_remap.emplace_back(pipe_fd[1], STDERR_FILENO); |
Scott Graham | 3ba02bd | 2017-05-25 23:16:39 | [diff] [blame] | 50 | |
Wez | 78d1265 | 2017-08-29 23:22:48 | [diff] [blame] | 51 | Process process = LaunchProcess(cmd_line, options); |
| 52 | close(pipe_fd[1]); |
| 53 | if (!process.IsValid()) { |
| 54 | close(pipe_fd[0]); |
Scott Graham | 3ba02bd | 2017-05-25 23:16:39 | [diff] [blame] | 55 | return false; |
| 56 | } |
| 57 | |
| 58 | output->clear(); |
| 59 | for (;;) { |
| 60 | char buffer[256]; |
Wez | 78d1265 | 2017-08-29 23:22:48 | [diff] [blame] | 61 | ssize_t bytes_read = read(pipe_fd[0], buffer, sizeof(buffer)); |
Scott Graham | 3ba02bd | 2017-05-25 23:16:39 | [diff] [blame] | 62 | if (bytes_read <= 0) |
| 63 | break; |
| 64 | output->append(buffer, bytes_read); |
| 65 | } |
Wez | 78d1265 | 2017-08-29 23:22:48 | [diff] [blame] | 66 | close(pipe_fd[0]); |
Scott Graham | 3ba02bd | 2017-05-25 23:16:39 | [diff] [blame] | 67 | |
Gabriel Charette | 6836c0d5 | 2021-01-11 17:40:26 | [diff] [blame] | 68 | // It is okay to allow this process to wait on the launched process as a |
| 69 | // process launched with GetAppOutput*() shouldn't wait back on the process |
| 70 | // that launched it. |
| 71 | internal::GetAppOutputScopedAllowBaseSyncPrimitives allow_wait; |
Scott Graham | 3ba02bd | 2017-05-25 23:16:39 | [diff] [blame] | 72 | return process.WaitForExit(exit_code); |
| 73 | } |
| 74 | |
Wez | 0629d40 | 2018-06-06 00:26:43 | [diff] [blame] | 75 | fdio_spawn_action_t FdioSpawnAction(uint32_t action) { |
| 76 | fdio_spawn_action_t new_action = {}; |
| 77 | new_action.action = action; |
| 78 | return new_action; |
| 79 | } |
Kevin Marshall | 2bd0455 | 2018-02-01 21:23:45 | [diff] [blame] | 80 | |
Wez | 0629d40 | 2018-06-06 00:26:43 | [diff] [blame] | 81 | fdio_spawn_action_t FdioSpawnActionCloneFd(int local_fd, int target_fd) { |
| 82 | fdio_spawn_action_t action = FdioSpawnAction(FDIO_SPAWN_ACTION_CLONE_FD); |
| 83 | action.fd.local_fd = local_fd; |
| 84 | action.fd.target_fd = target_fd; |
| 85 | return action; |
| 86 | } |
Kevin Marshall | 2bd0455 | 2018-02-01 21:23:45 | [diff] [blame] | 87 | |
Wez | 0629d40 | 2018-06-06 00:26:43 | [diff] [blame] | 88 | fdio_spawn_action_t FdioSpawnActionAddNamespaceEntry(const char* prefix, |
| 89 | zx_handle_t handle) { |
| 90 | fdio_spawn_action_t action = FdioSpawnAction(FDIO_SPAWN_ACTION_ADD_NS_ENTRY); |
| 91 | action.ns.prefix = prefix; |
| 92 | action.ns.handle = handle; |
| 93 | return action; |
| 94 | } |
| 95 | |
| 96 | fdio_spawn_action_t FdioSpawnActionAddHandle(uint32_t id, zx_handle_t handle) { |
| 97 | fdio_spawn_action_t action = FdioSpawnAction(FDIO_SPAWN_ACTION_ADD_HANDLE); |
| 98 | action.h.id = id; |
| 99 | action.h.handle = handle; |
| 100 | return action; |
| 101 | } |
Kevin Marshall | 2bd0455 | 2018-02-01 21:23:45 | [diff] [blame] | 102 | |
Sergey Ulanov | 53ab7dd | 2019-08-27 17:53:18 | [diff] [blame] | 103 | fdio_spawn_action_t FdioSpawnActionSetName(const char* name) { |
| 104 | fdio_spawn_action_t action = FdioSpawnAction(FDIO_SPAWN_ACTION_SET_NAME); |
| 105 | action.name.data = name; |
| 106 | return action; |
| 107 | } |
| 108 | |
Scott Graham | 3ba02bd | 2017-05-25 23:16:39 | [diff] [blame] | 109 | } // namespace |
| 110 | |
Wez | 35e50b5 | 2018-12-01 01:52:44 | [diff] [blame] | 111 | // static |
| 112 | uint32_t LaunchOptions::AddHandleToTransfer( |
| 113 | HandlesToTransferVector* handles_to_transfer, |
| 114 | zx_handle_t handle) { |
Sharon Yang | 9fadcefd | 2020-07-07 23:49:19 | [diff] [blame] | 115 | CHECK_LE(handles_to_transfer->size(), std::numeric_limits<uint16_t>::max()) |
| 116 | << "Number of handles to transfer exceeds total allowed"; |
Wez | 35e50b5 | 2018-12-01 01:52:44 | [diff] [blame] | 117 | uint32_t handle_id = PA_HND(PA_USER1, handles_to_transfer->size()); |
| 118 | handles_to_transfer->push_back({handle_id, handle}); |
| 119 | return handle_id; |
| 120 | } |
| 121 | |
scottmg | e5a1d49 | 2017-05-24 23:41:43 | [diff] [blame] | 122 | Process LaunchProcess(const CommandLine& cmdline, |
| 123 | const LaunchOptions& options) { |
| 124 | return LaunchProcess(cmdline.argv(), options); |
| 125 | } |
| 126 | |
| 127 | Process LaunchProcess(const std::vector<std::string>& argv, |
| 128 | const LaunchOptions& options) { |
Wez | 0629d40 | 2018-06-06 00:26:43 | [diff] [blame] | 129 | // fdio_spawn_etc() accepts an array of |fdio_spawn_action_t|, describing |
| 130 | // namespace entries, descriptors and handles to launch the child process |
David Dorwin | 8a971d32f | 2022-02-09 16:37:21 | [diff] [blame^] | 131 | // with. |fdio_spawn_action_t| does not own any values assigned to its |
| 132 | // members, so strings assigned to members must be valid through the |
| 133 | // fdio_spawn_etc() call. |
Wez | 0629d40 | 2018-06-06 00:26:43 | [diff] [blame] | 134 | std::vector<fdio_spawn_action_t> spawn_actions; |
| 135 | |
| 136 | // Handles to be transferred to the child are owned by this vector, so that |
| 137 | // they they are closed on early-exit, and can be release()d otherwise. |
Kevin Marshall | ad910ae2 | 2018-06-16 05:40:53 | [diff] [blame] | 138 | std::vector<zx::handle> transferred_handles; |
Wez | 0629d40 | 2018-06-06 00:26:43 | [diff] [blame] | 139 | |
| 140 | // Add caller-supplied handles for transfer. We must do this first to ensure |
| 141 | // that the handles are consumed even if some later step fails. |
| 142 | for (const auto& id_and_handle : options.handles_to_transfer) { |
| 143 | spawn_actions.push_back( |
| 144 | FdioSpawnActionAddHandle(id_and_handle.id, id_and_handle.handle)); |
| 145 | transferred_handles.emplace_back(id_and_handle.handle); |
| 146 | } |
| 147 | |
| 148 | // Determine the job under which to launch the new process. |
Wez | 82017b0e | 2018-07-09 17:21:10 | [diff] [blame] | 149 | zx::unowned_job job = options.job_handle != ZX_HANDLE_INVALID |
| 150 | ? zx::unowned_job(options.job_handle) |
| 151 | : GetDefaultJob(); |
| 152 | DCHECK(job->is_valid()); |
Wez | 0629d40 | 2018-06-06 00:26:43 | [diff] [blame] | 153 | |
| 154 | // Construct an |argv| array of C-strings from the supplied std::strings. |
scottmg | e5a1d49 | 2017-05-24 23:41:43 | [diff] [blame] | 155 | std::vector<const char*> argv_cstr; |
| 156 | argv_cstr.reserve(argv.size() + 1); |
Scott Graham | 3ba02bd | 2017-05-25 23:16:39 | [diff] [blame] | 157 | for (const auto& arg : argv) |
| 158 | argv_cstr.push_back(arg.c_str()); |
scottmg | e5a1d49 | 2017-05-24 23:41:43 | [diff] [blame] | 159 | argv_cstr.push_back(nullptr); |
| 160 | |
David Benjamin | 76ee79eb | 2019-03-15 17:02:09 | [diff] [blame] | 161 | // Determine the environment to pass to the new process. If |
| 162 | // |clear_environment|, |environment| or |current_directory| are set then we |
Wez | 0629d40 | 2018-06-06 00:26:43 | [diff] [blame] | 163 | // construct a new (possibly empty) environment, otherwise we let fdio_spawn() |
| 164 | // clone the caller's environment into the new process. |
Adam Lesinski | 3a72572 | 2020-10-01 14:40:36 | [diff] [blame] | 165 | uint32_t spawn_flags = FDIO_SPAWN_DEFAULT_LDSVC | FDIO_SPAWN_CLONE_UTC_CLOCK | |
| 166 | options.spawn_flags; |
Scott Graham | f6305969 | 2017-06-21 00:37:51 | [diff] [blame] | 167 | |
David Benjamin | 76ee79eb | 2019-03-15 17:02:09 | [diff] [blame] | 168 | EnvironmentMap environ_modifications = options.environment; |
Scott Graham | f6305969 | 2017-06-21 00:37:51 | [diff] [blame] | 169 | if (!options.current_directory.empty()) { |
| 170 | environ_modifications["PWD"] = options.current_directory.value(); |
Sergey Ulanov | fea2f07 | 2017-10-21 04:34:26 | [diff] [blame] | 171 | } else { |
| 172 | FilePath cwd; |
Kevin Marshall | c948f0f | 2018-05-14 03:34:45 | [diff] [blame] | 173 | GetCurrentDirectory(&cwd); |
Sergey Ulanov | fea2f07 | 2017-10-21 04:34:26 | [diff] [blame] | 174 | environ_modifications["PWD"] = cwd.value(); |
Scott Graham | f6305969 | 2017-06-21 00:37:51 | [diff] [blame] | 175 | } |
| 176 | |
Fabrice de Gans-Riberi | ee44a3b | 2020-10-10 00:21:13 | [diff] [blame] | 177 | std::unique_ptr<char*[]> new_environ; |
Wez | 0629d40 | 2018-06-06 00:26:43 | [diff] [blame] | 178 | if (!environ_modifications.empty()) { |
| 179 | char* const empty_environ = nullptr; |
David Benjamin | 76ee79eb | 2019-03-15 17:02:09 | [diff] [blame] | 180 | char* const* old_environ = |
| 181 | options.clear_environment ? &empty_environ : environ; |
| 182 | new_environ = |
| 183 | internal::AlterEnvironment(old_environ, environ_modifications); |
| 184 | } else if (!options.clear_environment) { |
Wez | 0629d40 | 2018-06-06 00:26:43 | [diff] [blame] | 185 | spawn_flags |= FDIO_SPAWN_CLONE_ENVIRON; |
| 186 | } |
Scott Graham | f6305969 | 2017-06-21 00:37:51 | [diff] [blame] | 187 | |
Wez | 0629d40 | 2018-06-06 00:26:43 | [diff] [blame] | 188 | // Add actions to clone handles for any specified paths into the new process' |
| 189 | // namespace. |
Kevin Marshall | ad910ae2 | 2018-06-16 05:40:53 | [diff] [blame] | 190 | if (!options.paths_to_clone.empty() || !options.paths_to_transfer.empty()) { |
Sergey Ulanov | f1b12ddf | 2018-11-27 02:56:58 | [diff] [blame] | 191 | DCHECK((options.spawn_flags & FDIO_SPAWN_CLONE_NAMESPACE) == 0); |
Wez | 0629d40 | 2018-06-06 00:26:43 | [diff] [blame] | 192 | transferred_handles.reserve(transferred_handles.size() + |
Kevin Marshall | ad910ae2 | 2018-06-16 05:40:53 | [diff] [blame] | 193 | options.paths_to_clone.size() + |
| 194 | options.paths_to_transfer.size()); |
Wez | 0629d40 | 2018-06-06 00:26:43 | [diff] [blame] | 195 | |
Kevin Marshall | ad910ae2 | 2018-06-16 05:40:53 | [diff] [blame] | 196 | for (const auto& path_to_transfer : options.paths_to_transfer) { |
| 197 | zx::handle handle(path_to_transfer.handle); |
Wez | 0629d40 | 2018-06-06 00:26:43 | [diff] [blame] | 198 | spawn_actions.push_back(FdioSpawnActionAddNamespaceEntry( |
Kevin Marshall | ad910ae2 | 2018-06-16 05:40:53 | [diff] [blame] | 199 | path_to_transfer.path.value().c_str(), handle.get())); |
Kevin Marshall | ad910ae2 | 2018-06-16 05:40:53 | [diff] [blame] | 200 | transferred_handles.push_back(std::move(handle)); |
| 201 | } |
| 202 | |
| 203 | for (const auto& path_to_clone : options.paths_to_clone) { |
Sergey Ulanov | 713b7777 | 2019-03-14 22:53:32 | [diff] [blame] | 204 | fidl::InterfaceHandle<::fuchsia::io::Directory> directory = |
Fabrice de Gans-Riberi | ee44a3b | 2020-10-10 00:21:13 | [diff] [blame] | 205 | base::OpenDirectoryHandle(path_to_clone); |
Sergey Ulanov | 713b7777 | 2019-03-14 22:53:32 | [diff] [blame] | 206 | if (!directory) { |
Kevin Marshall | ad910ae2 | 2018-06-16 05:40:53 | [diff] [blame] | 207 | LOG(WARNING) << "Could not open handle for path: " << path_to_clone; |
| 208 | return base::Process(); |
| 209 | } |
| 210 | |
Sergey Ulanov | 713b7777 | 2019-03-14 22:53:32 | [diff] [blame] | 211 | zx::handle handle = directory.TakeChannel(); |
| 212 | |
Kevin Marshall | ad910ae2 | 2018-06-16 05:40:53 | [diff] [blame] | 213 | spawn_actions.push_back(FdioSpawnActionAddNamespaceEntry( |
| 214 | path_to_clone.value().c_str(), handle.get())); |
Wez | 0629d40 | 2018-06-06 00:26:43 | [diff] [blame] | 215 | transferred_handles.push_back(std::move(handle)); |
Kevin Marshall | 2bd0455 | 2018-02-01 21:23:45 | [diff] [blame] | 216 | } |
| 217 | } |
| 218 | |
Wez | 0629d40 | 2018-06-06 00:26:43 | [diff] [blame] | 219 | // Add any file-descriptors to be cloned into the new process. |
| 220 | // Note that if FDIO_SPAWN_CLONE_STDIO is set, then any stdio entries in |
| 221 | // |fds_to_remap| will be used in place of the parent process' descriptors. |
Wez | ec2506f | 2017-08-03 17:49:18 | [diff] [blame] | 222 | for (const auto& src_target : options.fds_to_remap) { |
Wez | 0629d40 | 2018-06-06 00:26:43 | [diff] [blame] | 223 | spawn_actions.push_back( |
| 224 | FdioSpawnActionCloneFd(src_target.first, src_target.second)); |
Wez | ec2506f | 2017-08-03 17:49:18 | [diff] [blame] | 225 | } |
scottmg | e5a1d49 | 2017-05-24 23:41:43 | [diff] [blame] | 226 | |
Sergey Ulanov | 53ab7dd | 2019-08-27 17:53:18 | [diff] [blame] | 227 | // If |process_name_suffix| is specified then set process name as |
| 228 | // "<file_name><suffix>", otherwise leave the default value. |
David Dorwin | 8a971d32f | 2022-02-09 16:37:21 | [diff] [blame^] | 229 | std::string process_name; // Must outlive the fdio_spawn_etc() call. |
Sergey Ulanov | 53ab7dd | 2019-08-27 17:53:18 | [diff] [blame] | 230 | if (!options.process_name_suffix.empty()) { |
| 231 | process_name = base::FilePath(argv[0]).BaseName().value() + |
| 232 | options.process_name_suffix; |
| 233 | spawn_actions.push_back(FdioSpawnActionSetName(process_name.c_str())); |
| 234 | } |
| 235 | |
Wez | 157707d6 | 2018-07-10 22:48:47 | [diff] [blame] | 236 | zx::process process_handle; |
Wez | 0629d40 | 2018-06-06 00:26:43 | [diff] [blame] | 237 | // fdio_spawn_etc() will write a null-terminated scring to |error_message| in |
| 238 | // case of failure, so we avoid unnecessarily initializing it here. |
| 239 | char error_message[FDIO_SPAWN_ERR_MSG_MAX_LENGTH]; |
| 240 | zx_status_t status = fdio_spawn_etc( |
Wez | 82017b0e | 2018-07-09 17:21:10 | [diff] [blame] | 241 | job->get(), spawn_flags, argv_cstr[0], argv_cstr.data(), |
| 242 | new_environ.get(), spawn_actions.size(), spawn_actions.data(), |
Wez | 157707d6 | 2018-07-10 22:48:47 | [diff] [blame] | 243 | process_handle.reset_and_get_address(), error_message); |
Wez | 1603c32 | 2017-08-10 05:24:54 | [diff] [blame] | 244 | |
Wez | 0629d40 | 2018-06-06 00:26:43 | [diff] [blame] | 245 | // fdio_spawn_etc() will close all handles specified in add-handle actions, |
| 246 | // regardless of whether it succeeds or fails, so release our copies. |
| 247 | for (auto& transferred_handle : transferred_handles) |
Avi Drissman | 933398e | 2022-01-22 00:55:42 | [diff] [blame] | 248 | std::ignore = transferred_handle.release(); |
Wez | 0629d40 | 2018-06-06 00:26:43 | [diff] [blame] | 249 | |
| 250 | if (status != ZX_OK) { |
| 251 | ZX_LOG(ERROR, status) << "fdio_spawn: " << error_message; |
scottmg | e5a1d49 | 2017-05-24 23:41:43 | [diff] [blame] | 252 | return Process(); |
| 253 | } |
| 254 | |
Wez | 0629d40 | 2018-06-06 00:26:43 | [diff] [blame] | 255 | // Wrap the handle into a Process, and wait for it to terminate, if requested. |
| 256 | Process process(process_handle.release()); |
Wez | c6b685d | 2018-01-09 17:27:42 | [diff] [blame] | 257 | if (options.wait) { |
| 258 | status = zx_object_wait_one(process.Handle(), ZX_TASK_TERMINATED, |
| 259 | ZX_TIME_INFINITE, nullptr); |
Wez | 0629d40 | 2018-06-06 00:26:43 | [diff] [blame] | 260 | ZX_DCHECK(status == ZX_OK, status) << "zx_object_wait_one"; |
Wez | c6b685d | 2018-01-09 17:27:42 | [diff] [blame] | 261 | } |
| 262 | |
| 263 | return process; |
scottmg | e5a1d49 | 2017-05-24 23:41:43 | [diff] [blame] | 264 | } |
| 265 | |
Scott Graham | 3ba02bd | 2017-05-25 23:16:39 | [diff] [blame] | 266 | bool GetAppOutput(const CommandLine& cl, std::string* output) { |
Scott Graham | 3ba02bd | 2017-05-25 23:16:39 | [diff] [blame] | 267 | int exit_code; |
Wez | 78d1265 | 2017-08-29 23:22:48 | [diff] [blame] | 268 | bool result = GetAppOutputInternal(cl, false, output, &exit_code); |
Scott Graham | 3ba02bd | 2017-05-25 23:16:39 | [diff] [blame] | 269 | return result && exit_code == EXIT_SUCCESS; |
| 270 | } |
| 271 | |
Wez | 78d1265 | 2017-08-29 23:22:48 | [diff] [blame] | 272 | bool GetAppOutput(const std::vector<std::string>& argv, std::string* output) { |
| 273 | return GetAppOutput(CommandLine(argv), output); |
| 274 | } |
| 275 | |
Scott Graham | 3ba02bd | 2017-05-25 23:16:39 | [diff] [blame] | 276 | bool GetAppOutputAndError(const CommandLine& cl, std::string* output) { |
Wez | 78d1265 | 2017-08-29 23:22:48 | [diff] [blame] | 277 | int exit_code; |
| 278 | bool result = GetAppOutputInternal(cl, true, output, &exit_code); |
| 279 | return result && exit_code == EXIT_SUCCESS; |
Scott Graham | 3ba02bd | 2017-05-25 23:16:39 | [diff] [blame] | 280 | } |
| 281 | |
| 282 | bool GetAppOutputAndError(const std::vector<std::string>& argv, |
| 283 | std::string* output) { |
Wez | 78d1265 | 2017-08-29 23:22:48 | [diff] [blame] | 284 | return GetAppOutputAndError(CommandLine(argv), output); |
Scott Graham | 3ba02bd | 2017-05-25 23:16:39 | [diff] [blame] | 285 | } |
| 286 | |
| 287 | bool GetAppOutputWithExitCode(const CommandLine& cl, |
| 288 | std::string* output, |
| 289 | int* exit_code) { |
Scott Graham | 0b0f7d7 | 2017-07-26 01:47:11 | [diff] [blame] | 290 | // Contrary to GetAppOutput(), |true| return here means that the process was |
| 291 | // launched and the exit code was waited upon successfully, but not |
| 292 | // necessarily that the exit code was EXIT_SUCCESS. |
Wez | 78d1265 | 2017-08-29 23:22:48 | [diff] [blame] | 293 | return GetAppOutputInternal(cl, false, output, exit_code); |
Scott Graham | 3ba02bd | 2017-05-25 23:16:39 | [diff] [blame] | 294 | } |
| 295 | |
Sergey Ulanov | a93cf8b | 2017-12-01 21:52:53 | [diff] [blame] | 296 | void RaiseProcessToHighPriority() { |
| 297 | // Fuchsia doesn't provide an API to change process priority. |
| 298 | } |
| 299 | |
scottmg | e5a1d49 | 2017-05-24 23:41:43 | [diff] [blame] | 300 | } // namespace base |