From 2862a7843dbec433c78febaed5c4c6c64500078b Mon Sep 17 00:00:00 2001 From: Todd Poynor Date: Tue, 8 Dec 2015 18:14:44 -0800 Subject: [PATCH] metricsd binder: Abort if fail to register service Assert abort metricsd if binder service registration fails. If the addService() call fails (for reasons that at least include an SELinux policy denial), the call to joinThreadPool() apparently processes a stale pending weak dereference that triggers an abort on a probable double-free: F libc : Invalid address 0xbe8bfa30 passed to free: value not allocated F libc : Fatal signal 6 (SIGABRT), code -6 in tid 609 (metricsd) Since metricsd is severely hobbled if registration fails, abort and see if things work better the next time. If not, the crash loop will hopefully attract attention to the problem. Change-Id: I520d0eafb9cb25ee225d589bfd87df4e51f6b181 --- metricsd/uploader/bn_metricsd_impl.cc | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/metricsd/uploader/bn_metricsd_impl.cc b/metricsd/uploader/bn_metricsd_impl.cc index 113a705c7..2cbc2dae7 100644 --- a/metricsd/uploader/bn_metricsd_impl.cc +++ b/metricsd/uploader/bn_metricsd_impl.cc @@ -21,6 +21,7 @@ #include #include #include +#include #include #include @@ -33,11 +34,14 @@ static const char16_t kCrashTypeUser[] = u"user"; BnMetricsdImpl::BnMetricsdImpl(const std::shared_ptr& counters) : counters_(counters) { - CHECK(counters_); + CHECK(counters_) << "Invalid counters argument to constructor"; } void BnMetricsdImpl::Run() { - android::defaultServiceManager()->addService(getInterfaceDescriptor(), this); + android::status_t status = + android::defaultServiceManager()->addService(getInterfaceDescriptor(), + this); + CHECK(status == android::OK) << "Metricsd service registration failed"; android::ProcessState::self()->setThreadPoolMaxThreadCount(0); android::IPCThreadState::self()->disableBackgroundScheduling(true); android::IPCThreadState::self()->joinThreadPool();