OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 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 | 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 "base/process/launch.h" | 5 #include "base/process/launch.h" |
6 | 6 |
7 #include <launchpad/launchpad.h> | 7 #include <launchpad/launchpad.h> |
8 #include <magenta/process.h> | 8 #include <magenta/process.h> |
9 #include <unistd.h> | 9 #include <unistd.h> |
10 | 10 |
(...skipping 18 matching lines...) Expand all Loading... |
29 | 29 |
30 launchpad_t* lp; | 30 launchpad_t* lp; |
31 launchpad_create(MX_HANDLE_INVALID, argv_cstr[0], &lp); | 31 launchpad_create(MX_HANDLE_INVALID, argv_cstr[0], &lp); |
32 launchpad_load_from_file(lp, argv_cstr[0]); | 32 launchpad_load_from_file(lp, argv_cstr[0]); |
33 launchpad_set_args(lp, argv.size(), argv_cstr.data()); | 33 launchpad_set_args(lp, argv.size(), argv_cstr.data()); |
34 launchpad_clone(lp, LP_CLONE_MXIO_ROOT | LP_CLONE_MXIO_CWD | | 34 launchpad_clone(lp, LP_CLONE_MXIO_ROOT | LP_CLONE_MXIO_CWD | |
35 LP_CLONE_DEFAULT_JOB | LP_CLONE_ENVIRON); | 35 LP_CLONE_DEFAULT_JOB | LP_CLONE_ENVIRON); |
36 launchpad_clone_fd(lp, STDIN_FILENO, STDIN_FILENO); | 36 launchpad_clone_fd(lp, STDIN_FILENO, STDIN_FILENO); |
37 int pipe_fd; | 37 int pipe_fd; |
38 mx_status_t status = launchpad_add_pipe(lp, &pipe_fd, STDOUT_FILENO); | 38 mx_status_t status = launchpad_add_pipe(lp, &pipe_fd, STDOUT_FILENO); |
39 if (status != NO_ERROR) { | 39 if (status != MX_OK) { |
40 LOG(ERROR) << "launchpad_add_pipe failed: " << status; | 40 LOG(ERROR) << "launchpad_add_pipe failed: " << status; |
41 launchpad_destroy(lp); | 41 launchpad_destroy(lp); |
42 return false; | 42 return false; |
43 } | 43 } |
44 | 44 |
45 if (include_stderr) | 45 if (include_stderr) |
46 launchpad_clone_fd(lp, pipe_fd, STDERR_FILENO); | 46 launchpad_clone_fd(lp, pipe_fd, STDERR_FILENO); |
47 else | 47 else |
48 launchpad_clone_fd(lp, STDERR_FILENO, STDERR_FILENO); | 48 launchpad_clone_fd(lp, STDERR_FILENO, STDERR_FILENO); |
49 | 49 |
50 mx_handle_t proc; | 50 mx_handle_t proc; |
51 const char* errmsg; | 51 const char* errmsg; |
52 status = launchpad_go(lp, &proc, &errmsg); | 52 status = launchpad_go(lp, &proc, &errmsg); |
53 if (status != NO_ERROR) { | 53 if (status != MX_OK) { |
54 LOG(ERROR) << "launchpad_go failed: " << errmsg << ", status=" << status; | 54 LOG(ERROR) << "launchpad_go failed: " << errmsg << ", status=" << status; |
55 return false; | 55 return false; |
56 } | 56 } |
57 | 57 |
58 output->clear(); | 58 output->clear(); |
59 for (;;) { | 59 for (;;) { |
60 char buffer[256]; | 60 char buffer[256]; |
61 ssize_t bytes_read = read(pipe_fd, buffer, sizeof(buffer)); | 61 ssize_t bytes_read = read(pipe_fd, buffer, sizeof(buffer)); |
62 if (bytes_read <= 0) | 62 if (bytes_read <= 0) |
63 break; | 63 break; |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 | 114 |
115 if (options.fds_to_remap) { | 115 if (options.fds_to_remap) { |
116 for (const auto& src_target : *options.fds_to_remap) { | 116 for (const auto& src_target : *options.fds_to_remap) { |
117 launchpad_clone_fd(lp, src_target.first, src_target.second); | 117 launchpad_clone_fd(lp, src_target.first, src_target.second); |
118 } | 118 } |
119 } | 119 } |
120 | 120 |
121 mx_handle_t proc; | 121 mx_handle_t proc; |
122 const char* errmsg; | 122 const char* errmsg; |
123 mx_status_t status = launchpad_go(lp, &proc, &errmsg); | 123 mx_status_t status = launchpad_go(lp, &proc, &errmsg); |
124 if (status != NO_ERROR) { | 124 if (status != MX_OK) { |
125 LOG(ERROR) << "launchpad_go failed: " << errmsg << ", status=" << status; | 125 LOG(ERROR) << "launchpad_go failed: " << errmsg << ", status=" << status; |
126 return Process(); | 126 return Process(); |
127 } | 127 } |
128 | 128 |
129 return Process(proc); | 129 return Process(proc); |
130 } | 130 } |
131 | 131 |
132 bool GetAppOutput(const CommandLine& cl, std::string* output) { | 132 bool GetAppOutput(const CommandLine& cl, std::string* output) { |
133 return GetAppOutput(cl.argv(), output); | 133 return GetAppOutput(cl.argv(), output); |
134 } | 134 } |
(...skipping 16 matching lines...) Expand all Loading... |
151 } | 151 } |
152 | 152 |
153 bool GetAppOutputWithExitCode(const CommandLine& cl, | 153 bool GetAppOutputWithExitCode(const CommandLine& cl, |
154 std::string* output, | 154 std::string* output, |
155 int* exit_code) { | 155 int* exit_code) { |
156 bool result = GetAppOutputInternal(cl.argv(), false, output, exit_code); | 156 bool result = GetAppOutputInternal(cl.argv(), false, output, exit_code); |
157 return result && *exit_code == EXIT_SUCCESS; | 157 return result && *exit_code == EXIT_SUCCESS; |
158 } | 158 } |
159 | 159 |
160 } // namespace base | 160 } // namespace base |
OLD | NEW |