summaryrefslogtreecommitdiff
path: root/cmds/incidentd
diff options
context:
space:
mode:
authorTreeHugger Robot <treehugger-gerrit@google.com>2018-09-19 00:48:42 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2018-09-19 00:48:42 +0000
commit027a559172ea9c81ea80dfecd5ccd761689f4bbe (patch)
treeac01ce92538680cec856741f6cfe42bb79be9256 /cmds/incidentd
parentbc0e47c0c5e79b31fc715093d1425dbf4586ca6a (diff)
parent5b763c13472effa7df25cc53a44d5bdae9392410 (diff)
Merge "Handling potential SIGPIPE signals."
Diffstat (limited to 'cmds/incidentd')
-rw-r--r--cmds/incidentd/src/Section.cpp28
1 files changed, 25 insertions, 3 deletions
diff --git a/cmds/incidentd/src/Section.cpp b/cmds/incidentd/src/Section.cpp
index 87799b38906c..cd48af95d08a 100644
--- a/cmds/incidentd/src/Section.cpp
+++ b/cmds/incidentd/src/Section.cpp
@@ -407,7 +407,19 @@ WorkerThreadSection::WorkerThreadSection(int id, const int64_t timeoutMs, bool u
WorkerThreadSection::~WorkerThreadSection() {}
+void sigpipe_handler(int signum) {
+ if (signum == SIGPIPE) {
+ ALOGE("Wrote to a broken pipe\n");
+ } else {
+ ALOGE("Received unexpected signal: %d\n", signum);
+ }
+}
+
static void* worker_thread_func(void* cookie) {
+ // Don't crash the service if we write to a closed pipe (which can happen if
+ // dumping times out).
+ signal(SIGPIPE, sigpipe_handler);
+
WorkerThreadData* data = (WorkerThreadData*)cookie;
status_t err = data->section->BlockingCall(data->pipe.writeFd().get());
@@ -486,6 +498,7 @@ status_t WorkerThreadSection::Execute(ReportRequestSet* requests) const {
}
}
}
+
write_section_stats(requests->sectionStats(this->id), buffer);
if (timedOut || buffer.timedOut()) {
ALOGW("[%s] timed out", this->name.string());
@@ -773,7 +786,10 @@ status_t LogSection::BlockingCall(int pipeWriteFd) const {
}
}
gLastLogsRetrieved[mLogID] = lastTimestamp;
- proto.flush(pipeWriteFd);
+ if (!proto.flush(pipeWriteFd) && errno == EPIPE) {
+ ALOGE("[%s] wrote to a broken pipe\n", this->name.string());
+ return EPIPE;
+ }
return NO_ERROR;
}
@@ -875,7 +891,7 @@ status_t TombstoneSection::BlockingCall(int pipeWriteFd) const {
break;
}
if (cStatus != NO_ERROR) {
- ALOGE("TombstoneSection '%s' child had an issue: %s\n", this->name.string(), strerror(-cStatus));
+ ALOGE("[%s] child had an issue: %s\n", this->name.string(), strerror(-cStatus));
}
auto dump = std::make_unique<char[]>(buffer.size());
@@ -894,7 +910,13 @@ status_t TombstoneSection::BlockingCall(int pipeWriteFd) const {
dumpPipe.readFd().reset();
}
- proto.flush(pipeWriteFd);
+ if (!proto.flush(pipeWriteFd) && errno == EPIPE) {
+ ALOGE("[%s] wrote to a broken pipe\n", this->name.string());
+ if (err != NO_ERROR) {
+ return EPIPE;
+ }
+ }
+
return err;
}