Joe Onorato | 1754d74 | 2016-11-21 17:51:35 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #define LOG_TAG "incidentd" |
| 18 | |
| 19 | #include "Section.h" |
| 20 | #include "protobuf.h" |
| 21 | |
Yi Jin | b44f7d4 | 2017-07-21 12:12:59 -0700 | [diff] [blame] | 22 | #include <private/android_filesystem_config.h> |
Joe Onorato | 1754d74 | 2016-11-21 17:51:35 -0800 | [diff] [blame] | 23 | #include <binder/IServiceManager.h> |
| 24 | #include <mutex> |
Yi Jin | 0a3406f | 2017-06-22 19:23:11 -0700 | [diff] [blame] | 25 | #include <stdio.h> |
| 26 | #include <stdlib.h> |
| 27 | #include <string.h> |
| 28 | #include <wait.h> |
| 29 | #include <unistd.h> |
Joe Onorato | 1754d74 | 2016-11-21 17:51:35 -0800 | [diff] [blame] | 30 | |
| 31 | using namespace std; |
| 32 | |
Yi Jin | b44f7d4 | 2017-07-21 12:12:59 -0700 | [diff] [blame] | 33 | const int WAIT_MAX = 5; |
| 34 | const struct timespec WAIT_INTERVAL_NS = {0, 200 * 1000 * 1000}; |
Yi Jin | 0a3406f | 2017-06-22 19:23:11 -0700 | [diff] [blame] | 35 | const char* INCIDENT_HELPER = "/system/bin/incident_helper"; |
Yi Jin | b44f7d4 | 2017-07-21 12:12:59 -0700 | [diff] [blame] | 36 | |
| 37 | static pid_t |
| 38 | forkAndExecuteIncidentHelper(const int id, const char* name, Fpipe& p2cPipe, Fpipe& c2pPipe) |
| 39 | { |
| 40 | const char* ihArgs[] { INCIDENT_HELPER, "-s", to_string(id).c_str(), NULL }; |
| 41 | |
| 42 | // fork used in multithreaded environment, avoid adding unnecessary code in child process |
| 43 | pid_t pid = fork(); |
| 44 | if (pid == 0) { |
| 45 | // child process executes incident helper as nobody |
| 46 | if (setgid(AID_NOBODY) == -1) { |
| 47 | ALOGW("%s can't change gid: %s", name, strerror(errno)); |
| 48 | _exit(EXIT_FAILURE); |
| 49 | } |
| 50 | if (setuid(AID_NOBODY) == -1) { |
| 51 | ALOGW("%s can't change uid: %s", name, strerror(errno)); |
| 52 | _exit(EXIT_FAILURE); |
| 53 | } |
| 54 | |
| 55 | if (dup2(p2cPipe.readFd(), STDIN_FILENO) != 0 || !p2cPipe.close() || |
| 56 | dup2(c2pPipe.writeFd(), STDOUT_FILENO) != 1 || !c2pPipe.close()) { |
| 57 | ALOGW("%s can't setup stdin and stdout for incident helper", name); |
| 58 | _exit(EXIT_FAILURE); |
| 59 | } |
| 60 | |
| 61 | execv(INCIDENT_HELPER, const_cast<char**>(ihArgs)); |
| 62 | |
| 63 | ALOGW("%s failed in incident helper process: %s", name, strerror(errno)); |
| 64 | _exit(EXIT_FAILURE); // always exits with failure if any |
| 65 | } |
| 66 | // close the fds used in incident helper |
| 67 | close(p2cPipe.readFd()); |
| 68 | close(c2pPipe.writeFd()); |
| 69 | return pid; |
| 70 | } |
| 71 | |
| 72 | static status_t killChild(pid_t pid) { |
| 73 | int status; |
| 74 | kill(pid, SIGKILL); |
| 75 | if (waitpid(pid, &status, 0) == -1) return -1; |
| 76 | return WIFEXITED(status) == 0 ? NO_ERROR : -WEXITSTATUS(status); |
| 77 | } |
| 78 | |
| 79 | static status_t waitForChild(pid_t pid) { |
| 80 | int status; |
| 81 | bool died = false; |
| 82 | // wait for child to report status up to 1 seconds |
| 83 | for(int loop = 0; !died && loop < WAIT_MAX; loop++) { |
| 84 | if (waitpid(pid, &status, WNOHANG) == pid) died = true; |
| 85 | // sleep for 0.2 second |
| 86 | nanosleep(&WAIT_INTERVAL_NS, NULL); |
| 87 | } |
| 88 | if (!died) return killChild(pid); |
| 89 | return WIFEXITED(status) == 0 ? NO_ERROR : -WEXITSTATUS(status); |
| 90 | } |
Joe Onorato | 1754d74 | 2016-11-21 17:51:35 -0800 | [diff] [blame] | 91 | |
| 92 | // ================================================================================ |
Yi Jin | b44f7d4 | 2017-07-21 12:12:59 -0700 | [diff] [blame] | 93 | Section::Section(int i, const int64_t timeoutMs) |
| 94 | :id(i), timeoutMs(timeoutMs) |
Joe Onorato | 1754d74 | 2016-11-21 17:51:35 -0800 | [diff] [blame] | 95 | { |
| 96 | } |
| 97 | |
| 98 | Section::~Section() |
| 99 | { |
| 100 | } |
| 101 | |
| 102 | status_t |
| 103 | Section::WriteHeader(ReportRequestSet* requests, size_t size) const |
| 104 | { |
| 105 | ssize_t amt; |
| 106 | uint8_t buf[20]; |
| 107 | uint8_t* p = write_length_delimited_tag_header(buf, this->id, size); |
| 108 | return requests->write(buf, p-buf); |
| 109 | } |
| 110 | |
| 111 | // ================================================================================ |
Yi Jin | b44f7d4 | 2017-07-21 12:12:59 -0700 | [diff] [blame] | 112 | FileSection::FileSection(int id, const char* filename, const int64_t timeoutMs) |
| 113 | : Section(id, timeoutMs), mFilename(filename) { |
| 114 | name = filename; |
Yi Jin | 0a3406f | 2017-06-22 19:23:11 -0700 | [diff] [blame] | 115 | } |
| 116 | |
| 117 | FileSection::~FileSection() {} |
| 118 | |
| 119 | status_t FileSection::Execute(ReportRequestSet* requests) const { |
Yi Jin | b44f7d4 | 2017-07-21 12:12:59 -0700 | [diff] [blame] | 120 | // read from mFilename first, make sure the file is available |
| 121 | // add O_CLOEXEC to make sure it is closed when exec incident helper |
George Burgess IV | 6f9735b | 2017-08-03 16:08:29 -0700 | [diff] [blame^] | 122 | int fd = open(mFilename, O_RDONLY | O_CLOEXEC); |
Yi Jin | 0a3406f | 2017-06-22 19:23:11 -0700 | [diff] [blame] | 123 | if (fd == -1) { |
| 124 | ALOGW("FileSection '%s' failed to open file", this->name.string()); |
| 125 | return -errno; |
| 126 | } |
| 127 | |
Yi Jin | b44f7d4 | 2017-07-21 12:12:59 -0700 | [diff] [blame] | 128 | FdBuffer buffer; |
| 129 | Fpipe p2cPipe; |
| 130 | Fpipe c2pPipe; |
| 131 | // initiate pipes to pass data to/from incident_helper |
| 132 | if (!p2cPipe.init() || !c2pPipe.init()) { |
| 133 | ALOGW("FileSection '%s' failed to setup pipes", this->name.string()); |
Yi Jin | 0a3406f | 2017-06-22 19:23:11 -0700 | [diff] [blame] | 134 | return -errno; |
| 135 | } |
| 136 | |
Yi Jin | b44f7d4 | 2017-07-21 12:12:59 -0700 | [diff] [blame] | 137 | pid_t pid = forkAndExecuteIncidentHelper(this->id, this->name.string(), p2cPipe, c2pPipe); |
| 138 | if (pid == -1) { |
| 139 | ALOGW("FileSection '%s' failed to fork", this->name.string()); |
| 140 | return -errno; |
| 141 | } |
| 142 | |
| 143 | // parent process |
| 144 | status_t readStatus = buffer.readProcessedDataInStream(fd, p2cPipe.writeFd(), c2pPipe.readFd(), |
| 145 | this->timeoutMs); |
| 146 | if (readStatus != NO_ERROR || buffer.timedOut()) { |
| 147 | ALOGW("FileSection '%s' failed to read data from incident helper: %s, timedout: %s, kill: %s", |
| 148 | this->name.string(), strerror(-readStatus), buffer.timedOut() ? "true" : "false", |
| 149 | strerror(-killChild(pid))); |
| 150 | return readStatus; |
| 151 | } |
| 152 | |
| 153 | status_t ihStatus = waitForChild(pid); |
| 154 | if (ihStatus != NO_ERROR) { |
| 155 | ALOGW("FileSection '%s' abnormal child process: %s", this->name.string(), strerror(-ihStatus)); |
| 156 | return ihStatus; |
| 157 | } |
| 158 | |
| 159 | ALOGD("FileSection '%s' wrote %zd bytes in %d ms", this->name.string(), buffer.size(), |
Yi Jin | 0a3406f | 2017-06-22 19:23:11 -0700 | [diff] [blame] | 160 | (int)buffer.durationMs()); |
| 161 | WriteHeader(requests, buffer.size()); |
Yi Jin | b44f7d4 | 2017-07-21 12:12:59 -0700 | [diff] [blame] | 162 | status_t err = buffer.write(requests); |
Yi Jin | 0a3406f | 2017-06-22 19:23:11 -0700 | [diff] [blame] | 163 | if (err != NO_ERROR) { |
| 164 | ALOGW("FileSection '%s' failed writing: %s", this->name.string(), strerror(-err)); |
| 165 | return err; |
| 166 | } |
| 167 | |
| 168 | return NO_ERROR; |
| 169 | } |
| 170 | |
| 171 | // ================================================================================ |
Joe Onorato | 1754d74 | 2016-11-21 17:51:35 -0800 | [diff] [blame] | 172 | struct WorkerThreadData : public virtual RefBase |
| 173 | { |
| 174 | const WorkerThreadSection* section; |
| 175 | int fds[2]; |
| 176 | |
| 177 | // Lock protects these fields |
| 178 | mutex lock; |
| 179 | bool workerDone; |
| 180 | status_t workerError; |
| 181 | |
| 182 | WorkerThreadData(const WorkerThreadSection* section); |
| 183 | virtual ~WorkerThreadData(); |
| 184 | |
| 185 | int readFd() { return fds[0]; } |
| 186 | int writeFd() { return fds[1]; } |
| 187 | }; |
| 188 | |
| 189 | WorkerThreadData::WorkerThreadData(const WorkerThreadSection* sec) |
| 190 | :section(sec), |
| 191 | workerDone(false), |
| 192 | workerError(NO_ERROR) |
| 193 | { |
| 194 | fds[0] = -1; |
| 195 | fds[1] = -1; |
| 196 | } |
| 197 | |
| 198 | WorkerThreadData::~WorkerThreadData() |
| 199 | { |
| 200 | } |
| 201 | |
| 202 | // ================================================================================ |
| 203 | WorkerThreadSection::WorkerThreadSection(int id) |
| 204 | :Section(id) |
| 205 | { |
| 206 | } |
| 207 | |
| 208 | WorkerThreadSection::~WorkerThreadSection() |
| 209 | { |
| 210 | } |
| 211 | |
| 212 | static void* |
| 213 | worker_thread_func(void* cookie) |
| 214 | { |
| 215 | WorkerThreadData* data = (WorkerThreadData*)cookie; |
| 216 | status_t err = data->section->BlockingCall(data->writeFd()); |
| 217 | |
| 218 | { |
| 219 | unique_lock<mutex> lock(data->lock); |
| 220 | data->workerDone = true; |
| 221 | data->workerError = err; |
| 222 | } |
| 223 | |
| 224 | close(data->writeFd()); |
| 225 | data->decStrong(data->section); |
| 226 | // data might be gone now. don't use it after this point in this thread. |
| 227 | return NULL; |
| 228 | } |
| 229 | |
| 230 | status_t |
| 231 | WorkerThreadSection::Execute(ReportRequestSet* requests) const |
| 232 | { |
| 233 | status_t err = NO_ERROR; |
| 234 | pthread_t thread; |
| 235 | pthread_attr_t attr; |
| 236 | bool timedOut = false; |
| 237 | FdBuffer buffer; |
| 238 | |
| 239 | // Data shared between this thread and the worker thread. |
| 240 | sp<WorkerThreadData> data = new WorkerThreadData(this); |
| 241 | |
| 242 | // Create the pipe |
| 243 | err = pipe(data->fds); |
| 244 | if (err != 0) { |
| 245 | return -errno; |
| 246 | } |
| 247 | |
| 248 | // The worker thread needs a reference and we can't let the count go to zero |
| 249 | // if that thread is slow to start. |
| 250 | data->incStrong(this); |
| 251 | |
| 252 | // Create the thread |
| 253 | err = pthread_attr_init(&attr); |
| 254 | if (err != 0) { |
| 255 | return -err; |
| 256 | } |
| 257 | // TODO: Do we need to tweak thread priority? |
| 258 | err = pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); |
| 259 | if (err != 0) { |
| 260 | pthread_attr_destroy(&attr); |
| 261 | return -err; |
| 262 | } |
| 263 | err = pthread_create(&thread, &attr, worker_thread_func, (void*)data.get()); |
| 264 | if (err != 0) { |
| 265 | pthread_attr_destroy(&attr); |
| 266 | return -err; |
| 267 | } |
| 268 | pthread_attr_destroy(&attr); |
| 269 | |
| 270 | // Loop reading until either the timeout or the worker side is done (i.e. eof). |
Yi Jin | b44f7d4 | 2017-07-21 12:12:59 -0700 | [diff] [blame] | 271 | err = buffer.read(data->readFd(), this->timeoutMs); |
Joe Onorato | 1754d74 | 2016-11-21 17:51:35 -0800 | [diff] [blame] | 272 | if (err != NO_ERROR) { |
| 273 | // TODO: Log this error into the incident report. |
| 274 | ALOGW("WorkerThreadSection '%s' reader failed with error '%s'", this->name.string(), |
| 275 | strerror(-err)); |
| 276 | } |
| 277 | |
| 278 | // Done with the read fd. The worker thread closes the write one so |
| 279 | // we never race and get here first. |
| 280 | close(data->readFd()); |
| 281 | |
| 282 | // If the worker side is finished, then return its error (which may overwrite |
| 283 | // our possible error -- but it's more interesting anyway). If not, then we timed out. |
| 284 | { |
| 285 | unique_lock<mutex> lock(data->lock); |
| 286 | if (!data->workerDone) { |
| 287 | // We timed out |
| 288 | timedOut = true; |
| 289 | } else { |
| 290 | if (data->workerError != NO_ERROR) { |
| 291 | err = data->workerError; |
| 292 | // TODO: Log this error into the incident report. |
| 293 | ALOGW("WorkerThreadSection '%s' worker failed with error '%s'", this->name.string(), |
| 294 | strerror(-err)); |
| 295 | } |
| 296 | } |
| 297 | } |
| 298 | |
| 299 | if (timedOut || buffer.timedOut()) { |
| 300 | ALOGW("WorkerThreadSection '%s' timed out", this->name.string()); |
| 301 | return NO_ERROR; |
| 302 | } |
| 303 | |
| 304 | if (buffer.truncated()) { |
| 305 | // TODO: Log this into the incident report. |
| 306 | } |
| 307 | |
| 308 | // TODO: There was an error with the command or buffering. Report that. For now |
| 309 | // just exit with a log messasge. |
| 310 | if (err != NO_ERROR) { |
| 311 | ALOGW("WorkerThreadSection '%s' failed with error '%s'", this->name.string(), |
| 312 | strerror(-err)); |
| 313 | return NO_ERROR; |
| 314 | } |
| 315 | |
| 316 | // Write the data that was collected |
Yi Jin | b44f7d4 | 2017-07-21 12:12:59 -0700 | [diff] [blame] | 317 | ALOGD("WorkerThreadSection '%s' wrote %zd bytes in %d ms", name.string(), buffer.size(), |
Joe Onorato | 1754d74 | 2016-11-21 17:51:35 -0800 | [diff] [blame] | 318 | (int)buffer.durationMs()); |
| 319 | WriteHeader(requests, buffer.size()); |
| 320 | err = buffer.write(requests); |
| 321 | if (err != NO_ERROR) { |
| 322 | ALOGW("WorkerThreadSection '%s' failed writing: '%s'", this->name.string(), strerror(-err)); |
| 323 | return err; |
| 324 | } |
| 325 | |
| 326 | return NO_ERROR; |
| 327 | } |
| 328 | |
| 329 | // ================================================================================ |
Yi Jin | b44f7d4 | 2017-07-21 12:12:59 -0700 | [diff] [blame] | 330 | void CommandSection::init(const char* command, va_list args) |
| 331 | { |
| 332 | va_list copied_args; |
| 333 | va_copy(copied_args, args); |
| 334 | int numOfArgs = 0; |
| 335 | while(va_arg(args, const char*) != NULL) { |
| 336 | numOfArgs++; |
| 337 | } |
| 338 | |
| 339 | // allocate extra 1 for command and 1 for NULL terminator |
| 340 | mCommand = (const char**)malloc(sizeof(const char*) * (numOfArgs + 2)); |
| 341 | |
| 342 | mCommand[0] = command; |
| 343 | name = command; |
| 344 | for (int i=0; i<numOfArgs; i++) { |
| 345 | const char* arg = va_arg(copied_args, const char*); |
| 346 | mCommand[i+1] = arg; |
| 347 | name += " "; |
| 348 | name += arg; |
| 349 | } |
| 350 | mCommand[numOfArgs+1] = NULL; |
| 351 | va_end(copied_args); |
| 352 | } |
| 353 | |
| 354 | CommandSection::CommandSection(int id, const int64_t timeoutMs, const char* command, ...) |
| 355 | : Section(id, timeoutMs) |
Joe Onorato | 1754d74 | 2016-11-21 17:51:35 -0800 | [diff] [blame] | 356 | { |
| 357 | va_list args; |
Yi Jin | b44f7d4 | 2017-07-21 12:12:59 -0700 | [diff] [blame] | 358 | va_start(args, command); |
| 359 | init(command, args); |
Joe Onorato | 1754d74 | 2016-11-21 17:51:35 -0800 | [diff] [blame] | 360 | va_end(args); |
Yi Jin | b44f7d4 | 2017-07-21 12:12:59 -0700 | [diff] [blame] | 361 | } |
Joe Onorato | 1754d74 | 2016-11-21 17:51:35 -0800 | [diff] [blame] | 362 | |
Yi Jin | b44f7d4 | 2017-07-21 12:12:59 -0700 | [diff] [blame] | 363 | CommandSection::CommandSection(int id, const char* command, ...) |
| 364 | : Section(id) |
| 365 | { |
| 366 | va_list args; |
| 367 | va_start(args, command); |
| 368 | init(command, args); |
Joe Onorato | 1754d74 | 2016-11-21 17:51:35 -0800 | [diff] [blame] | 369 | va_end(args); |
| 370 | } |
| 371 | |
| 372 | CommandSection::~CommandSection() |
| 373 | { |
Yi Jin | b44f7d4 | 2017-07-21 12:12:59 -0700 | [diff] [blame] | 374 | free(mCommand); |
Joe Onorato | 1754d74 | 2016-11-21 17:51:35 -0800 | [diff] [blame] | 375 | } |
| 376 | |
| 377 | status_t |
Yi Jin | b44f7d4 | 2017-07-21 12:12:59 -0700 | [diff] [blame] | 378 | CommandSection::Execute(ReportRequestSet* requests) const |
Joe Onorato | 1754d74 | 2016-11-21 17:51:35 -0800 | [diff] [blame] | 379 | { |
Yi Jin | b44f7d4 | 2017-07-21 12:12:59 -0700 | [diff] [blame] | 380 | FdBuffer buffer; |
| 381 | Fpipe cmdPipe; |
| 382 | Fpipe ihPipe; |
| 383 | |
| 384 | if (!cmdPipe.init() || !ihPipe.init()) { |
| 385 | ALOGW("CommandSection '%s' failed to setup pipes", this->name.string()); |
| 386 | return -errno; |
| 387 | } |
| 388 | |
| 389 | pid_t cmdPid = fork(); |
| 390 | if (cmdPid == -1) { |
| 391 | ALOGW("CommandSection '%s' failed to fork", this->name.string()); |
| 392 | return -errno; |
| 393 | } |
| 394 | // child process to execute the command as root |
| 395 | if (cmdPid == 0) { |
| 396 | // replace command's stdout with ihPipe's write Fd |
| 397 | if (dup2(cmdPipe.writeFd(), STDOUT_FILENO) != 1 || !ihPipe.close() || !cmdPipe.close()) { |
| 398 | ALOGW("CommandSection '%s' failed to set up stdout: %s", this->name.string(), strerror(errno)); |
| 399 | _exit(EXIT_FAILURE); |
| 400 | } |
| 401 | execv(this->mCommand[0], (char *const *) this->mCommand); |
| 402 | int err = errno; // record command error code |
| 403 | ALOGW("CommandSection '%s' failed in executing command: %s", this->name.string(), strerror(errno)); |
| 404 | _exit(err); // exit with command error code |
| 405 | } |
| 406 | pid_t ihPid = forkAndExecuteIncidentHelper(this->id, this->name.string(), cmdPipe, ihPipe); |
| 407 | if (ihPid == -1) { |
| 408 | ALOGW("CommandSection '%s' failed to fork", this->name.string()); |
| 409 | return -errno; |
| 410 | } |
| 411 | |
| 412 | close(cmdPipe.writeFd()); |
| 413 | status_t readStatus = buffer.read(ihPipe.readFd(), this->timeoutMs); |
| 414 | if (readStatus != NO_ERROR || buffer.timedOut()) { |
| 415 | ALOGW("CommandSection '%s' failed to read data from incident helper: %s, " |
| 416 | "timedout: %s, kill command: %s, kill incident helper: %s", |
| 417 | this->name.string(), strerror(-readStatus), buffer.timedOut() ? "true" : "false", |
| 418 | strerror(-killChild(cmdPid)), strerror(-killChild(ihPid))); |
| 419 | return readStatus; |
| 420 | } |
| 421 | |
| 422 | // TODO: wait for command here has one trade-off: the failed status of command won't be detected until |
| 423 | // buffer timeout, but it has advatage on starting the data stream earlier. |
| 424 | status_t cmdStatus = waitForChild(cmdPid); |
| 425 | status_t ihStatus = waitForChild(ihPid); |
| 426 | if (cmdStatus != NO_ERROR || ihStatus != NO_ERROR) { |
| 427 | ALOGW("CommandSection '%s' abnormal child processes, return status: command: %s, incidnet helper: %s", |
| 428 | this->name.string(), strerror(-cmdStatus), strerror(-ihStatus)); |
| 429 | return cmdStatus != NO_ERROR ? cmdStatus : ihStatus; |
| 430 | } |
| 431 | |
| 432 | ALOGD("CommandSection '%s' wrote %zd bytes in %d ms", this->name.string(), buffer.size(), |
| 433 | (int)buffer.durationMs()); |
| 434 | WriteHeader(requests, buffer.size()); |
| 435 | status_t err = buffer.write(requests); |
| 436 | if (err != NO_ERROR) { |
| 437 | ALOGW("CommandSection '%s' failed writing: %s", this->name.string(), strerror(-err)); |
| 438 | return err; |
| 439 | } |
Joe Onorato | 1754d74 | 2016-11-21 17:51:35 -0800 | [diff] [blame] | 440 | return NO_ERROR; |
| 441 | } |
| 442 | |
| 443 | // ================================================================================ |
| 444 | DumpsysSection::DumpsysSection(int id, const char* service, ...) |
| 445 | :WorkerThreadSection(id), |
| 446 | mService(service) |
| 447 | { |
| 448 | name = "dumpsys "; |
| 449 | name += service; |
| 450 | |
| 451 | va_list args; |
| 452 | va_start(args, service); |
| 453 | while (true) { |
Yi Jin | 0a3406f | 2017-06-22 19:23:11 -0700 | [diff] [blame] | 454 | const char* arg = va_arg(args, const char*); |
Joe Onorato | 1754d74 | 2016-11-21 17:51:35 -0800 | [diff] [blame] | 455 | if (arg == NULL) { |
| 456 | break; |
| 457 | } |
| 458 | mArgs.add(String16(arg)); |
| 459 | name += " "; |
| 460 | name += arg; |
| 461 | } |
| 462 | va_end(args); |
| 463 | } |
| 464 | |
| 465 | DumpsysSection::~DumpsysSection() |
| 466 | { |
| 467 | } |
| 468 | |
| 469 | status_t |
| 470 | DumpsysSection::BlockingCall(int pipeWriteFd) const |
| 471 | { |
| 472 | // checkService won't wait for the service to show up like getService will. |
| 473 | sp<IBinder> service = defaultServiceManager()->checkService(mService); |
Yi Jin | 0a3406f | 2017-06-22 19:23:11 -0700 | [diff] [blame] | 474 | |
Joe Onorato | 1754d74 | 2016-11-21 17:51:35 -0800 | [diff] [blame] | 475 | if (service == NULL) { |
| 476 | // Returning an error interrupts the entire incident report, so just |
| 477 | // log the failure. |
| 478 | // TODO: have a meta record inside the report that would log this |
| 479 | // failure inside the report, because the fact that we can't find |
| 480 | // the service is good data in and of itself. This is running in |
| 481 | // another thread so lock that carefully... |
| 482 | ALOGW("DumpsysSection: Can't lookup service: %s", String8(mService).string()); |
| 483 | return NO_ERROR; |
| 484 | } |
| 485 | |
| 486 | service->dump(pipeWriteFd, mArgs); |
| 487 | |
| 488 | return NO_ERROR; |
| 489 | } |