blob: 08959263838d294a8a03bc79516573f263dfb327 [file] [log] [blame]
Joe Onorato1754d742016-11-21 17:51:35 -08001/*
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
Yi Jin99c248f2017-08-25 18:11:58 -070019#include "EncodedBuffer.h"
20#include "FdBuffer.h"
21#include "Privacy.h"
Joe Onorato1754d742016-11-21 17:51:35 -080022#include "Section.h"
Yi Jin99c248f2017-08-25 18:11:58 -070023
24#include "io_util.h"
Joe Onorato1754d742016-11-21 17:51:35 -080025#include "protobuf.h"
Yi Jin99c248f2017-08-25 18:11:58 -070026#include "section_list.h"
Joe Onorato1754d742016-11-21 17:51:35 -080027
Yi Jinb44f7d42017-07-21 12:12:59 -070028#include <private/android_filesystem_config.h>
Joe Onorato1754d742016-11-21 17:51:35 -080029#include <binder/IServiceManager.h>
Yi Jin0f047162017-09-05 13:44:22 -070030#include <map>
Joe Onorato1754d742016-11-21 17:51:35 -080031#include <mutex>
Yi Jin0a3406f2017-06-22 19:23:11 -070032#include <wait.h>
33#include <unistd.h>
Joe Onorato1754d742016-11-21 17:51:35 -080034
35using namespace std;
36
Yi Jinb44f7d42017-07-21 12:12:59 -070037const int WAIT_MAX = 5;
38const struct timespec WAIT_INTERVAL_NS = {0, 200 * 1000 * 1000};
Yi Jin0a3406f2017-06-22 19:23:11 -070039const char* INCIDENT_HELPER = "/system/bin/incident_helper";
Yi Jinb44f7d42017-07-21 12:12:59 -070040
41static pid_t
42forkAndExecuteIncidentHelper(const int id, const char* name, Fpipe& p2cPipe, Fpipe& c2pPipe)
43{
Yi Jin0ed9b682017-08-18 14:51:20 -070044 const char* ihArgs[] { INCIDENT_HELPER, "-s", String8::format("%d", id).string(), NULL };
Yi Jinb44f7d42017-07-21 12:12:59 -070045
46 // fork used in multithreaded environment, avoid adding unnecessary code in child process
47 pid_t pid = fork();
48 if (pid == 0) {
49 // child process executes incident helper as nobody
50 if (setgid(AID_NOBODY) == -1) {
51 ALOGW("%s can't change gid: %s", name, strerror(errno));
52 _exit(EXIT_FAILURE);
53 }
54 if (setuid(AID_NOBODY) == -1) {
55 ALOGW("%s can't change uid: %s", name, strerror(errno));
56 _exit(EXIT_FAILURE);
57 }
58
59 if (dup2(p2cPipe.readFd(), STDIN_FILENO) != 0 || !p2cPipe.close() ||
60 dup2(c2pPipe.writeFd(), STDOUT_FILENO) != 1 || !c2pPipe.close()) {
61 ALOGW("%s can't setup stdin and stdout for incident helper", name);
62 _exit(EXIT_FAILURE);
63 }
64
65 execv(INCIDENT_HELPER, const_cast<char**>(ihArgs));
66
67 ALOGW("%s failed in incident helper process: %s", name, strerror(errno));
68 _exit(EXIT_FAILURE); // always exits with failure if any
69 }
70 // close the fds used in incident helper
71 close(p2cPipe.readFd());
72 close(c2pPipe.writeFd());
73 return pid;
74}
75
Yi Jin99c248f2017-08-25 18:11:58 -070076// ================================================================================
Yi Jinb44f7d42017-07-21 12:12:59 -070077static status_t killChild(pid_t pid) {
78 int status;
79 kill(pid, SIGKILL);
80 if (waitpid(pid, &status, 0) == -1) return -1;
81 return WIFEXITED(status) == 0 ? NO_ERROR : -WEXITSTATUS(status);
82}
83
84static status_t waitForChild(pid_t pid) {
85 int status;
86 bool died = false;
87 // wait for child to report status up to 1 seconds
88 for(int loop = 0; !died && loop < WAIT_MAX; loop++) {
89 if (waitpid(pid, &status, WNOHANG) == pid) died = true;
90 // sleep for 0.2 second
91 nanosleep(&WAIT_INTERVAL_NS, NULL);
92 }
93 if (!died) return killChild(pid);
94 return WIFEXITED(status) == 0 ? NO_ERROR : -WEXITSTATUS(status);
95}
Joe Onorato1754d742016-11-21 17:51:35 -080096
97// ================================================================================
Yi Jin99c248f2017-08-25 18:11:58 -070098static const Privacy*
99GetPrivacyOfSection(int id)
100{
101 if (id < 0) return NULL;
102 int i=0;
103 while (PRIVACY_POLICY_LIST[i] != NULL) {
104 const Privacy* p = PRIVACY_POLICY_LIST[i];
105 if (p->field_id == (uint32_t)id) return p;
106 if (p->field_id > (uint32_t)id) return NULL;
107 i++;
108 }
109 return NULL;
110}
111
112static status_t
Yi Jin0f047162017-09-05 13:44:22 -0700113WriteToRequest(const int id, const int fd, EncodedBuffer& buffer)
Yi Jin99c248f2017-08-25 18:11:58 -0700114{
Yi Jin0f047162017-09-05 13:44:22 -0700115 if (buffer.size() == 0) return NO_ERROR;
116
Yi Jin99c248f2017-08-25 18:11:58 -0700117 status_t err = NO_ERROR;
118 uint8_t buf[20];
Yi Jin99c248f2017-08-25 18:11:58 -0700119 uint8_t *p = write_length_delimited_tag_header(buf, id, buffer.size());
120 err = write_all(fd, buf, p-buf);
121 if (err == NO_ERROR) {
122 err = buffer.flush(fd);
Yi Jin99c248f2017-08-25 18:11:58 -0700123 }
124 return err;
125}
126
127static status_t
128WriteToReportRequests(const int id, const FdBuffer& buffer, ReportRequestSet* requests)
129{
Yi Jin0f047162017-09-05 13:44:22 -0700130 status_t err = -EBADF;
Yi Jin99c248f2017-08-25 18:11:58 -0700131 EncodedBuffer encodedBuffer(buffer, GetPrivacyOfSection(id));
132 int writeable = 0;
133
Yi Jin0f047162017-09-05 13:44:22 -0700134 // The streaming ones, group requests by spec in order to save unnecessary strip operations
135 map<PrivacySpec, vector<sp<ReportRequest>>> requestsBySpec;
Yi Jin99c248f2017-08-25 18:11:58 -0700136 for (ReportRequestSet::iterator it = requests->begin(); it != requests->end(); it++) {
137 sp<ReportRequest> request = *it;
Yi Jin0f047162017-09-05 13:44:22 -0700138 if (!request->args.containsSection(id) || request->fd < 0 || request->err != NO_ERROR) {
139 continue; // skip invalid request
Yi Jin99c248f2017-08-25 18:11:58 -0700140 }
Yi Jin0f047162017-09-05 13:44:22 -0700141 PrivacySpec spec = new_spec_from_args(request->args.dest());
142 requestsBySpec[spec].push_back(request);
143 }
144
145 for (map<PrivacySpec, vector<sp<ReportRequest>>>::iterator mit = requestsBySpec.begin(); mit != requestsBySpec.end(); mit++) {
146 PrivacySpec spec = mit->first;
147 err = encodedBuffer.strip(spec);
148 if (err != NO_ERROR) return err; // it means the encodedBuffer data is corrupted.
149 if (encodedBuffer.size() == 0) continue;
150
151 for (vector<sp<ReportRequest>>::iterator it = mit->second.begin(); it != mit->second.end(); it++) {
152 sp<ReportRequest> request = *it;
153 err = WriteToRequest(id, request->fd, encodedBuffer);
154 if (err != NO_ERROR) {
155 request->err = err;
156 } else {
157 writeable++;
158 }
159 ALOGD("Section %d flushed %zu bytes to fd %d with spec %d", id, encodedBuffer.size(), request->fd, spec.dest);
160 }
161 encodedBuffer.clear();
Yi Jin99c248f2017-08-25 18:11:58 -0700162 }
163
164 // The dropbox file
165 if (requests->mainFd() >= 0) {
Yi Jin0f047162017-09-05 13:44:22 -0700166 err = encodedBuffer.strip(get_default_dropbox_spec());
167 if (err != NO_ERROR) return err; // the buffer data is corrupted.
168
169 err = WriteToRequest(id, requests->mainFd(), encodedBuffer);
Yi Jin99c248f2017-08-25 18:11:58 -0700170 if (err != NO_ERROR) {
171 requests->setMainFd(-1);
172 } else {
173 writeable++;
174 }
175 }
176 // only returns error if there is no fd to write to.
177 return writeable > 0 ? NO_ERROR : err;
178}
179
180// ================================================================================
Yi Jinb44f7d42017-07-21 12:12:59 -0700181Section::Section(int i, const int64_t timeoutMs)
182 :id(i), timeoutMs(timeoutMs)
Joe Onorato1754d742016-11-21 17:51:35 -0800183{
184}
185
186Section::~Section()
187{
188}
189
Joe Onorato1754d742016-11-21 17:51:35 -0800190// ================================================================================
Yi Jinb44f7d42017-07-21 12:12:59 -0700191FileSection::FileSection(int id, const char* filename, const int64_t timeoutMs)
192 : Section(id, timeoutMs), mFilename(filename) {
193 name = filename;
Yi Jin0a3406f2017-06-22 19:23:11 -0700194}
195
196FileSection::~FileSection() {}
197
Yi Jin99c248f2017-08-25 18:11:58 -0700198status_t
199FileSection::Execute(ReportRequestSet* requests) const
200{
Yi Jinb44f7d42017-07-21 12:12:59 -0700201 // read from mFilename first, make sure the file is available
202 // add O_CLOEXEC to make sure it is closed when exec incident helper
George Burgess IV6f9735b2017-08-03 16:08:29 -0700203 int fd = open(mFilename, O_RDONLY | O_CLOEXEC);
Yi Jin0a3406f2017-06-22 19:23:11 -0700204 if (fd == -1) {
205 ALOGW("FileSection '%s' failed to open file", this->name.string());
206 return -errno;
207 }
208
Yi Jinb44f7d42017-07-21 12:12:59 -0700209 FdBuffer buffer;
210 Fpipe p2cPipe;
211 Fpipe c2pPipe;
212 // initiate pipes to pass data to/from incident_helper
213 if (!p2cPipe.init() || !c2pPipe.init()) {
214 ALOGW("FileSection '%s' failed to setup pipes", this->name.string());
Yi Jin0a3406f2017-06-22 19:23:11 -0700215 return -errno;
216 }
217
Yi Jinb44f7d42017-07-21 12:12:59 -0700218 pid_t pid = forkAndExecuteIncidentHelper(this->id, this->name.string(), p2cPipe, c2pPipe);
219 if (pid == -1) {
220 ALOGW("FileSection '%s' failed to fork", this->name.string());
221 return -errno;
222 }
223
224 // parent process
225 status_t readStatus = buffer.readProcessedDataInStream(fd, p2cPipe.writeFd(), c2pPipe.readFd(),
226 this->timeoutMs);
227 if (readStatus != NO_ERROR || buffer.timedOut()) {
228 ALOGW("FileSection '%s' failed to read data from incident helper: %s, timedout: %s, kill: %s",
229 this->name.string(), strerror(-readStatus), buffer.timedOut() ? "true" : "false",
230 strerror(-killChild(pid)));
231 return readStatus;
232 }
233
234 status_t ihStatus = waitForChild(pid);
235 if (ihStatus != NO_ERROR) {
236 ALOGW("FileSection '%s' abnormal child process: %s", this->name.string(), strerror(-ihStatus));
237 return ihStatus;
238 }
239
240 ALOGD("FileSection '%s' wrote %zd bytes in %d ms", this->name.string(), buffer.size(),
Yi Jin0a3406f2017-06-22 19:23:11 -0700241 (int)buffer.durationMs());
Yi Jin99c248f2017-08-25 18:11:58 -0700242 status_t err = WriteToReportRequests(this->id, buffer, requests);
Yi Jin0a3406f2017-06-22 19:23:11 -0700243 if (err != NO_ERROR) {
244 ALOGW("FileSection '%s' failed writing: %s", this->name.string(), strerror(-err));
245 return err;
246 }
247
248 return NO_ERROR;
249}
250
251// ================================================================================
Joe Onorato1754d742016-11-21 17:51:35 -0800252struct WorkerThreadData : public virtual RefBase
253{
254 const WorkerThreadSection* section;
255 int fds[2];
256
257 // Lock protects these fields
258 mutex lock;
259 bool workerDone;
260 status_t workerError;
261
262 WorkerThreadData(const WorkerThreadSection* section);
263 virtual ~WorkerThreadData();
264
265 int readFd() { return fds[0]; }
266 int writeFd() { return fds[1]; }
267};
268
269WorkerThreadData::WorkerThreadData(const WorkerThreadSection* sec)
270 :section(sec),
271 workerDone(false),
272 workerError(NO_ERROR)
273{
274 fds[0] = -1;
275 fds[1] = -1;
276}
277
278WorkerThreadData::~WorkerThreadData()
279{
280}
281
282// ================================================================================
283WorkerThreadSection::WorkerThreadSection(int id)
284 :Section(id)
285{
286}
287
288WorkerThreadSection::~WorkerThreadSection()
289{
290}
291
292static void*
293worker_thread_func(void* cookie)
294{
295 WorkerThreadData* data = (WorkerThreadData*)cookie;
296 status_t err = data->section->BlockingCall(data->writeFd());
297
298 {
299 unique_lock<mutex> lock(data->lock);
300 data->workerDone = true;
301 data->workerError = err;
302 }
303
304 close(data->writeFd());
305 data->decStrong(data->section);
306 // data might be gone now. don't use it after this point in this thread.
307 return NULL;
308}
309
310status_t
311WorkerThreadSection::Execute(ReportRequestSet* requests) const
312{
313 status_t err = NO_ERROR;
314 pthread_t thread;
315 pthread_attr_t attr;
316 bool timedOut = false;
317 FdBuffer buffer;
318
319 // Data shared between this thread and the worker thread.
320 sp<WorkerThreadData> data = new WorkerThreadData(this);
321
322 // Create the pipe
323 err = pipe(data->fds);
324 if (err != 0) {
325 return -errno;
326 }
327
328 // The worker thread needs a reference and we can't let the count go to zero
329 // if that thread is slow to start.
330 data->incStrong(this);
331
332 // Create the thread
333 err = pthread_attr_init(&attr);
334 if (err != 0) {
335 return -err;
336 }
337 // TODO: Do we need to tweak thread priority?
338 err = pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
339 if (err != 0) {
340 pthread_attr_destroy(&attr);
341 return -err;
342 }
343 err = pthread_create(&thread, &attr, worker_thread_func, (void*)data.get());
344 if (err != 0) {
345 pthread_attr_destroy(&attr);
346 return -err;
347 }
348 pthread_attr_destroy(&attr);
349
350 // Loop reading until either the timeout or the worker side is done (i.e. eof).
Yi Jinb44f7d42017-07-21 12:12:59 -0700351 err = buffer.read(data->readFd(), this->timeoutMs);
Joe Onorato1754d742016-11-21 17:51:35 -0800352 if (err != NO_ERROR) {
353 // TODO: Log this error into the incident report.
354 ALOGW("WorkerThreadSection '%s' reader failed with error '%s'", this->name.string(),
355 strerror(-err));
356 }
357
358 // Done with the read fd. The worker thread closes the write one so
359 // we never race and get here first.
360 close(data->readFd());
361
362 // If the worker side is finished, then return its error (which may overwrite
363 // our possible error -- but it's more interesting anyway). If not, then we timed out.
364 {
365 unique_lock<mutex> lock(data->lock);
366 if (!data->workerDone) {
367 // We timed out
368 timedOut = true;
369 } else {
370 if (data->workerError != NO_ERROR) {
371 err = data->workerError;
372 // TODO: Log this error into the incident report.
373 ALOGW("WorkerThreadSection '%s' worker failed with error '%s'", this->name.string(),
374 strerror(-err));
375 }
376 }
377 }
378
379 if (timedOut || buffer.timedOut()) {
380 ALOGW("WorkerThreadSection '%s' timed out", this->name.string());
381 return NO_ERROR;
382 }
383
384 if (buffer.truncated()) {
385 // TODO: Log this into the incident report.
386 }
387
388 // TODO: There was an error with the command or buffering. Report that. For now
389 // just exit with a log messasge.
390 if (err != NO_ERROR) {
391 ALOGW("WorkerThreadSection '%s' failed with error '%s'", this->name.string(),
392 strerror(-err));
393 return NO_ERROR;
394 }
395
396 // Write the data that was collected
Yi Jinb44f7d42017-07-21 12:12:59 -0700397 ALOGD("WorkerThreadSection '%s' wrote %zd bytes in %d ms", name.string(), buffer.size(),
Joe Onorato1754d742016-11-21 17:51:35 -0800398 (int)buffer.durationMs());
Yi Jin99c248f2017-08-25 18:11:58 -0700399 err = WriteToReportRequests(this->id, buffer, requests);
Joe Onorato1754d742016-11-21 17:51:35 -0800400 if (err != NO_ERROR) {
401 ALOGW("WorkerThreadSection '%s' failed writing: '%s'", this->name.string(), strerror(-err));
402 return err;
403 }
404
405 return NO_ERROR;
406}
407
408// ================================================================================
Yi Jin99c248f2017-08-25 18:11:58 -0700409void
410CommandSection::init(const char* command, va_list args)
Yi Jinb44f7d42017-07-21 12:12:59 -0700411{
412 va_list copied_args;
Yi Jinb44f7d42017-07-21 12:12:59 -0700413 int numOfArgs = 0;
Yi Jin4ef28b72017-08-14 14:45:28 -0700414
415 va_copy(copied_args, args);
416 while(va_arg(copied_args, const char*) != NULL) {
Yi Jinb44f7d42017-07-21 12:12:59 -0700417 numOfArgs++;
418 }
Yi Jin4ef28b72017-08-14 14:45:28 -0700419 va_end(copied_args);
Yi Jinb44f7d42017-07-21 12:12:59 -0700420
421 // allocate extra 1 for command and 1 for NULL terminator
422 mCommand = (const char**)malloc(sizeof(const char*) * (numOfArgs + 2));
423
424 mCommand[0] = command;
425 name = command;
426 for (int i=0; i<numOfArgs; i++) {
Yi Jin4ef28b72017-08-14 14:45:28 -0700427 const char* arg = va_arg(args, const char*);
Yi Jinb44f7d42017-07-21 12:12:59 -0700428 mCommand[i+1] = arg;
429 name += " ";
430 name += arg;
431 }
432 mCommand[numOfArgs+1] = NULL;
Yi Jinb44f7d42017-07-21 12:12:59 -0700433}
434
435CommandSection::CommandSection(int id, const int64_t timeoutMs, const char* command, ...)
436 : Section(id, timeoutMs)
Joe Onorato1754d742016-11-21 17:51:35 -0800437{
438 va_list args;
Yi Jinb44f7d42017-07-21 12:12:59 -0700439 va_start(args, command);
440 init(command, args);
Joe Onorato1754d742016-11-21 17:51:35 -0800441 va_end(args);
Yi Jinb44f7d42017-07-21 12:12:59 -0700442}
Joe Onorato1754d742016-11-21 17:51:35 -0800443
Yi Jinb44f7d42017-07-21 12:12:59 -0700444CommandSection::CommandSection(int id, const char* command, ...)
445 : Section(id)
446{
447 va_list args;
448 va_start(args, command);
449 init(command, args);
Joe Onorato1754d742016-11-21 17:51:35 -0800450 va_end(args);
451}
452
453CommandSection::~CommandSection()
454{
Yi Jinb44f7d42017-07-21 12:12:59 -0700455 free(mCommand);
Joe Onorato1754d742016-11-21 17:51:35 -0800456}
457
458status_t
Yi Jinb44f7d42017-07-21 12:12:59 -0700459CommandSection::Execute(ReportRequestSet* requests) const
Joe Onorato1754d742016-11-21 17:51:35 -0800460{
Yi Jinb44f7d42017-07-21 12:12:59 -0700461 FdBuffer buffer;
462 Fpipe cmdPipe;
463 Fpipe ihPipe;
464
465 if (!cmdPipe.init() || !ihPipe.init()) {
466 ALOGW("CommandSection '%s' failed to setup pipes", this->name.string());
467 return -errno;
468 }
469
470 pid_t cmdPid = fork();
471 if (cmdPid == -1) {
472 ALOGW("CommandSection '%s' failed to fork", this->name.string());
473 return -errno;
474 }
475 // child process to execute the command as root
476 if (cmdPid == 0) {
477 // replace command's stdout with ihPipe's write Fd
478 if (dup2(cmdPipe.writeFd(), STDOUT_FILENO) != 1 || !ihPipe.close() || !cmdPipe.close()) {
479 ALOGW("CommandSection '%s' failed to set up stdout: %s", this->name.string(), strerror(errno));
480 _exit(EXIT_FAILURE);
481 }
482 execv(this->mCommand[0], (char *const *) this->mCommand);
483 int err = errno; // record command error code
484 ALOGW("CommandSection '%s' failed in executing command: %s", this->name.string(), strerror(errno));
485 _exit(err); // exit with command error code
486 }
487 pid_t ihPid = forkAndExecuteIncidentHelper(this->id, this->name.string(), cmdPipe, ihPipe);
488 if (ihPid == -1) {
489 ALOGW("CommandSection '%s' failed to fork", this->name.string());
490 return -errno;
491 }
492
493 close(cmdPipe.writeFd());
494 status_t readStatus = buffer.read(ihPipe.readFd(), this->timeoutMs);
495 if (readStatus != NO_ERROR || buffer.timedOut()) {
496 ALOGW("CommandSection '%s' failed to read data from incident helper: %s, "
497 "timedout: %s, kill command: %s, kill incident helper: %s",
498 this->name.string(), strerror(-readStatus), buffer.timedOut() ? "true" : "false",
499 strerror(-killChild(cmdPid)), strerror(-killChild(ihPid)));
500 return readStatus;
501 }
502
503 // TODO: wait for command here has one trade-off: the failed status of command won't be detected until
504 // buffer timeout, but it has advatage on starting the data stream earlier.
505 status_t cmdStatus = waitForChild(cmdPid);
506 status_t ihStatus = waitForChild(ihPid);
507 if (cmdStatus != NO_ERROR || ihStatus != NO_ERROR) {
Yi Jinadd11e92017-07-30 16:10:07 -0700508 ALOGW("CommandSection '%s' abnormal child processes, return status: command: %s, incident helper: %s",
Yi Jinb44f7d42017-07-21 12:12:59 -0700509 this->name.string(), strerror(-cmdStatus), strerror(-ihStatus));
510 return cmdStatus != NO_ERROR ? cmdStatus : ihStatus;
511 }
512
513 ALOGD("CommandSection '%s' wrote %zd bytes in %d ms", this->name.string(), buffer.size(),
514 (int)buffer.durationMs());
Yi Jin99c248f2017-08-25 18:11:58 -0700515 status_t err = WriteToReportRequests(this->id, buffer, requests);
Yi Jinb44f7d42017-07-21 12:12:59 -0700516 if (err != NO_ERROR) {
517 ALOGW("CommandSection '%s' failed writing: %s", this->name.string(), strerror(-err));
518 return err;
519 }
Joe Onorato1754d742016-11-21 17:51:35 -0800520 return NO_ERROR;
521}
522
523// ================================================================================
524DumpsysSection::DumpsysSection(int id, const char* service, ...)
525 :WorkerThreadSection(id),
526 mService(service)
527{
528 name = "dumpsys ";
529 name += service;
530
531 va_list args;
532 va_start(args, service);
533 while (true) {
Yi Jin0a3406f2017-06-22 19:23:11 -0700534 const char* arg = va_arg(args, const char*);
Joe Onorato1754d742016-11-21 17:51:35 -0800535 if (arg == NULL) {
536 break;
537 }
538 mArgs.add(String16(arg));
539 name += " ";
540 name += arg;
541 }
542 va_end(args);
543}
544
545DumpsysSection::~DumpsysSection()
546{
547}
548
549status_t
550DumpsysSection::BlockingCall(int pipeWriteFd) const
551{
552 // checkService won't wait for the service to show up like getService will.
553 sp<IBinder> service = defaultServiceManager()->checkService(mService);
Yi Jin0a3406f2017-06-22 19:23:11 -0700554
Joe Onorato1754d742016-11-21 17:51:35 -0800555 if (service == NULL) {
556 // Returning an error interrupts the entire incident report, so just
557 // log the failure.
558 // TODO: have a meta record inside the report that would log this
559 // failure inside the report, because the fact that we can't find
560 // the service is good data in and of itself. This is running in
561 // another thread so lock that carefully...
562 ALOGW("DumpsysSection: Can't lookup service: %s", String8(mService).string());
563 return NO_ERROR;
564 }
565
566 service->dump(pipeWriteFd, mArgs);
567
568 return NO_ERROR;
569}