libbinder: report binder error in abort message
This bug has been eluding me for years. It's so rare,
you never see the logcat. I only see the crash stacks.
I'm going to guess it's FD exhaustion causing this?
But we'll see...
Bug: 197637414
Test: boot
Change-Id: I78533a8de7cfb5edb7226cd6cfeac5b8aa6ffdf0
diff --git a/libs/binder/ProcessState.cpp b/libs/binder/ProcessState.cpp
index fb2781b..8485ecd 100644
--- a/libs/binder/ProcessState.cpp
+++ b/libs/binder/ProcessState.cpp
@@ -516,22 +516,23 @@
return mDriverName;
}
-static unique_fd open_driver(const char* driver) {
+static unique_fd open_driver(const char* driver, String8* error) {
auto fd = unique_fd(open(driver, O_RDWR | O_CLOEXEC));
if (!fd.ok()) {
- PLOGE("Opening '%s' failed", driver);
+ error->appendFormat("%d (%s) Opening '%s' failed", errno, strerror(errno), driver);
return {};
}
int vers = 0;
int result = ioctl(fd.get(), BINDER_VERSION, &vers);
if (result == -1) {
- PLOGE("Binder ioctl to obtain version failed");
+ error->appendFormat("%d (%s) Binder ioctl to obtain version failed", errno,
+ strerror(errno));
return {};
}
if (result != 0 || vers != BINDER_CURRENT_PROTOCOL_VERSION) {
- ALOGE("Binder driver protocol(%d) does not match user space protocol(%d)! "
- "ioctl() return value: %d",
- vers, BINDER_CURRENT_PROTOCOL_VERSION, result);
+ error->appendFormat("Binder driver protocol(%d) does not match user space protocol(%d)! "
+ "ioctl() return value: %d",
+ vers, BINDER_CURRENT_PROTOCOL_VERSION, result);
return {};
}
size_t maxThreads = DEFAULT_MAX_BINDER_THREADS;
@@ -565,7 +566,8 @@
mThreadPoolStarted(false),
mThreadPoolSeq(1),
mCallRestriction(CallRestriction::NONE) {
- unique_fd opened = open_driver(driver);
+ String8 error;
+ unique_fd opened = open_driver(driver, &error);
if (opened.ok()) {
// mmap the binder, providing a chunk of virtual address space to receive transactions.
@@ -580,8 +582,9 @@
}
#ifdef __ANDROID__
- LOG_ALWAYS_FATAL_IF(!opened.ok(), "Binder driver '%s' could not be opened. Terminating.",
- driver);
+ LOG_ALWAYS_FATAL_IF(!opened.ok(),
+ "Binder driver '%s' could not be opened. Error: %s. Terminating.",
+ error.c_str(), driver);
#endif
if (opened.ok()) {