Mike Frysinger | 8155d08 | 2012-04-06 15:23:18 -0400 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium OS Authors. All rights reserved. |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 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 "update_engine/subprocess.h" |
Darin Petkov | a0b9e77 | 2011-10-06 05:05:56 -0700 | [diff] [blame] | 6 | |
Alex Deymo | 29b8153 | 2015-07-09 11:51:49 -0700 | [diff] [blame] | 7 | #include <fcntl.h> |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 8 | #include <stdlib.h> |
| 9 | #include <string.h> |
Kenneth Waters | a7fcafa | 2010-09-21 10:27:03 -0700 | [diff] [blame] | 10 | #include <unistd.h> |
Darin Petkov | a0b9e77 | 2011-10-06 05:05:56 -0700 | [diff] [blame] | 11 | |
Ben Chan | 02f7c1d | 2014-10-18 15:18:02 -0700 | [diff] [blame] | 12 | #include <memory> |
Darin Petkov | a0b9e77 | 2011-10-06 05:05:56 -0700 | [diff] [blame] | 13 | #include <string> |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 14 | #include <vector> |
Darin Petkov | a0b9e77 | 2011-10-06 05:05:56 -0700 | [diff] [blame] | 15 | |
Alex Deymo | 29b8153 | 2015-07-09 11:51:49 -0700 | [diff] [blame] | 16 | #include <base/bind.h> |
Darin Petkov | a0b9e77 | 2011-10-06 05:05:56 -0700 | [diff] [blame] | 17 | #include <base/logging.h> |
Alex Deymo | 29b8153 | 2015-07-09 11:51:49 -0700 | [diff] [blame] | 18 | #include <base/posix/eintr_wrapper.h> |
Alex Vakulenko | 75039d7 | 2014-03-25 12:36:28 -0700 | [diff] [blame] | 19 | #include <base/strings/string_util.h> |
| 20 | #include <base/strings/stringprintf.h> |
Darin Petkov | a0b9e77 | 2011-10-06 05:05:56 -0700 | [diff] [blame] | 21 | |
Alex Deymo | 44666f9 | 2014-07-22 20:29:24 -0700 | [diff] [blame] | 22 | #include "update_engine/glib_utils.h" |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 23 | |
Alex Deymo | 29b8153 | 2015-07-09 11:51:49 -0700 | [diff] [blame] | 24 | using chromeos::MessageLoop; |
Alex Deymo | bc91a27 | 2014-05-20 16:45:33 -0700 | [diff] [blame] | 25 | using std::shared_ptr; |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 26 | using std::string; |
Ben Chan | 02f7c1d | 2014-10-18 15:18:02 -0700 | [diff] [blame] | 27 | using std::unique_ptr; |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 28 | using std::vector; |
| 29 | |
| 30 | namespace chromeos_update_engine { |
| 31 | |
| 32 | void Subprocess::GChildExitedCallback(GPid pid, gint status, gpointer data) { |
Darin Petkov | 6f03a3b | 2010-11-10 14:27:14 -0800 | [diff] [blame] | 33 | SubprocessRecord* record = reinterpret_cast<SubprocessRecord*>(data); |
| 34 | |
Alex Deymo | 29b8153 | 2015-07-09 11:51:49 -0700 | [diff] [blame] | 35 | // Make sure we read any remaining process output and then close the pipe. |
| 36 | OnStdoutReady(record); |
Darin Petkov | 6f03a3b | 2010-11-10 14:27:14 -0800 | [diff] [blame] | 37 | |
Alex Deymo | 29b8153 | 2015-07-09 11:51:49 -0700 | [diff] [blame] | 38 | MessageLoop::current()->CancelTask(record->task_id); |
| 39 | record->task_id = MessageLoop::kTaskIdNull; |
| 40 | if (IGNORE_EINTR(close(record->stdout_fd)) != 0) { |
| 41 | PLOG(ERROR) << "Error closing fd " << record->stdout_fd; |
| 42 | } |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 43 | g_spawn_close_pid(pid); |
Andrew de los Reyes | c1d5c93 | 2011-04-20 17:15:47 -0700 | [diff] [blame] | 44 | gint use_status = status; |
| 45 | if (WIFEXITED(status)) |
| 46 | use_status = WEXITSTATUS(status); |
| 47 | |
Darin Petkov | 6f03a3b | 2010-11-10 14:27:14 -0800 | [diff] [blame] | 48 | if (status) { |
Andrew de los Reyes | c1d5c93 | 2011-04-20 17:15:47 -0700 | [diff] [blame] | 49 | LOG(INFO) << "Subprocess status: " << use_status; |
Darin Petkov | 6f03a3b | 2010-11-10 14:27:14 -0800 | [diff] [blame] | 50 | } |
| 51 | if (!record->stdout.empty()) { |
| 52 | LOG(INFO) << "Subprocess output:\n" << record->stdout; |
| 53 | } |
| 54 | if (record->callback) { |
Andrew de los Reyes | c1d5c93 | 2011-04-20 17:15:47 -0700 | [diff] [blame] | 55 | record->callback(use_status, record->stdout, record->callback_data); |
Darin Petkov | 6f03a3b | 2010-11-10 14:27:14 -0800 | [diff] [blame] | 56 | } |
| 57 | Get().subprocess_records_.erase(record->tag); |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 58 | } |
| 59 | |
Kenneth Waters | a7fcafa | 2010-09-21 10:27:03 -0700 | [diff] [blame] | 60 | void Subprocess::GRedirectStderrToStdout(gpointer user_data) { |
| 61 | dup2(1, 2); |
| 62 | } |
| 63 | |
Alex Deymo | 29b8153 | 2015-07-09 11:51:49 -0700 | [diff] [blame] | 64 | void Subprocess::OnStdoutReady(SubprocessRecord* record) { |
Darin Petkov | 6f03a3b | 2010-11-10 14:27:14 -0800 | [diff] [blame] | 65 | char buf[1024]; |
Alex Deymo | 29b8153 | 2015-07-09 11:51:49 -0700 | [diff] [blame] | 66 | ssize_t rc = 0; |
| 67 | do { |
| 68 | rc = HANDLE_EINTR(read(record->stdout_fd, buf, arraysize(buf))); |
| 69 | if (rc < 0) { |
| 70 | // EAGAIN and EWOULDBLOCK are normal return values when there's no more |
| 71 | // input as we are in non-blocking mode. |
| 72 | if (errno != EWOULDBLOCK && errno != EAGAIN) { |
| 73 | PLOG(ERROR) << "Error reading fd " << record->stdout_fd; |
| 74 | } |
Alex Deymo | 957cf4d | 2015-07-14 23:18:33 -0700 | [diff] [blame^] | 75 | } else if (rc == 0) { |
| 76 | // A value of 0 means that the child closed its end of the pipe and there |
| 77 | // is nothing else to read from stdout. |
| 78 | MessageLoop::current()->CancelTask(record->task_id); |
| 79 | record->task_id = MessageLoop::kTaskIdNull; |
Alex Deymo | 29b8153 | 2015-07-09 11:51:49 -0700 | [diff] [blame] | 80 | } else { |
| 81 | record->stdout.append(buf, rc); |
| 82 | } |
| 83 | } while (rc > 0); |
Darin Petkov | 6f03a3b | 2010-11-10 14:27:14 -0800 | [diff] [blame] | 84 | } |
| 85 | |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 86 | namespace { |
| 87 | void FreeArgv(char** argv) { |
| 88 | for (int i = 0; argv[i]; i++) { |
| 89 | free(argv[i]); |
Alex Vakulenko | 88b591f | 2014-08-28 16:48:57 -0700 | [diff] [blame] | 90 | argv[i] = nullptr; |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 91 | } |
| 92 | } |
Andrew de los Reyes | 3270f74 | 2010-07-15 22:28:14 -0700 | [diff] [blame] | 93 | |
Chris Masone | c6c57a5 | 2010-09-23 13:06:14 -0700 | [diff] [blame] | 94 | void FreeArgvInError(char** argv) { |
| 95 | FreeArgv(argv); |
| 96 | LOG(ERROR) << "Ran out of memory copying args."; |
| 97 | } |
| 98 | |
Andrew de los Reyes | 3270f74 | 2010-07-15 22:28:14 -0700 | [diff] [blame] | 99 | // Note: Caller responsible for free()ing the returned value! |
Alex Vakulenko | 88b591f | 2014-08-28 16:48:57 -0700 | [diff] [blame] | 100 | // Will return null on failure and free any allocated memory. |
Andrew de los Reyes | 3270f74 | 2010-07-15 22:28:14 -0700 | [diff] [blame] | 101 | char** ArgPointer() { |
| 102 | const char* keys[] = {"LD_LIBRARY_PATH", "PATH"}; |
| 103 | char** ret = new char*[arraysize(keys) + 1]; |
| 104 | int pointer = 0; |
| 105 | for (size_t i = 0; i < arraysize(keys); i++) { |
Andrew de los Reyes | 3270f74 | 2010-07-15 22:28:14 -0700 | [diff] [blame] | 106 | if (getenv(keys[i])) { |
Alex Vakulenko | 75039d7 | 2014-03-25 12:36:28 -0700 | [diff] [blame] | 107 | ret[pointer] = strdup(base::StringPrintf("%s=%s", keys[i], |
| 108 | getenv(keys[i])).c_str()); |
Chris Masone | c6c57a5 | 2010-09-23 13:06:14 -0700 | [diff] [blame] | 109 | if (!ret[pointer]) { |
| 110 | FreeArgv(ret); |
| 111 | delete [] ret; |
Alex Vakulenko | 88b591f | 2014-08-28 16:48:57 -0700 | [diff] [blame] | 112 | return nullptr; |
Chris Masone | c6c57a5 | 2010-09-23 13:06:14 -0700 | [diff] [blame] | 113 | } |
| 114 | ++pointer; |
Andrew de los Reyes | 3270f74 | 2010-07-15 22:28:14 -0700 | [diff] [blame] | 115 | } |
| 116 | } |
Alex Vakulenko | 88b591f | 2014-08-28 16:48:57 -0700 | [diff] [blame] | 117 | ret[pointer] = nullptr; |
Andrew de los Reyes | 3270f74 | 2010-07-15 22:28:14 -0700 | [diff] [blame] | 118 | return ret; |
| 119 | } |
| 120 | |
| 121 | class ScopedFreeArgPointer { |
| 122 | public: |
Alex Vakulenko | d2779df | 2014-06-16 13:19:00 -0700 | [diff] [blame] | 123 | explicit ScopedFreeArgPointer(char** arr) : arr_(arr) {} |
Andrew de los Reyes | 3270f74 | 2010-07-15 22:28:14 -0700 | [diff] [blame] | 124 | ~ScopedFreeArgPointer() { |
| 125 | if (!arr_) |
| 126 | return; |
| 127 | for (int i = 0; arr_[i]; i++) |
| 128 | free(arr_[i]); |
| 129 | delete[] arr_; |
| 130 | } |
| 131 | private: |
| 132 | char** arr_; |
| 133 | DISALLOW_COPY_AND_ASSIGN(ScopedFreeArgPointer); |
| 134 | }; |
Alex Vakulenko | d2779df | 2014-06-16 13:19:00 -0700 | [diff] [blame] | 135 | } // namespace |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 136 | |
Darin Petkov | 85d02b7 | 2011-05-17 13:25:51 -0700 | [diff] [blame] | 137 | uint32_t Subprocess::Exec(const vector<string>& cmd, |
Andrew de los Reyes | 3270f74 | 2010-07-15 22:28:14 -0700 | [diff] [blame] | 138 | ExecCallback callback, |
| 139 | void* p) { |
Alex Deymo | 29b8153 | 2015-07-09 11:51:49 -0700 | [diff] [blame] | 140 | return ExecFlags(cmd, static_cast<GSpawnFlags>(0), true, callback, p); |
| 141 | } |
| 142 | |
| 143 | uint32_t Subprocess::ExecFlags(const vector<string>& cmd, |
| 144 | GSpawnFlags flags, |
| 145 | bool redirect_stderr_to_stdout, |
| 146 | ExecCallback callback, |
| 147 | void* p) { |
| 148 | unique_ptr<gchar*, utils::GLibStrvFreeDeleter> argv( |
| 149 | utils::StringVectorToGStrv(cmd)); |
Andrew de los Reyes | 08c4e27 | 2010-04-15 14:02:17 -0700 | [diff] [blame] | 150 | |
Andrew de los Reyes | 3270f74 | 2010-07-15 22:28:14 -0700 | [diff] [blame] | 151 | char** argp = ArgPointer(); |
Chris Masone | c6c57a5 | 2010-09-23 13:06:14 -0700 | [diff] [blame] | 152 | if (!argp) { |
Alex Vakulenko | 88b591f | 2014-08-28 16:48:57 -0700 | [diff] [blame] | 153 | FreeArgvInError(argv.get()); // null in argv[i] terminates argv. |
Chris Masone | c6c57a5 | 2010-09-23 13:06:14 -0700 | [diff] [blame] | 154 | return 0; |
| 155 | } |
Andrew de los Reyes | 3270f74 | 2010-07-15 22:28:14 -0700 | [diff] [blame] | 156 | ScopedFreeArgPointer argp_free(argp); |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 157 | |
Darin Petkov | 6f03a3b | 2010-11-10 14:27:14 -0800 | [diff] [blame] | 158 | shared_ptr<SubprocessRecord> record(new SubprocessRecord); |
| 159 | record->callback = callback; |
| 160 | record->callback_data = p; |
| 161 | gint stdout_fd = -1; |
Alex Deymo | 3e0b53e | 2014-08-12 23:12:25 -0700 | [diff] [blame] | 162 | GError* error = nullptr; |
Darin Petkov | 6f03a3b | 2010-11-10 14:27:14 -0800 | [diff] [blame] | 163 | bool success = g_spawn_async_with_pipes( |
Alex Vakulenko | 88b591f | 2014-08-28 16:48:57 -0700 | [diff] [blame] | 164 | nullptr, // working directory |
Darin Petkov | 6f03a3b | 2010-11-10 14:27:14 -0800 | [diff] [blame] | 165 | argv.get(), |
| 166 | argp, |
Alex Deymo | 29b8153 | 2015-07-09 11:51:49 -0700 | [diff] [blame] | 167 | static_cast<GSpawnFlags>(flags | G_SPAWN_DO_NOT_REAP_CHILD), // flags |
| 168 | // child setup function: |
| 169 | redirect_stderr_to_stdout ? GRedirectStderrToStdout : nullptr, |
Alex Vakulenko | 88b591f | 2014-08-28 16:48:57 -0700 | [diff] [blame] | 170 | nullptr, // child setup data pointer |
Alex Deymo | 29b8153 | 2015-07-09 11:51:49 -0700 | [diff] [blame] | 171 | &record->pid, |
Alex Vakulenko | 88b591f | 2014-08-28 16:48:57 -0700 | [diff] [blame] | 172 | nullptr, |
Darin Petkov | 6f03a3b | 2010-11-10 14:27:14 -0800 | [diff] [blame] | 173 | &stdout_fd, |
Alex Vakulenko | 88b591f | 2014-08-28 16:48:57 -0700 | [diff] [blame] | 174 | nullptr, |
Alex Deymo | 3e0b53e | 2014-08-12 23:12:25 -0700 | [diff] [blame] | 175 | &error); |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 176 | if (!success) { |
Alex Deymo | 3e0b53e | 2014-08-12 23:12:25 -0700 | [diff] [blame] | 177 | LOG(ERROR) << "g_spawn_async failed: " << utils::GetAndFreeGError(&error); |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 178 | return 0; |
| 179 | } |
Darin Petkov | 6f03a3b | 2010-11-10 14:27:14 -0800 | [diff] [blame] | 180 | record->tag = |
Alex Deymo | 29b8153 | 2015-07-09 11:51:49 -0700 | [diff] [blame] | 181 | g_child_watch_add(record->pid, GChildExitedCallback, record.get()); |
| 182 | record->stdout_fd = stdout_fd; |
Darin Petkov | 6f03a3b | 2010-11-10 14:27:14 -0800 | [diff] [blame] | 183 | subprocess_records_[record->tag] = record; |
| 184 | |
Alex Deymo | 29b8153 | 2015-07-09 11:51:49 -0700 | [diff] [blame] | 185 | // Capture the subprocess output. Make our end of the pipe non-blocking. |
| 186 | int fd_flags = fcntl(stdout_fd, F_GETFL, 0) | O_NONBLOCK; |
| 187 | if (HANDLE_EINTR(fcntl(record->stdout_fd, F_SETFL, fd_flags)) < 0) { |
| 188 | LOG(ERROR) << "Unable to set non-blocking I/O mode on fd " |
| 189 | << record->stdout_fd << "."; |
| 190 | } |
| 191 | |
| 192 | record->task_id = MessageLoop::current()->WatchFileDescriptor( |
| 193 | FROM_HERE, |
| 194 | record->stdout_fd, |
| 195 | MessageLoop::WatchMode::kWatchRead, |
| 196 | true, |
| 197 | base::Bind(&Subprocess::OnStdoutReady, record.get())); |
| 198 | |
Darin Petkov | 6f03a3b | 2010-11-10 14:27:14 -0800 | [diff] [blame] | 199 | return record->tag; |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 200 | } |
| 201 | |
Alex Deymo | 29b8153 | 2015-07-09 11:51:49 -0700 | [diff] [blame] | 202 | void Subprocess::KillExec(uint32_t tag) { |
| 203 | const auto& record = subprocess_records_.find(tag); |
| 204 | if (record == subprocess_records_.end()) |
| 205 | return; |
| 206 | record->second->callback = nullptr; |
| 207 | kill(record->second->pid, SIGTERM); |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 208 | } |
| 209 | |
Darin Petkov | 85d02b7 | 2011-05-17 13:25:51 -0700 | [diff] [blame] | 210 | bool Subprocess::SynchronousExecFlags(const vector<string>& cmd, |
| 211 | GSpawnFlags flags, |
Andrew de los Reyes | 5a23283 | 2010-10-12 16:20:54 -0700 | [diff] [blame] | 212 | int* return_code, |
Darin Petkov | 85d02b7 | 2011-05-17 13:25:51 -0700 | [diff] [blame] | 213 | string* stdout) { |
| 214 | if (stdout) { |
| 215 | *stdout = ""; |
| 216 | } |
Alex Vakulenko | 88b591f | 2014-08-28 16:48:57 -0700 | [diff] [blame] | 217 | GError* err = nullptr; |
Ben Chan | 02f7c1d | 2014-10-18 15:18:02 -0700 | [diff] [blame] | 218 | unique_ptr<char*[]> argv(new char*[cmd.size() + 1]); |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 219 | for (unsigned int i = 0; i < cmd.size(); i++) { |
| 220 | argv[i] = strdup(cmd[i].c_str()); |
Chris Masone | c6c57a5 | 2010-09-23 13:06:14 -0700 | [diff] [blame] | 221 | if (!argv[i]) { |
Alex Vakulenko | 88b591f | 2014-08-28 16:48:57 -0700 | [diff] [blame] | 222 | FreeArgvInError(argv.get()); // null in argv[i] terminates argv. |
Chris Masone | c6c57a5 | 2010-09-23 13:06:14 -0700 | [diff] [blame] | 223 | return false; |
| 224 | } |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 225 | } |
Alex Vakulenko | 88b591f | 2014-08-28 16:48:57 -0700 | [diff] [blame] | 226 | argv[cmd.size()] = nullptr; |
Andrew de los Reyes | 3270f74 | 2010-07-15 22:28:14 -0700 | [diff] [blame] | 227 | |
| 228 | char** argp = ArgPointer(); |
Chris Masone | c6c57a5 | 2010-09-23 13:06:14 -0700 | [diff] [blame] | 229 | if (!argp) { |
Alex Vakulenko | 88b591f | 2014-08-28 16:48:57 -0700 | [diff] [blame] | 230 | FreeArgvInError(argv.get()); // null in argv[i] terminates argv. |
Chris Masone | c6c57a5 | 2010-09-23 13:06:14 -0700 | [diff] [blame] | 231 | return false; |
| 232 | } |
Andrew de los Reyes | 3270f74 | 2010-07-15 22:28:14 -0700 | [diff] [blame] | 233 | ScopedFreeArgPointer argp_free(argp); |
| 234 | |
| 235 | char* child_stdout; |
Andrew de los Reyes | 5a23283 | 2010-10-12 16:20:54 -0700 | [diff] [blame] | 236 | bool success = g_spawn_sync( |
Alex Vakulenko | 88b591f | 2014-08-28 16:48:57 -0700 | [diff] [blame] | 237 | nullptr, // working directory |
Andrew de los Reyes | 5a23283 | 2010-10-12 16:20:54 -0700 | [diff] [blame] | 238 | argv.get(), |
| 239 | argp, |
Andrew de los Reyes | 50f3649 | 2010-11-01 13:57:12 -0700 | [diff] [blame] | 240 | static_cast<GSpawnFlags>(G_SPAWN_STDERR_TO_DEV_NULL | |
| 241 | G_SPAWN_SEARCH_PATH | flags), // flags |
Andrew de los Reyes | 5a23283 | 2010-10-12 16:20:54 -0700 | [diff] [blame] | 242 | GRedirectStderrToStdout, // child setup function |
Alex Vakulenko | 88b591f | 2014-08-28 16:48:57 -0700 | [diff] [blame] | 243 | nullptr, // data for child setup function |
Andrew de los Reyes | 5a23283 | 2010-10-12 16:20:54 -0700 | [diff] [blame] | 244 | &child_stdout, |
Alex Vakulenko | 88b591f | 2014-08-28 16:48:57 -0700 | [diff] [blame] | 245 | nullptr, |
Andrew de los Reyes | 5a23283 | 2010-10-12 16:20:54 -0700 | [diff] [blame] | 246 | return_code, |
| 247 | &err); |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 248 | FreeArgv(argv.get()); |
Darin Petkov | a0b9e77 | 2011-10-06 05:05:56 -0700 | [diff] [blame] | 249 | LOG_IF(INFO, err) << utils::GetAndFreeGError(&err); |
Darin Petkov | 478435e | 2011-05-17 11:46:31 -0700 | [diff] [blame] | 250 | if (child_stdout) { |
Darin Petkov | 85d02b7 | 2011-05-17 13:25:51 -0700 | [diff] [blame] | 251 | if (stdout) { |
| 252 | *stdout = child_stdout; |
| 253 | } else if (*child_stdout) { |
Darin Petkov | 478435e | 2011-05-17 11:46:31 -0700 | [diff] [blame] | 254 | LOG(INFO) << "Subprocess output:\n" << child_stdout; |
| 255 | } |
| 256 | g_free(child_stdout); |
| 257 | } |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 258 | return success; |
| 259 | } |
| 260 | |
Alex Deymo | f329b93 | 2014-10-30 01:37:48 -0700 | [diff] [blame] | 261 | bool Subprocess::SynchronousExec(const vector<string>& cmd, |
Darin Petkov | 85d02b7 | 2011-05-17 13:25:51 -0700 | [diff] [blame] | 262 | int* return_code, |
Alex Deymo | f329b93 | 2014-10-30 01:37:48 -0700 | [diff] [blame] | 263 | string* stdout) { |
Darin Petkov | 85d02b7 | 2011-05-17 13:25:51 -0700 | [diff] [blame] | 264 | return SynchronousExecFlags(cmd, |
| 265 | static_cast<GSpawnFlags>(0), |
| 266 | return_code, |
| 267 | stdout); |
| 268 | } |
| 269 | |
Darin Petkov | 6f03a3b | 2010-11-10 14:27:14 -0800 | [diff] [blame] | 270 | bool Subprocess::SubprocessInFlight() { |
Alex Deymo | 29b8153 | 2015-07-09 11:51:49 -0700 | [diff] [blame] | 271 | for (const auto& tag_record_pair : subprocess_records_) { |
| 272 | if (tag_record_pair.second->callback) |
Darin Petkov | 6f03a3b | 2010-11-10 14:27:14 -0800 | [diff] [blame] | 273 | return true; |
| 274 | } |
| 275 | return false; |
| 276 | } |
| 277 | |
Alex Vakulenko | 88b591f | 2014-08-28 16:48:57 -0700 | [diff] [blame] | 278 | Subprocess* Subprocess::subprocess_singleton_ = nullptr; |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 279 | |
| 280 | } // namespace chromeos_update_engine |